michael-o commented on code in PR #732:
URL: 
https://github.com/apache/maven-doxia-sitetools/pull/732#discussion_r4454349267


##########
doxia-integration-tools/src/main/java/org/apache/maven/doxia/tools/DefaultSiteTool.java:
##########
@@ -921,13 +922,13 @@ private File resolveSiteDescriptor(
                 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

Review Comment:
   ...is



##########
doxia-integration-tools/src/main/java/org/apache/maven/doxia/tools/DefaultSiteTool.java:
##########
@@ -776,7 +776,8 @@ public List<Locale> getSiteLocales(String locales) {
      * 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>

Review Comment:
   I don'T see where the system property is analyzed here.



##########
doxia-integration-tools/src/main/java/org/apache/maven/doxia/tools/SiteTool.java:
##########
@@ -40,11 +40,42 @@
  */
 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";

Review Comment:
   maven.doxiaSitetools.defaultLocale
   
   Dots denote a hierarchy, by convention. `default` isn't hierarchy node...



##########
doxia-integration-tools/src/main/java/org/apache/maven/doxia/tools/SiteTool.java:
##########
@@ -40,11 +40,42 @@
  */
 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 = Locale.ROOT;
+    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] : "");
+    }

Review Comment:
   This should should be harmonized, be in sync with 
https://github.com/apache/maven-doxia-sitetools/pull/732/changes#diff-b78c4b78c9a6807443efdcd992fed832034d04cda82471f16bd5b02fd9d560b4R804-R824



##########
doxia-integration-tools/src/main/java/org/apache/maven/doxia/tools/SiteTool.java:
##########
@@ -40,11 +40,42 @@
  */
 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 = Locale.ROOT;
+    static Locale toLocale(String code) {
+        if (code == null || code.trim().isEmpty()) {
+            return Locale.ROOT;
+        }
+        String trimmed = code.trim();
+        if (trimmed.indexOf('-') >= 0) {

Review Comment:
   contains?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to