From 0ea1c6b63a00a491575a4d0da2c01d8cadc6d5cc Mon Sep 17 00:00:00 2001 From: Foivos Zakkak Date: Thu, 17 Oct 2024 12:08:33 +0300 Subject: [PATCH] Address Guillaume's comments --- .../deployment/steps/LocaleProcessor.java | 4 +-- .../steps/NativeImageFeatureStep.java | 26 +++++++++++++------ .../runtime/LocalesBuildTimeConfig.java | 2 +- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/core/deployment/src/main/java/io/quarkus/deployment/steps/LocaleProcessor.java b/core/deployment/src/main/java/io/quarkus/deployment/steps/LocaleProcessor.java index ef44b09da972c..ba3062e7ae52e 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/steps/LocaleProcessor.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/steps/LocaleProcessor.java @@ -116,7 +116,7 @@ public boolean getAsBoolean() { */ @Deprecated public static String nativeImageUserLanguage(NativeConfig nativeConfig, LocalesBuildTimeConfig localesBuildTimeConfig) { - String language = LocalesBuildTimeConfig.DEFAULT_LANGUAGE; + String language = System.getProperty("user.language", "en"); if (localesBuildTimeConfig.defaultLocale.isPresent()) { language = localesBuildTimeConfig.defaultLocale.get().getLanguage(); } @@ -140,7 +140,7 @@ public static String nativeImageUserLanguage(NativeConfig nativeConfig, LocalesB */ @Deprecated public static String nativeImageUserCountry(NativeConfig nativeConfig, LocalesBuildTimeConfig localesBuildTimeConfig) { - String country = LocalesBuildTimeConfig.DEFAULT_COUNTRY; + String country = System.getProperty("user.country", ""); if (localesBuildTimeConfig.defaultLocale.isPresent()) { country = localesBuildTimeConfig.defaultLocale.get().getCountry(); } diff --git a/core/deployment/src/main/java/io/quarkus/deployment/steps/NativeImageFeatureStep.java b/core/deployment/src/main/java/io/quarkus/deployment/steps/NativeImageFeatureStep.java index bd1c13c911eb0..8b585e4d37131 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/steps/NativeImageFeatureStep.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/steps/NativeImageFeatureStep.java @@ -93,23 +93,17 @@ public void write(String s, byte[] bytes) { overallCatch.invokeStaticMethod(BUILD_TIME_INITIALIZATION, overallCatch.marshalAsArray(String.class, overallCatch.load(""))); // empty string means initialize everything + ResultHandle graalVMVersion = overallCatch.invokeStaticMethod(GRAALVM_VERSION_GET_CURRENT); + // Set the user.language and user.country system properties to the default locale // The deprecated option takes precedence for users who are already using it. if (nativeConfig.userLanguage().isPresent()) { overallCatch.invokeStaticMethod(REGISTER_RUNTIME_SYSTEM_PROPERTIES, overallCatch.load("user.language"), overallCatch.load(nativeConfig.userLanguage().get())); - if (nativeConfig.userCountry().isPresent()) { - overallCatch.invokeStaticMethod(REGISTER_RUNTIME_SYSTEM_PROPERTIES, - overallCatch.load("user.country"), overallCatch.load(nativeConfig.userCountry().get())); - } } else if (localesBuildTimeConfig.defaultLocale.isPresent()) { overallCatch.invokeStaticMethod(REGISTER_RUNTIME_SYSTEM_PROPERTIES, overallCatch.load("user.language"), overallCatch.load(localesBuildTimeConfig.defaultLocale.get().getLanguage())); - overallCatch.invokeStaticMethod(REGISTER_RUNTIME_SYSTEM_PROPERTIES, - overallCatch.load("user.country"), - overallCatch.load(localesBuildTimeConfig.defaultLocale.get().getCountry())); } else { - ResultHandle graalVMVersion = overallCatch.invokeStaticMethod(GRAALVM_VERSION_GET_CURRENT); BranchResult graalVm24_2Test = overallCatch .ifGreaterEqualZero(overallCatch.invokeVirtualMethod(GRAALVM_VERSION_COMPARE_TO, graalVMVersion, overallCatch.marshalAsArray(int.class, overallCatch.load(24), overallCatch.load(2)))); @@ -118,6 +112,22 @@ public void write(String s, byte[] bytes) { greaterEqual24_2.invokeStaticMethod(REGISTER_RUNTIME_SYSTEM_PROPERTIES, greaterEqual24_2.load("user.language"), greaterEqual24_2.load("en")); + } + } + // The deprecated option takes precedence for users who are already using it. + if (nativeConfig.userCountry().isPresent()) { + overallCatch.invokeStaticMethod(REGISTER_RUNTIME_SYSTEM_PROPERTIES, + overallCatch.load("user.country"), overallCatch.load(nativeConfig.userCountry().get())); + } else if (localesBuildTimeConfig.defaultLocale.isPresent()) { + overallCatch.invokeStaticMethod(REGISTER_RUNTIME_SYSTEM_PROPERTIES, + overallCatch.load("user.country"), + overallCatch.load(localesBuildTimeConfig.defaultLocale.get().getCountry())); + } else { + BranchResult graalVm24_2Test = overallCatch + .ifGreaterEqualZero(overallCatch.invokeVirtualMethod(GRAALVM_VERSION_COMPARE_TO, graalVMVersion, + overallCatch.marshalAsArray(int.class, overallCatch.load(24), overallCatch.load(2)))); + /* GraalVM >= 24.2 */ + try (BytecodeCreator greaterEqual24_2 = graalVm24_2Test.trueBranch()) { greaterEqual24_2.invokeStaticMethod(REGISTER_RUNTIME_SYSTEM_PROPERTIES, greaterEqual24_2.load("user.country"), greaterEqual24_2.load("US")); diff --git a/core/runtime/src/main/java/io/quarkus/runtime/LocalesBuildTimeConfig.java b/core/runtime/src/main/java/io/quarkus/runtime/LocalesBuildTimeConfig.java index e3d1bfc077544..311b54dd70a50 100644 --- a/core/runtime/src/main/java/io/quarkus/runtime/LocalesBuildTimeConfig.java +++ b/core/runtime/src/main/java/io/quarkus/runtime/LocalesBuildTimeConfig.java @@ -51,6 +51,6 @@ public class LocalesBuildTimeConfig { * Defaults to the JVM's default locale if not set. Starting with GraalVM for JDK 24, it defaults to {@code en-US} * for native executables. */ - @ConfigItem(defaultValue = DEFAULT_LANGUAGE + "-" + DEFAULT_COUNTRY, defaultValueDocumentation = "Build system locale") + @ConfigItem() public Optional defaultLocale; }