From 5d7152a1f09032bd3511653264806c8c0ad19a1e Mon Sep 17 00:00:00 2001 From: Iurii Ignatko Date: Fri, 22 Nov 2024 11:07:26 +0100 Subject: [PATCH] Fix Acceptance tests (#504) * Try acceptance tests with a newer base version for the plugin * Fix xpath for button selection and change test to integration * Update test harness version * Update JDK requirement * Update codenarc * Update toolchain for acceptance tests * Remove unnecessary jenkins version filtering * Set JAVA_HOME to run Jenkins itself * Revert back the test harness version * Remove toolchain for acceptance test * Update gradle version in tests * Reset default version of gradle in old tests * Update gradle tool setup * Remove Gradle 5.x from certain testing scenarios * Update default version for acceptance tests * Remove toolchain setup in acceptance tests * Bring back toolchain setup for compilation --- acceptance-tests/build.gradle.kts | 32 ++++++------------- build.gradle.kts | 4 +-- .../gradle/BuildScanIntegrationTest.groovy | 9 +++--- ...dScanInjectionGradleIntegrationTest.groovy | 2 +- ...DevelocityExceptionLogProcessorTest.groovy | 4 +-- .../injection/InjectionConfigTest.groovy | 3 +- .../MavenExtensionsDetectorTest.groovy | 8 ++--- 7 files changed, 26 insertions(+), 36 deletions(-) diff --git a/acceptance-tests/build.gradle.kts b/acceptance-tests/build.gradle.kts index dbeae7df..3a03194d 100644 --- a/acceptance-tests/build.gradle.kts +++ b/acceptance-tests/build.gradle.kts @@ -11,6 +11,8 @@ plugins { val ciJenkinsBuild: Boolean by (gradle as ExtensionAware).extra java { + // Only used for compilation. We don't rely on toolchain for running the tests, + // as Jenkins ATH doesn't allow to specify the JAVA_HOME. toolchain { languageVersion.set(JavaLanguageVersion.of(11)) } @@ -40,18 +42,13 @@ dependencies { add(gradlePlugin.name, project(path = ":", configuration = "gradlePluginJpi")) } -val currentJava = JavaVersion.current() - val jenkinsVersions = listOf( JenkinsVersion.LATEST, JenkinsVersion.LATEST_LTS, - JenkinsVersion.V2_401 + JenkinsVersion.V2_440 ) jenkinsVersions - .filter { jenkinsVersion -> - jenkinsVersion.isDefault || currentJava.isCompatibleWith(jenkinsVersion.requiredJavaVersion) - } .forEach { jenkinsVersion -> val downloadJenkinsTask = tasks.register("downloadJenkins${jenkinsVersion.label}") { @@ -85,10 +82,6 @@ jenkinsVersions !ciJenkinsBuild && !OperatingSystem.current().isWindows } - javaLauncher.set(javaToolchains.launcherFor { - languageVersion.set(jenkinsVersion.javaVersion) - }) - systemProperties( mapOf( "jdk.xml.xpathExprOpLimit" to 150 @@ -107,26 +100,23 @@ jenkinsVersions } } -data class JenkinsVersion(val version: String, val downloadUrl: URL, val javaVersion: JavaLanguageVersion) { +data class JenkinsVersion(val version: String, val downloadUrl: URL) { companion object { private const val LATEST_VERSION = "latest" private const val LATEST_LTS_VERSION = "latest-lts" - private const val V2_401_VERSION = "2.401.3" + private const val V2_440_VERSION = "2.440.3" private const val MIRROR = "https://updates.jenkins.io" private val JENKINS_VERSION_PATTERN = "^\\d+([.]\\d+)*?\$".toRegex() - private val JAVA_11 = JavaLanguageVersion.of(11) - private val JAVA_17 = JavaLanguageVersion.of(17) - - val LATEST = of(LATEST_VERSION, JAVA_17) + val LATEST = of(LATEST_VERSION) val LATEST_LTS = of(LATEST_LTS_VERSION) - val V2_401 = of(V2_401_VERSION) + val V2_440 = of(V2_440_VERSION) - private fun of(version: String, javaVersion: JavaLanguageVersion = JAVA_11): JenkinsVersion { + private fun of(version: String): JenkinsVersion { val downloadUrl = when (version) { LATEST_VERSION -> "${MIRROR}/current/latest/jenkins.war" @@ -139,14 +129,14 @@ data class JenkinsVersion(val version: String, val downloadUrl: URL, val javaVer } } - return JenkinsVersion(version, URL(downloadUrl), javaVersion) + return JenkinsVersion(version, URL(downloadUrl)) } private fun isJenkinsVersion(version: String) = JENKINS_VERSION_PATTERN.matches(version) } val isDefault: Boolean - get() = version == V2_401_VERSION + get() = version == V2_440_VERSION val label: String get() = if (isJenkinsVersion(version)) { @@ -155,6 +145,4 @@ data class JenkinsVersion(val version: String, val downloadUrl: URL, val javaVer version.split("-").joinToString(separator = "") { it.capitalized() } } - val requiredJavaVersion: JavaVersion - get() = JavaVersion.toVersion(javaVersion.toString()) } diff --git a/build.gradle.kts b/build.gradle.kts index 17952404..717cd3b7 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -16,9 +16,9 @@ plugins { group = "org.jenkins-ci.plugins" description = "This plugin adds Gradle support to Jenkins" -val coreBaseVersion = "2.401" +val coreBaseVersion = "2.440" val corePatchVersion = "3" -val coreBomVersion = "2745.vc7b_fe4c876fa_" +val coreBomVersion = "3387.v0f2773fa_3200" val gradleExt = (gradle as ExtensionAware).extra diff --git a/src/test/groovy/hudson/plugins/gradle/BuildScanIntegrationTest.groovy b/src/test/groovy/hudson/plugins/gradle/BuildScanIntegrationTest.groovy index d186ddf5..52a12fa5 100644 --- a/src/test/groovy/hudson/plugins/gradle/BuildScanIntegrationTest.groovy +++ b/src/test/groovy/hudson/plugins/gradle/BuildScanIntegrationTest.groovy @@ -91,13 +91,14 @@ class BuildScanIntegrationTest extends BaseGradleIntegrationTest { def 'detects build scan in pipeline log'() { given: + gradleInstallationRule.gradleVersion = '7.3.3' gradleInstallationRule.addInstallation() def pipelineJob = j.createProject(WorkflowJob) pipelineJob.setDefinition(new CpsFlowDefinition(""" node { stage('Build') { // Run the maven build - def gradleHome = tool name: '5.5', type: 'gradle' + def gradleHome = tool name: '${gradleInstallationRule.gradleVersion}', type: 'gradle' writeFile file: 'settings.gradle', text: '' writeFile file: 'build.gradle', text: "buildScan { termsOfServiceUrl = 'https://gradle.com/terms-of-service'; termsOfServiceAgree = 'yes' }" if (isUnix()) { @@ -125,7 +126,7 @@ node { def 'detects build scan in pipeline log using withGradle'() { given: - gradleInstallationRule.gradleVersion = '5.6.4' + gradleInstallationRule.gradleVersion = '7.3.3' gradleInstallationRule.addInstallation() def pipelineJob = j.createProject(WorkflowJob) pipelineJob.setDefinition(new CpsFlowDefinition(""" @@ -174,7 +175,7 @@ node { def 'does not find build scans in pipeline logs when none have been published'() { given: - gradleInstallationRule.gradleVersion = '5.6.4' + gradleInstallationRule.gradleVersion = '7.3.3' gradleInstallationRule.addInstallation() def pipelineJob = j.createProject(WorkflowJob) pipelineJob.setDefinition(new CpsFlowDefinition(""" @@ -206,7 +207,7 @@ node { def 'does not find build scans in pipeline logs when none have been published with withGradle'() { given: - gradleInstallationRule.gradleVersion = '5.6.4' + gradleInstallationRule.gradleVersion = '7.3.3' gradleInstallationRule.addInstallation() def pipelineJob = j.createProject(WorkflowJob) pipelineJob.setDefinition(new CpsFlowDefinition(""" diff --git a/src/test/groovy/hudson/plugins/gradle/injection/BuildScanInjectionGradleIntegrationTest.groovy b/src/test/groovy/hudson/plugins/gradle/injection/BuildScanInjectionGradleIntegrationTest.groovy index 31723e68..75c4c6f4 100644 --- a/src/test/groovy/hudson/plugins/gradle/injection/BuildScanInjectionGradleIntegrationTest.groovy +++ b/src/test/groovy/hudson/plugins/gradle/injection/BuildScanInjectionGradleIntegrationTest.groovy @@ -30,7 +30,7 @@ class BuildScanInjectionGradleIntegrationTest extends BaseGradleIntegrationTest private static final String MSG_INIT_SCRIPT_APPLIED = "Connection to Develocity: http://foo.com" - private static final List GRADLE_VERSIONS = ['4.10.3', '5.6.4', '6.9.4', '7.6.4', '8.9'] + private static final List GRADLE_VERSIONS = ['4.10.3', '6.9.4', '7.6.4', '8.9'] private static final EnvVars EMPTY_ENV = new EnvVars() diff --git a/src/test/groovy/hudson/plugins/gradle/injection/DevelocityExceptionLogProcessorTest.groovy b/src/test/groovy/hudson/plugins/gradle/injection/DevelocityExceptionLogProcessorTest.groovy index c1d9c74d..99336852 100644 --- a/src/test/groovy/hudson/plugins/gradle/injection/DevelocityExceptionLogProcessorTest.groovy +++ b/src/test/groovy/hudson/plugins/gradle/injection/DevelocityExceptionLogProcessorTest.groovy @@ -2,13 +2,13 @@ package hudson.plugins.gradle.injection import hudson.console.ConsoleNote import hudson.model.Actionable +import hudson.plugins.gradle.BaseJenkinsIntegrationTest import hudson.plugins.gradle.BuildScanAction -import spock.lang.Specification import spock.lang.Subject import java.nio.charset.StandardCharsets -class DevelocityExceptionLogProcessorTest extends Specification { +class DevelocityExceptionLogProcessorTest extends BaseJenkinsIntegrationTest { private static final String GRADLE_PLUGIN_ERROR = "Internal error in Gradle Enterprise Gradle plugin: com.acme.FooBar" private static final String MAVEN_EXTENSION_ERROR = "[ERROR] Internal error in Gradle Enterprise Maven extension: com.acme.FooBar" diff --git a/src/test/groovy/hudson/plugins/gradle/injection/InjectionConfigTest.groovy b/src/test/groovy/hudson/plugins/gradle/injection/InjectionConfigTest.groovy index a8cd8f60..493959b3 100644 --- a/src/test/groovy/hudson/plugins/gradle/injection/InjectionConfigTest.groovy +++ b/src/test/groovy/hudson/plugins/gradle/injection/InjectionConfigTest.groovy @@ -334,7 +334,8 @@ class InjectionConfigTest extends BaseJenkinsIntegrationTest { } private static HtmlButton getAddButton(HtmlForm form, String label) { - def xpath = "//div[text() = '$label']/following-sibling::div[contains(@class, 'setting-main')]//span[contains(@class, 'repeatable-add')]//button[text() = 'Add']" + def xpath = "//div[text() = '$label']/following-sibling::div[contains(@class, 'setting-main')]//button[contains(@class, 'repeatable-add')]" + return form.getFirstByXPath(xpath) } } diff --git a/src/test/groovy/hudson/plugins/gradle/injection/MavenExtensionsDetectorTest.groovy b/src/test/groovy/hudson/plugins/gradle/injection/MavenExtensionsDetectorTest.groovy index c09437e4..6fa7b17d 100644 --- a/src/test/groovy/hudson/plugins/gradle/injection/MavenExtensionsDetectorTest.groovy +++ b/src/test/groovy/hudson/plugins/gradle/injection/MavenExtensionsDetectorTest.groovy @@ -30,7 +30,7 @@ class MavenExtensionsDetectorTest extends Specification { dir { '.mvn' { 'extensions.xml'(generateExtensionsXml( - *(extensions.collect({ MavenCoordinates.parseCoordinates(it) })))) + *(extensions.collect { MavenCoordinates.parseCoordinates(it) }))) } } @@ -68,9 +68,9 @@ class MavenExtensionsDetectorTest extends Specification { dir { '.mvn' { 'extensions.xml'( - generateExtensionsXml( - MavenCoordinates.parseCoordinates('my:ext:1.0'), - MavenCoordinates.parseCoordinates('my:ext-ccud:1.0'))) + generateExtensionsXml( + MavenCoordinates.parseCoordinates('my:ext:1.0'), + MavenCoordinates.parseCoordinates('my:ext-ccud:1.0'))) } }