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 <atual@gradle.com>
This commit is contained in:
Iurii Ignatko 2024-03-25 16:34:45 +02:00 committed by GitHub
parent 393df4bfa2
commit c276584302
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 28 additions and 31 deletions

View file

@ -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
}
}
}
}

View file

@ -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)