slachiewicz commented on code in PR #732:
URL:
https://github.com/apache/maven-doxia-sitetools/pull/732#discussion_r4459546475
##########
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:
Fixed in 2d55ae7.
##########
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:
Right, `SiteTool` reads it when the class is loaded; the Javadoc now says so
(2d55ae7).
##########
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:
Renamed to `maven.doxiaSitetools.defaultLocale` (2d55ae7).
##########
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:
Yes, `contains("-")` now.
##########
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:
`codeToLocale` now parses with `SiteTool.toLocale`, keeping `system`,
`default` and the warning for more than three parts, so the `locales` parameter
and the property accept the same forms, language tags included (2d55ae7).
--
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]