Skip to content

Commit

Permalink
added support for graalvm version strings without minor version
Browse files Browse the repository at this point in the history
  • Loading branch information
ennerf committed Nov 7, 2023
1 parent 992e31e commit c685783
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,21 +122,22 @@ public Path getGraalPath() {
}

public Version getGraalVersion() throws IOException {
String pattern = "GraalVM .*?(\\d\\d.\\d.\\d)";
ProcessRunner graalJava;
try {
graalJava = new ProcessRunner(
getGraalVMBinPath().resolve("java").toString(),
"--version");
graalJava = new ProcessRunner(getGraalVMBinPath().resolve("java").toString(), "-version");
graalJava.runProcess("java-version");
} catch (InterruptedException e) {
throw new IOException("Couldn't determine GraalVM version, " + e.toString());
}
String output = graalJava.getResponse();
return parseGraalVersion(graalJava.getResponse());
}

static Version parseGraalVersion(String versionString) {
String pattern = "GraalVM (\\d{1,2}(\\.\\d+){0,2})";
Pattern r = Pattern.compile(pattern);
Matcher m = r.matcher(output);
Matcher m = r.matcher(versionString);
if (!m.find())
throw new IOException("Couldn't determine GraalVM version");
throw new IllegalArgumentException("Couldn't determine GraalVM version from: " + versionString);
return new Version(m.group(1));
}

Expand Down Expand Up @@ -679,16 +680,20 @@ public Version getGraalVMJavaVersion() throws IOException {
} catch (InterruptedException e) {
throw new IllegalArgumentException("$GRAALVM_HOME/bin/java -version process failed");
}
String pattern = "version \"(\\d{1,2}(\\.\\d+){0,2})\"";
Pattern r = Pattern.compile(pattern);
List<String> responses = graalJava.getResponses();
if (responses == null || responses.isEmpty()) {
throw new IOException("Couldn't determine GraalVM's Java version");
}
String realVersion = responses.get(0).replaceAll("-internal", "");
return parseGraalVMJavaVersion(responses.get(0));
}

static Version parseGraalVMJavaVersion(String versionString) {
String realVersion = versionString.replaceAll("-internal", "");
String pattern = "version \"(\\d{1,2}(\\.\\d+){0,2})\"";
Pattern r = Pattern.compile(pattern);
Matcher m = r.matcher(realVersion);
if (!m.find()) {
throw new IOException("Couldn't determine GraalVM's Java version for " + responses.get(0));
throw new IllegalArgumentException("Couldn't determine GraalVM's Java version from: " + realVersion);
}
return new Version(m.group(1));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,67 @@ static Stream<Arguments> versioningSchemeParameters() {
Arguments.of("22.0.2", false)
);
}

@ParameterizedTest
@MethodSource("graalVersionOutputs")
void testParseGraalVMVersion(Version graalVersion, Version javaVersion, String output) {
assertEquals(graalVersion.toString(), InternalProjectConfiguration.parseGraalVersion(output).toString());
}

@ParameterizedTest
@MethodSource("graalVersionOutputs")
void testParseGraalVMJavaVersion(Version graalVersion, Version javaVersion, String output) {
assertEquals(javaVersion.toString(), InternalProjectConfiguration.parseGraalVMJavaVersion(output).toString());
}

