Skip to content

Commit

Permalink
Test injection with different DV plugin versions
Browse files Browse the repository at this point in the history
Previously, our test coverage for injection of the DV plugin was limited to the latest DV plugin. The only exception was testing v3.16.2, but even then we failed to test setting the DV URL, capture fingerprints, etc.

With this change, we now test running the init-script with different DV versions to inject, ensuring our script continues to support injection of older plugin versions (which may be required if the DV server environment is out of date).
  • Loading branch information
bigdaz committed Nov 6, 2024
1 parent f892f05 commit 7544a72
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 101 deletions.
15 changes: 8 additions & 7 deletions src/main/resources/develocity-injection.init.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ void enableDevelocityInjection() {
}
if (!scanPluginComponent) {
def pluginClass = dvOrGe(DEVELOCITY_PLUGIN_CLASS, BUILD_SCAN_PLUGIN_CLASS)
logger.lifecycle("Applying $pluginClass via init script")
applyPluginExternally(pluginManager, pluginClass)
def pluginVersion = dvOrGe(develocityPluginVersion, "1.16")
applyPluginExternally(pluginManager, pluginClass, pluginVersion)
def rootExtension = dvOrGe(
{ develocity },
{ buildScan }
Expand Down Expand Up @@ -237,7 +237,7 @@ void enableDevelocityInjection() {
it.moduleVersion.with { group == "com.gradle" && name == "common-custom-user-data-gradle-plugin" }
}
if (!ccudPluginComponent) {
logger.lifecycle("Applying $CCUD_PLUGIN_CLASS via init script")
logger.lifecycle("Applying $CCUD_PLUGIN_CLASS with version $ccudPluginVersion via init script")
pluginManager.apply(initscript.classLoader.loadClass(CCUD_PLUGIN_CLASS))
}
}
Expand All @@ -248,8 +248,7 @@ void enableDevelocityInjection() {
if (develocityPluginVersion) {
if (!settings.pluginManager.hasPlugin(GRADLE_ENTERPRISE_PLUGIN_ID) && !settings.pluginManager.hasPlugin(DEVELOCITY_PLUGIN_ID)) {
def pluginClass = dvOrGe(DEVELOCITY_PLUGIN_CLASS, GRADLE_ENTERPRISE_PLUGIN_CLASS)
logger.lifecycle("Applying $pluginClass via init script")
applyPluginExternally(settings.pluginManager, pluginClass)
applyPluginExternally(settings.pluginManager, pluginClass, develocityPluginVersion)
if (develocityUrl) {
logger.lifecycle("Connection to Develocity: $develocityUrl, allowUntrustedServer: $develocityAllowUntrustedServer, captureFileFingerprints: $develocityCaptureFileFingerprints")
eachDevelocitySettingsExtension(settings) { ext ->
Expand Down Expand Up @@ -314,15 +313,17 @@ void enableDevelocityInjection() {

if (ccudPluginVersion) {
if (!settings.pluginManager.hasPlugin(CCUD_PLUGIN_ID)) {
logger.lifecycle("Applying $CCUD_PLUGIN_CLASS via init script")
logger.lifecycle("Applying $CCUD_PLUGIN_CLASS with version $ccudPluginVersion via init script")
settings.pluginManager.apply(initscript.classLoader.loadClass(CCUD_PLUGIN_CLASS))
}
}
}
}
}

void applyPluginExternally(def pluginManager, String pluginClassName) {
void applyPluginExternally(def pluginManager, String pluginClassName, String pluginVersion) {
logger.lifecycle("Applying $pluginClassName with version $pluginVersion via init script")

def externallyApplied = 'develocity.externally-applied'
def externallyAppliedDeprecated = 'gradle.enterprise.externally-applied'
def oldValue = System.getProperty(externallyApplied)
Expand Down
22 changes: 16 additions & 6 deletions src/test/groovy/com/gradle/BaseInitScriptTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ abstract class BaseInitScriptTest extends Specification {
static final TestGradleVersion GRADLE_8_0 = new TestGradleVersion(GradleVersion.version('8.0.2'), 8, 19)
static final TestGradleVersion GRADLE_8_X = new TestGradleVersion(GradleVersion.version('8.7'), 8, 21)

static final List<TestGradleVersion> ALL_VERSIONS = [
static final List<TestGradleVersion> ALL_GRADLE_VERSIONS = [
GRADLE_3_X, // First version where TestKit supports environment variables
GRADLE_4_X,
GRADLE_5_X,
Expand All @@ -37,11 +37,21 @@ abstract class BaseInitScriptTest extends Specification {
GRADLE_8_X,
]

static final List<TestGradleVersion> CONFIGURATION_CACHE_VERSIONS =
[GRADLE_7_X, GRADLE_8_0, GRADLE_8_X].intersect(ALL_VERSIONS)

static final List<TestGradleVersion> SETTINGS_PLUGIN_VERSIONS =
[GRADLE_6_X, GRADLE_7_X, GRADLE_8_0, GRADLE_8_X].intersect(ALL_VERSIONS)
static final List<TestGradleVersion> CONFIGURATION_CACHE_GRADLE_VERSIONS =
[GRADLE_7_X, GRADLE_8_0, GRADLE_8_X].intersect(ALL_GRADLE_VERSIONS)

// Gradle + plugin versions to test DV injection: used to test with project with no DV plugin defined
static def getVersionsToTestForPluginInjection(List<TestGradleVersion> gradleVersions = ALL_GRADLE_VERSIONS) {
[
gradleVersions,
[
"3.6.4", // Support server back to GE 2021.1
"3.16.2", // Last version before switch to Develocity
"3.17", // First Develocity plugin
DEVELOCITY_PLUGIN_VERSION // Latest Develocity plugin
]
].combinations()
}

static final String PUBLIC_BUILD_SCAN_ID = 'i2wepy2gr7ovw'
static final String DEFAULT_SCAN_UPLOAD_TOKEN = 'scan-upload-token'
Expand Down
10 changes: 5 additions & 5 deletions src/test/groovy/com/gradle/TestBuildScanCapture.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class TestBuildScanCapture extends BaseInitScriptTest {
buildScanUrlIsNotCaptured(result)

where:
testGradleVersion << ALL_VERSIONS
testGradleVersion << ALL_GRADLE_VERSIONS
}

@Requires({data.testGradleVersion.compatibleWithCurrentJvm})
Expand All @@ -26,14 +26,14 @@ class TestBuildScanCapture extends BaseInitScriptTest {
captureBuildScanLinks()

when:
def config = TestDevelocityInjection.createTestConfig(mockScansServer.address, DEVELOCITY_PLUGIN_VERSION)
def config = TestDevelocityInjection.createTestConfig(mockScansServer.address, testPluginVersion)
def result = run(['help'], testGradleVersion.gradleVersion, config.envVars)

then:
buildScanUrlIsCaptured(result)

where:
testGradleVersion << ALL_VERSIONS
[testGradleVersion, testPluginVersion] << versionsToTestForPluginInjection
}

@Requires({data.testGradleVersion.compatibleWithCurrentJvm})
Expand All @@ -50,7 +50,7 @@ class TestBuildScanCapture extends BaseInitScriptTest {
buildScanUrlIsCaptured(result)

where:
testGradleVersion << ALL_VERSIONS
testGradleVersion << ALL_GRADLE_VERSIONS
}


Expand All @@ -74,7 +74,7 @@ class TestBuildScanCapture extends BaseInitScriptTest {
buildScanUrlIsCaptured(result)

where:
testGradleVersion << CONFIGURATION_CACHE_VERSIONS
testGradleVersion << CONFIGURATION_CACHE_GRADLE_VERSIONS
}

void buildScanUrlIsCaptured(BuildResult result) {
Expand Down
Loading

0 comments on commit 7544a72

Please sign in to comment.