This is an automated email from the ASF dual-hosted git repository. slachiewicz pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/maven-doxia-sitetools.git
commit 77326e725bd94554ba5ef293af556549eb573cf7 Author: Sylwester Lachiewicz <[email protected]> AuthorDate: Tue Nov 3 19:25:00 2026 +0000 Rename the property to maven.doxiaSitetools.defaultLocale and parse locales once codeToLocale now parses with SiteTool.toLocale, so the locales parameter and the default locale property accept the same forms, language tags included; more than three parts is still ignored with a warning. --- .../apache/maven/doxia/tools/DefaultSiteTool.java | 29 ++++++---------------- .../org/apache/maven/doxia/tools/SiteTool.java | 7 +++--- .../org/apache/maven/doxia/tools/SiteToolTest.java | 4 +++ 3 files changed, 16 insertions(+), 24 deletions(-) diff --git a/doxia-integration-tools/src/main/java/org/apache/maven/doxia/tools/DefaultSiteTool.java b/doxia-integration-tools/src/main/java/org/apache/maven/doxia/tools/DefaultSiteTool.java index 555db21..dd7d901 100644 --- a/doxia-integration-tools/src/main/java/org/apache/maven/doxia/tools/DefaultSiteTool.java +++ b/doxia-integration-tools/src/main/java/org/apache/maven/doxia/tools/DefaultSiteTool.java @@ -781,8 +781,10 @@ public class DefaultSiteTool implements SiteTool { * object. * <p>If localeCode = <code>system</code>, return the current value of the default locale for this instance * of the Java Virtual Machine.</p> - * <p>If localeCode = <code>default</code>, return {@link SiteTool#DEFAULT_LOCALE}, the root locale unless the - * system property {@value SiteTool#DEFAULT_LOCALE_PROPERTY} sets another one.</p> + * <p>If localeCode = <code>default</code>, return {@link SiteTool#DEFAULT_LOCALE}, which {@link SiteTool} reads + * from the system property {@value SiteTool#DEFAULT_LOCALE_PROPERTY} when it is loaded.</p> + * <p>Any other code is parsed by {@link SiteTool#toLocale(String)}, so it may also be a language tag such as + * {@code en-US}.</p> * * @param localeCode the locale code string. * @return a java.util.Locale object instanced or null if errors occurred @@ -802,30 +804,15 @@ public class DefaultSiteTool implements SiteTool { return SiteTool.DEFAULT_LOCALE; } - String language = ""; - String country = ""; - String variant = ""; - - StringTokenizer tokenizer = new StringTokenizer(localeCode, "_"); - final int maxTokens = 3; - if (tokenizer.countTokens() > maxTokens) { + final int maxParts = 3; + if (localeCode.split("_", -1).length > maxParts) { if (LOGGER.isWarnEnabled()) { LOGGER.warn("Invalid java.util.Locale format for '" + localeCode + "' entry - IGNORING"); } return null; } - if (tokenizer.hasMoreTokens()) { - language = tokenizer.nextToken(); - if (tokenizer.hasMoreTokens()) { - country = tokenizer.nextToken(); - if (tokenizer.hasMoreTokens()) { - variant = tokenizer.nextToken(); - } - } - } - - return new Locale(language, country, variant); + return SiteTool.toLocale(localeCode); } // ---------------------------------------------------------------------- @@ -930,7 +917,7 @@ public class DefaultSiteTool implements SiteTool { + "', trying without locale..."); } - // parents attach site.xml with the plain "site" classifier, whatever the default locale + // parents attach site.xml with the plain "site" classifier, whatever the default locale is siteDescriptor = resolveSiteDescriptor(project, repoSession, remoteProjectRepositories, ""); if (siteDescriptor == null) { LOGGER.debug("No site descriptor found for '" + project.getId() + "' without locale"); diff --git a/doxia-integration-tools/src/main/java/org/apache/maven/doxia/tools/SiteTool.java b/doxia-integration-tools/src/main/java/org/apache/maven/doxia/tools/SiteTool.java index 6b19049..61166c0 100644 --- a/doxia-integration-tools/src/main/java/org/apache/maven/doxia/tools/SiteTool.java +++ b/doxia-integration-tools/src/main/java/org/apache/maven/doxia/tools/SiteTool.java @@ -45,7 +45,7 @@ public interface SiteTool { * * @since 2.2.0 */ - String DEFAULT_LOCALE_PROPERTY = "maven.doxia.sitetools.default.locale"; + String DEFAULT_LOCALE_PROPERTY = "maven.doxiaSitetools.defaultLocale"; /** * The locale by default for a Maven Site: the root locale, unless the system property @@ -59,7 +59,8 @@ public interface SiteTool { /** * Parses a locale such as {@code en}, {@code en_US} or {@code en_US_POSIX}, the reverse of * {@link Locale#toString()}, or a language tag such as {@code en-US}. Never throws: a code it cannot read gives - * as much of the locale as it could read. + * as much of the locale as it could read. The {@code locales} parameter of the Maven Site Plugin is parsed the + * same way. * * @param code the locale code, may be {@code null} * @return the locale, or {@link Locale#ROOT} when {@code code} is {@code null} or blank @@ -70,7 +71,7 @@ public interface SiteTool { return Locale.ROOT; } String trimmed = code.trim(); - if (trimmed.indexOf('-') >= 0) { + if (trimmed.contains("-")) { return Locale.forLanguageTag(trimmed); } String[] parts = trimmed.split("_", 3); diff --git a/doxia-integration-tools/src/test/java/org/apache/maven/doxia/tools/SiteToolTest.java b/doxia-integration-tools/src/test/java/org/apache/maven/doxia/tools/SiteToolTest.java index 726c6e0..f42640f 100644 --- a/doxia-integration-tools/src/test/java/org/apache/maven/doxia/tools/SiteToolTest.java +++ b/doxia-integration-tools/src/test/java/org/apache/maven/doxia/tools/SiteToolTest.java @@ -511,6 +511,10 @@ class SiteToolTest { // by default, only DEFAULT_LOCALE assertEquals(Collections.singletonList(SiteTool.DEFAULT_LOCALE), tool.getSiteLocales("")); + + // parsed like the default locale property: a language tag, and more than three parts ignored + assertEquals(Arrays.asList(SiteTool.DEFAULT_LOCALE, Locale.US), tool.getSiteLocales("default,en-US")); + assertEquals(Collections.singletonList(SiteTool.DEFAULT_LOCALE), tool.getSiteLocales("default,en_US_POSIX_x")); } @Test
