Skip to content

Commit

Permalink
Workaround for a bug in 6.1.x
Browse files Browse the repository at this point in the history
The bug (#11971) makes the build under test, called by the TAPI,
fail because the working directory is the working directory of
Gradle itself. This causes the test to try to read the verification
metadata file of Gradle itself, which exists, instead of not finding
any verification file like it should, because the build under test
doesn't have any.

The workaround is to change the working directory from the build
under test.
  • Loading branch information
melix committed Jan 24, 2020
1 parent ad9a050 commit 3fea044
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 2 additions & 0 deletions gradle/verification-metadata.xml
Expand Up @@ -7,6 +7,8 @@
<verify-signatures>true</verify-signatures>
<trusted-artifacts>
<trust group="gradle" name="gradle"/>
<!-- TAPI tests use a generated version of the Tooling API -->
<trust group="org[.]gradle$" name="gradle-tooling-api$" version=".*[0-9]+[+]0000" regex="true"/>
<trust group="net[.]rubygrapefruit" name="native-platform.*" version=".*snapshot.*" regex="true"/>
<trust file=".*-javadoc[.]jar" regex="true"/>
<trust file=".*-sources[.]jar" regex="true"/>
Expand Down
Expand Up @@ -25,6 +25,7 @@ import org.gradle.test.fixtures.file.LeaksFileHandles
import org.gradle.test.fixtures.file.TestFile
import org.gradle.tooling.model.kotlin.dsl.KotlinDslScriptModel
import org.gradle.tooling.model.kotlin.dsl.KotlinDslScriptsModel
import org.gradle.util.TextUtil

import java.lang.reflect.Proxy

Expand All @@ -33,10 +34,22 @@ import static org.hamcrest.CoreMatchers.containsString
import static org.hamcrest.CoreMatchers.hasItem
import static org.junit.Assert.assertThat


@TargetGradleVersion(">=6.0")
@LeaksFileHandles("Kotlin Compiler Daemon taking time to shut down")
class KotlinDslScriptsModelCrossVersionSpec extends AbstractKotlinScriptModelCrossVersionTest {
String currentWorkingDir

def setup() {
// we change the working directory because of a bug in 6.1.x where the verification
// file is fetched from the working directory instead of the project directory,
// which causes the verification file of Gradle itself being used to verify the build
// under test
currentWorkingDir = System.getProperty("user.dir")
}

def cleanup() {
System.setProperty("user.dir", currentWorkingDir)
}

def "can fetch model for the scripts of a build"() {

Expand All @@ -51,6 +64,7 @@ class KotlinDslScriptsModelCrossVersionSpec extends AbstractKotlinScriptModelCro

and:
assertModelMatchesBuildSpec(model, spec)

}

def "can fetch model for the scripts of a build in lenient mode"() {
Expand Down Expand Up @@ -222,6 +236,13 @@ class KotlinDslScriptsModelCrossVersionSpec extends AbstractKotlinScriptModelCro
def bJar = withEmptyJar("classes_b.jar")
def precompiledJar = withEmptyJar("classes_b_precompiled.jar")

def patchBuild = ""
def baseVersion = targetDist.version.baseVersion.version
if (baseVersion in ["6.1", "6.1.1"]) {
// see comment on top of the test class, changing working directory
patchBuild = """System.setProperty("user.dir", "${TextUtil.escapeString(temporaryFolder.testDirectory.absolutePath)}")"""
}

def some = withFile("some.gradle.kts", """
buildscript {
dependencies {
Expand All @@ -235,6 +256,7 @@ class KotlinDslScriptsModelCrossVersionSpec extends AbstractKotlinScriptModelCro
classpath(files("${escapeString(settingsJar)}"))
}
}
$patchBuild
apply(from = "some.gradle.kts")
include("a", "b")
""")
Expand Down

0 comments on commit 3fea044

Please sign in to comment.