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

Fix and improve major JDK version detection. #523

Merged
merged 3 commits into from
Oct 13, 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 @@ -61,6 +61,10 @@ public class NativeImageUtils {

private static final Pattern graalvmVersionPattern = Pattern.compile("^(GraalVM|native-image) ([0-9]+)\\.([0-9]+)\\.([0-9]+).*");

private static final Pattern javaVersionPattern = Pattern.compile("^native-image ([0-9]+).*", Pattern.DOTALL);
private static final Pattern javaVersionLegacyPattern = Pattern.compile(".* \\(Java Version ([0-9]+)\\.([0-9]+)\\.([0-9]+).*");


private static final Pattern SAFE_SHELL_ARG = Pattern.compile("[A-Za-z0-9@%_\\-+=:,./]+");

public static void maybeCreateConfigureUtilSymlink(File configureUtilFile, Path nativeImageExecutablePath) {
Expand Down Expand Up @@ -170,9 +174,14 @@ public static void checkVersion(String requiredVersion, String versionToCheck) {
}

public static int getMajorJDKVersion(String versionString) {
Matcher matcher = graalvmVersionPattern.matcher(versionString.trim());
String trimmedVersionString = versionString.trim();
Matcher matcher = javaVersionPattern.matcher(versionString.trim());
if (matcher.matches()) {
return Integer.parseInt(matcher.group(2));
return Integer.parseInt(matcher.group(1));
}
Matcher legacyMatcher = javaVersionLegacyPattern.matcher(trimmedVersionString);
if (legacyMatcher.matches()) {
return Integer.parseInt(legacyMatcher.group(1));
}
return -1;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,21 +65,33 @@ void invalidRequiredVersion() {

@Test
void checkGraalVMCEVersion() {
NativeImageUtils.checkVersion("22", "GraalVM 22.3.0 Java 17 CE (Java Version 17.0.5+8-jvmci-22.3-b08)");
NativeImageUtils.checkVersion("22.3", "GraalVM 22.3.0 Java 17 CE (Java Version 17.0.5+8-jvmci-22.3-b08)");
NativeImageUtils.checkVersion("22.3.0", "GraalVM 22.3.0 Java 17 CE (Java Version 17.0.5+8-jvmci-22.3-b08)");
String graalVMCE_22_3 = "GraalVM 22.3.0 Java 17 CE (Java Version 17.0.5+8-jvmci-22.3-b08)";
NativeImageUtils.checkVersion("22", graalVMCE_22_3);
NativeImageUtils.checkVersion("22.3", graalVMCE_22_3);
NativeImageUtils.checkVersion("22.3.0", graalVMCE_22_3);
Assertions.assertEquals(17, NativeImageUtils.getMajorJDKVersion(graalVMCE_22_3));

String graalVMCEForJDK17 = "native-image 17.0.7 2023-04-18\nGraalVM Runtime Environment GraalVM CE 17.0.7+4.1 (build 17.0.7+4-jvmci-23.0-b10)\nSubstrate VM GraalVM CE 17.0.7+4.1 (build 17.0.7+4, serial gc)";
NativeImageUtils.checkVersion("22.3.0", graalVMCEForJDK17);
NativeImageUtils.checkVersion("23", graalVMCEForJDK17);
NativeImageUtils.checkVersion("23.0", graalVMCEForJDK17);
NativeImageUtils.checkVersion("23.0.0", graalVMCEForJDK17);
Assertions.assertEquals(17, NativeImageUtils.getMajorJDKVersion(graalVMCEForJDK17));

String graalVMCEForJDK20 = "native-image 20 2023-04-18\nGraalVM Runtime Environment GraalVM CE 20+34.1 (build 20+34-jvmci-23.0-b10)\nSubstrate VM GraalVM CE 20+34.1 (build 20+34, serial gc)";
NativeImageUtils.checkVersion("22.3.0", graalVMCEForJDK20);
NativeImageUtils.checkVersion("23", graalVMCEForJDK20);
NativeImageUtils.checkVersion("23.0", graalVMCEForJDK20);
NativeImageUtils.checkVersion("23.0.0", graalVMCEForJDK20);
Assertions.assertEquals(20, NativeImageUtils.getMajorJDKVersion(graalVMCEForJDK20));

String graalVMCEForJDK21 = "native-image 21 2023-09-19\nGraalVM Runtime Environment GraalVM CE 21+35.1 (build 21+35-jvmci-23.1-b15)\nSubstrate VM GraalVM CE 21+35.1 (build 21+35, serial gc)";
NativeImageUtils.checkVersion("22.3.0", graalVMCEForJDK20);
NativeImageUtils.checkVersion("23", graalVMCEForJDK20);
NativeImageUtils.checkVersion("23.0", graalVMCEForJDK20);
NativeImageUtils.checkVersion("23.1", graalVMCEForJDK20);
NativeImageUtils.checkVersion("23.1.0", graalVMCEForJDK20);
Assertions.assertEquals(21, NativeImageUtils.getMajorJDKVersion(graalVMCEForJDK21));
}

@Test
Expand All @@ -90,25 +102,39 @@ void checkGraalVMCEDevVersion() {
NativeImageUtils.checkVersion("22.3.0", "GraalVM 23.0.0-dev Java 17.0.6+2-jvmci-23.0-b04 CE (Java Version 17.0.6+2-jvmci-23.0-b04)");
NativeImageUtils.checkVersion("22.3.0", "GraalVM dev CE (Java Version 19+36-jvmci-23.0-b01)");
NativeImageUtils.checkVersion("22.3.0", "native-image dev CE (Java Version 19+36-jvmci-23.0-b01)");
String latestGraalVMDevFormat = "native-image 21 2023-09-19\nGraalVM Runtime Environment GraalVM CE 21-dev+35.1 (build 21+35-jvmci-23.1-b15)\nSubstrate VM GraalVM CE 21-dev+35.1 (build 21+35, serial gc)";
NativeImageUtils.checkVersion("22.3.0", latestGraalVMDevFormat);
}

@Test
void checkGraalVMEEVersion() {
NativeImageUtils.checkVersion("22", "GraalVM 22.3.0 Java 17 EE (Java Version 17.0.5+9-LTS-jvmci-22.3-b07)");
NativeImageUtils.checkVersion("22.3", "GraalVM 22.3.0 Java 17 EE (Java Version 17.0.5+9-LTS-jvmci-22.3-b07)");
NativeImageUtils.checkVersion("22.3.0", "GraalVM 22.3.0 Java 17 EE (Java Version 17.0.5+9-LTS-jvmci-22.3-b07)");
}

@Test
void checkOracleGraalVMVersion() {
String oracleGraalVMForJDK17 = "native-image 17.0.7 2023-04-18\nGraalVM Runtime Environment Oracle GraalVM (build 17.0.7+8-jvmci-23.0-b10)\nSubstrate VM Oracle GraalVM (build 17.0.7+8, serial gc)";
NativeImageUtils.checkVersion("22.3.0", oracleGraalVMForJDK17);
NativeImageUtils.checkVersion("23", oracleGraalVMForJDK17);
NativeImageUtils.checkVersion("23.0", oracleGraalVMForJDK17);
NativeImageUtils.checkVersion("23.0.0", oracleGraalVMForJDK17);
Assertions.assertEquals(17, NativeImageUtils.getMajorJDKVersion(oracleGraalVMForJDK17));

String oracleGraalVMForJDK20 = "native-image 20.0.1 2023-04-18\nGraalVM Runtime Environment Oracle GraalVM 20.0.1+9.1 (build 20.0.1+9-jvmci-23.0-b10)\nSubstrate VM Oracle GraalVM 20.0.1+9.1 (build 20.0.1+9, serial gc)";
NativeImageUtils.checkVersion("22.3.0", oracleGraalVMForJDK20);
NativeImageUtils.checkVersion("23", oracleGraalVMForJDK20);
NativeImageUtils.checkVersion("23.0", oracleGraalVMForJDK20);
NativeImageUtils.checkVersion("23.0.0", oracleGraalVMForJDK20);
Assertions.assertEquals(20, NativeImageUtils.getMajorJDKVersion(oracleGraalVMForJDK20));

String oracleGraalVMForJDK21 = "native-image 21 2023-09-19\nGraalVM Runtime Environment Oracle GraalVM 21+35.1 (build 21+35-jvmci-23.1-b15)\nSubstrate VM Oracle GraalVM 21+35.1 (build 21+35, serial gc, compressed references)";
NativeImageUtils.checkVersion("22.3.0", oracleGraalVMForJDK21);
NativeImageUtils.checkVersion("23", oracleGraalVMForJDK21);
NativeImageUtils.checkVersion("23.1", oracleGraalVMForJDK21);
NativeImageUtils.checkVersion("23.1.0", oracleGraalVMForJDK21);
Assertions.assertEquals(21, NativeImageUtils.getMajorJDKVersion(oracleGraalVMForJDK21));
}

@Test
Expand Down
8 changes: 6 additions & 2 deletions docs/src/docs/asciidoc/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,19 @@ If you are using alternative build systems, see <<alternative-build-systems.adoc
[[changelog]]
== Changelog

=== Release 0.9.27
=== Release 0.9.28

* Update JUnit configuration for native testing on GraalVM for JDK 21 with `--strict-image-heap` mode.
* Fix path escaping problem for Windows users
* Fix and improve major JDK version detection.

==== Gradle plugin

- Remove use of deprecated `getConvention` APIs

=== Release 0.9.27

* Update JUnit configuration for native testing on GraalVM for JDK 21 with `--strict-image-heap` mode.

=== Release 0.9.26

* Relax GraalVM version check for dev versions
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ mavenEmbedder = "3.8.6"
mavenWagon = "3.4.3"
graalvm = "22.3.3"
jackson = "2.13.5"
junitPlatform = "1.9.3"
junitPlatform = "1.10.0"
junitJupiter = "5.10.0"
aether = "1.1.0"
slf4j = "1.7.9"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
native.gradle.plugin.version = 0.9.28-SNAPSHOT
junit.jupiter.version = 5.10.0
junit.platform.version = 1.9.3
junit.platform.version = 1.10.0
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
native.gradle.plugin.version = 0.9.28-SNAPSHOT
junit.jupiter.version = 5.10.0
junit.platform.version = 1.9.3
junit.platform.version = 1.10.0
2 changes: 1 addition & 1 deletion samples/java-application-with-reflection/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
native.gradle.plugin.version = 0.9.28-SNAPSHOT
junit.jupiter.version = 5.10.0
junit.platform.version = 1.9.3
junit.platform.version = 1.10.0
2 changes: 1 addition & 1 deletion samples/java-application-with-resources/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
native.gradle.plugin.version = 0.9.28-SNAPSHOT
junit.jupiter.version = 5.10.0
junit.platform.version = 1.9.3
junit.platform.version = 1.10.0
2 changes: 1 addition & 1 deletion samples/java-application-with-tests/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
native.gradle.plugin.version = 0.9.28-SNAPSHOT
junit.jupiter.version = 5.10.0
junit.platform.version = 1.9.3
junit.platform.version = 1.10.0
2 changes: 1 addition & 1 deletion samples/java-application/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
native.gradle.plugin.version = 0.9.28-SNAPSHOT
junit.jupiter.version = 5.10.0
junit.platform.version = 1.9.3
junit.platform.version = 1.10.0
2 changes: 1 addition & 1 deletion samples/java-library/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
native.gradle.plugin.version = 0.9.28-SNAPSHOT
junit.jupiter.version = 5.10.0
junit.platform.version = 1.9.3
junit.platform.version = 1.10.0
2 changes: 1 addition & 1 deletion samples/kotlin-application-with-tests/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
native.gradle.plugin.version = 0.9.28-SNAPSHOT
junit.jupiter.version = 5.10.0
junit.platform.version = 1.9.3
junit.platform.version = 1.10.0
2 changes: 1 addition & 1 deletion samples/multi-project-with-tests/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
native.gradle.plugin.version = 0.9.28-SNAPSHOT
junit.jupiter.version = 5.10.0
junit.platform.version = 1.9.3
junit.platform.version = 1.10.0
2 changes: 1 addition & 1 deletion samples/native-config-integration/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
native.gradle.plugin.version = 0.9.28-SNAPSHOT
junit.jupiter.version = 5.10.0
junit.platform.version = 1.9.3
junit.platform.version = 1.10.0