Skip to content

Commit

Permalink
Merge pull request #16445 from zakkak/fix-16131
Browse files Browse the repository at this point in the history
Update GraalVM parsing to support upcoming 21.1
  • Loading branch information
geoand authored Apr 14, 2021
2 parents e7b78bc + c8c79e0 commit 52a0320
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,9 @@
final class GraalVM {
static final class Version implements Comparable<Version> {
private static final Pattern PATTERN = Pattern.compile(
"GraalVM Version (([1-9][0-9]*)\\.([0-9]+)\\.[0-9]+|\\p{XDigit}*)[^(\n$]*(\\(Mandrel Distribution\\))?\\s*");
"(GraalVM|native-image)( Version)? ([1-9][0-9]*)\\.([0-9]+)\\.[0-9]+(-dev\\p{XDigit}*)?([^\n$]*)\\s*");

static final Version UNVERSIONED = new Version("Undefined", -1, -1, Distribution.ORACLE);
static final Version SNAPSHOT_ORACLE = new Version("Snapshot", Integer.MAX_VALUE, Integer.MAX_VALUE,
Distribution.ORACLE);
static final Version SNAPSHOT_MANDREL = new Version("Snapshot", Integer.MAX_VALUE, Integer.MAX_VALUE,
Distribution.MANDREL);

static final Version VERSION_20_3 = new Version("GraalVM 20.3", 20, 3, Distribution.ORACLE);
static final Version VERSION_21_0 = new Version("GraalVM 21.0", 21, 0, Distribution.ORACLE);

Expand Down Expand Up @@ -50,10 +45,6 @@ boolean isMandrel() {
return distribution == Distribution.MANDREL;
}

boolean isSnapshot() {
return this == SNAPSHOT_ORACLE || this == SNAPSHOT_MANDREL;
}

boolean isNewerThan(Version version) {
return this.compareTo(version) > 0;
}
Expand Down Expand Up @@ -81,27 +72,21 @@ static Version of(Stream<String> lines) {
final String line = it.next();
final Matcher matcher = PATTERN.matcher(line);
if (matcher.find() && matcher.groupCount() >= 3) {
final String distro = matcher.group(4);
if (isSnapshot(matcher.group(2))) {
return isMandrel(distro) ? SNAPSHOT_MANDREL : SNAPSHOT_ORACLE;
} else {
return new Version(
line,
Integer.parseInt(matcher.group(2)), Integer.parseInt(matcher.group(3)),
isMandrel(distro) ? Distribution.MANDREL : Distribution.ORACLE);
}
final String major = matcher.group(3);
final String minor = matcher.group(4);
final String distro = matcher.group(6);
return new Version(
line,
Integer.parseInt(major), Integer.parseInt(minor),
isMandrel(distro) ? Distribution.MANDREL : Distribution.ORACLE);
}
}

return UNVERSIONED;
}

private static boolean isSnapshot(String s) {
return s == null;
}

private static boolean isMandrel(String s) {
return "(Mandrel Distribution)".equals(s);
return s.contains("Mandrel Distribution");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ public class NativeImageBuildStepTest {

@Test
public void testGraalVMVersionDetected() {
assertVersion(1, 0, ORACLE, Version.of(Stream.of("GraalVM Version 1.0.0")));
assertVersion(19, 3, ORACLE, Version.of(Stream.of("GraalVM Version 19.3.0")));
assertVersion(19, 3, ORACLE, Version.of(Stream.of("GraalVM Version 19.3.3")));
assertVersion(20, 0, ORACLE, Version.of(Stream.of("GraalVM Version 20.0.0")));
assertVersion(20, 1, ORACLE, Version.of(Stream.of("GraalVM Version 20.1.0 (Java Version 11.0.7)")));
assertVersion(20, 1, MANDREL, Version
.of(Stream.of("GraalVM Version 20.1.0.1.Alpha2 56d4ee1b28 (Mandrel Distribution) (Java Version 11.0.8)")));
Expand All @@ -28,6 +24,14 @@ public void testGraalVMVersionDetected() {
.of(Stream.of("GraalVM Version 21.0.0.0-0b3 (Mandrel Distribution) (Java Version 11.0.8)")));
assertVersion(20, 3, MANDREL, Version
.of(Stream.of("GraalVM Version 20.3.1.2-dev (Mandrel Distribution) (Java Version 11.0.8)")));
assertVersion(21, 1, MANDREL, Version
.of(Stream.of("native-image 21.1.0.0 Java 11 Mandrel Distribution (Java Version 11.0.11)")));
assertVersion(21, 1, MANDREL, Version
.of(Stream.of("GraalVM 21.1.0.0 Java 11 Mandrel Distribution (Java Version 11.0.11)")));
assertVersion(21, 1, ORACLE, Version
.of(Stream.of("GraalVM 21.1.0 Java 11 CE (Java Version 11.0.11+5-jvmci-21.1-b02)")));
assertVersion(21, 1, ORACLE, Version
.of(Stream.of("native-image 21.1.0.0 Java 11 CE (Java Version 11.0.11+5-jvmci-21.1-b02)")));
}

static void assertVersion(int major, int minor, Distribution distro, Version version) {
Expand All @@ -46,21 +50,9 @@ public void testGraalVMVersionUndetected() {
assertThat(Version.of(Stream.of("foo bar")).isDetected()).isFalse();
}

@Test
public void testGraalVMVersionSnapshot() {
assertSnapshot(MANDREL,
Version.of(Stream.of("GraalVM Version beb2fd6 (Mandrel Distribution) (Java Version 11.0.9-internal)")));
}

static void assertSnapshot(Distribution distro, Version version) {
assertThat(version.distribution).isEqualTo(distro);
assertThat(version.isDetected()).isEqualTo(true);
assertThat(version.isSnapshot()).isEqualTo(true);
}

@Test
public void testGraalVMVersionsOlderThan() {
assertOlderThan("GraalVM Version 1.0.0", "GraalVM Version 19.3.0");
assertOlderThan("GraalVM Version 19.3.0", "GraalVM Version 20.2.0");
assertOlderThan("GraalVM Version 20.0.0", "GraalVM Version 20.1.0");
}

Expand Down

0 comments on commit 52a0320

Please sign in to comment.