From 115059d515f6273af50fe3f13dec3632a1e108be Mon Sep 17 00:00:00 2001 From: Foivos Zakkak Date: Tue, 14 Nov 2023 09:58:25 +0200 Subject: [PATCH 1/3] Refactor NativeImageBuildStep to reduce code duplication --- .../pkg/builditem/ArtifactResultBuildItem.java | 6 +++--- .../deployment/pkg/steps/JarResultBuildStep.java | 2 +- .../deployment/pkg/steps/NativeImageBuildStep.java | 10 ++-------- .../io/quarkus/runner/bootstrap/AugmentActionImpl.java | 8 +++----- .../java/io/quarkus/bootstrap/app/ArtifactResult.java | 6 +++--- 5 files changed, 12 insertions(+), 20 deletions(-) diff --git a/core/deployment/src/main/java/io/quarkus/deployment/pkg/builditem/ArtifactResultBuildItem.java b/core/deployment/src/main/java/io/quarkus/deployment/pkg/builditem/ArtifactResultBuildItem.java index 031abef44544b..a96468ab8b83a 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/pkg/builditem/ArtifactResultBuildItem.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/pkg/builditem/ArtifactResultBuildItem.java @@ -16,9 +16,9 @@ public final class ArtifactResultBuildItem extends MultiBuildItem { private final Path path; private final String type; - private final Map metadata; + private final Map metadata; - public ArtifactResultBuildItem(Path path, String type, Map metadata) { + public ArtifactResultBuildItem(Path path, String type, Map metadata) { this.path = path; this.type = type; this.metadata = metadata; @@ -32,7 +32,7 @@ public String getType() { return type; } - public Map getMetadata() { + public Map getMetadata() { return metadata; } } diff --git a/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/JarResultBuildStep.java b/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/JarResultBuildStep.java index 06dc22675293c..ad00129f0f466 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/JarResultBuildStep.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/JarResultBuildStep.java @@ -176,7 +176,7 @@ OutputTargetBuildItem outputTarget(BuildSystemTargetBuildItem bst, PackageConfig ArtifactResultBuildItem jarOutput(JarBuildItem jarBuildItem) { if (jarBuildItem.getLibraryDir() != null) { return new ArtifactResultBuildItem(jarBuildItem.getPath(), PackageConfig.JAR, - Collections.singletonMap("library-dir", jarBuildItem.getLibraryDir())); + Collections.singletonMap("library-dir", jarBuildItem.getLibraryDir().toString())); } else { return new ArtifactResultBuildItem(jarBuildItem.getPath(), PackageConfig.JAR, Collections.emptyMap()); } diff --git a/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/NativeImageBuildStep.java b/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/NativeImageBuildStep.java index 77ad5a2dc78eb..33027514c089d 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/NativeImageBuildStep.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/NativeImageBuildStep.java @@ -10,11 +10,9 @@ import java.nio.file.StandardCopyOption; import java.util.ArrayList; import java.util.Collections; -import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Locale; -import java.util.Map; import java.util.Objects; import java.util.Optional; import java.util.stream.Collectors; @@ -89,12 +87,8 @@ void nativeImageFeatures(BuildProducer features) { @BuildStep(onlyIf = NativeBuild.class) ArtifactResultBuildItem result(NativeImageBuildItem image) { NativeImageBuildItem.GraalVMVersion graalVMVersion = image.getGraalVMInfo(); - Map graalVMInfoProps = new HashMap<>(); - graalVMInfoProps.put("graalvm.version.full", graalVMVersion.getFullVersion()); - graalVMInfoProps.put("graalvm.version.version", graalVMVersion.getVersion()); - graalVMInfoProps.put("graalvm.version.javaVersion", "" + graalVMVersion.getJavaVersion()); - graalVMInfoProps.put("graalvm.version.distribution", graalVMVersion.getDistribution()); - return new ArtifactResultBuildItem(image.getPath(), PackageConfig.NATIVE, graalVMInfoProps); + return new ArtifactResultBuildItem(image.getPath(), PackageConfig.BuiltInType.NATIVE.getValue(), + graalVMVersion.toMap()); } @BuildStep(onlyIf = NativeSourcesBuild.class) diff --git a/core/deployment/src/main/java/io/quarkus/runner/bootstrap/AugmentActionImpl.java b/core/deployment/src/main/java/io/quarkus/runner/bootstrap/AugmentActionImpl.java index ecba0b08bbfbe..d6df9bc896645 100644 --- a/core/deployment/src/main/java/io/quarkus/runner/bootstrap/AugmentActionImpl.java +++ b/core/deployment/src/main/java/io/quarkus/runner/bootstrap/AugmentActionImpl.java @@ -228,12 +228,10 @@ private void writeArtifactResultMetadataFile(BuildSystemTargetBuildItem outputTa if (lastResult.getPath() != null) { properties.put("path", outputTargetBuildItem.getOutputDirectory().relativize(lastResult.getPath()).toString()); } - Map metadata = lastResult.getMetadata(); + Map metadata = lastResult.getMetadata(); if (metadata != null) { - for (Map.Entry entry : metadata.entrySet()) { - if (entry.getValue() instanceof String) { - properties.put("metadata." + entry.getKey(), entry.getValue()); - } + for (Map.Entry entry : metadata.entrySet()) { + properties.put("metadata." + entry.getKey(), entry.getValue()); } } try (FileOutputStream fos = new FileOutputStream(quarkusArtifactMetadataPath.toFile())) { diff --git a/independent-projects/bootstrap/core/src/main/java/io/quarkus/bootstrap/app/ArtifactResult.java b/independent-projects/bootstrap/core/src/main/java/io/quarkus/bootstrap/app/ArtifactResult.java index 640bc85b18df8..ba6aaf68ab579 100644 --- a/independent-projects/bootstrap/core/src/main/java/io/quarkus/bootstrap/app/ArtifactResult.java +++ b/independent-projects/bootstrap/core/src/main/java/io/quarkus/bootstrap/app/ArtifactResult.java @@ -7,9 +7,9 @@ public class ArtifactResult { private final Path path; private final String type; - private final Map metadata; + private final Map metadata; - public ArtifactResult(Path path, String type, Map metadata) { + public ArtifactResult(Path path, String type, Map metadata) { this.path = path; this.type = type; this.metadata = metadata; @@ -23,7 +23,7 @@ public String getType() { return type; } - public Map getMetadata() { + public Map getMetadata() { return metadata; } } From ee6f56664a92c1dae7d9a2fefff4cdc19560c5cc Mon Sep 17 00:00:00 2001 From: Foivos Zakkak Date: Tue, 14 Nov 2023 10:10:00 +0200 Subject: [PATCH 2/3] Fix version retrieval from quarkus-artifact.properties The parseable version is in `metadata.graalvm.version.full` not in `metadata.graalvm.version.version`. --- .../test/junit/DisableIfBuiltWithGraalVMNewerThanCondition.java | 2 +- .../test/junit/DisableIfBuiltWithGraalVMOlderThanCondition.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test-framework/junit5/src/main/java/io/quarkus/test/junit/DisableIfBuiltWithGraalVMNewerThanCondition.java b/test-framework/junit5/src/main/java/io/quarkus/test/junit/DisableIfBuiltWithGraalVMNewerThanCondition.java index 57a48a22a7209..4304ec31ff042 100644 --- a/test-framework/junit5/src/main/java/io/quarkus/test/junit/DisableIfBuiltWithGraalVMNewerThanCondition.java +++ b/test-framework/junit5/src/main/java/io/quarkus/test/junit/DisableIfBuiltWithGraalVMNewerThanCondition.java @@ -36,7 +36,7 @@ public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext con Properties quarkusArtifactProperties = readQuarkusArtifactProperties(context); try { GraalVM.Version version = GraalVM.Version - .of(quarkusArtifactProperties.getProperty("metadata.graalvm.version.version").lines()); + .of(quarkusArtifactProperties.getProperty("metadata.graalvm.version.full").lines()); int comparison = annotationValue.getVersion().compareTo(version); if (comparison < 0) { return ConditionEvaluationResult.disabled("Native binary was built with GraalVM{version=" + version.toString() diff --git a/test-framework/junit5/src/main/java/io/quarkus/test/junit/DisableIfBuiltWithGraalVMOlderThanCondition.java b/test-framework/junit5/src/main/java/io/quarkus/test/junit/DisableIfBuiltWithGraalVMOlderThanCondition.java index d7cf3db239844..44eda6c744d4a 100644 --- a/test-framework/junit5/src/main/java/io/quarkus/test/junit/DisableIfBuiltWithGraalVMOlderThanCondition.java +++ b/test-framework/junit5/src/main/java/io/quarkus/test/junit/DisableIfBuiltWithGraalVMOlderThanCondition.java @@ -36,7 +36,7 @@ public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext con Properties quarkusArtifactProperties = readQuarkusArtifactProperties(context); try { GraalVM.Version version = GraalVM.Version - .of(quarkusArtifactProperties.getProperty("metadata.graalvm.version.version").lines()); + .of(quarkusArtifactProperties.getProperty("metadata.graalvm.version.full").lines()); int comparison = annotationValue.getVersion().compareTo(version); if (comparison > 0) { return ConditionEvaluationResult.disabled("Native binary was built with GraalVM{version=" + version.toString() From 4f6c97e71d6db8455438e4aebd50478561af71bd Mon Sep 17 00:00:00 2001 From: Foivos Zakkak Date: Tue, 14 Nov 2023 10:13:57 +0200 Subject: [PATCH 3/3] Make testLambdaCapturing conditional on GraalVM version Starting with GraalVM 24.0 lambda class names match the ones from HotSpot. --- .../it/main/RegisterForReflectionITCase.java | 16 +++++++++++++--- .../io/quarkus/test/junit/GraalVMVersion.java | 3 ++- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/integration-tests/main/src/test/java/io/quarkus/it/main/RegisterForReflectionITCase.java b/integration-tests/main/src/test/java/io/quarkus/it/main/RegisterForReflectionITCase.java index 53fb22ecfc1b7..ef72c927992f2 100644 --- a/integration-tests/main/src/test/java/io/quarkus/it/main/RegisterForReflectionITCase.java +++ b/integration-tests/main/src/test/java/io/quarkus/it/main/RegisterForReflectionITCase.java @@ -5,6 +5,9 @@ import org.junit.jupiter.api.Test; +import io.quarkus.test.junit.DisableIfBuiltWithGraalVMNewerThan; +import io.quarkus.test.junit.DisableIfBuiltWithGraalVMOlderThan; +import io.quarkus.test.junit.GraalVMVersion; import io.quarkus.test.junit.QuarkusIntegrationTest; import io.restassured.RestAssured; @@ -56,14 +59,21 @@ public void testTargetWithoutNested() { } @Test - public void testLambdaCapturing() { - final String resourceLambda = BASE_PKG + ".ResourceLambda"; - + @DisableIfBuiltWithGraalVMNewerThan(GraalVMVersion.GRAALVM_23_1_0) + public void testLambdaCapturingPre24_0() { // Starting with GraalVM 22.1 support Lambda functions serialization // (see https://github.com/oracle/graal/issues/3756) RestAssured.given().when().get("/reflection/lambda").then().body(startsWith("Comparator$$Lambda$")); } + @Test + @DisableIfBuiltWithGraalVMOlderThan(GraalVMVersion.GRAALVM_24_0_0) + public void testLambdaCapturingPost23_1() { + // Starting with GraalVM 24.0 lambda class names match the ones from HotSpot + // (see https://github.com/oracle/graal/pull/7775) + RestAssured.given().when().get("/reflection/lambda").then().body(startsWith("Comparator$$Lambda/")); + } + private void assertRegistration(String expected, String queryParam) { RestAssured.given().queryParam("className", queryParam).when().get(ENDPOINT).then().body(is(expected)); } diff --git a/test-framework/junit5/src/main/java/io/quarkus/test/junit/GraalVMVersion.java b/test-framework/junit5/src/main/java/io/quarkus/test/junit/GraalVMVersion.java index c157cfbdb0ff2..df95a13f166b9 100644 --- a/test-framework/junit5/src/main/java/io/quarkus/test/junit/GraalVMVersion.java +++ b/test-framework/junit5/src/main/java/io/quarkus/test/junit/GraalVMVersion.java @@ -3,7 +3,8 @@ import io.quarkus.deployment.pkg.steps.GraalVM; public enum GraalVMVersion { - GRAALVM_23_1_0(GraalVM.Version.VERSION_23_1_0); + GRAALVM_23_1_0(GraalVM.Version.VERSION_23_1_0), + GRAALVM_24_0_0(GraalVM.Version.VERSION_24_0_0); private final GraalVM.Version version;