Skip to content

Commit

Permalink
Test more DV plugin versions (#13)
Browse files Browse the repository at this point in the history
This PR extends coverage of the init-script to include more plugin versions.

These tests exposed an issue when enforcing the DV URL on a project that already
applies the `com.gradle.build-scan:[3.17,3.18.1]` plugin.  As such, these versions are excluded from testing for now.
  • Loading branch information
bigdaz authored Nov 9, 2024
2 parents 36c8414 + ede45fc commit 3c5c0f7
Show file tree
Hide file tree
Showing 4 changed files with 355 additions and 237 deletions.
27 changes: 12 additions & 15 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 = atLeastGradle5 ? develocityPluginVersion : "1.16"
applyPluginExternally(pluginManager, pluginClass, pluginVersion)
def rootExtension = dvOrGe(
{ develocity },
{ buildScan }
Expand Down Expand Up @@ -197,15 +197,12 @@ void enableDevelocityInjection() {
}
}

if (develocityUrl && develocityEnforceUrl) {
logger.lifecycle("Enforcing Develocity: $develocityUrl, allowUntrustedServer: $develocityAllowUntrustedServer, captureFileFingerprints: $develocityCaptureFileFingerprints")
}

pluginManager.withPlugin(BUILD_SCAN_PLUGIN_ID) {
// Only execute if develocity plugin isn't applied.
if (gradle.rootProject.extensions.findByName("develocity")) return
afterEvaluate {
if (develocityUrl && develocityEnforceUrl) {
logger.lifecycle("Enforcing Develocity: $develocityUrl, allowUntrustedServer: $develocityAllowUntrustedServer")
buildScan.server = develocityUrl
buildScan.allowUntrustedServer = develocityAllowUntrustedServer
}
Expand All @@ -220,6 +217,7 @@ void enableDevelocityInjection() {
pluginManager.withPlugin(DEVELOCITY_PLUGIN_ID) {
afterEvaluate {
if (develocityUrl && develocityEnforceUrl) {
logger.lifecycle("Enforcing Develocity: $develocityUrl, allowUntrustedServer: $develocityAllowUntrustedServer")
develocity.server = develocityUrl
develocity.allowUntrustedServer = develocityAllowUntrustedServer
}
Expand All @@ -237,7 +235,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 +246,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 @@ -282,13 +279,10 @@ void enableDevelocityInjection() {
)
}

if (develocityUrl && develocityEnforceUrl) {
logger.lifecycle("Enforcing Develocity: $develocityUrl, allowUntrustedServer: $develocityAllowUntrustedServer, captureFileFingerprints: $develocityCaptureFileFingerprints")
}

eachDevelocitySettingsExtension(settings,
{ develocity ->
if (develocityUrl && develocityEnforceUrl) {
logger.lifecycle("Enforcing Develocity: $develocityUrl, allowUntrustedServer: $develocityAllowUntrustedServer")
develocity.server = develocityUrl
develocity.allowUntrustedServer = develocityAllowUntrustedServer
}
Expand All @@ -300,6 +294,7 @@ void enableDevelocityInjection() {
},
{ gradleEnterprise ->
if (develocityUrl && develocityEnforceUrl) {
logger.lifecycle("Enforcing Develocity: $develocityUrl, allowUntrustedServer: $develocityAllowUntrustedServer")
gradleEnterprise.server = develocityUrl
gradleEnterprise.allowUntrustedServer = develocityAllowUntrustedServer
}
Expand All @@ -314,15 +309,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
Loading

0 comments on commit 3c5c0f7

Please sign in to comment.