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 8db1bafb7a1096..2de3d952c85232 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 @@ -80,9 +80,9 @@ public boolean getAsBoolean() { (nativeConfig.userCountry().isPresent() && !Locale.getDefault().getCountry().equals(nativeConfig.userCountry().get())) || - !Locale.getDefault().equals(localesBuildTimeConfig.defaultLocale) + !Locale.getDefault().equals(localesBuildTimeConfig.defaultLocale()) || - localesBuildTimeConfig.locales.stream().anyMatch(l -> !Locale.getDefault().equals(l)); + localesBuildTimeConfig.locales().stream().anyMatch(l -> !Locale.getDefault().equals(l)); } } @@ -95,7 +95,7 @@ public boolean getAsBoolean() { * effectively LocalesBuildTimeConfig.DEFAULT_LANGUAGE if none of the aforementioned is set. */ public static String nativeImageUserLanguage(NativeConfig nativeConfig, LocalesBuildTimeConfig localesBuildTimeConfig) { - String language = localesBuildTimeConfig.defaultLocale.getLanguage(); + String language = localesBuildTimeConfig.defaultLocale().getLanguage(); if (nativeConfig.userLanguage().isPresent()) { log.warn(DEPRECATED_USER_LANGUAGE_WARNING); // The deprecated option takes precedence for users who are already using it. @@ -114,7 +114,7 @@ public static String nativeImageUserLanguage(NativeConfig nativeConfig, LocalesB * set. */ public static String nativeImageUserCountry(NativeConfig nativeConfig, LocalesBuildTimeConfig localesBuildTimeConfig) { - String country = localesBuildTimeConfig.defaultLocale.getCountry(); + String country = localesBuildTimeConfig.defaultLocale().getCountry(); if (nativeConfig.userCountry().isPresent()) { log.warn(DEPRECATED_USER_COUNTRY_WARNING); // The deprecated option takes precedence for users who are already using it. @@ -133,7 +133,7 @@ public static String nativeImageUserCountry(NativeConfig nativeConfig, LocalesBu */ public static String nativeImageIncludeLocales(NativeConfig nativeConfig, LocalesBuildTimeConfig localesBuildTimeConfig) { // We start with what user sets as needed locales - final Set additionalLocales = new HashSet<>(localesBuildTimeConfig.locales); + final Set additionalLocales = new HashSet<>(localesBuildTimeConfig.locales()); if (additionalLocales.contains(Locale.ROOT)) { return "all"; @@ -141,7 +141,7 @@ public static String nativeImageIncludeLocales(NativeConfig nativeConfig, Locale // We subtract what we already declare for native-image's user.language or user.country. // Note the deprecated options still count. - additionalLocales.remove(localesBuildTimeConfig.defaultLocale); + additionalLocales.remove(localesBuildTimeConfig.defaultLocale()); if (nativeConfig.userCountry().isPresent() && nativeConfig.userLanguage().isPresent()) { additionalLocales.remove(new Locale(nativeConfig.userLanguage().get(), nativeConfig.userCountry().get())); } else if (nativeConfig.userLanguage().isPresent()) { 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 deb6fd4dae7a35..724e618d62e875 100644 --- a/core/runtime/src/main/java/io/quarkus/runtime/LocalesBuildTimeConfig.java +++ b/core/runtime/src/main/java/io/quarkus/runtime/LocalesBuildTimeConfig.java @@ -3,16 +3,18 @@ import java.util.Locale; import java.util.Set; -import io.quarkus.runtime.annotations.ConfigItem; import io.quarkus.runtime.annotations.ConfigPhase; import io.quarkus.runtime.annotations.ConfigRoot; +import io.smallrye.config.ConfigMapping; +import io.smallrye.config.WithDefault; -@ConfigRoot(name = ConfigItem.PARENT, phase = ConfigPhase.BUILD_AND_RUN_TIME_FIXED) -public class LocalesBuildTimeConfig { +@ConfigRoot(phase = ConfigPhase.BUILD_AND_RUN_TIME_FIXED) +@ConfigMapping(prefix = "quarkus") +public interface LocalesBuildTimeConfig { // We set to en as the default language when all else fails since this is what the JDK does as well - public static final String DEFAULT_LANGUAGE = "${user.language:en}"; - public static final String DEFAULT_COUNTRY = "${user.country:}"; + String DEFAULT_LANGUAGE = "${user.language:en}"; + String DEFAULT_COUNTRY = "${user.country:}"; /** * The set of supported locales that can be consumed by the extensions. @@ -27,9 +29,8 @@ public class LocalesBuildTimeConfig { * A special string "all" is translated as ROOT Locale and then used in native-image * to include all locales. Image size penalty applies. */ - @ConfigItem(defaultValue = DEFAULT_LANGUAGE + "-" - + DEFAULT_COUNTRY, defaultValueDocumentation = "Set containing the build system locale") - public Set locales; + @WithDefault(DEFAULT_LANGUAGE + "-" + DEFAULT_COUNTRY) + Set locales(); /** * Default locale that can be consumed by the extensions. @@ -41,6 +42,6 @@ public class LocalesBuildTimeConfig { * Native-image build uses this property to derive {@code user.language} and {@code user.country} for the application's * runtime. */ - @ConfigItem(defaultValue = DEFAULT_LANGUAGE + "-" + DEFAULT_COUNTRY, defaultValueDocumentation = "Build system locale") - public Locale defaultLocale; + @WithDefault(DEFAULT_LANGUAGE + "-" + DEFAULT_COUNTRY) + Locale defaultLocale(); } diff --git a/extensions/hibernate-validator/runtime/src/main/java/io/quarkus/hibernate/validator/runtime/HibernateValidatorRecorder.java b/extensions/hibernate-validator/runtime/src/main/java/io/quarkus/hibernate/validator/runtime/HibernateValidatorRecorder.java index 88b808fd141428..fca90bb51885a3 100644 --- a/extensions/hibernate-validator/runtime/src/main/java/io/quarkus/hibernate/validator/runtime/HibernateValidatorRecorder.java +++ b/extensions/hibernate-validator/runtime/src/main/java/io/quarkus/hibernate/validator/runtime/HibernateValidatorRecorder.java @@ -79,9 +79,9 @@ public void created(BeanContainer container) { configuration.builtinConstraints(detectedBuiltinConstraints) .initializeBeanMetaData(classesToBeValidated) // Locales, Locale ROOT means all locales in this setting. - .locales(localesBuildTimeConfig.locales.contains(Locale.ROOT) ? Set.of(Locale.getAvailableLocales()) - : localesBuildTimeConfig.locales) - .defaultLocale(localesBuildTimeConfig.defaultLocale) + .locales(localesBuildTimeConfig.locales().contains(Locale.ROOT) ? Set.of(Locale.getAvailableLocales()) + : localesBuildTimeConfig.locales()) + .defaultLocale(localesBuildTimeConfig.defaultLocale()) .beanMetaDataClassNormalizer(new ArcProxyBeanMetaDataClassNormalizer()); if (hibernateValidatorBuildTimeConfig.expressionLanguage().constraintExpressionFeatureLevel().isPresent()) { diff --git a/extensions/qute/deployment/src/main/java/io/quarkus/qute/deployment/MessageBundleProcessor.java b/extensions/qute/deployment/src/main/java/io/quarkus/qute/deployment/MessageBundleProcessor.java index a78a3331d11d70..55effed423b001 100644 --- a/extensions/qute/deployment/src/main/java/io/quarkus/qute/deployment/MessageBundleProcessor.java +++ b/extensions/qute/deployment/src/main/java/io/quarkus/qute/deployment/MessageBundleProcessor.java @@ -1215,7 +1215,7 @@ private String getDefaultLocale(AnnotationInstance bundleAnnotation, LocalesBuil AnnotationValue localeValue = bundleAnnotation.value(BUNDLE_LOCALE); String defaultLocale; if (localeValue == null || localeValue.asString().equals(MessageBundle.DEFAULT_LOCALE)) { - defaultLocale = locales.defaultLocale.toLanguageTag(); + defaultLocale = locales.defaultLocale().toLanguageTag(); } else { defaultLocale = localeValue.asString(); } diff --git a/extensions/qute/runtime/src/main/java/io/quarkus/qute/runtime/EngineProducer.java b/extensions/qute/runtime/src/main/java/io/quarkus/qute/runtime/EngineProducer.java index 48a5360c3e92eb..d46a43fa9dc18a 100644 --- a/extensions/qute/runtime/src/main/java/io/quarkus/qute/runtime/EngineProducer.java +++ b/extensions/qute/runtime/src/main/java/io/quarkus/qute/runtime/EngineProducer.java @@ -93,7 +93,7 @@ public EngineProducer(QuteContext context, QuteConfig config, QuteRuntimeConfig this.templateRoots = context.getTemplateRoots(); this.tags = context.getTags(); this.templatePathExclude = config.templatePathExclude; - this.defaultLocale = locales.defaultLocale; + this.defaultLocale = locales.defaultLocale(); this.defaultCharset = config.defaultCharset; this.container = Arc.container();