From fa1276eff589c4e6580614f7bba204d81cee0982 Mon Sep 17 00:00:00 2001 From: Roberto Perez Alcolea Date: Mon, 30 Oct 2023 14:51:24 -0700 Subject: [PATCH] Add configuration cache to integration tests where possible --- .../plugin/info/GitSetupLauncherSpec.groovy | 2 + .../plugin/info/BaseIntegrationSpec.groovy | 10 +++ .../info/BaseIntegrationTestKitSpec.groovy | 10 +++ .../InfoBrokerPluginIntegrationSpec.groovy | 4 +- .../InfoPluginConfigurationCacheSpec.groovy | 25 ------- .../info/InfoPluginIntegrationSpec.groovy | 7 +- .../InfoPluginIntegrationTestKitSpec.groovy | 71 +++++++------------ ...ContinuousIntegrationInfoPluginSpec.groovy | 3 +- .../InfoJarManifestPluginLauncherSpec.groovy | 3 +- ...nfoPropertiesFilePluginLauncherSpec.groovy | 3 +- 10 files changed, 60 insertions(+), 78 deletions(-) create mode 100644 src/test/groovy/nebula/plugin/info/BaseIntegrationSpec.groovy create mode 100644 src/test/groovy/nebula/plugin/info/BaseIntegrationTestKitSpec.groovy delete mode 100644 src/test/groovy/nebula/plugin/info/InfoPluginConfigurationCacheSpec.groovy diff --git a/src/integTest/groovy/nebula/plugin/info/GitSetupLauncherSpec.groovy b/src/integTest/groovy/nebula/plugin/info/GitSetupLauncherSpec.groovy index 25132447..598265d5 100644 --- a/src/integTest/groovy/nebula/plugin/info/GitSetupLauncherSpec.groovy +++ b/src/integTest/groovy/nebula/plugin/info/GitSetupLauncherSpec.groovy @@ -39,6 +39,8 @@ abstract class GitSetupLauncherSpec extends IntegrationSpec { '''.stripIndent() initializeBuildGradleSettingsGradle() + // Enable configuration cache :) + new File(projectDir, 'gradle.properties') << '''org.gradle.configuration-cache=true'''.stripIndent() git.add(patterns: ['build.gradle', 'settings.gradle', '.gitignore']) git.commit(message: 'Setup') diff --git a/src/test/groovy/nebula/plugin/info/BaseIntegrationSpec.groovy b/src/test/groovy/nebula/plugin/info/BaseIntegrationSpec.groovy new file mode 100644 index 00000000..d3c51bfd --- /dev/null +++ b/src/test/groovy/nebula/plugin/info/BaseIntegrationSpec.groovy @@ -0,0 +1,10 @@ +package nebula.plugin.info + +import nebula.test.IntegrationSpec + +abstract class BaseIntegrationSpec extends IntegrationSpec { + def setup() { + // Enable configuration cache :) + new File(projectDir, 'gradle.properties') << '''org.gradle.configuration-cache=true'''.stripIndent() + } +} diff --git a/src/test/groovy/nebula/plugin/info/BaseIntegrationTestKitSpec.groovy b/src/test/groovy/nebula/plugin/info/BaseIntegrationTestKitSpec.groovy new file mode 100644 index 00000000..a9fdfe3d --- /dev/null +++ b/src/test/groovy/nebula/plugin/info/BaseIntegrationTestKitSpec.groovy @@ -0,0 +1,10 @@ +package nebula.plugin.info + +import nebula.test.IntegrationTestKitSpec + +abstract class BaseIntegrationTestKitSpec extends IntegrationTestKitSpec { + def setup() { + // Enable configuration cache :) + new File(projectDir, 'gradle.properties') << '''org.gradle.configuration-cache=true'''.stripIndent() + } +} diff --git a/src/test/groovy/nebula/plugin/info/InfoBrokerPluginIntegrationSpec.groovy b/src/test/groovy/nebula/plugin/info/InfoBrokerPluginIntegrationSpec.groovy index 53507651..abf5adfa 100644 --- a/src/test/groovy/nebula/plugin/info/InfoBrokerPluginIntegrationSpec.groovy +++ b/src/test/groovy/nebula/plugin/info/InfoBrokerPluginIntegrationSpec.groovy @@ -16,10 +16,9 @@ package nebula.plugin.info -import nebula.test.IntegrationSpec import nebula.test.functional.ExecutionResult -class InfoBrokerPluginIntegrationSpec extends IntegrationSpec { +class InfoBrokerPluginIntegrationSpec extends BaseIntegrationSpec { def 'it returns build reports at the end of the build'() { given: @@ -40,6 +39,7 @@ class InfoBrokerPluginIntegrationSpec extends IntegrationSpec { } """.stripIndent() + new File(projectDir, 'gradle.properties').text = '''org.gradle.configuration-cache=false'''.stripIndent() when: ExecutionResult result = runTasksSuccessfully('createReport') diff --git a/src/test/groovy/nebula/plugin/info/InfoPluginConfigurationCacheSpec.groovy b/src/test/groovy/nebula/plugin/info/InfoPluginConfigurationCacheSpec.groovy deleted file mode 100644 index 33a5e263..00000000 --- a/src/test/groovy/nebula/plugin/info/InfoPluginConfigurationCacheSpec.groovy +++ /dev/null @@ -1,25 +0,0 @@ -package nebula.plugin.info - -import nebula.test.IntegrationTestKitSpec - -class InfoPluginConfigurationCacheSpec extends IntegrationTestKitSpec { - - def 'plugin applies with configuration cache'() { - buildFile << """ - plugins { - id 'com.netflix.nebula.info' - id 'java' - } - """ - writeHelloWorld('nebula.app') - - - when: - runTasks('--configuration-cache', 'jar', '-s') - def result = runTasks('--configuration-cache', 'jar', '-s') - - then: - result.output.contains('Reusing configuration cache') - } - -} diff --git a/src/test/groovy/nebula/plugin/info/InfoPluginIntegrationSpec.groovy b/src/test/groovy/nebula/plugin/info/InfoPluginIntegrationSpec.groovy index cd9d1756..88e008ea 100644 --- a/src/test/groovy/nebula/plugin/info/InfoPluginIntegrationSpec.groovy +++ b/src/test/groovy/nebula/plugin/info/InfoPluginIntegrationSpec.groovy @@ -15,10 +15,9 @@ */ package nebula.plugin.info -import nebula.test.IntegrationSpec import nebula.test.functional.ExecutionResult -class InfoPluginIntegrationSpec extends IntegrationSpec { +class InfoPluginIntegrationSpec extends BaseIntegrationSpec { def 'it returns build reports at the end of the build'() { given: buildFile << """ @@ -49,6 +48,7 @@ class InfoPluginIntegrationSpec extends IntegrationSpec { rootProject.name='buildscript-singlemodule-test' """ this.writeHelloWorld('com.nebula.test') + new File(projectDir, 'gradle.properties').text = '''org.gradle.configuration-cache=false'''.stripIndent() when: ExecutionResult result = runTasksSuccessfully('assemble') @@ -88,6 +88,7 @@ class InfoPluginIntegrationSpec extends IntegrationSpec { } '''.stripIndent()) writeHelloWorld('nebula.app', app) + new File(projectDir, 'gradle.properties').text = '''org.gradle.configuration-cache=false'''.stripIndent() when: ExecutionResult result = runTasksSuccessfully('build') @@ -130,6 +131,8 @@ class InfoPluginIntegrationSpec extends IntegrationSpec { rootProject.name='test-jenkins-jpi' """ writeHelloWorld('com.nebula.test') + // JPI plugin might not be configuration cache compatible yet + new File(projectDir, 'gradle.properties').text = '''org.gradle.configuration-cache=false'''.stripIndent() when: ExecutionResult result = runTasksSuccessfully('assemble') diff --git a/src/test/groovy/nebula/plugin/info/InfoPluginIntegrationTestKitSpec.groovy b/src/test/groovy/nebula/plugin/info/InfoPluginIntegrationTestKitSpec.groovy index c7ba91f8..f2e57210 100644 --- a/src/test/groovy/nebula/plugin/info/InfoPluginIntegrationTestKitSpec.groovy +++ b/src/test/groovy/nebula/plugin/info/InfoPluginIntegrationTestKitSpec.groovy @@ -15,9 +15,7 @@ */ package nebula.plugin.info -import nebula.test.IntegrationTestKitSpec - -class InfoPluginIntegrationTestKitSpec extends IntegrationTestKitSpec { +class InfoPluginIntegrationTestKitSpec extends BaseIntegrationTestKitSpec { def 'it returns manifest reports at the end of the build - toolchains'() { given: buildFile << """ @@ -45,11 +43,7 @@ class InfoPluginIntegrationTestKitSpec extends IntegrationTestKitSpec { dependencies { implementation 'com.google.guava:guava:18.0' } - def broker = project.plugins.getPlugin(${InfoBrokerPlugin.name}) - gradle.buildFinished { - println broker.buildManifest() - } """.stripIndent() settingsFile << """ @@ -58,11 +52,11 @@ class InfoPluginIntegrationTestKitSpec extends IntegrationTestKitSpec { this.writeHelloWorld('com.nebula.test') when: - def result = runTasks('assemble') + def result = runTasks('assemble', 'writeManifestProperties') then: - println result.output - result.output.contains('Build-Java-Version=17') + def manifest = new File(projectDir, 'build/manifest/buildscript-singlemodule-test.properties') + manifest.text.contains('Build-Java-Version=17') } def 'reports proper jdk version when configuring toolchain in compile task'() { @@ -99,11 +93,6 @@ class InfoPluginIntegrationTestKitSpec extends IntegrationTestKitSpec { dependencies { implementation 'com.google.guava:guava:18.0' } - def broker = project.plugins.getPlugin(${InfoBrokerPlugin.name}) - - gradle.buildFinished { - println broker.buildManifest() - } """.stripIndent() settingsFile << """ @@ -112,12 +101,13 @@ class InfoPluginIntegrationTestKitSpec extends IntegrationTestKitSpec { this.writeHelloWorld('com.nebula.test') when: - def result = runTasks('assemble') + def result = runTasks('assemble', 'writeManifestProperties') then: - result.output.contains('Build-Java-Version=17') - assert result.output.contains('X-Compile-Target-JDK=8') || result.output.contains('X-Compile-Target-JDK=1.8') - assert result.output.contains('X-Compile-Source-JDK=8') || result.output.contains('X-Compile-Target-JDK=1.8') + def manifest = new File(projectDir, 'build/manifest/buildscript-singlemodule-test.properties') + manifest.text.contains('Build-Java-Version=17') + assert manifest.text.contains('X-Compile-Target-JDK=8') || manifest.text.contains('X-Compile-Target-JDK=1.8') + assert manifest.text.contains('X-Compile-Source-JDK=8') || manifest.text.contains('X-Compile-Target-JDK=1.8') } def 'reports proper jdk version when configuring target/source compatibility in compile task + toolchains'() { @@ -155,11 +145,7 @@ class InfoPluginIntegrationTestKitSpec extends IntegrationTestKitSpec { dependencies { implementation 'com.google.guava:guava:18.0' } - def broker = project.plugins.getPlugin(${InfoBrokerPlugin.name}) - - gradle.buildFinished { - println broker.buildManifest() - } + """.stripIndent() settingsFile << """ @@ -168,12 +154,13 @@ class InfoPluginIntegrationTestKitSpec extends IntegrationTestKitSpec { this.writeHelloWorld('com.nebula.test') when: - def result = runTasks('assemble') + def result = runTasks('assemble', 'writeManifestProperties') then: - result.output.contains('Build-Java-Version=17') - result.output.contains('X-Compile-Target-JDK=1.8') - result.output.contains('X-Compile-Source-JDK=1.8') + def manifest = new File(projectDir, 'build/manifest/buildscript-singlemodule-test.properties') + manifest.text.contains('Build-Java-Version=17') + manifest.text.contains('X-Compile-Target-JDK=1.8') + manifest.text.contains('X-Compile-Source-JDK=1.8') } def 'reports proper jdk version when configuring target/source compatibility in compile task + toolchains (multi language)'() { @@ -215,11 +202,6 @@ class InfoPluginIntegrationTestKitSpec extends IntegrationTestKitSpec { dependencies { implementation 'com.google.guava:guava:18.0' } - def broker = project.plugins.getPlugin(${InfoBrokerPlugin.name}) - - gradle.buildFinished { - println broker.buildManifest() - } """.stripIndent() settingsFile << """ @@ -228,12 +210,13 @@ class InfoPluginIntegrationTestKitSpec extends IntegrationTestKitSpec { this.writeHelloWorld('com.nebula.test') when: - def result = runTasks('assemble') + def result = runTasks('assemble', 'writeManifestProperties') then: - result.output.contains('Build-Java-Version=17') - result.output.contains('X-Compile-Target-JDK=11') - result.output.contains('X-Compile-Source-JDK=11') + def manifest = new File(projectDir, 'build/manifest/buildscript-singlemodule-test.properties') + manifest.text.contains('Build-Java-Version=17') + manifest.text.contains('X-Compile-Target-JDK=11') + manifest.text.contains('X-Compile-Source-JDK=11') } def 'reports proper jdk version when configuring target/source compatibility in compile task + toolchains (scala support)'() { @@ -276,11 +259,6 @@ class InfoPluginIntegrationTestKitSpec extends IntegrationTestKitSpec { dependencies { implementation 'com.google.guava:guava:18.0' } - def broker = project.plugins.getPlugin(${InfoBrokerPlugin.name}) - - gradle.buildFinished { - println broker.buildManifest() - } """.stripIndent() settingsFile << """ @@ -289,12 +267,13 @@ class InfoPluginIntegrationTestKitSpec extends IntegrationTestKitSpec { this.writeHelloWorld('com.nebula.test') when: - def result = runTasks('assemble') + def result = runTasks('assemble', 'writeManifestProperties') then: - result.output.contains('Build-Java-Version=17') - result.output.contains('X-Compile-Target-JDK=11') - result.output.contains('X-Compile-Source-JDK=11') + def manifest = new File(projectDir, 'build/manifest/buildscript-singlemodule-test.properties') + manifest.text.contains('Build-Java-Version=17') + manifest.text.contains('X-Compile-Target-JDK=11') + manifest.text.contains('X-Compile-Source-JDK=11') } } diff --git a/src/test/groovy/nebula/plugin/info/ci/ContinuousIntegrationInfoPluginSpec.groovy b/src/test/groovy/nebula/plugin/info/ci/ContinuousIntegrationInfoPluginSpec.groovy index af02839c..754d1ea8 100644 --- a/src/test/groovy/nebula/plugin/info/ci/ContinuousIntegrationInfoPluginSpec.groovy +++ b/src/test/groovy/nebula/plugin/info/ci/ContinuousIntegrationInfoPluginSpec.groovy @@ -1,5 +1,6 @@ package nebula.plugin.info.ci +import nebula.plugin.info.BaseIntegrationSpec import nebula.plugin.info.InfoBrokerPlugin import nebula.plugin.info.reporting.InfoJarManifestPlugin import nebula.test.IntegrationSpec @@ -13,7 +14,7 @@ import java.util.jar.JarFile import java.util.jar.Manifest @IgnoreIf({ System.getenv('TITUS_TASK_ID') || jvm.isJava21() || jvm.isJava17() }) -class ContinuousIntegrationInfoPluginSpec extends IntegrationSpec { +class ContinuousIntegrationInfoPluginSpec extends BaseIntegrationSpec { @Rule public final EnvironmentVariables environmentVariables = new EnvironmentVariables() diff --git a/src/test/groovy/nebula/plugin/info/reporting/InfoJarManifestPluginLauncherSpec.groovy b/src/test/groovy/nebula/plugin/info/reporting/InfoJarManifestPluginLauncherSpec.groovy index 4988aa23..411f660a 100644 --- a/src/test/groovy/nebula/plugin/info/reporting/InfoJarManifestPluginLauncherSpec.groovy +++ b/src/test/groovy/nebula/plugin/info/reporting/InfoJarManifestPluginLauncherSpec.groovy @@ -16,6 +16,7 @@ package nebula.plugin.info.reporting +import nebula.plugin.info.BaseIntegrationSpec import nebula.plugin.info.InfoBrokerPlugin import nebula.plugin.info.basic.BasicInfoPlugin import nebula.test.IntegrationSpec @@ -26,7 +27,7 @@ import java.util.jar.Attributes import java.util.jar.JarFile import java.util.jar.Manifest -class InfoJarManifestPluginLauncherSpec extends IntegrationSpec { +class InfoJarManifestPluginLauncherSpec extends BaseIntegrationSpec { def 'jar task is marked UP-TO-DATE if ran before successfully and manifest changes are ignored'() { writeHelloWorld('nebula.test') diff --git a/src/test/groovy/nebula/plugin/info/reporting/InfoPropertiesFilePluginLauncherSpec.groovy b/src/test/groovy/nebula/plugin/info/reporting/InfoPropertiesFilePluginLauncherSpec.groovy index 90002097..f5df1083 100644 --- a/src/test/groovy/nebula/plugin/info/reporting/InfoPropertiesFilePluginLauncherSpec.groovy +++ b/src/test/groovy/nebula/plugin/info/reporting/InfoPropertiesFilePluginLauncherSpec.groovy @@ -1,5 +1,6 @@ package nebula.plugin.info.reporting +import nebula.plugin.info.BaseIntegrationSpec import nebula.plugin.info.InfoBrokerPlugin import nebula.plugin.info.basic.BasicInfoPlugin import nebula.test.IntegrationSpec @@ -7,7 +8,7 @@ import nebula.test.IntegrationSpec import java.util.jar.JarFile -class InfoPropertiesFilePluginLauncherSpec extends IntegrationSpec { +class InfoPropertiesFilePluginLauncherSpec extends BaseIntegrationSpec { def 'jar task is marked UP-TO-DATE if ran before successfully and metadata changes are ignored'() { writeHelloWorld('nebula.test') buildFile << """