-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The org.ajoberstar.grgit-service is the new underlying behavior for org.ajoberstar.grgit, building on the work from @runningcode and @abelom. The service plugin only registers a GrgitService, but leaves it up to plugins (or builds) to grab the service and try to use it. Alternatively, the existing grgit plugin applies the service plugin and eagerly resolves it to provide the prior grgit extension property. A breaking change is that any project which wants to access a pre-initialized grgit instance now must apply the grgit plugin. This reduces the amount of cross-project logic going on, which Gradle has discouraged for a while (but can be hard to avoid). Some plugins may have use cases to register their own GrgitService instances that are used for their own behavior (the gradle-git-publish plugin will take advantage of this once it upgrades to use grgit 5). All projects using grgit-service plugin will share a Grgit instance, which is also controlled to avoid concurrent access. (That doesn't affect other plugins/builds registering their own GrgitService instances).
- Loading branch information
1 parent
1982af3
commit 2aba52c
Showing
13 changed files
with
315 additions
and
220 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 0 additions & 101 deletions
101
grgit-gradle/src/compatTest/groovy/org/ajoberstar/grgit/gradle/ConfigCacheTest.groovy
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
...dle/src/compatTest/groovy/org/ajoberstar/grgit/gradle/GrgitServicePluginCompatTest.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
package org.ajoberstar.grgit.gradle | ||
|
||
import spock.lang.Specification | ||
|
||
import org.ajoberstar.grgit.Grgit | ||
import org.gradle.testkit.runner.GradleRunner | ||
import org.gradle.testkit.runner.BuildResult | ||
import org.gradle.testkit.runner.TaskOutcome | ||
import spock.lang.TempDir | ||
|
||
class GrgitServicePluginCompatTest extends Specification { | ||
@TempDir File tempDir | ||
File projectDir | ||
File buildFile | ||
|
||
def setup() { | ||
projectDir = new File(tempDir, 'project') | ||
buildFile = projectFile('build.gradle') | ||
buildFile << '''\ | ||
import org.ajoberstar.grgit.gradle.GrgitService | ||
plugins { | ||
id 'org.ajoberstar.grgit-service' | ||
} | ||
tasks.register("doStuff", DoStuffTask.class) { | ||
service = grgitService.service | ||
} | ||
class DoStuffTask extends DefaultTask { | ||
@Input | ||
final Property<GrgitService> service | ||
@Inject | ||
DoStuffTask(ObjectFactory objectFactory) { | ||
this.service = objectFactory.property(GrgitService.class); | ||
} | ||
@TaskAction | ||
void execute() { | ||
println service.get().grgit.describe() | ||
} | ||
} | ||
''' | ||
} | ||
|
||
def 'with no repo, accessing service fails'() { | ||
given: | ||
// nothing | ||
when: | ||
def result = buildAndFail('doStuff', '--configuration-cache') | ||
then: | ||
result.task(':doStuff').outcome == TaskOutcome.FAILED | ||
} | ||
|
||
def 'with repo, plugin opens the repo as grgit'() { | ||
given: | ||
Grgit git = Grgit.init(dir: projectDir) | ||
projectFile('1.txt') << '1' | ||
git.add(patterns: ['1.txt']) | ||
git.commit(message: 'yay') | ||
git.tag.add(name: '1.0.0') | ||
when: | ||
def result = build('doStuff', '--quiet', '--configuration-cache') | ||
then: | ||
result.task(':doStuff').outcome == TaskOutcome.SUCCESS | ||
result.output.normalize() == '1.0.0\n' | ||
} | ||
|
||
def 'with repo, plugin closes the repo after build is finished'() { | ||
given: | ||
Grgit git = Grgit.init(dir: projectDir) | ||
projectFile('1.txt') << '1' | ||
git.add(patterns: ['1.txt']) | ||
git.commit(message: 'yay') | ||
git.tag.add(name: '1.0.0') | ||
when: | ||
def result = build('doStuff', '--info', '--configuration-cache') | ||
then: | ||
result.task(':doStuff').outcome == TaskOutcome.SUCCESS | ||
result.output.contains('Closing Git repo') | ||
} | ||
|
||
private BuildResult build(String... args) { | ||
return GradleRunner.create() | ||
.withGradleVersion(System.properties['compat.gradle.version']) | ||
.withPluginClasspath() | ||
.withProjectDir(projectDir) | ||
.forwardOutput() | ||
.withArguments((args + '--stacktrace') as String[]) | ||
.build() | ||
} | ||
|
||
private BuildResult buildAndFail(String... args) { | ||
return GradleRunner.create() | ||
.withGradleVersion(System.properties['compat.gradle.version']) | ||
.withPluginClasspath() | ||
.withProjectDir(projectDir) | ||
.forwardOutput() | ||
.withArguments((args + '--stacktrace') as String[]) | ||
.buildAndFail() | ||
} | ||
|
||
private File projectFile(String path) { | ||
File file = new File(projectDir, path) | ||
file.parentFile.mkdirs() | ||
return file | ||
} | ||
} |
41 changes: 0 additions & 41 deletions
41
grgit-gradle/src/main/groovy/org/ajoberstar/grgit/gradle/GrgitBuildService.groovy
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.