Skip to content

Commit

Permalink
Support Liberica NIK GraalVM version parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
gastaldi committed Jan 11, 2024
1 parent 781060d commit bac4131
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ static final class VersionParseHelper {
private static final String JVMCI_BUILD_PREFIX = "jvmci-";
private static final String MANDREL_VERS_PREFIX = "Mandrel-";

private static final String LIBERICA_NIK_VERS_PREFIX = "Liberica-NIK-";

// Java version info (suitable for Runtime.Version.parse()). See java.lang.VersionProps
private static final String VNUM = "(?<VNUM>[1-9][0-9]*(?:(?:\\.0)*\\.[1-9][0-9]*)*)";
private static final String PRE = "(?:-(?<PRE>[a-zA-Z0-9]+))?";
Expand Down Expand Up @@ -68,19 +70,47 @@ static Version parse(List<String> lines) {
if (vendorVersion.contains("-dev")) {
graalVersion = graalVersion + "-dev";
}
String mandrelVersion = mandrelVersion(vendorVersion);
Distribution dist = isMandrel(vendorVersion) ? Distribution.MANDREL : Distribution.GRAALVM;
String versNum = (dist == Distribution.MANDREL ? mandrelVersion : graalVersion);
String versNum;
Distribution dist;
if (isMandrel(vendorVersion)) {
dist = Distribution.MANDREL;
versNum = mandrelVersion(vendorVersion);
} else if (isLiberica(vendorVersion)) {
dist = Distribution.LIBERICA;
versNum = libericaVersion(vendorVersion);
} else {
dist = Distribution.GRAALVM;
versNum = graalVersion;
}
if (versNum == null) {
return UNKNOWN_VERSION;
}
return new Version(lines.stream().collect(Collectors.joining("\n")),
return new Version(String.join("\n", lines),
versNum, v, dist);
} else {
return UNKNOWN_VERSION;
}
}

private static boolean isLiberica(String vendorVersion) {
if (vendorVersion == null) {
return false;
}
return !vendorVersion.isBlank() && vendorVersion.startsWith(LIBERICA_NIK_VERS_PREFIX);
}

private static String libericaVersion(String vendorVersion) {
if (vendorVersion == null) {
return null;
}
int idx = vendorVersion.indexOf(LIBERICA_NIK_VERS_PREFIX);
if (idx < 0) {
return null;
}
String version = vendorVersion.substring(idx + LIBERICA_NIK_VERS_PREFIX.length());
return matchVersion(version);
}

private static boolean isMandrel(String vendorVersion) {
if (vendorVersion == null) {
return false;
Expand Down Expand Up @@ -244,7 +274,7 @@ public static Version of(Stream<String> output) {
String stringOutput = output.collect(Collectors.joining("\n"));
List<String> lines = stringOutput.lines()
.dropWhile(l -> !l.startsWith("GraalVM") && !l.startsWith("native-image"))
.collect(Collectors.toUnmodifiableList());
.toList();

if (lines.size() == 3) {
// Attempt to parse the new 3-line version scheme first.
Expand Down Expand Up @@ -322,6 +352,7 @@ public boolean isJava17() {

enum Distribution {
GRAALVM,
LIBERICA,
MANDREL;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,18 @@ static void assertVersion(Version graalVmVersion, Distribution distro, Version v
}
}

@Test
public void testGraalVM21LibericaVersionParser() {
Version graalVM21Dev = Version.of(Stream.of(("native-image 21.0.1 2023-10-17\n"
+ "GraalVM Runtime Environment Liberica-NIK-23.1.1-1 (build 21.0.1+12-LTS)\n"
+ "Substrate VM Liberica-NIK-23.1.1-1 (build 21.0.1+12-LTS, serial gc)").split("\\n")));
assertThat(graalVM21Dev.distribution.name()).isEqualTo("LIBERICA");
assertThat(graalVM21Dev.getVersionAsString()).isEqualTo("23.1.1");
assertThat(graalVM21Dev.javaVersion.toString()).isEqualTo("21.0.1+12-LTS");
assertThat(graalVM21Dev.javaVersion.feature()).isEqualTo(21);
assertThat(graalVM21Dev.javaVersion.update()).isEqualTo(1);
}

@Test
public void testGraalVM21VersionParser() {
Version graalVM21Dev = Version.of(Stream.of(("native-image 21 2023-09-19\n"
Expand Down

0 comments on commit bac4131

Please sign in to comment.