mirror of
https://github.com/gradle/actions
synced 2024-11-27 20:02:19 +00:00
Fix Develocity deprecation warnings triggered by init-scripts
This commit is contained in:
parent
0ac212a9d2
commit
c93523a078
5 changed files with 107 additions and 56 deletions
|
@ -3,6 +3,13 @@
|
|||
*/
|
||||
import org.gradle.util.GradleVersion
|
||||
|
||||
def BUILD_SCAN_PLUGIN_ID = "com.gradle.build-scan"
|
||||
def BUILD_SCAN_EXTENSION = "buildScan"
|
||||
def DEVELOCITY_PLUGIN_ID = "com.gradle.develocity"
|
||||
def DEVELOCITY_EXTENSION = "develocity"
|
||||
def GE_PLUGIN_ID = "com.gradle.enterprise"
|
||||
def GE_EXTENSION = "gradleEnterprise"
|
||||
|
||||
// Only run against root build. Do not run against included builds.
|
||||
def isTopLevelBuild = gradle.getParent() == null
|
||||
if (isTopLevelBuild) {
|
||||
|
@ -23,13 +30,16 @@ if (isTopLevelBuild) {
|
|||
captureUsingBuildFinished(gradle, invocationId)
|
||||
}
|
||||
|
||||
// The `buildScanPublished` hook allows the capture of the Build Scan URI.
|
||||
// Results captured this way will overwrite any results from the other mechanism.
|
||||
settings.pluginManager.withPlugin("com.gradle.enterprise") {
|
||||
captureUsingBuildScanPublished(settings.extensions["gradleEnterprise"].buildScan, settings.rootProject, invocationId)
|
||||
|
||||
settings.pluginManager.withPlugin(GE_PLUGIN_ID) {
|
||||
// Only execute if develocity plugin isn't applied.
|
||||
if (!settings.extensions.findByName(DEVELOCITY_EXTENSION)) {
|
||||
captureUsingBuildScanPublished(settings.extensions[GE_EXTENSION].buildScan, settings.rootProject, invocationId)
|
||||
}
|
||||
}
|
||||
settings.pluginManager.withPlugin("com.gradle.develocity") {
|
||||
captureUsingBuildScanPublished(settings.extensions["develocity"].buildScan, settings.rootProject, invocationId)
|
||||
|
||||
settings.pluginManager.withPlugin(DEVELOCITY_PLUGIN_ID) {
|
||||
captureUsingBuildScanPublished(settings.extensions[DEVELOCITY_EXTENSION].buildScan, settings.rootProject, invocationId)
|
||||
}
|
||||
}
|
||||
} else if (atLeastGradle3) {
|
||||
|
@ -37,15 +47,22 @@ if (isTopLevelBuild) {
|
|||
// By default, use 'buildFinished' to capture build results
|
||||
captureUsingBuildFinished(gradle, invocationId)
|
||||
|
||||
// The `buildScanPublished` hook allows the capture of the Build Scan URI.
|
||||
// Results captured this way will overwrite any results from 'buildFinished'.
|
||||
gradle.rootProject.pluginManager.withPlugin("com.gradle.build-scan") {
|
||||
captureUsingBuildScanPublished(gradle.rootProject.extensions["buildScan"], gradle.rootProject, invocationId)
|
||||
gradle.rootProject.pluginManager.withPlugin(BUILD_SCAN_PLUGIN_ID) {
|
||||
// Only execute if develocity plugin isn't applied.
|
||||
if (!gradle.rootProject.extensions.findByName(DEVELOCITY_EXTENSION)) {
|
||||
captureUsingBuildScanPublished(gradle.rootProject.extensions[BUILD_SCAN_EXTENSION], gradle.rootProject, invocationId)
|
||||
}
|
||||
}
|
||||
|
||||
gradle.rootProject.pluginManager.withPlugin(DEVELOCITY_PLUGIN_ID) {
|
||||
captureUsingBuildScanPublished(gradle.rootProject.extensions[DEVELOCITY_EXTENSION].buildScan, gradle.rootProject, invocationId)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The `buildScanPublished` hook allows the capture of the Build Scan URI.
|
||||
// Results captured this way will overwrite any results from 'buildFinished'.
|
||||
def captureUsingBuildScanPublished(buildScanExtension, rootProject, invocationId) {
|
||||
buildScanExtension.with {
|
||||
def buildResults = new BuildResults(invocationId, gradle, rootProject)
|
||||
|
|
|
@ -80,13 +80,9 @@ def BUILD_SCAN_PLUGIN_CLASS = 'com.gradle.scan.plugin.BuildScanPlugin'
|
|||
|
||||
def GRADLE_ENTERPRISE_PLUGIN_ID = 'com.gradle.enterprise'
|
||||
def GRADLE_ENTERPRISE_PLUGIN_CLASS = 'com.gradle.enterprise.gradleplugin.GradleEnterprisePlugin'
|
||||
def GRADLE_ENTERPRISE_EXTENSION_CLASS = 'com.gradle.enterprise.gradleplugin.GradleEnterpriseExtension'
|
||||
|
||||
def DEVELOCITY_PLUGIN_ID = 'com.gradle.develocity'
|
||||
def DEVELOCITY_PLUGIN_CLASS = 'com.gradle.develocity.agent.gradle.DevelocityPlugin'
|
||||
def DEVELOCITY_CONFIGURATION_CLASS = 'com.gradle.develocity.agent.gradle.DevelocityConfiguration'
|
||||
|
||||
def SETTINGS_EXTENSION_CLASSES = [GRADLE_ENTERPRISE_EXTENSION_CLASS, DEVELOCITY_CONFIGURATION_CLASS]
|
||||
|
||||
def CI_AUTO_INJECTION_CUSTOM_VALUE_NAME = 'CI auto injection'
|
||||
def CCUD_PLUGIN_ID = 'com.gradle.common-custom-user-data-gradle-plugin'
|
||||
|
@ -194,6 +190,8 @@ if (GradleVersion.current() < GradleVersion.version('6.0')) {
|
|||
}
|
||||
|
||||
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) {
|
||||
buildScan.server = develocityUrl
|
||||
|
@ -242,61 +240,64 @@ if (GradleVersion.current() < GradleVersion.version('6.0')) {
|
|||
applyPluginExternally(settings.pluginManager, pluginClass)
|
||||
if (develocityUrl) {
|
||||
logger.lifecycle("Connection to Develocity: $develocityUrl, allowUntrustedServer: $develocityAllowUntrustedServer, captureFileFingerprints: $develocityCaptureFileFingerprints")
|
||||
eachDevelocitySettingsExtension(settings, SETTINGS_EXTENSION_CLASSES) { ext ->
|
||||
eachDevelocitySettingsExtension(settings) { ext ->
|
||||
ext.server = develocityUrl
|
||||
ext.allowUntrustedServer = develocityAllowUntrustedServer
|
||||
}
|
||||
}
|
||||
|
||||
eachDevelocitySettingsExtension(settings, SETTINGS_EXTENSION_CLASSES) { ext ->
|
||||
eachDevelocitySettingsExtension(settings) { ext ->
|
||||
ext.buildScan.uploadInBackground = buildScanUploadInBackground
|
||||
ext.buildScan.value CI_AUTO_INJECTION_CUSTOM_VALUE_NAME, ciAutoInjectionCustomValueValue
|
||||
}
|
||||
|
||||
eachDevelocitySettingsExtension(settings, [GRADLE_ENTERPRISE_EXTENSION_CLASS]) { ext ->
|
||||
ext.buildScan.publishAlways()
|
||||
if (isAtLeast(develocityPluginVersion, '2.1')) {
|
||||
eachDevelocitySettingsExtension(settings,
|
||||
{ develocity ->
|
||||
logger.lifecycle("Setting captureFileFingerprints: $develocityCaptureFileFingerprints")
|
||||
if (isAtLeast(develocityPluginVersion, '3.7')) {
|
||||
ext.buildScan.capture.taskInputFiles = develocityCaptureFileFingerprints
|
||||
} else {
|
||||
ext.buildScan.captureTaskInputFiles = develocityCaptureFileFingerprints
|
||||
develocity.buildScan.capture.fileFingerprints = develocityCaptureFileFingerprints
|
||||
},
|
||||
{ gradleEnterprise ->
|
||||
gradleEnterprise.buildScan.publishAlways()
|
||||
if (isAtLeast(develocityPluginVersion, '2.1')) {
|
||||
logger.lifecycle("Setting captureFileFingerprints: $develocityCaptureFileFingerprints")
|
||||
if (isAtLeast(develocityPluginVersion, '3.7')) {
|
||||
gradleEnterprise.buildScan.capture.taskInputFiles = develocityCaptureFileFingerprints
|
||||
} else {
|
||||
gradleEnterprise.buildScan.captureTaskInputFiles = develocityCaptureFileFingerprints
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
eachDevelocitySettingsExtension(settings, [DEVELOCITY_CONFIGURATION_CLASS]) { ext ->
|
||||
ext.buildScan.capture.fileFingerprints = develocityCaptureFileFingerprints
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
if (develocityUrl && develocityEnforceUrl) {
|
||||
logger.lifecycle("Enforcing Develocity: $develocityUrl, allowUntrustedServer: $develocityAllowUntrustedServer, captureFileFingerprints: $develocityCaptureFileFingerprints")
|
||||
}
|
||||
|
||||
eachDevelocitySettingsExtension(settings, [GRADLE_ENTERPRISE_EXTENSION_CLASS]) { ext ->
|
||||
if (develocityUrl && develocityEnforceUrl) {
|
||||
ext.server = develocityUrl
|
||||
ext.allowUntrustedServer = develocityAllowUntrustedServer
|
||||
}
|
||||
eachDevelocitySettingsExtension(settings,
|
||||
{ develocity ->
|
||||
if (develocityUrl && develocityEnforceUrl) {
|
||||
develocity.server = develocityUrl
|
||||
develocity.allowUntrustedServer = develocityAllowUntrustedServer
|
||||
}
|
||||
|
||||
if (buildScanTermsOfUseUrl && buildScanTermsOfUseAgree) {
|
||||
ext.buildScan.termsOfServiceUrl = buildScanTermsOfUseUrl
|
||||
ext.buildScan.termsOfServiceAgree = buildScanTermsOfUseAgree
|
||||
}
|
||||
}
|
||||
if (buildScanTermsOfUseUrl && buildScanTermsOfUseAgree) {
|
||||
develocity.buildScan.termsOfUseUrl = buildScanTermsOfUseUrl
|
||||
develocity.buildScan.termsOfUseAgree = buildScanTermsOfUseAgree
|
||||
}
|
||||
},
|
||||
{ gradleEnterprise ->
|
||||
if (develocityUrl && develocityEnforceUrl) {
|
||||
gradleEnterprise.server = develocityUrl
|
||||
gradleEnterprise.allowUntrustedServer = develocityAllowUntrustedServer
|
||||
}
|
||||
|
||||
eachDevelocitySettingsExtension(settings, [DEVELOCITY_CONFIGURATION_CLASS]) { ext ->
|
||||
if (develocityUrl && develocityEnforceUrl) {
|
||||
ext.server = develocityUrl
|
||||
ext.allowUntrustedServer = develocityAllowUntrustedServer
|
||||
if (buildScanTermsOfUseUrl && buildScanTermsOfUseAgree) {
|
||||
gradleEnterprise.buildScan.termsOfServiceUrl = buildScanTermsOfUseUrl
|
||||
gradleEnterprise.buildScan.termsOfServiceAgree = buildScanTermsOfUseAgree
|
||||
}
|
||||
}
|
||||
|
||||
if (buildScanTermsOfUseUrl && buildScanTermsOfUseAgree) {
|
||||
ext.buildScan.termsOfUseUrl = buildScanTermsOfUseUrl
|
||||
ext.buildScan.termsOfUseAgree = buildScanTermsOfUseAgree
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
if (ccudPluginVersion) {
|
||||
|
@ -331,10 +332,26 @@ void applyPluginExternally(def pluginManager, String pluginClassName) {
|
|||
}
|
||||
}
|
||||
|
||||
static def eachDevelocitySettingsExtension(def settings, List<String> publicTypes, def action) {
|
||||
settings.extensions.extensionsSchema.elements.findAll { publicTypes.contains(it.publicType.concreteClass.name) }
|
||||
/**
|
||||
* Apply the `dvAction` to all 'develocity' extensions.
|
||||
* If no 'develocity' extensions are found, apply the `geAction` to all 'gradleEnterprise' extensions.
|
||||
* (The develocity plugin creates both extensions, and we want to prefer configuring 'develocity').
|
||||
*/
|
||||
static def eachDevelocitySettingsExtension(def settings, def dvAction, def geAction = dvAction) {
|
||||
def GRADLE_ENTERPRISE_EXTENSION_CLASS = 'com.gradle.enterprise.gradleplugin.GradleEnterpriseExtension'
|
||||
def DEVELOCITY_CONFIGURATION_CLASS = 'com.gradle.develocity.agent.gradle.DevelocityConfiguration'
|
||||
|
||||
def dvExtensions = settings.extensions.extensionsSchema.elements
|
||||
.findAll { it.publicType.concreteClass.name == DEVELOCITY_CONFIGURATION_CLASS }
|
||||
.collect { settings[it.name] }
|
||||
if (!dvExtensions.empty) {
|
||||
dvExtensions.each(dvAction)
|
||||
} else {
|
||||
def geExtensions = settings.extensions.extensionsSchema.elements
|
||||
.findAll { it.publicType.concreteClass.name == GRADLE_ENTERPRISE_EXTENSION_CLASS }
|
||||
.collect { settings[it.name] }
|
||||
.each(action)
|
||||
geExtensions.each(geAction)
|
||||
}
|
||||
}
|
||||
|
||||
static boolean isAtLeast(String versionUnderTest, String referenceVersion) {
|
||||
|
|
|
@ -54,6 +54,8 @@ class BaseInitScriptTest extends Specification {
|
|||
File settingsFile
|
||||
File buildFile
|
||||
|
||||
boolean allowDevelocityDeprecationWarning = false
|
||||
|
||||
@TempDir
|
||||
File testProjectDir
|
||||
|
||||
|
@ -200,14 +202,16 @@ task expectFailure {
|
|||
}
|
||||
|
||||
BuildResult run(List<String> args, String initScript, GradleVersion gradleVersion = GradleVersion.current(), List<String> jvmArgs = [], Map<String, String> envVars = [:]) {
|
||||
createRunner(initScript, args, gradleVersion, jvmArgs, envVars).build()
|
||||
def result = createRunner(args, initScript, gradleVersion, jvmArgs, envVars).build()
|
||||
assertNoDeprecationWarning(result)
|
||||
}
|
||||
|
||||
BuildResult runAndFail(List<String> args, String initScript, GradleVersion gradleVersion = GradleVersion.current(), List<String> jvmArgs = [], Map<String, String> envVars = [:]) {
|
||||
createRunner(initScript, args, gradleVersion, jvmArgs, envVars).buildAndFail()
|
||||
def result = createRunner(args, initScript, gradleVersion, jvmArgs, envVars).buildAndFail()
|
||||
assertNoDeprecationWarning(result)
|
||||
}
|
||||
|
||||
GradleRunner createRunner(String initScript, List<String> args, GradleVersion gradleVersion = GradleVersion.current(), List<String> jvmArgs = [], Map<String, String> envVars = [:]) {
|
||||
GradleRunner createRunner(List<String> args, String initScript, GradleVersion gradleVersion = GradleVersion.current(), List<String> jvmArgs = [], Map<String, String> envVars = [:]) {
|
||||
File initScriptsDir = new File(testProjectDir, "initScripts")
|
||||
args << '-I' << new File(initScriptsDir, initScript).absolutePath
|
||||
|
||||
|
@ -236,6 +240,13 @@ task expectFailure {
|
|||
}
|
||||
}
|
||||
|
||||
BuildResult assertNoDeprecationWarning(BuildResult result) {
|
||||
if (!allowDevelocityDeprecationWarning) {
|
||||
assert !result.output.contains("WARNING: The following functionality has been deprecated")
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
static final class TestGradleVersion {
|
||||
|
||||
final GradleVersion gradleVersion
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.gradle.gradlebuildaction
|
||||
|
||||
import groovy.json.JsonSlurper
|
||||
import org.gradle.util.GradleVersion
|
||||
|
||||
import static org.junit.Assume.assumeTrue
|
||||
|
||||
|
@ -199,6 +200,7 @@ class TestBuildResultRecorder extends BaseInitScriptTest {
|
|||
}
|
||||
""" + settingsFile.text
|
||||
|
||||
allowDevelocityDeprecationWarning = true
|
||||
run(testGradleVersion.gradleVersion)
|
||||
|
||||
then:
|
||||
|
|
|
@ -134,6 +134,10 @@ class TestDevelocityInjection extends BaseInitScriptTest {
|
|||
declareDevelocityPluginApplication(testGradleVersion.gradleVersion)
|
||||
|
||||
when:
|
||||
// Init-script emits deprecation warnings when CCUD plugin is applied on Gradle 5.6.4
|
||||
if (testGradleVersion.gradleVersion.version == "5.6.4") {
|
||||
allowDevelocityDeprecationWarning = true
|
||||
}
|
||||
def result = run(testGradleVersion, testConfig().withCCUDPlugin())
|
||||
|
||||
then:
|
||||
|
|
Loading…
Reference in a new issue