From 0dd7009a0abdc035bcba3a2180509a0dd5cbbf0e Mon Sep 17 00:00:00 2001 From: Ramon Leon Date: Mon, 20 Jan 2020 03:24:36 +0100 Subject: [PATCH] [JENKINS-60678] Fix java checking on ComputerLauncher for AdoptOpenJDK 11 (#4434) * [JENKINS-60678] Fix java checking on ComputerLauncher for AdoptOpenJDK 11 * [JENKINS-60678] Add more JDKs tests to check ComputerLauncher checks them correctly --- .../java/hudson/slaves/ComputerLauncher.java | 2 +- .../hudson/slaves/ComputerLauncherTest.java | 30 +++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/hudson/slaves/ComputerLauncher.java b/core/src/main/java/hudson/slaves/ComputerLauncher.java index 7efb9f4a4150..38ee6d70be53 100644 --- a/core/src/main/java/hudson/slaves/ComputerLauncher.java +++ b/core/src/main/java/hudson/slaves/ComputerLauncher.java @@ -180,7 +180,7 @@ protected static void checkJavaVersion(final PrintStream logger, String javaComm final BufferedReader r) throws IOException { String line; - Pattern p = Pattern.compile("(?i)(?:java|openjdk) version \"([0-9.]+).*\""); + Pattern p = Pattern.compile("(?i)(?:java|openjdk) version \"([0-9.]+).*\".*"); while (null != (line = r.readLine())) { Matcher m = p.matcher(line); if (m.matches()) { diff --git a/core/src/test/java/hudson/slaves/ComputerLauncherTest.java b/core/src/test/java/hudson/slaves/ComputerLauncherTest.java index 93fac0cb29d0..4ff10d0dd52d 100644 --- a/core/src/test/java/hudson/slaves/ComputerLauncherTest.java +++ b/core/src/test/java/hudson/slaves/ComputerLauncherTest.java @@ -32,6 +32,8 @@ import org.apache.commons.io.output.NullOutputStream; import org.junit.Test; +import org.jvnet.hudson.test.Issue; + import static org.junit.Assert.*; public class ComputerLauncherTest { @@ -68,6 +70,34 @@ public class ComputerLauncherTest { assertChecked("java version \"1.10.0_02\"\nJava(TM) SE Runtime Environment (build 1.10.0_02-b01)\nJava HotSpot(TM) Server VM (build 23.1-b03, mixed mode)\n", "1.10.0"); } + @Issue("JENKINS-60678") + @Test public void adoptOpenJDK11() throws IOException { + assertChecked("openjdk version \"11.0.5\" 2019-10-15\n" + + "OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.5+10)\n" + + "OpenJDK 64-Bit Server VM AdoptOpenJDK (build 11.0.5+10, mixed mode)", "11.0.5"); + } + + @Issue("JENKINS-60678") + @Test public void amazonCorrettoJDK11() throws IOException { + assertChecked("openjdk version \"11.0.6\" 2020-01-14 LTS\n" + + "OpenJDK Runtime Environment Corretto-11.0.6.10.1 (build 11.0.6+10-LTS)\n" + + "OpenJDK 64-Bit Server VM Corretto-11.0.6.10.1 (build 11.0.6+10-LTS, mixed mode)", "11.0.6"); + } + + @Issue("JENKINS-60678") + @Test public void openJDK1106() throws IOException { + assertChecked("openjdk version \"11.0.6\" 2020-01-14\n" + + "OpenJDK Runtime Environment 18.9 (build 11.0.6+10)\n" + + "OpenJDK 64-Bit Server VM 18.9 (build 11.0.6+10, mixed mode)", "11.0.6"); + } + + @Issue("JENKINS-60678") + @Test public void azulZuluOpenJDK11() throws IOException { + assertChecked("openjdk version \"11.0.5\" 2019-10-15 LTS\n" + + "OpenJDK Runtime Environment Zulu11.35+15-CA (build 11.0.5+10-LTS)\n" + + "OpenJDK 64-Bit Server VM Zulu11.35+15-CA (build 11.0.5+10-LTS, mixed mode)", "11.0.5"); + } + private static void assertChecked(String text, String spec) throws IOException { ByteArrayOutputStream os = new ByteArrayOutputStream(); ComputerLauncher.checkJavaVersion(new PrintStream(os), "bin/java", new BufferedReader(new StringReader(text)));