From 59fd219365a139d620e0efd9bac7436c2b6892c7 Mon Sep 17 00:00:00 2001 From: Vaidotas Valuckas Date: Thu, 6 May 2021 12:38:45 +0300 Subject: [PATCH] Update unit and TAPI tests to avoid deprecated method calls Spiking removal of deprecated SourceDirectorySet methods relvealed that the changed tests were depending on this method. This change updates the tests to not use deprecated to-be-removed methods when replacement is available. --- .../gradle/api/plugins/JavaBasePluginTest.groovy | 2 +- .../integtests/tooling/TestLauncherSpec.groovy | 14 +++++++++++++- .../r26/TestLauncherCrossVersionSpec.groovy | 3 ++- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/subprojects/plugins/src/test/groovy/org/gradle/api/plugins/JavaBasePluginTest.groovy b/subprojects/plugins/src/test/groovy/org/gradle/api/plugins/JavaBasePluginTest.groovy index 5012e9a16b36..ae36a46ac51a 100644 --- a/subprojects/plugins/src/test/groovy/org/gradle/api/plugins/JavaBasePluginTest.groovy +++ b/subprojects/plugins/src/test/groovy/org/gradle/api/plugins/JavaBasePluginTest.groovy @@ -286,7 +286,7 @@ class JavaBasePluginTest extends AbstractProjectBuilderSpec { when: project.pluginManager.apply(JavaBasePlugin) project.sourceSets.create('custom') - project.sourceSets.custom.java.outputDir = classesDir + project.sourceSets.custom.java.destinationDirectory.set(classesDir) project.sourceSets.custom.output.resourcesDir = resourcesDir then: diff --git a/subprojects/tooling-api/src/crossVersionTest/groovy/org/gradle/integtests/tooling/TestLauncherSpec.groovy b/subprojects/tooling-api/src/crossVersionTest/groovy/org/gradle/integtests/tooling/TestLauncherSpec.groovy index 1ec74c4e80ec..e7f56f858981 100644 --- a/subprojects/tooling-api/src/crossVersionTest/groovy/org/gradle/integtests/tooling/TestLauncherSpec.groovy +++ b/subprojects/tooling-api/src/crossVersionTest/groovy/org/gradle/integtests/tooling/TestLauncherSpec.groovy @@ -171,11 +171,12 @@ abstract class TestLauncherSpec extends ToolingApiSpecification implements WithO settingsFile << "rootProject.name = 'testproject'\n" buildFile.text = simpleJavaProject() + def classesDir = 'file("build/classes/moreTests")' buildFile << """ sourceSets { moreTests { java.srcDir "src/test" - ${separateClassesDirs(targetVersion) ? "java.outputDir" : "output.classesDir"} = file("build/classes/moreTests") + ${destinationDirectoryCode(classesDir)} compileClasspath = compileClasspath + sourceSets.test.compileClasspath runtimeClasspath = runtimeClasspath + sourceSets.test.runtimeClasspath } @@ -226,6 +227,17 @@ abstract class TestLauncherSpec extends ToolingApiSpecification implements WithO version.baseVersion >= GradleVersion.version("4.0") } + String destinationDirectoryCode(String destinationDirectory) { + //${separateClassesDirs(targetVersion) ? "java.outputDir" : "output.classesDir"} = file("build/classes/moreTests") + if (!separateClassesDirs(targetVersion)) { + return "output.classesDir = $destinationDirectory" + } + if (targetVersion.baseVersion < GradleVersion.version("6.1")) { + return "java.outputDir = $destinationDirectory" + } + return "java.destinationDirectory.set($destinationDirectory)" + } + def changeTestSource() { // adding two more test methods file("src/test/java/example/MyTest.java").text = """ diff --git a/subprojects/tooling-api/src/crossVersionTest/groovy/org/gradle/integtests/tooling/r26/TestLauncherCrossVersionSpec.groovy b/subprojects/tooling-api/src/crossVersionTest/groovy/org/gradle/integtests/tooling/r26/TestLauncherCrossVersionSpec.groovy index 55f879f38235..0f69ea29ae77 100644 --- a/subprojects/tooling-api/src/crossVersionTest/groovy/org/gradle/integtests/tooling/r26/TestLauncherCrossVersionSpec.groovy +++ b/subprojects/tooling-api/src/crossVersionTest/groovy/org/gradle/integtests/tooling/r26/TestLauncherCrossVersionSpec.groovy @@ -450,11 +450,12 @@ class TestLauncherCrossVersionSpec extends TestLauncherSpec { settingsFile << "rootProject.name = 'testproject'\n" buildFile.text = simpleJavaProject() + def classesDir = 'file("build/classes/moreTests")' buildFile << """ sourceSets { moreTests { java.srcDir "src/test" - ${separateClassesDirs(targetVersion) ? "java.outputDir" : "output.classesDir"} = file("build/classes/moreTests") + ${destinationDirectoryCode(classesDir)} compileClasspath = compileClasspath + sourceSets.test.compileClasspath runtimeClasspath = runtimeClasspath + sourceSets.test.runtimeClasspath }