From c276584302d4e637967851a78a9e98c18a7d28da Mon Sep 17 00:00:00 2001 From: Iurii Ignatko Date: Mon, 25 Mar 2024 16:34:45 +0200 Subject: [PATCH] Capture task input files when plugin not applied (#77) This PR changes the behavior such that task input files are captured when the environment variable is explicitly specified and for the cases when the plugin is not applied. --------- Co-authored-by: Alexis Tual --- ...adle-actions.inject-develocity.init.gradle | 44 +++++++------------ .../TestDevelocityInjection.groovy | 15 +++++-- 2 files changed, 28 insertions(+), 31 deletions(-) diff --git a/sources/src/resources/init-scripts/gradle-actions.inject-develocity.init.gradle b/sources/src/resources/init-scripts/gradle-actions.inject-develocity.init.gradle index 45eb18a..2f04921 100644 --- a/sources/src/resources/init-scripts/gradle-actions.inject-develocity.init.gradle +++ b/sources/src/resources/init-scripts/gradle-actions.inject-develocity.init.gradle @@ -94,7 +94,7 @@ def geUrl = getInputParam('develocity.url') def geAllowUntrustedServer = Boolean.parseBoolean(getInputParam('develocity.allow-untrusted-server')) def geEnforceUrl = Boolean.parseBoolean(getInputParam('develocity.enforce-url')) def buildScanUploadInBackground = Boolean.parseBoolean(getInputParam('develocity.build-scan.upload-in-background')) -def geCaptureFileFingerprints = Boolean.parseBoolean(getInputParam('develocity.capture-file-fingerprints')) +def develocityCaptureFileFingerprints = getInputParam('develocity.capture-file-fingerprints') ? Boolean.parseBoolean(getInputParam('develocity.capture-file-fingerprints')) : true def gePluginVersion = getInputParam('develocity.plugin.version') def ccudPluginVersion = getInputParam('develocity.ccud-plugin.version') def buildScanTermsOfServiceUrl = getInputParam('build-scan.terms-of-service.url') @@ -123,36 +123,30 @@ if (GradleVersion.current() < GradleVersion.version('6.0')) { logger.lifecycle("Applying $BUILD_SCAN_PLUGIN_CLASS via init script") applyPluginExternally(pluginManager, BUILD_SCAN_PLUGIN_CLASS) if (geUrl) { - logger.lifecycle("Connection to Develocity: $geUrl, allowUntrustedServer: $geAllowUntrustedServer, captureFileFingerprints: $geCaptureFileFingerprints") + logger.lifecycle("Connection to Develocity: $geUrl, allowUntrustedServer: $geAllowUntrustedServer") buildScan.server = geUrl buildScan.allowUntrustedServer = geAllowUntrustedServer } buildScan.publishAlways() - if (isAtLeast(gePluginVersion, '2.1') && atLeastGradle5) { - if (isAtLeast(gePluginVersion, '3.7')) { - buildScan.capture.taskInputFiles = geCaptureFileFingerprints - } else { - buildScan.captureTaskInputFiles = geCaptureFileFingerprints - } - } if (buildScan.metaClass.respondsTo(buildScan, 'setUploadInBackground', Boolean)) buildScan.uploadInBackground = buildScanUploadInBackground // uploadInBackground not available for build-scan-plugin 1.16 buildScan.value CI_AUTO_INJECTION_CUSTOM_VALUE_NAME, CI_AUTO_INJECTION_CUSTOM_VALUE_VALUE + if (isAtLeast(gePluginVersion, '2.1') && atLeastGradle5) { + logger.lifecycle("Setting captureFileFingerprints: $develocityCaptureFileFingerprints") + if (isAtLeast(gePluginVersion, '3.7')) { + buildScan.capture.taskInputFiles = develocityCaptureFileFingerprints + } else { + buildScan.captureTaskInputFiles = develocityCaptureFileFingerprints + } + } } if (geUrl && geEnforceUrl) { pluginManager.withPlugin(BUILD_SCAN_PLUGIN_ID) { afterEvaluate { - logger.lifecycle("Enforcing Develocity: $geUrl, allowUntrustedServer: $geAllowUntrustedServer, captureFileFingerprints: $geCaptureFileFingerprints") + logger.lifecycle("Enforcing Develocity: $geUrl, allowUntrustedServer: $geAllowUntrustedServer") buildScan.server = geUrl buildScan.allowUntrustedServer = geAllowUntrustedServer } - if (isAtLeast(gePluginVersion, '2.1') && atLeastGradle5) { - if (isAtLeast(gePluginVersion, '3.7')) { - buildScan.capture.taskInputFiles = geCaptureFileFingerprints - } else { - buildScan.captureTaskInputFiles = geCaptureFileFingerprints - } - } } } @@ -181,17 +175,18 @@ if (GradleVersion.current() < GradleVersion.version('6.0')) { applyPluginExternally(settings.pluginManager, DEVELOCITY_PLUGIN_CLASS) eachDevelocityExtension(settings, DEVELOCITY_EXTENSION_CLASS) { ext -> if (geUrl) { - logger.lifecycle("Connection to Develocity: $geUrl, allowUntrustedServer: $geAllowUntrustedServer, captureFileFingerprints: $geCaptureFileFingerprints") + logger.lifecycle("Connection to Develocity: $geUrl, allowUntrustedServer: $geAllowUntrustedServer") ext.server = geUrl ext.allowUntrustedServer = geAllowUntrustedServer } ext.buildScan.publishAlways() ext.buildScan.uploadInBackground = buildScanUploadInBackground if (isAtLeast(gePluginVersion, '2.1')) { + logger.lifecycle("Setting captureFileFingerprints: $develocityCaptureFileFingerprints") if (isAtLeast(gePluginVersion, '3.7')) { - ext.buildScan.capture.taskInputFiles = geCaptureFileFingerprints + ext.buildScan.capture.taskInputFiles = develocityCaptureFileFingerprints } else { - ext.buildScan.captureTaskInputFiles = geCaptureFileFingerprints + ext.buildScan.captureTaskInputFiles = develocityCaptureFileFingerprints } } ext.buildScan.value CI_AUTO_INJECTION_CUSTOM_VALUE_NAME, CI_AUTO_INJECTION_CUSTOM_VALUE_VALUE @@ -200,16 +195,9 @@ if (GradleVersion.current() < GradleVersion.version('6.0')) { if (geUrl && geEnforceUrl) { eachDevelocityExtension(settings, DEVELOCITY_EXTENSION_CLASS) { ext -> - logger.lifecycle("Enforcing Develocity: $geUrl, allowUntrustedServer: $geAllowUntrustedServer, captureFileFingerprints: $geCaptureFileFingerprints") + logger.lifecycle("Enforcing Develocity: $geUrl, allowUntrustedServer: $geAllowUntrustedServer") ext.server = geUrl ext.allowUntrustedServer = geAllowUntrustedServer - if (isAtLeast(gePluginVersion, '2.1')) { - if (isAtLeast(gePluginVersion, '3.7')) { - ext.buildScan.capture.taskInputFiles = geCaptureFileFingerprints - } else { - ext.buildScan.captureTaskInputFiles = geCaptureFileFingerprints - } - } } } diff --git a/sources/test/init-scripts/src/test/groovy/com/gradle/gradlebuildaction/TestDevelocityInjection.groovy b/sources/test/init-scripts/src/test/groovy/com/gradle/gradlebuildaction/TestDevelocityInjection.groovy index 03a2bb6..f19eefc 100644 --- a/sources/test/init-scripts/src/test/groovy/com/gradle/gradlebuildaction/TestDevelocityInjection.groovy +++ b/sources/test/init-scripts/src/test/groovy/com/gradle/gradlebuildaction/TestDevelocityInjection.groovy @@ -234,8 +234,11 @@ class TestDevelocityInjection extends BaseInitScriptTest { then: outputContainsDevelocityPluginApplicationViaInitScript(result, testGradleVersion.gradleVersion) - outputContainsDevelocityConnectionInfo(result, mockScansServer.address.toString(), true, true) + outputContainsDevelocityConnectionInfo(result, mockScansServer.address.toString(), true) outputMissesCcudPluginApplicationViaInitScript(result) + if (testGradleVersion.gradleVersion >= GRADLE_5_X.gradleVersion) { + outputCaptureFileFingerprints(result, true) + } and: outputContainsBuildScanUrl(result) @@ -344,12 +347,18 @@ class TestDevelocityInjection extends BaseInitScriptTest { assert !result.output.contains(pluginApplicationLogMsg) } - void outputContainsDevelocityConnectionInfo(BuildResult result, String geUrl, boolean geAllowUntrustedServer, boolean geCaptureFileFingerprints = false) { - def geConnectionInfo = "Connection to Develocity: $geUrl, allowUntrustedServer: $geAllowUntrustedServer, captureFileFingerprints: $geCaptureFileFingerprints" + void outputContainsDevelocityConnectionInfo(BuildResult result, String geUrl, boolean geAllowUntrustedServer) { + def geConnectionInfo = "Connection to Develocity: $geUrl, allowUntrustedServer: $geAllowUntrustedServer" assert result.output.contains(geConnectionInfo) assert 1 == result.output.count(geConnectionInfo) } + void outputCaptureFileFingerprints(BuildResult result, boolean captureFileFingerprints) { + def captureFileFingerprintsInfo = "Setting captureFileFingerprints: $captureFileFingerprints" + assert result.output.contains(captureFileFingerprintsInfo) + assert 1 == result.output.count(captureFileFingerprintsInfo) + } + void outputContainsPluginRepositoryInfo(BuildResult result, String gradlePluginRepositoryUrl, boolean withCredentials = false) { def repositoryInfo = "Develocity plugins resolution: ${gradlePluginRepositoryUrl}" assert result.output.contains(repositoryInfo)