Skip to content

Commit

Permalink
Add configuration cache to integration tests where possible
Browse files Browse the repository at this point in the history
  • Loading branch information
rpalcolea committed Oct 30, 2023
1 parent 48437b2 commit fa1276e
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
10 changes: 10 additions & 0 deletions src/test/groovy/nebula/plugin/info/BaseIntegrationSpec.groovy
Original file line number Diff line number Diff line change
@@ -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()
}
}
Original file line number Diff line number Diff line change
@@ -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()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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')
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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 << """
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 << """
Expand Down Expand Up @@ -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 << """
Expand All @@ -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'() {
Expand Down Expand Up @@ -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 << """
Expand All @@ -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'() {
Expand Down Expand Up @@ -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 << """
Expand All @@ -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)'() {
Expand Down Expand Up @@ -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 << """
Expand All @@ -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)'() {
Expand Down Expand Up @@ -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 << """
Expand All @@ -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')
}
}
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
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

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 << """
Expand Down

0 comments on commit fa1276e

Please sign in to comment.