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 56513d439ba4b499424875f7d8f9b6e227b20fbe Author: Sylwester Lachiewicz <[email protected]> AuthorDate: Tue Nov 3 10:28:18 2026 +0000 Read the default locale from one property and keep the parent descriptor fallback maven.doxia.sitetools.default.locale takes the form of the site plugin's locales parameter (en_US) or a language tag (en-US). The last fallback for a parent's site descriptor asks for the plain site classifier, which is what parents attach: with a non-root default locale it asked for site_<locale> again and dropped every inherited descriptor. --- .../apache/maven/doxia/tools/DefaultSiteTool.java | 11 ++++--- .../org/apache/maven/doxia/tools/SiteTool.java | 38 +++++++++++++++++++--- .../org/apache/maven/doxia/tools/SiteToolTest.java | 24 ++++++++++++++ 3 files changed, 63 insertions(+), 10 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 00b918f..555db21 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,7 +781,8 @@ 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 the root locale.</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> * * @param localeCode the locale code string. * @return a java.util.Locale object instanced or null if errors occurred @@ -926,13 +927,13 @@ public class DefaultSiteTool implements SiteTool { return siteDescriptor; } LOGGER.debug("No site descriptor found for '" + project.getId() + "' for locale '" + language - + "', trying without language (default locale)..."); + + "', trying without locale..."); } - siteDescriptor = resolveSiteDescriptor( - project, repoSession, remoteProjectRepositories, SiteTool.DEFAULT_LOCALE.toString()); + // parents attach site.xml with the plain "site" classifier, whatever the default locale + siteDescriptor = resolveSiteDescriptor(project, repoSession, remoteProjectRepositories, ""); if (siteDescriptor == null) { - LOGGER.debug("No site descriptor found for '" + project.getId() + "' with default locale"); + LOGGER.debug("No site descriptor found for '" + project.getId() + "' without locale"); } return siteDescriptor; } 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 d341262..6b19049 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 @@ -40,14 +40,42 @@ import org.eclipse.aether.repository.RemoteRepository; */ public interface SiteTool { /** - * The locale by default for a Maven Site. + * The system property that sets {@link #DEFAULT_LOCALE}, in the form of the {@code locales} parameter of the + * Maven Site Plugin, such as {@code en} or {@code en_US}, or as a language tag, such as {@code en-US}. + * + * @since 2.2.0 + */ + String DEFAULT_LOCALE_PROPERTY = "maven.doxia.sitetools.default.locale"; + + /** + * The locale by default for a Maven Site: the root locale, unless the system property + * {@value #DEFAULT_LOCALE_PROPERTY} names another one. The property is read once, when this class is loaded. * * @see Locale#ROOT + * @see #toLocale(String) + */ + Locale DEFAULT_LOCALE = toLocale(System.getProperty(DEFAULT_LOCALE_PROPERTY)); + + /** + * 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. + * + * @param code the locale code, may be {@code null} + * @return the locale, or {@link Locale#ROOT} when {@code code} is {@code null} or blank + * @since 2.2.0 */ - Locale DEFAULT_LOCALE = new Locale( - System.getProperty("maven.doxia.sitetools.user.language", ""), - System.getProperty("maven.doxia.sitetools.user.country", ""), - System.getProperty("maven.doxia.sitetools.user.variant", "")); + static Locale toLocale(String code) { + if (code == null || code.trim().isEmpty()) { + return Locale.ROOT; + } + String trimmed = code.trim(); + if (trimmed.indexOf('-') >= 0) { + return Locale.forLanguageTag(trimmed); + } + String[] parts = trimmed.split("_", 3); + return new Locale(parts[0], parts.length > 1 ? parts[1] : "", parts.length > 2 ? parts[2] : ""); + } /** * Get a skin artifact from one of the repositories. 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 d3badc7..726c6e0 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 @@ -366,6 +366,30 @@ class SiteToolTest { result); } + @Test + void siteDescriptorFromRepositoryFallsBackToPlainClassifier() throws Exception { + SiteToolMavenProjectStub project = new SiteToolMavenProjectStub("site-tool-test"); + project.setGroupId("org.apache.maven"); + project.setArtifactId("maven-site"); + project.setVersion("1.0"); + + File descriptor = tool.getSiteDescriptorFromRepository( + project, newRepoSession(), project.getRemoteProjectRepositories(), Locale.US); + + assertEquals("maven-site-1.0-site.xml", descriptor.getName()); + } + + @Test + void toLocale() { + assertEquals(Locale.ROOT, SiteTool.toLocale(null)); + assertEquals(Locale.ROOT, SiteTool.toLocale(" ")); + assertEquals(Locale.ENGLISH, SiteTool.toLocale("en")); + assertEquals(Locale.US, SiteTool.toLocale("en_US")); + assertEquals(Locale.US, SiteTool.toLocale("en-US")); + assertEquals(new Locale("en", "US", "POSIX"), SiteTool.toLocale("en_US_POSIX")); + assertEquals(Locale.ROOT, SiteTool.toLocale("not a language tag-")); + } + /** * @throws Exception */
