Unverified Commit c2765843 authored by Iurii Ignatko's avatar Iurii Ignatko Committed by GitHub
Browse files

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: default avatarAlexis Tual <[email protected]>
parent 393df4bf
Loading
Loading
Loading
Loading
+13 −25
Changes for sources/src/resources/init-scripts/gradle-actions.inject-develocity.init.gradle: 13 added lines, 25 removed lines.
Original line number Diff line number Diff line
@@ -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 (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 = geCaptureFileFingerprints
                            buildScan.capture.taskInputFiles = develocityCaptureFileFingerprints
                        } else {
                            buildScan.captureTaskInputFiles = geCaptureFileFingerprints
                            buildScan.captureTaskInputFiles = develocityCaptureFileFingerprints
                        }
                    }
                    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 (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
                        }
                    }
                }
            }

+12 −3
Changes for sources/test/init-scripts/src/test/groovy/com/gradle/gradlebuildaction/TestDevelocityInjection.groovy: 12 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -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)