Skip to content

Commit

Permalink
Fail when GraalVM / Mandrel version detection fails
Browse files Browse the repository at this point in the history
It's easy to miss the error message and Quarkus will assume the version
is a snapshot of GraalVM making it harder to debug.

The benefits of supporting arbitrary versions from dev/snapshot builds
doesn't seem to justify the above so it's better to just fail and
require a proper version in dev/snapshot builds.
  • Loading branch information
zakkak committed Jul 17, 2023
1 parent d903356 commit dc6ed7e
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ public static final class Version implements Comparable<Version> {
"(GraalVM|native-image)( Version)? " + VersionParseHelper.VERS_FORMAT + "(?<distro>.*?)?" +
"(\\(Java Version (?<jfeature>[0-9]+)(\\.(?<jinterim>[0-9]*)\\.(?<jupdate>[0-9]*))?.*)?$");

static final Version UNVERSIONED = new Version("Undefined", "snapshot", Distribution.ORACLE);
static final Version VERSION_21_3 = new Version("GraalVM 21.3", "21.3", Distribution.ORACLE);
static final Version VERSION_21_3_0 = new Version("GraalVM 21.3.0", "21.3.0", Distribution.ORACLE);
public static final Version VERSION_22_3_0 = new Version("GraalVM 22.3.0", "22.3.0", Distribution.ORACLE);
Expand Down Expand Up @@ -160,10 +159,6 @@ String getFullVersion() {
return fullVersion;
}

boolean isDetected() {
return this != UNVERSIONED;
}

boolean isObsolete() {
return this.compareTo(MINIMUM) < 0;
}
Expand Down Expand Up @@ -204,10 +199,7 @@ static Version of(Stream<String> output) {

if (lines.size() == 3) {
// Attempt to parse the new 3-line version scheme first.
Version v = VersionParseHelper.parse(lines);
if (v != VersionParseHelper.UNKNOWN_VERSION) {
return v;
}
return VersionParseHelper.parse(lines);
} else if (lines.size() == 1) {
// Old, single line version parsing logic
final String line = lines.get(0);
Expand All @@ -234,7 +226,8 @@ static Version of(Stream<String> output) {
}
}

return UNVERSIONED;
throw new IllegalArgumentException(
"Cannot parse version from output: " + output.collect(Collectors.joining("\n")));
}

private static boolean isMandrel(String s) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,12 +216,7 @@ public NativeImageBuildItem build(NativeConfig nativeConfig, LocalesBuildTimeCon

buildRunner.setup(processInheritIODisabled.isPresent() || processInheritIODisabledBuildItem.isPresent());
final GraalVM.Version graalVMVersion = buildRunner.getGraalVMVersion();

if (graalVMVersion.isDetected()) {
checkGraalVMVersion(graalVMVersion);
} else {
log.error("Unable to get GraalVM version from the native-image binary.");
}
checkGraalVMVersion(graalVMVersion);

try {
if (nativeConfig.cleanupServer()) {
Expand Down Expand Up @@ -568,7 +563,7 @@ static class Builder {
private Path outputDir;
private String runnerJarName;
private String noPIE = "";
private GraalVM.Version graalVMVersion = GraalVM.Version.UNVERSIONED;
private GraalVM.Version graalVMVersion = null;
private String nativeImageName;
private boolean classpathIsBroken;
private boolean containerBuild;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,19 +86,13 @@ public void testGraalVMVersionDetected() {
}

static void assertVersion(org.graalvm.home.Version graalVmVersion, Distribution distro, Version version) {
assertThat(version.isDetected()).isEqualTo(true);
assertThat(graalVmVersion.compareTo(version.version)).isEqualTo(0);
assertThat(version.distribution).isEqualTo(distro);
if (distro == MANDREL) {
assertThat(version.isMandrel()).isTrue();
}
}

@Test
public void testGraalVMVersionUndetected() {
assertThat(Version.of(Stream.of("foo bar")).isDetected()).isFalse();
}

@Test
public void testGraalVMVersionsOlderThan() {
assertOlderThan("GraalVM Version 19.3.6 CE", "GraalVM Version 20.2.0 (Java Version 11.0.9)");
Expand Down

0 comments on commit dc6ed7e

Please sign in to comment.