From 355efa0cb41b4a574ce9fc37e38811fa7e1dbda3 Mon Sep 17 00:00:00 2001 From: Bruno Caballero Date: Tue, 3 Dec 2024 13:47:13 +0100 Subject: [PATCH] Improve GraalVM version check. --- .../graalvm/buildtools/utils/NativeImageUtils.java | 2 +- .../buildtools/utils/NativeImageUtilsTest.java | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/common/utils/src/main/java/org/graalvm/buildtools/utils/NativeImageUtils.java b/common/utils/src/main/java/org/graalvm/buildtools/utils/NativeImageUtils.java index e6d2db8b3..2e1949bf0 100644 --- a/common/utils/src/main/java/org/graalvm/buildtools/utils/NativeImageUtils.java +++ b/common/utils/src/main/java/org/graalvm/buildtools/utils/NativeImageUtils.java @@ -60,7 +60,7 @@ public class NativeImageUtils { private static final Pattern requiredVersionPattern = Pattern.compile("^([0-9]+)(?:\\.([0-9]+)?)?(?:\\.([0-9]+)?)?$"); - private static final Pattern graalvmVersionPattern = Pattern.compile("^(GraalVM|native-image) ([0-9]+)\\.([0-9]+)\\.([0-9]+).*"); + private static final Pattern graalvmVersionPattern = Pattern.compile("^(GraalVM|native-image) ([0-9]+)\\.([0-9]+)\\.([0-9]+).*", Pattern.DOTALL); 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]+).*"); diff --git a/common/utils/src/test/java/org/graalvm/buildtools/utils/NativeImageUtilsTest.java b/common/utils/src/test/java/org/graalvm/buildtools/utils/NativeImageUtilsTest.java index 5d775ae8d..713274a4f 100644 --- a/common/utils/src/test/java/org/graalvm/buildtools/utils/NativeImageUtilsTest.java +++ b/common/utils/src/test/java/org/graalvm/buildtools/utils/NativeImageUtilsTest.java @@ -137,6 +137,17 @@ void checkOracleGraalVMVersion() { Assertions.assertEquals(21, NativeImageUtils.getMajorJDKVersion(oracleGraalVMForJDK21)); } + @Test + void checkOtherGraalVMVersion() { + String otherGraalVMForJDK23 = "native-image 23.0.1 2024-10-15\nJava(TM) SE Runtime Environment Foo Bar 23.0.1+11.1 (build 23.0.1+11-foo-bar-jvmci-b01)\n" + + "Java HotSpot(TM) 64-Bit Server VM Foo Bar 23.0.1+11.1 (build 23.0.1+11-foo-bar-jvmci-b01, mixed mode, sharing)"; + NativeImageUtils.checkVersion("22.3.0", otherGraalVMForJDK23); + NativeImageUtils.checkVersion("23", otherGraalVMForJDK23); + NativeImageUtils.checkVersion("23.0", otherGraalVMForJDK23); + NativeImageUtils.checkVersion("23.0.1", otherGraalVMForJDK23); + Assertions.assertEquals(23, NativeImageUtils.getMajorJDKVersion(otherGraalVMForJDK23)); + } + @Test void checkGreaterVersion() { NativeImageUtils.checkVersion("22", "GraalVM 23.2.1");