From 5fe6d49a871cb6509ecf91845147cb33c78a6b84 Mon Sep 17 00:00:00 2001 From: Guillaume Smet Date: Tue, 20 Jun 2023 10:46:24 +0200 Subject: [PATCH] Fix version detection when the image is downloaded for the first time We need to filter the output coming from Docker downloading the image. --- .../quarkus/deployment/pkg/steps/GraalVM.java | 24 ++++++-------- .../deployment/pkg/steps/GraalVMTest.java | 31 +++++++++++++++++++ 2 files changed, 40 insertions(+), 15 deletions(-) diff --git a/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/GraalVM.java b/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/GraalVM.java index c0d2800571e177..2487ddbcff85b5 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/GraalVM.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/GraalVM.java @@ -1,8 +1,5 @@ package io.quarkus.deployment.pkg.steps; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -200,17 +197,20 @@ public int compareTo(Version o) { return this.version.compareTo(o.version); } - static Version of(Stream lines) { - List linesList = toList(lines); // relies on ordering of the stream - if (linesList.size() == 3) { + static Version of(Stream output) { + List lines = output + .dropWhile(l -> !l.startsWith("GraalVM") && !l.startsWith("native-image")) + .collect(Collectors.toUnmodifiableList()); + + if (lines.size() == 3) { // Attempt to parse the new 3-line version scheme first. - Version v = VersionParseHelper.parse(linesList); + Version v = VersionParseHelper.parse(lines); if (v != VersionParseHelper.UNKNOWN_VERSION) { return v; } - } else if (linesList.size() == 1) { + } else if (lines.size() == 1) { // Old, single line version parsing logic - final String line = linesList.get(0); + final String line = lines.get(0); final Matcher oldVersMatcher = OLD_VERS_PATTERN.matcher(line); if (oldVersMatcher.find()) { // GraalVM/Mandrel old, single line, version scheme: @@ -237,12 +237,6 @@ static Version of(Stream lines) { return UNVERSIONED; } - // For JDK 11 source level compatibility. stream.toList() API is JDK 16+ - @SuppressWarnings("unchecked") - private static List toList(Stream stream) { - return (List) Collections.unmodifiableList(new ArrayList<>(Arrays.asList(stream.toArray()))); - } - private static boolean isMandrel(String s) { return s != null && s.contains("Mandrel Distribution"); } diff --git a/core/deployment/src/test/java/io/quarkus/deployment/pkg/steps/GraalVMTest.java b/core/deployment/src/test/java/io/quarkus/deployment/pkg/steps/GraalVMTest.java index 4ebafae2fed33d..f795aab93638d3 100644 --- a/core/deployment/src/test/java/io/quarkus/deployment/pkg/steps/GraalVMTest.java +++ b/core/deployment/src/test/java/io/quarkus/deployment/pkg/steps/GraalVMTest.java @@ -27,10 +27,41 @@ public void testGraalVMVersionDetected() { Version.of(Stream.of(("native-image 17.0.6 2023-01-17\n" + "GraalVM Runtime Environment Mandrel-23.0.0-dev (build 17.0.6+10)\n" + "Substrate VM Mandrel-23.0.0-dev (build 17.0.6+10, serial gc)").split("\\n")))); + assertVersion(org.graalvm.home.Version.create(23, 0, 0), MANDREL, + Version.of(Stream.of(("native-image 17.0.7 2023-04-18\n" + + "OpenJDK Runtime Environment Mandrel-23.0.0.0-Final (build 17.0.7+7)\n" + + "OpenJDK 64-Bit Server VM Mandrel-23.0.0.0-Final (build 17.0.7+7, mixed mode)").split("\\n")))); + // should also work when the image is not around and we have to download it + assertVersion(org.graalvm.home.Version.create(23, 0, 0), MANDREL, + Version.of( + Stream.of(("Unable to find image 'quay.io/quarkus/ubi-quarkus-mandrel-builder-image:jdk-17' locally\n" + + "jdk-17: Pulling from quarkus/ubi-quarkus-mandrel-builder-image\n" + + "a49367d57626: Already exists\n" + + "3a83b3d8356a: Already exists\n" + + "d8dd24f2bc88: Already exists\n" + + "99bd64fd6c37: Already exists\n" + + "7a13281b4a63: Already exists\n" + + "ae3db351551e: Already exists\n" + + "eee108cfab2c: Already exists\n" + + "d38abde1651d: Already exists\n" + + "cac4ef5d11c0: Already exists\n" + + "89e5b13e9084: Already exists\n" + + "68897e59054c: Already exists\n" + + "774633828afc: Already exists\n" + + "6708d473f3dc: Already exists\n" + + "4f4fb700ef54: Already exists\n" + + "4f4fb700ef54: Already exists\n" + + "Digest: sha256:2833f8ed2cdfcbdf88134a46b5ab7e4dfee8f7cbde60f819f86e59eb73c2491c\n" + + "Status: Downloaded newer image for quay.io/quarkus/ubi-quarkus-mandrel-builder-image:jdk-17\n" + + "native-image 17.0.7 2023-04-18\n" + + "OpenJDK Runtime Environment Mandrel-23.0.0.0-Final (build 17.0.7+7)\n" + + "OpenJDK 64-Bit Server VM Mandrel-23.0.0.0-Final (build 17.0.7+7, mixed mode)") + .split("\\n")))); assertVersion(org.graalvm.home.Version.create(23, 0), ORACLE, Version.of(Stream.of(("native-image 20 2023-03-21\n" + "GraalVM Runtime Environment GraalVM CE (build 20+34-jvmci-23.0-b10)\n" + "Substrate VM GraalVM CE (build 20+34, serial gc)").split("\\n")))); + // Older version parsing assertVersion(org.graalvm.home.Version.create(20, 1), ORACLE, Version.of(Stream.of("GraalVM Version 20.1.0 (Java Version 11.0.7)")));