Skip to content

Commit

Permalink
[JENKINS-60678] Fix java checking on ComputerLauncher for AdoptOpenJD…
Browse files Browse the repository at this point in the history
…K 11 (#4434)

* [JENKINS-60678] Fix java checking on ComputerLauncher for AdoptOpenJDK 11

* [JENKINS-60678] Add more JDKs tests to check ComputerLauncher checks them correctly
  • Loading branch information
MRamonLeon authored and oleg-nenashev committed Jan 20, 2020
1 parent 1568f32 commit 0dd7009
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion core/src/main/java/hudson/slaves/ComputerLauncher.java
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
30 changes: 30 additions & 0 deletions core/src/test/java/hudson/slaves/ComputerLauncherTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)));
Expand Down

0 comments on commit 0dd7009

Please sign in to comment.