From ecabef3f191b635d7aef0fa66a5e28364254ccff Mon Sep 17 00:00:00 2001 From: Mark Waite Date: Sun, 13 Aug 2023 16:58:06 -0600 Subject: [PATCH] Test with Java 21 (#1002) * Remove Java 8 test support No longer support Java 8 * Run one test per core on ci.jenkins.io Faster tests are less expensive and pass for me. * Test with Java 21 * Don't run parallel tests, ci.jenkins.io fails * Remove unnecessary trailing anchor from regex * Update a comment that mentioned Java 8 * Test Jenkins 2.401.3, not 2.414 2.414 has changed cloud naming in a way that breaks the test --- Jenkinsfile | 3 ++- .../DockerComputerAttachConnectorTest.java | 6 +++--- .../connector/DockerComputerConnectorTest.java | 13 +++---------- 3 files changed, 8 insertions(+), 14 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 1e731da27..f82132330 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -6,8 +6,9 @@ buildPlugin( useContainerAgent: false, // Show failures on all configurations failFast: false, - // Test Java 11 with minimum Jenkins version, Java 17 with a more recent version + // Test Java 11, 17, and 21 configurations: [ [platform: 'linux', jdk: 17], + [platform: 'linux', jdk: '21', jenkins: '2.401.3'], [platform: 'windows', jdk: 11], ]) diff --git a/src/test/java/io/jenkins/docker/connector/DockerComputerAttachConnectorTest.java b/src/test/java/io/jenkins/docker/connector/DockerComputerAttachConnectorTest.java index d8e81950c..de51bea9a 100644 --- a/src/test/java/io/jenkins/docker/connector/DockerComputerAttachConnectorTest.java +++ b/src/test/java/io/jenkins/docker/connector/DockerComputerAttachConnectorTest.java @@ -21,9 +21,9 @@ public void connectAgentViaDirectAttach() throws Exception { @Test public void connectAgentViaDirectAttachWithCustomCmd() throws Exception { final DockerComputerAttachConnector connector = new DockerComputerAttachConnector(COMMON_IMAGE_USERNAME); - // We could setJavaExe("/usr/local/openjdk-8/bin/java") too, but that'd mean - // we'd break the instant that the public docker image's JVM updates to 9 or - // higher; best stick to just using the $PATH. + // We could setJavaExe("/opt/jdk-11/bin/java") too, but that'd + // mean we'd break the instant that the public docker image's JVM + // updates to a newer JDK; best stick to just using the $PATH. connector.setJvmArgsString("-Xmx1g" + "\n" + "-Dfoo=bar\n"); connector.setEntryPointCmdString("java\n" + "${" + ArgumentVariables.JvmArgs.getName() + "}\n" diff --git a/src/test/java/io/jenkins/docker/connector/DockerComputerConnectorTest.java b/src/test/java/io/jenkins/docker/connector/DockerComputerConnectorTest.java index 355488dbd..3ed96e415 100644 --- a/src/test/java/io/jenkins/docker/connector/DockerComputerConnectorTest.java +++ b/src/test/java/io/jenkins/docker/connector/DockerComputerConnectorTest.java @@ -48,19 +48,12 @@ private static int getJavaVersion() { final String systemPropertyName = "java.version"; final String javaVersion = System.getProperty(systemPropertyName); try { - if (javaVersion.startsWith("1.")) { - // we're using Java 8 or lower so the syntax is 1.x where x is the version we - // want. - // ... and we know that x will be a single digit. - // e.g. 1.8.1 is Java 8, 1.6.3 is Java 6 etc. - final String secondNumber = javaVersion.substring(2, 3); - return Integer.parseInt(secondNumber); - } - // otherwise we're using Java 9 or higher so the syntax is x.n... + // We're using Java 9 or higher so the syntax is x.n... // ... but x might be multiple digits. // e.g. 9.0 is Java 9, 11.123.4 is Java 11 etc. + // Early access builds report as "21-ea". Remove all text after "-". final int indexOfPeriod = javaVersion.indexOf('.'); - final String firstNumber = indexOfPeriod < 0 ? javaVersion : javaVersion.substring(0, indexOfPeriod); + final String firstNumber = javaVersion.replaceAll("[-.].*", ""); return Integer.parseInt(firstNumber); } catch (RuntimeException ex) { throw new IllegalStateException(