Skip to content

Commit

Permalink
Address Guillaume's comments
Browse files Browse the repository at this point in the history
  • Loading branch information
zakkak committed Oct 17, 2024
1 parent 2d8ba3e commit 0ea1c6b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))));
Expand All @@ -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"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Locale> defaultLocale;
}

0 comments on commit 0ea1c6b

Please sign in to comment.