Skip to content

Commit

Permalink
Adapt locales support for GraalVM >= 24.2
Browse files Browse the repository at this point in the history
Starting with GraalVM for JDK 24 (24.2) native image will no longer set
the locale default at build time. As a result, the default locale won't
be included by default in the native image unless explicitly specified.

See oracle/graal#9694
  • Loading branch information
zakkak committed Sep 23, 2024
1 parent ffd0c78 commit af4f16c
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ public static final class Version implements Comparable<Version> {
public static final Version VERSION_23_0_0 = new Version("GraalVM 23.0.0", "23.0.0", "17", Distribution.GRAALVM);
public static final Version VERSION_23_1_0 = new Version("GraalVM 23.1.0", "23.1.0", "21", Distribution.GRAALVM);
public static final Version VERSION_24_0_0 = new Version("GraalVM 24.0.0", "24.0.0", "22", Distribution.GRAALVM);
public static final Version VERSION_24_1_0 = new Version("GraalVM 24.1.0", "24.1.0", "23", Distribution.GRAALVM);
public static final Version VERSION_24_2_0 = new Version("GraalVM 24.2.0", "24.2.0", "24", Distribution.GRAALVM);

/**
* The minimum version of GraalVM supported by Quarkus.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -750,23 +750,35 @@ public NativeImageInvokerInfo build() {
}

final String userLanguage = LocaleProcessor.nativeImageUserLanguage(nativeConfig, localesBuildTimeConfig);
String userLocale = "";
if (!userLanguage.isEmpty()) {
nativeImageArgs.add("-J-Duser.language=" + userLanguage);
userLocale = userLanguage;
}
final String userCountry = LocaleProcessor.nativeImageUserCountry(nativeConfig, localesBuildTimeConfig);
if (!userCountry.isEmpty()) {
nativeImageArgs.add("-J-Duser.country=" + userCountry);
if (!userLocale.isEmpty()) {
userLocale += "," + userCountry;
}
}
final String includeLocales = LocaleProcessor.nativeImageIncludeLocales(nativeConfig, localesBuildTimeConfig);
String includeLocales = LocaleProcessor.nativeImageIncludeLocales(nativeConfig, localesBuildTimeConfig);
if (!includeLocales.isEmpty()) {
if ("all".equals(includeLocales)) {
log.warn(
"Your application is setting the 'quarkus.locales' configuration key to include 'all'. " +
"All JDK locales, languages, currencies, etc. will be included, inflating the size of the executable.");
addExperimentalVMOption(nativeImageArgs, "-H:+IncludeAllLocales");
} else {
// Explicitly include user's locale (needed since https://github.com/oracle/graal/pull/9694)
if (!userLocale.isEmpty()) {
includeLocales += "," + userLocale;
}
addExperimentalVMOption(nativeImageArgs, "-H:IncludeLocales=" + includeLocales);
}
} else if (!userLocale.isEmpty()) {
// Explicitly include user's locale (needed since https://github.com/oracle/graal/pull/9694)
addExperimentalVMOption(nativeImageArgs, "-H:IncludeLocales=" + userLocale);
}

nativeImageArgs.add("-J-Dfile.encoding=" + nativeConfig.fileEncoding());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import static org.hamcrest.Matchers.equalToIgnoringCase;
import static org.hamcrest.Matchers.is;

import io.quarkus.test.junit.DisableIfBuiltWithGraalVMNewerThan;
import io.quarkus.test.junit.DisableIfBuiltWithGraalVMOlderThan;
import io.quarkus.test.junit.GraalVMVersion;
import org.apache.http.HttpStatus;
import org.jboss.logging.Logger;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -81,7 +84,8 @@ public void testTimeZones(String zone, String language, String name) {
}

@Test
public void testDefaultLocale() {
@DisableIfBuiltWithGraalVMNewerThan(value = GraalVMVersion.GRAALVM_24_1_0)
public void testDefaultLocaleBefore24_2() {
RestAssured.given().when()
.get("/default/de-CH")
.then()
Expand All @@ -94,6 +98,21 @@ public void testDefaultLocale() {
.log().all();
}

@Test
@DisableIfBuiltWithGraalVMOlderThan(value = GraalVMVersion.GRAALVM_24_2_0)
public void testDefaultLocaleAfter24_1() {
RestAssured.given().when()
.get("/default/de-CH")
.then()
.statusCode(HttpStatus.SC_OK)
/*
* "Schweiz" is the correct name for Switzerland in German.
* German is the default language as per the application.properties.
*/
.body(is("Schweiz"))
.log().all();
}

@Test
public void testMissingLocaleSorryItaly() {
RestAssured.given().when()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ quarkus.locales=de,fr-FR,ja,uk-UA
# used in your application properties. This test uses it only to verify compatibility.
quarkus.native.user-language=cs
quarkus.default-locale=en-US
quarkus.test.arg-line=-Duser.language=de
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

public enum GraalVMVersion {
GRAALVM_23_1_0(GraalVM.Version.VERSION_23_1_0),
GRAALVM_24_0_0(GraalVM.Version.VERSION_24_0_0);
GRAALVM_24_0_0(GraalVM.Version.VERSION_24_0_0),
GRAALVM_24_1_0(GraalVM.Version.VERSION_24_1_0),
GRAALVM_24_2_0(GraalVM.Version.VERSION_24_2_0);

private final GraalVM.Version version;

Expand Down

0 comments on commit af4f16c

Please sign in to comment.