From ac3e7b3e00d2c3202aff224c59c982d736715dbf Mon Sep 17 00:00:00 2001 From: Foivos Zakkak Date: Wed, 16 Oct 2024 10:05:23 +0300 Subject: [PATCH 1/2] Don't pass '--enable-monitoring=heapdump' unconditionally on windows The feature is not supported on Windows Closes https://github.com/quarkusio/quarkus/issues/43895 --- .../deployment/pkg/steps/NativeImageBuildStep.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) 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 5a6f9643ceb58..2c4be668f23d7 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 @@ -932,13 +932,18 @@ public NativeImageInvokerInfo build() { } List monitoringOptions = new ArrayList<>(); - monitoringOptions.add(NativeConfig.MonitoringOption.HEAPDUMP); + if (!SystemUtils.IS_OS_WINDOWS || containerBuild) { + // --enable-monitoring=heapdump is not supported on Windows + monitoringOptions.add(NativeConfig.MonitoringOption.HEAPDUMP); + } if (nativeConfig.monitoring().isPresent()) { monitoringOptions.addAll(nativeConfig.monitoring().get()); } - nativeImageArgs.add("--enable-monitoring=" + monitoringOptions.stream() - .distinct() - .map(o -> o.name().toLowerCase(Locale.ROOT)).collect(Collectors.joining(","))); + if (!monitoringOptions.isEmpty()) { + nativeImageArgs.add("--enable-monitoring=" + monitoringOptions.stream() + .distinct() + .map(o -> o.name().toLowerCase(Locale.ROOT)).collect(Collectors.joining(","))); + } if (nativeConfig.autoServiceLoaderRegistration()) { addExperimentalVMOption(nativeImageArgs, "-H:+UseServiceLoaderFeature"); From 26c2c4833aa4860220824cbd5710222e66889fc2 Mon Sep 17 00:00:00 2001 From: Foivos Zakkak Date: Wed, 16 Oct 2024 11:24:37 +0300 Subject: [PATCH 2/2] Refactor: Use io.smallrye.common.os.OS Instead of org.apache.commons.lang3.SystemUtils; --- .../deployment/pkg/steps/NativeImageBuildStep.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) 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 2c4be668f23d7..287b61399b985 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 @@ -18,7 +18,6 @@ import java.util.stream.Collectors; import java.util.stream.Stream; -import org.apache.commons.lang3.SystemUtils; import org.jboss.logging.Logger; import io.quarkus.bootstrap.util.IoUtils; @@ -53,6 +52,7 @@ import io.quarkus.runtime.graal.DisableLoggingFeature; import io.quarkus.sbom.ApplicationComponent; import io.quarkus.sbom.ApplicationManifestConfig; +import io.smallrye.common.os.OS; public class NativeImageBuildStep { @@ -210,7 +210,7 @@ public NativeImageBuildItem build(NativeConfig nativeConfig, LocalesBuildTimeCon String pie = ""; boolean isContainerBuild = nativeImageRunner.isContainerBuild(); - if (!isContainerBuild && SystemUtils.IS_OS_LINUX) { + if (!isContainerBuild && OS.LINUX.isCurrent()) { if (nativeConfig.pie().isPresent() && nativeConfig.pie().get()) { pie = detectPIE(); } else { @@ -332,7 +332,7 @@ private String getNativeImageName(OutputTargetBuildItem outputTargetBuildItem, P private String getResultingExecutableName(String nativeImageName, boolean isContainerBuild) { String resultingExecutableName = nativeImageName; - if (SystemUtils.IS_OS_WINDOWS && !isContainerBuild) { + if (OS.WINDOWS.isCurrent() && !isContainerBuild) { //once image is generated it gets added .exe on Windows resultingExecutableName = resultingExecutableName + ".exe"; } @@ -354,7 +354,7 @@ public NativeImageRunnerBuildItem resolveNativeImageBuildRunner(NativeConfig nat String executableName = getNativeImageExecutableName(); String errorMessage = "Cannot find the `" + executableName + "` in the GRAALVM_HOME, JAVA_HOME and System PATH."; - if (!SystemUtils.IS_OS_LINUX) { + if (!OS.LINUX.isCurrent()) { // Delay the error: if we're just building native sources, we may not need the build runner at all. return new NativeImageRunnerBuildItem(new NativeImageBuildRunnerError(errorMessage)); } @@ -474,7 +474,7 @@ private static void copySourcesToSourceCache(OutputTargetBuildItem outputTargetB private RuntimeException imageGenerationFailed(int exitValue, boolean isContainerBuild) { if (exitValue == OOM_ERROR_VALUE) { - if (isContainerBuild && !SystemUtils.IS_OS_LINUX) { + if (isContainerBuild && !OS.LINUX.isCurrent()) { return new ImageGenerationFailureException("Image generation failed. Exit code was " + exitValue + " which indicates an out of memory error. The most likely cause is Docker not being given enough memory. Also consider increasing the Xmx value for native image generation by setting the \"" + QUARKUS_XMX_PROPERTY + "\" property"); @@ -554,7 +554,7 @@ private static NativeImageBuildLocalRunner getNativeImageBuildLocalRunner(Native } private static String getNativeImageExecutableName() { - return SystemUtils.IS_OS_WINDOWS ? "native-image.cmd" : "native-image"; + return OS.WINDOWS.isCurrent() ? "native-image.cmd" : "native-image"; } private static String detectNoPIE() { @@ -932,7 +932,7 @@ public NativeImageInvokerInfo build() { } List monitoringOptions = new ArrayList<>(); - if (!SystemUtils.IS_OS_WINDOWS || containerBuild) { + if (!OS.WINDOWS.isCurrent() || containerBuild) { // --enable-monitoring=heapdump is not supported on Windows monitoringOptions.add(NativeConfig.MonitoringOption.HEAPDUMP); }