Skip to content

Commit

Permalink
Fix GraalVM version pattern matching and add test for isJava17
Browse files Browse the repository at this point in the history
The regexp group "distro" was greedy and was capturing the java version
as well.
  • Loading branch information
zakkak committed Nov 29, 2021
1 parent ebd6d37 commit 2cfbd4f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
final class GraalVM {
static final class Version implements Comparable<Version> {
private static final Pattern PATTERN = Pattern.compile(
"(GraalVM|native-image)( Version)? (?<version>[1-9][0-9]*(\\.[0-9]+)+(-dev\\p{XDigit}*)?)(?<distro>[^\n$]*)(Java Version (?<javaVersion>[^)]+))?\\s*");
"(GraalVM|native-image)( Version)? (?<version>[1-9][0-9]*(\\.[0-9]+)+(-dev\\p{XDigit}*)?)(?<distro>.*?)?(\\(Java Version (?<javaVersion>[^)]+)\\))?$");

static final Version UNVERSIONED = new Version("Undefined", "snapshot", Distribution.ORACLE);
static final Version VERSION_21_2 = new Version("GraalVM 21.2", "21.2", Distribution.ORACLE);
Expand Down Expand Up @@ -100,6 +100,7 @@ private static boolean isMandrel(String s) {
public String toString() {
return "Version{" +
"version=" + version +
", fullVersion=" + fullVersion +
", distribution=" + distribution +
", javaVersion=" + javaVersion +
'}';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,17 @@ static void assertNewerThan(String version, String other) {
assertThat(Version.of(Stream.of(version)).isNewerThan(Version.of(Stream.of(other)))).isTrue();
}

@Test
public void testGraalVMVersionIsJava17() {
Version graalVM21_3_11 = Version.of(Stream.of("GraalVM 21.3.0 Java 11 CE (Java Version 11.0.13+7-jvmci-21.3-b05)"));
assertThat(graalVM21_3_11.isJava17()).isFalse();
Version graalVM21_3_17 = Version.of(Stream.of("GraalVM 21.3.0 Java 17 CE (Java Version 17.0.1+12-jvmci-21.3-b05)"));
assertThat(graalVM21_3_17.isJava17()).isTrue();
Version mandrel21_3_11 = Version
.of(Stream.of("native-image 21.3.0.0-Final Mandrel Distribution (Java Version 11.0.13+8)"));
assertThat(mandrel21_3_11.isJava17()).isFalse();
Version mandrel21_3_17 = Version
.of(Stream.of("native-image 21.3.0.0-Final Mandrel Distribution (Java Version 17.0.1+12)"));
assertThat(mandrel21_3_17.isJava17()).isTrue();
}
}

0 comments on commit 2cfbd4f

Please sign in to comment.