forked from n0mer/gradle-git-properties
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make plugin work during configuration phase again
The changes in n0mer#164 to support the Gradle configuration cache broke using the plugin during configuration phase of Gradle (e. g. as part of a custom plugin via `buildSrc` and similar use cases). Fixes n0mer#169
- Loading branch information
Showing
4 changed files
with
165 additions
and
41 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
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
135 changes: 135 additions & 0 deletions
135
src/test/groovy/com/gorylenko/BuildSrcFunctionalTest.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,135 @@ | ||
package com.gorylenko | ||
|
||
import com.gorylenko.properties.GitRepositoryBuilder | ||
import org.gradle.testkit.runner.GradleRunner | ||
import org.gradle.testkit.runner.TaskOutcome | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.junit.rules.TemporaryFolder | ||
|
||
import static org.junit.Assert.assertEquals | ||
import static org.junit.Assert.assertTrue | ||
|
||
public class BuildSrcFunctionalTest { | ||
@Rule | ||
public final TemporaryFolder temporaryFolder = new TemporaryFolder() | ||
|
||
@Test | ||
public void testPluginSucceedsDuringConfigurationPhase() { | ||
def projectDir = temporaryFolder.newFolder() | ||
def runner = GradleRunner.create() | ||
.withPluginClasspath() | ||
.withArguments("check") | ||
.withProjectDir(projectDir) | ||
|
||
def classpathString = runner.pluginClasspath | ||
.collect { "'$it'" } | ||
.join(", ") | ||
|
||
def buildSrcDir = new File(projectDir, "buildSrc") | ||
buildSrcDir.mkdirs() | ||
new File(buildSrcDir, "build.gradle") << """\ | ||
plugins { | ||
id("groovy-gradle-plugin") | ||
} | ||
repositories { | ||
gradlePluginPortal() | ||
} | ||
dependencies { | ||
runtimeClasspath files($classpathString) | ||
} | ||
""" | ||
def pluginSourceDir = buildSrcDir.toPath().resolve("src").resolve("main").resolve("groovy").toFile() | ||
pluginSourceDir.mkdirs() | ||
new File(pluginSourceDir, "test-plugin.gradle") << """\ | ||
plugins { | ||
id("java") | ||
id("com.gorylenko.gradle-git-properties") | ||
} | ||
""" | ||
new File(projectDir, "settings.gradle") << """\ | ||
pluginManagement { | ||
plugins { | ||
id("com.gorylenko.gradle-git-properties") | ||
} | ||
} | ||
""".stripIndent() | ||
new File(projectDir, "build.gradle") << """\ | ||
plugins { | ||
id("test-plugin") | ||
} | ||
""".stripIndent() | ||
|
||
GitRepositoryBuilder.setupProjectDir(projectDir, { gitRepoBuilder -> | ||
// commit 1 new file "hello.txt" | ||
gitRepoBuilder.commitFile("hello.txt", "Hello", "Added hello.txt") | ||
}) | ||
|
||
def result = runner.build() | ||
|
||
assertEquals(TaskOutcome.SUCCESS, result.task(":generateGitProperties").outcome) | ||
} | ||
|
||
@Test | ||
public void testPluginCanOverrideGitPropertiesResourceDir() { | ||
def projectDir = temporaryFolder.newFolder() | ||
def runner = GradleRunner.create() | ||
.withPluginClasspath() | ||
.withArguments("check") | ||
.withProjectDir(projectDir) | ||
|
||
def classpathString = runner.pluginClasspath | ||
.collect { "'$it'" } | ||
.join(", ") | ||
|
||
def buildSrcDir = new File(projectDir, "buildSrc") | ||
buildSrcDir.mkdirs() | ||
def gitPropDir = new File(projectDir, "gitProp") | ||
gitPropDir.mkdirs() | ||
new File(buildSrcDir, "build.gradle") << """\ | ||
plugins { | ||
id("groovy-gradle-plugin") | ||
} | ||
repositories { | ||
gradlePluginPortal() | ||
} | ||
dependencies { | ||
runtimeClasspath files($classpathString) | ||
} | ||
""" | ||
def pluginSourceDir = buildSrcDir.toPath().resolve("src").resolve("main").resolve("groovy").toFile() | ||
pluginSourceDir.mkdirs() | ||
new File(pluginSourceDir, "test-plugin.gradle") << """\ | ||
plugins { | ||
id("java") | ||
id("com.gorylenko.gradle-git-properties") | ||
} | ||
""" | ||
new File(projectDir, "settings.gradle") << """\ | ||
pluginManagement { | ||
plugins { | ||
id("com.gorylenko.gradle-git-properties") | ||
} | ||
} | ||
""".stripIndent() | ||
new File(projectDir, "build.gradle") << """\ | ||
plugins { | ||
id("test-plugin") | ||
} | ||
gitProperties { | ||
gitPropertiesResourceDir = layout.projectDirectory.dir("gitProp") | ||
} | ||
""".stripIndent() | ||
|
||
GitRepositoryBuilder.setupProjectDir(projectDir, { gitRepoBuilder -> | ||
// commit 1 new file "hello.txt" | ||
gitRepoBuilder.commitFile("hello.txt", "Hello", "Added hello.txt") | ||
}) | ||
|
||
def result = runner.build() | ||
|
||
assertEquals(TaskOutcome.SUCCESS, result.task(":generateGitProperties").outcome) | ||
assertTrue(gitPropDir.list().contains("git.properties")) | ||
} | ||
} |