65
65
import org .apache .maven .artifact .handler .manager .ArtifactHandlerManager ;
66
66
import org .apache .maven .artifact .versioning .ArtifactVersion ;
67
67
import org .apache .maven .artifact .versioning .DefaultArtifactVersion ;
68
+ import org .apache .maven .doxia .tools .SiteTool ;
68
69
import org .apache .maven .execution .MavenSession ;
69
70
import org .apache .maven .model .Dependency ;
70
71
import org .apache .maven .model .Plugin ;
@@ -269,6 +270,12 @@ public abstract class AbstractJavadocMojo extends AbstractMojo {
269
270
// Mojo components
270
271
// ----------------------------------------------------------------------
271
272
273
+ /**
274
+ * SiteTool.
275
+ */
276
+ @ Component
277
+ protected SiteTool siteTool ;
278
+
272
279
/**
273
280
* Archiver manager
274
281
*
@@ -4264,64 +4271,8 @@ private void validateJavadocOptions() throws MavenReportException {
4264
4271
}
4265
4272
4266
4273
// locale
4267
- if (this .locale != null && !this .locale .isEmpty ()) {
4268
- StringTokenizer tokenizer = new StringTokenizer (this .locale , "_" );
4269
- final int maxTokens = 3 ;
4270
- if (tokenizer .countTokens () > maxTokens ) {
4271
- throw new MavenReportException (
4272
- "Unsupported option <locale/> '" + this .locale + "', should be language_country_variant." );
4273
- }
4274
-
4275
- Locale localeObject = null ;
4276
- if (tokenizer .hasMoreTokens ()) {
4277
- String language = tokenizer .nextToken ().toLowerCase (Locale .ENGLISH );
4278
- if (!Arrays .asList (Locale .getISOLanguages ()).contains (language )) {
4279
- throw new MavenReportException (
4280
- "Unsupported language '" + language + "' in option <locale/> '" + this .locale + "'" );
4281
- }
4282
- localeObject = new Locale (language );
4283
-
4284
- if (tokenizer .hasMoreTokens ()) {
4285
- String country = tokenizer .nextToken ().toUpperCase (Locale .ENGLISH );
4286
- if (!Arrays .asList (Locale .getISOCountries ()).contains (country )) {
4287
- throw new MavenReportException (
4288
- "Unsupported country '" + country + "' in option <locale/> '" + this .locale + "'" );
4289
- }
4290
- localeObject = new Locale (language , country );
4291
-
4292
- if (tokenizer .hasMoreTokens ()) {
4293
- String variant = tokenizer .nextToken ();
4294
- localeObject = new Locale (language , country , variant );
4295
- }
4296
- }
4297
- }
4298
-
4299
- if (localeObject == null ) {
4300
- throw new MavenReportException (
4301
- "Unsupported option <locale/> '" + this .locale + "', should be language_country_variant." );
4302
- }
4303
-
4304
- this .locale = localeObject .toString ();
4305
- final List <Locale > availableLocalesList = Arrays .asList (Locale .getAvailableLocales ());
4306
- if (StringUtils .isNotEmpty (localeObject .getVariant ()) && !availableLocalesList .contains (localeObject )) {
4307
- StringBuilder sb = new StringBuilder ();
4308
- sb .append ("Unsupported option <locale/> with variant '" ).append (this .locale );
4309
- sb .append ("'" );
4310
-
4311
- localeObject = new Locale (localeObject .getLanguage (), localeObject .getCountry ());
4312
- this .locale = localeObject .toString ();
4313
-
4314
- sb .append (", trying to use <locale/> without variant, i.e. '" )
4315
- .append (this .locale )
4316
- .append ("'" );
4317
- if (getLog ().isWarnEnabled ()) {
4318
- getLog ().warn (sb .toString ());
4319
- }
4320
- }
4321
-
4322
- if (!availableLocalesList .contains (localeObject )) {
4323
- throw new MavenReportException ("Unsupported option <locale/> '" + this .locale + "'" );
4324
- }
4274
+ if (StringUtils .isNotEmpty (this .locale )) {
4275
+ this .locale = siteTool .getSiteLocales (locale ).get (0 ).toString ();
4325
4276
}
4326
4277
}
4327
4278
@@ -5902,8 +5853,7 @@ private boolean isJavadocVMInitError(String output) {
5902
5853
5903
5854
/**
5904
5855
* @param p not null
5905
- * @return the javadoc link based on the project url i.e. <code>${project.url}/${destDir}</code> where
5906
- * <code>destDir</code> is configued in the Javadoc plugin configuration (<code>apidocs</code> by default).
5856
+ * @return the javadoc link based on the project url i.e. <code>${project.url}/apidocs</code>.
5907
5857
* @since 2.6
5908
5858
*/
5909
5859
private static String getJavadocLink (MavenProject p ) {
@@ -5912,15 +5862,8 @@ private static String getJavadocLink(MavenProject p) {
5912
5862
}
5913
5863
5914
5864
String url = cleanUrl (p .getUrl ());
5915
- String destDir = "apidocs" ; // see JavadocReport#destDir
5916
-
5917
- final String pluginId = "org.apache.maven.plugins:maven-javadoc-plugin" ;
5918
- String destDirConfigured = getPluginParameter (p , pluginId , "destDir" );
5919
- if (destDirConfigured != null ) {
5920
- destDir = destDirConfigured ;
5921
- }
5922
5865
5923
- return url + "/" + destDir ;
5866
+ return url + "/apidocs" ;
5924
5867
}
5925
5868
5926
5869
/**
0 commit comments