static Stream<Arguments> graalVersionOutputs() {
// outputs of 'java -version'
return Stream.of(
// ======== Gluon Builds ========

// graalvm-svm-java17-linux-gluon-22.1.0.1-Final
Arguments.of(new Version("22.1.0"), new Version("17.0.3"), "openjdk version \"17.0.3\" 2022-04-19\n" +
"OpenJDK Runtime Environment GraalVM 22.1.0.1 (build 17.0.3+7-jvmci-22.1-b06)\n" +
"OpenJDK 64-Bit Server VM GraalVM 22.1.0.1 (build 17.0.3+7-jvmci-22.1-b06, mixed mode, sharing)"),

// graalvm-svm-java17-windows-gluon-22.0.0.3-Final
Arguments.of(new Version("22.0.0"), new Version("17.0.2"), "openjdk version \"17.0.2\" 2022-01-18\n" +
"OpenJDK Runtime Environment GraalVM 22.0.0.2 (build 17.0.2+8-jvmci-22.0-b05)\n" +
"OpenJDK 64-Bit Server VM GraalVM 22.0.0.2 (build 17.0.2+8-jvmci-22.0-b05, mixed mode, sharing)"),

// graalvm-svm-java17-windows-gluon-22.1.0.1-Final
Arguments.of(new Version("22.1.0"), new Version("17.0.3"), "openjdk version \"17.0.3\" 2022-04-19\n" +
"OpenJDK Runtime Environment GraalVM 22.1.0.1 (build 17.0.3+7-jvmci-22.1-b06)\n" +
"OpenJDK 64-Bit Server VM GraalVM 22.1.0.1 (build 17.0.3+7-jvmci-22.1-b06, mixed mode, sharing)"),

// ======== Oracle Builds ========

// graalvm-jdk-17.0.7+8.1
Arguments.of(new Version("17.0.7"), new Version("17.0.7"), "java version \"17.0.7\" 2023-04-18 LTS\n" +
"Java(TM) SE Runtime Environment Oracle GraalVM 17.0.7+8.1 (build 17.0.7+8-LTS-jvmci-23.0-b12)\n" +
"Java HotSpot(TM) 64-Bit Server VM Oracle GraalVM 17.0.7+8.1 (build 17.0.7+8-LTS-jvmci-23.0-b12, mixed mode, sharing)"),

// graalvm-jdk-20.0.1+9.1
Arguments.of(new Version("20.0.1"), new Version("20.0.1"), "java version \"20.0.1\" 2023-04-18\n" +
"Java(TM) SE Runtime Environment Oracle GraalVM 20.0.1+9.1 (build 20.0.1+9-jvmci-23.0-b12)\n" +
"Java HotSpot(TM) 64-Bit Server VM Oracle GraalVM 20.0.1+9.1 (build 20.0.1+9-jvmci-23.0-b12, mixed mode, sharing)"),

// graalvm-jdk-21+35.1
Arguments.of(new Version("21"), new Version("21"), "java version \"21\" 2023-09-19\n" +
"Java(TM) SE Runtime Environment Oracle GraalVM 21+35.1 (build 21+35-jvmci-23.1-b15)\n" +
"Java HotSpot(TM) 64-Bit Server VM Oracle GraalVM 21+35.1 (build 21+35-jvmci-23.1-b15, mixed mode, sharing)"),

// graalvm-jdk-17.0.9+11.1
Arguments.of(new Version("17.0.9"), new Version("17.0.9"), "java version \"17.0.9\" 2023-10-17 LTS\n" +
"Java(TM) SE Runtime Environment Oracle GraalVM 17.0.9+11.1 (build 17.0.9+11-LTS-jvmci-23.0-b21)\n" +
"Java HotSpot(TM) 64-Bit Server VM Oracle GraalVM 17.0.9+11.1 (build 17.0.9+11-LTS-jvmci-23.0-b21, mixed mode, sharing)"),

// graalvm-jdk-21.0.1+12.1
Arguments.of(new Version("21.0.1"), new Version("21.0.1"), "java version \"21.0.1\" 2023-10-17\n" +
"Java(TM) SE Runtime Environment Oracle GraalVM 21.0.1+12.1 (build 21.0.1+12-jvmci-23.1-b19)\n" +
"Java HotSpot(TM) 64-Bit Server VM Oracle GraalVM 21.0.1+12.1 (build 21.0.1+12-jvmci-23.1-b19, mixed mode, sharing)")

);
}

}

0 comments on commit c685783

Please sign in to comment.