Skip to content

Commit 0ea1c6b

Browse files
committed
Address Guillaume's comments
1 parent 2d8ba3e commit 0ea1c6b

File tree

3 files changed

+21
-11
lines changed

3 files changed

+21
-11
lines changed

core/deployment/src/main/java/io/quarkus/deployment/steps/LocaleProcessor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public boolean getAsBoolean() {
116116
*/
117117
@Deprecated
118118
public static String nativeImageUserLanguage(NativeConfig nativeConfig, LocalesBuildTimeConfig localesBuildTimeConfig) {
119-
String language = LocalesBuildTimeConfig.DEFAULT_LANGUAGE;
119+
String language = System.getProperty("user.language", "en");
120120
if (localesBuildTimeConfig.defaultLocale.isPresent()) {
121121
language = localesBuildTimeConfig.defaultLocale.get().getLanguage();
122122
}
@@ -140,7 +140,7 @@ public static String nativeImageUserLanguage(NativeConfig nativeConfig, LocalesB
140140
*/
141141
@Deprecated
142142
public static String nativeImageUserCountry(NativeConfig nativeConfig, LocalesBuildTimeConfig localesBuildTimeConfig) {
143-
String country = LocalesBuildTimeConfig.DEFAULT_COUNTRY;
143+
String country = System.getProperty("user.country", "");
144144
if (localesBuildTimeConfig.defaultLocale.isPresent()) {
145145
country = localesBuildTimeConfig.defaultLocale.get().getCountry();
146146
}

core/deployment/src/main/java/io/quarkus/deployment/steps/NativeImageFeatureStep.java

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -93,23 +93,17 @@ public void write(String s, byte[] bytes) {
9393
overallCatch.invokeStaticMethod(BUILD_TIME_INITIALIZATION,
9494
overallCatch.marshalAsArray(String.class, overallCatch.load(""))); // empty string means initialize everything
9595

96+
ResultHandle graalVMVersion = overallCatch.invokeStaticMethod(GRAALVM_VERSION_GET_CURRENT);
97+
// Set the user.language and user.country system properties to the default locale
9698
// The deprecated option takes precedence for users who are already using it.
9799
if (nativeConfig.userLanguage().isPresent()) {
98100
overallCatch.invokeStaticMethod(REGISTER_RUNTIME_SYSTEM_PROPERTIES,
99101
overallCatch.load("user.language"), overallCatch.load(nativeConfig.userLanguage().get()));
100-
if (nativeConfig.userCountry().isPresent()) {
101-
overallCatch.invokeStaticMethod(REGISTER_RUNTIME_SYSTEM_PROPERTIES,
102-
overallCatch.load("user.country"), overallCatch.load(nativeConfig.userCountry().get()));
103-
}
104102
} else if (localesBuildTimeConfig.defaultLocale.isPresent()) {
105103
overallCatch.invokeStaticMethod(REGISTER_RUNTIME_SYSTEM_PROPERTIES,
106104
overallCatch.load("user.language"),
107105
overallCatch.load(localesBuildTimeConfig.defaultLocale.get().getLanguage()));
108-
overallCatch.invokeStaticMethod(REGISTER_RUNTIME_SYSTEM_PROPERTIES,
109-
overallCatch.load("user.country"),
110-
overallCatch.load(localesBuildTimeConfig.defaultLocale.get().getCountry()));
111106
} else {
112-
ResultHandle graalVMVersion = overallCatch.invokeStaticMethod(GRAALVM_VERSION_GET_CURRENT);
113107
BranchResult graalVm24_2Test = overallCatch
114108
.ifGreaterEqualZero(overallCatch.invokeVirtualMethod(GRAALVM_VERSION_COMPARE_TO, graalVMVersion,
115109
overallCatch.marshalAsArray(int.class, overallCatch.load(24), overallCatch.load(2))));
@@ -118,6 +112,22 @@ public void write(String s, byte[] bytes) {
118112
greaterEqual24_2.invokeStaticMethod(REGISTER_RUNTIME_SYSTEM_PROPERTIES,
119113
greaterEqual24_2.load("user.language"),
120114
greaterEqual24_2.load("en"));
115+
}
116+
}
117+
// The deprecated option takes precedence for users who are already using it.
118+
if (nativeConfig.userCountry().isPresent()) {
119+
overallCatch.invokeStaticMethod(REGISTER_RUNTIME_SYSTEM_PROPERTIES,
120+
overallCatch.load("user.country"), overallCatch.load(nativeConfig.userCountry().get()));
121+
} else if (localesBuildTimeConfig.defaultLocale.isPresent()) {
122+
overallCatch.invokeStaticMethod(REGISTER_RUNTIME_SYSTEM_PROPERTIES,
123+
overallCatch.load("user.country"),
124+
overallCatch.load(localesBuildTimeConfig.defaultLocale.get().getCountry()));
125+
} else {
126+
BranchResult graalVm24_2Test = overallCatch
127+
.ifGreaterEqualZero(overallCatch.invokeVirtualMethod(GRAALVM_VERSION_COMPARE_TO, graalVMVersion,
128+
overallCatch.marshalAsArray(int.class, overallCatch.load(24), overallCatch.load(2))));
129+
/* GraalVM >= 24.2 */
130+
try (BytecodeCreator greaterEqual24_2 = graalVm24_2Test.trueBranch()) {
121131
greaterEqual24_2.invokeStaticMethod(REGISTER_RUNTIME_SYSTEM_PROPERTIES,
122132
greaterEqual24_2.load("user.country"),
123133
greaterEqual24_2.load("US"));

core/runtime/src/main/java/io/quarkus/runtime/LocalesBuildTimeConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,6 @@ public class LocalesBuildTimeConfig {
5151
* Defaults to the JVM's default locale if not set. Starting with GraalVM for JDK 24, it defaults to {@code en-US}
5252
* for native executables.
5353
*/
54-
@ConfigItem(defaultValue = DEFAULT_LANGUAGE + "-" + DEFAULT_COUNTRY, defaultValueDocumentation = "Build system locale")
54+
@ConfigItem()
5555
public Optional<Locale> defaultLocale;
5656
}

0 commit comments

Comments
 (0)