Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Develocity deprecation warnings triggered by init-scripts #423

Merged
merged 3 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions acceptance-tests/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ data class JenkinsVersion(val version: String, val downloadUrl: URL, val javaVer

private const val LATEST_VERSION = "latest"
private const val LATEST_LTS_VERSION = "latest-lts"
private const val V2_375_VERSION = "2.375.4"
private const val V2_388_VERSION = "2.388"

private const val MIRROR = "https://updates.jenkins.io"

Expand All @@ -123,7 +123,7 @@ data class JenkinsVersion(val version: String, val downloadUrl: URL, val javaVer

val LATEST = of(LATEST_VERSION)
val LATEST_LTS = of(LATEST_LTS_VERSION)
val V2_375 = of(V2_375_VERSION)
val V2_375 = of(V2_388_VERSION)

private fun of(version: String, javaVersion: JavaLanguageVersion = JAVA_11): JenkinsVersion {
val downloadUrl =
Expand All @@ -145,7 +145,7 @@ data class JenkinsVersion(val version: String, val downloadUrl: URL, val javaVer
}

val isDefault: Boolean
get() = version == V2_375_VERSION
get() = version == V2_388_VERSION

val label: String
get() = if (isJenkinsVersion(version)) {
Expand Down
115 changes: 66 additions & 49 deletions src/main/resources/hudson/plugins/gradle/injection/init-script.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ initscript {
dependencies {
if (develocityPluginVersion) {
if (atLeastGradle5) {
if (GradleVersion.version(develocityPluginVersion).baseVersion >= GradleVersion.version("3.17")) {
if (GradleVersion.version(develocityPluginVersion) >= GradleVersion.version("3.17")) {
classpath "com.gradle:develocity-gradle-plugin:$develocityPluginVersion"
} else {
classpath "com.gradle:gradle-enterprise-gradle-plugin:$develocityPluginVersion"
Expand All @@ -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'
Expand Down Expand Up @@ -119,7 +115,7 @@ def develocityUrl = getInputParam('develocity.url')
def develocityAllowUntrustedServer = Boolean.parseBoolean(getInputParam('develocity.allow-untrusted-server'))
def develocityEnforceUrl = Boolean.parseBoolean(getInputParam('develocity.enforce-url'))
def buildScanUploadInBackground = Boolean.parseBoolean(getInputParam('develocity.build-scan.upload-in-background'))
def develocityCaptureFileFingerprints = Boolean.parseBoolean(getInputParam('develocity.capture-file-fingerprints'))
def develocityCaptureFileFingerprints = getInputParam('develocity.capture-file-fingerprints') ? Boolean.parseBoolean(getInputParam('develocity.capture-file-fingerprints')) : true
def develocityPluginVersion = getInputParam('develocity.plugin.version')
def ccudPluginVersion = getInputParam('develocity.ccud-plugin.version')
def buildScanTermsOfUseUrl = getInputParam('develocity.terms-of-use.url')
Expand All @@ -128,7 +124,7 @@ def ciAutoInjectionCustomValueValue = getInputParam('develocity.auto-injection.c

def atLeastGradle5 = GradleVersion.current() >= GradleVersion.version('5.0')
def atLeastGradle4 = GradleVersion.current() >= GradleVersion.version('4.0')
def shouldApplyDevelocityPlugin = atLeastGradle5 && isAtLeast(develocityPluginVersion, '3.17')
def shouldApplyDevelocityPlugin = atLeastGradle5 && develocityPluginVersion && isAtLeast(develocityPluginVersion, '3.17')

def dvOrGe = { def dvValue, def geValue ->
if (shouldApplyDevelocityPlugin) {
Expand Down Expand Up @@ -166,7 +162,7 @@ if (GradleVersion.current() < GradleVersion.version('6.0')) {
{ rootExtension }
)
if (develocityUrl) {
logger.lifecycle("Connection to Develocity: $develocityUrl, allowUntrustedServer: $develocityAllowUntrustedServer")
logger.lifecycle("Connection to Develocity: $develocityUrl, allowUntrustedServer: $develocityAllowUntrustedServer, captureFileFingerprints: $develocityCaptureFileFingerprints")
rootExtension.server = develocityUrl
rootExtension.allowUntrustedServer = develocityAllowUntrustedServer
}
Expand All @@ -180,7 +176,7 @@ if (GradleVersion.current() < GradleVersion.version('6.0')) {
if (isAtLeast(develocityPluginVersion, '2.1') && atLeastGradle5) {
logger.lifecycle("Setting captureFileFingerprints: $develocityCaptureFileFingerprints")
if (isAtLeast(develocityPluginVersion, '3.17')) {
buildScanExtension.capture.fileFingerprints = develocityCaptureFileFingerprints
buildScanExtension.capture.fileFingerprints.set(develocityCaptureFileFingerprints)
} else if (isAtLeast(develocityPluginVersion, '3.7')) {
buildScanExtension.capture.taskInputFiles = develocityCaptureFileFingerprints
} else {
Expand All @@ -190,10 +186,12 @@ if (GradleVersion.current() < GradleVersion.version('6.0')) {
}

if (develocityUrl && develocityEnforceUrl) {
logger.lifecycle("Enforcing Develocity: $develocityUrl, allowUntrustedServer: $develocityAllowUntrustedServer")
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) {
buildScan.server = develocityUrl
Expand Down Expand Up @@ -241,62 +239,65 @@ if (GradleVersion.current() < GradleVersion.version('6.0')) {
logger.lifecycle("Applying $pluginClass via init script")
applyPluginExternally(settings.pluginManager, pluginClass)
if (develocityUrl) {
logger.lifecycle("Connection to Develocity: $develocityUrl, allowUntrustedServer: $develocityAllowUntrustedServer")
eachDevelocitySettingsExtension(settings, SETTINGS_EXTENSION_CLASSES) { ext ->
logger.lifecycle("Connection to Develocity: $develocityUrl, allowUntrustedServer: $develocityAllowUntrustedServer, captureFileFingerprints: $develocityCaptureFileFingerprints")
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')) {
if (isAtLeast(develocityPluginVersion, '3.7')) {
eachDevelocitySettingsExtension(settings,
{ develocity ->
logger.lifecycle("Setting captureFileFingerprints: $develocityCaptureFileFingerprints")
develocity.buildScan.capture.fileFingerprints = develocityCaptureFileFingerprints
},
{ gradleEnterprise ->
gradleEnterprise.buildScan.publishAlways()
if (isAtLeast(develocityPluginVersion, '2.1')) {
logger.lifecycle("Setting captureFileFingerprints: $develocityCaptureFileFingerprints")
ext.buildScan.capture.taskInputFiles = develocityCaptureFileFingerprints
} else {
ext.buildScan.captureTaskInputFiles = 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")
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
}

if (buildScanTermsOfUseUrl && buildScanTermsOfUseAgree) {
ext.buildScan.termsOfServiceUrl = buildScanTermsOfUseUrl
ext.buildScan.termsOfServiceAgree = buildScanTermsOfUseAgree
}
}
eachDevelocitySettingsExtension(settings,
{ develocity ->
if (develocityUrl && develocityEnforceUrl) {
develocity.server = develocityUrl
develocity.allowUntrustedServer = develocityAllowUntrustedServer
}

eachDevelocitySettingsExtension(settings, [DEVELOCITY_CONFIGURATION_CLASS]) { ext ->
if (develocityUrl && develocityEnforceUrl) {
ext.server = develocityUrl
ext.allowUntrustedServer = develocityAllowUntrustedServer
}
if (buildScanTermsOfUseUrl && buildScanTermsOfUseAgree) {
develocity.buildScan.termsOfUseUrl = buildScanTermsOfUseUrl
develocity.buildScan.termsOfUseAgree = buildScanTermsOfUseAgree
}
},
{ gradleEnterprise ->
if (develocityUrl && develocityEnforceUrl) {
gradleEnterprise.server = develocityUrl
gradleEnterprise.allowUntrustedServer = develocityAllowUntrustedServer
}

if (buildScanTermsOfUseUrl && buildScanTermsOfUseAgree) {
ext.buildScan.termsOfUseUrl = buildScanTermsOfUseUrl
ext.buildScan.termsOfUseAgree = buildScanTermsOfUseAgree
if (buildScanTermsOfUseUrl && buildScanTermsOfUseAgree) {
gradleEnterprise.buildScan.termsOfServiceUrl = buildScanTermsOfUseUrl
gradleEnterprise.buildScan.termsOfServiceAgree = buildScanTermsOfUseAgree
}
}
}
)
}

if (ccudPluginVersion) {
Expand Down Expand Up @@ -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] }
.each(action)
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] }
geExtensions.each(geAction)
}
}

static boolean isAtLeast(String versionUnderTest, String referenceVersion) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ abstract class BaseGradleIntegrationTest extends AbstractIntegrationTest {

public final GradleInstallationRule gradleInstallationRule = new GradleInstallationRule(j)
static final String DEVELOCITY_PLUGIN_VERSION = '3.17'
static final String CCUD_PLUGIN_VERSION = '2.0'

@Rule
public final RuleChain rules = RuleChain.outerRule(noSpaceInTmpDirs).around(j).around(gradleInstallationRule)
Expand Down Expand Up @@ -46,6 +47,7 @@ abstract class BaseGradleIntegrationTest extends AbstractIntegrationTest {
withInjectionConfig {
enabled = true
gradlePluginVersion = gradleVersion < '5.0' ? "1.16" : DEVELOCITY_PLUGIN_VERSION
ccudPluginVersion = gradlePluginVersion == '1.6' ? '1.13' : CCUD_PLUGIN_VERSION
gradlePluginRepositoryUrl = repositoryAddress?.toString()
gradleCaptureTaskInputFiles = captureTaskInputFiles
}
Expand Down
Loading