Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added support for graalvm version strings without minor version #1234

Merged
merged 2 commits into from
Nov 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,75 @@ 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 ========
ennerf marked this conversation as resolved.
Show resolved Hide resolved

// 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)"),

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: add a comment about GraalVM CE builds?

Copy link
Contributor

@jperedadnr jperedadnr Nov 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tested against recent GraalVM 21, the changes from this PR are fine, but to complete the build it needs the changes from #1236

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kristofdho we'll integrate this PR before yours. Would be good if you can do another review?

Arguments.of(new Version("17.0.7"), new Version("17.0.7"), "openjdk version \"17.0.7\" 2023-04-18\n" +
"OpenJDK Runtime Environment GraalVM CE 17.0.7+7.1 (build 17.0.7+7-jvmci-23.0-b12)\n" +
"OpenJDK 64-Bit Server VM GraalVM CE 17.0.7+7.1 (build 17.0.7+7-jvmci-23.0-b12, mixed mode, sharing)"),

Arguments.of(new Version("21"), new Version("21"), "openjdk version \"21\" 2023-09-19\n" +
"OpenJDK Runtime Environment GraalVM CE 21+35.1 (build 21+35-jvmci-23.1-b15)\n" +
"OpenJDK 64-Bit Server VM GraalVM CE 21+35.1 (build 21+35-jvmci-23.1-b15, mixed mode, sharing)")

);
}

}
Loading