From b8ff115f50e294f0cec96bddc88d8fb44fd7aca8 Mon Sep 17 00:00:00 2001 From: Michael Osipov Date: Sun, 30 Apr 2023 11:25:56 +0200 Subject: [PATCH] Prepare for Doxia 2.0.0 --- pom.xml | 23 +++-- .../plugins/javadoc/AbstractJavadocMojo.java | 83 +++++-------------- .../maven/plugins/javadoc/JavadocJar.java | 4 +- .../maven/plugins/javadoc/JavadocReport.java | 16 ++-- .../javadoc/AggregatorJavadocReportTest.java | 8 +- .../maven/plugins/javadoc/JavadocJarTest.java | 7 +- .../plugins/javadoc/JavadocReportTest.java | 20 ++--- .../javadoc/TestJavadocReportTest.java | 7 +- .../wrong-locale-test-plugin-config.xml | 52 ------------ 9 files changed, 66 insertions(+), 154 deletions(-) delete mode 100644 src/test/resources/unit/validate-options-test/wrong-locale-test-plugin-config.xml diff --git a/pom.xml b/pom.xml index e1110c1c8..708acc4a8 100644 --- a/pom.xml +++ b/pom.xml @@ -28,7 +28,7 @@ under the License. maven-javadoc-plugin - 3.5.1-SNAPSHOT + 3.6.0-SNAPSHOT maven-plugin Apache Maven Javadoc Plugin @@ -112,16 +112,15 @@ under the License. 8 3.2.5 - 1.11.1 - 1.11.1 + 2.0.0-M10 2.4 1.0.0.v20140518 1.1.2 9.4.50.v20221201 - 3.12.1 - 3.4.2 + 4.0.0-M8 + 4.0.0-M1-SNAPSHOT 2023-02-12T17:50:15Z 1.7.36 @@ -209,7 +208,7 @@ under the License. org.apache.maven.reporting maven-reporting-api - 3.1.1 + 4.0.0-M6 org.apache.maven @@ -231,14 +230,20 @@ under the License. org.apache.maven.doxia doxia-sink-api - ${doxiaVersion} + 2.0.0-M6 org.apache.maven.doxia doxia-site-renderer - ${doxia-sitetoolsVersion} + ${doxiaSitetoolsVersion} + + + + org.apache.maven.doxia + doxia-integration-tools + ${doxiaSitetoolsVersion} @@ -285,7 +290,7 @@ under the License. org.codehaus.plexus plexus-utils - 3.5.0 + 3.5.1 commons-io diff --git a/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java b/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java index e9f38d544..ed5adeff7 100644 --- a/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java +++ b/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java @@ -66,6 +66,7 @@ import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.versioning.ArtifactVersion; import org.apache.maven.artifact.versioning.DefaultArtifactVersion; +import org.apache.maven.doxia.tools.SiteTool; import org.apache.maven.execution.MavenSession; import org.apache.maven.model.Dependency; import org.apache.maven.model.Plugin; @@ -271,6 +272,12 @@ public abstract class AbstractJavadocMojo extends AbstractMojo { // Mojo components // ---------------------------------------------------------------------- + /** + * SiteTool. + */ + @Component + protected SiteTool siteTool; + /** * Archiver manager * @@ -330,8 +337,8 @@ public abstract class AbstractJavadocMojo extends AbstractMojo { @Parameter(defaultValue = "${project}", readonly = true, required = true) protected MavenProject project; - @Parameter(defaultValue = "${mojoExecution}", readonly = true) - private MojoExecution mojo; + @Parameter(defaultValue = "${mojoExecution}", readonly = true, required = true) + protected MojoExecution mojoExecution; /** * Specify if the Javadoc should operate in offline mode. @@ -423,10 +430,10 @@ public abstract class AbstractJavadocMojo extends AbstractMojo { private ArtifactRepository localRepository; /** - * The projects in the reactor for aggregation report. + * The reactor projects. */ - @Parameter(property = "reactorProjects", readonly = true) - private List reactorProjects; + @Parameter(defaultValue = "${reactorProjects}", required = true, readonly = true) + protected List reactorProjects; /** * Set this to true to debug the Javadoc plugin. With this, javadoc.bat(or.sh), @@ -1821,7 +1828,7 @@ public void execute() throws MojoExecutionException, MojoFailureException { abstract void doExecute() throws MojoExecutionException, MojoFailureException; protected final void verifyRemovedParameter(String paramName) { - Xpp3Dom configDom = mojo.getConfiguration(); + Xpp3Dom configDom = mojoExecution.getConfiguration(); if (configDom != null) { if (configDom.getChild(paramName) != null) { throw new IllegalArgumentException( @@ -1831,7 +1838,7 @@ protected final void verifyRemovedParameter(String paramName) { } private void verifyReplacedParameter(String oldParamName, String newParamNew) { - Xpp3Dom configDom = mojo.getConfiguration(); + Xpp3Dom configDom = mojoExecution.getConfiguration(); if (configDom != null) { if (configDom.getChild(oldParamName) != null) { throw new IllegalArgumentException("parameter '" + oldParamName + "' has been replaced with " @@ -4239,63 +4246,7 @@ private void validateJavadocOptions() throws MavenReportException { // locale if (StringUtils.isNotEmpty(this.locale)) { - StringTokenizer tokenizer = new StringTokenizer(this.locale, "_"); - final int maxTokens = 3; - if (tokenizer.countTokens() > maxTokens) { - throw new MavenReportException( - "Unsupported option '" + this.locale + "', should be language_country_variant."); - } - - Locale localeObject = null; - if (tokenizer.hasMoreTokens()) { - String language = tokenizer.nextToken().toLowerCase(Locale.ENGLISH); - if (!Arrays.asList(Locale.getISOLanguages()).contains(language)) { - throw new MavenReportException( - "Unsupported language '" + language + "' in option '" + this.locale + "'"); - } - localeObject = new Locale(language); - - if (tokenizer.hasMoreTokens()) { - String country = tokenizer.nextToken().toUpperCase(Locale.ENGLISH); - if (!Arrays.asList(Locale.getISOCountries()).contains(country)) { - throw new MavenReportException( - "Unsupported country '" + country + "' in option '" + this.locale + "'"); - } - localeObject = new Locale(language, country); - - if (tokenizer.hasMoreTokens()) { - String variant = tokenizer.nextToken(); - localeObject = new Locale(language, country, variant); - } - } - } - - if (localeObject == null) { - throw new MavenReportException( - "Unsupported option '" + this.locale + "', should be language_country_variant."); - } - - this.locale = localeObject.toString(); - final List availableLocalesList = Arrays.asList(Locale.getAvailableLocales()); - if (StringUtils.isNotEmpty(localeObject.getVariant()) && !availableLocalesList.contains(localeObject)) { - StringBuilder sb = new StringBuilder(); - sb.append("Unsupported option with variant '").append(this.locale); - sb.append("'"); - - localeObject = new Locale(localeObject.getLanguage(), localeObject.getCountry()); - this.locale = localeObject.toString(); - - sb.append(", trying to use without variant, i.e. '") - .append(this.locale) - .append("'"); - if (getLog().isWarnEnabled()) { - getLog().warn(sb.toString()); - } - } - - if (!availableLocalesList.contains(localeObject)) { - throw new MavenReportException("Unsupported option '" + this.locale + "'"); - } + this.locale = siteTool.getSiteLocales(locale).get(0).toString(); } } @@ -6009,6 +5960,10 @@ protected void logError(String message, Throwable t) { } } + protected List getReactorProjects() { + return reactorProjects; + } + /** * @param prefix The prefix of the exception. * @param e The exception. diff --git a/src/main/java/org/apache/maven/plugins/javadoc/JavadocJar.java b/src/main/java/org/apache/maven/plugins/javadoc/JavadocJar.java index e295edd24..98bed568d 100644 --- a/src/main/java/org/apache/maven/plugins/javadoc/JavadocJar.java +++ b/src/main/java/org/apache/maven/plugins/javadoc/JavadocJar.java @@ -21,12 +21,12 @@ import java.io.File; import java.io.IOException; import java.util.List; -import java.util.Locale; import org.apache.maven.archiver.MavenArchiveConfiguration; import org.apache.maven.archiver.MavenArchiver; import org.apache.maven.artifact.DependencyResolutionRequiredException; import org.apache.maven.artifact.handler.ArtifactHandler; +import org.apache.maven.doxia.tools.SiteTool; import org.apache.maven.model.Resource; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugins.annotations.Component; @@ -178,7 +178,7 @@ public void doExecute() throws MojoExecutionException { } try { - executeReport(Locale.getDefault()); + executeReport(SiteTool.DEFAULT_LOCALE); } catch (MavenReportException e) { failOnError("MavenReportException: Error while generating Javadoc", e); } catch (RuntimeException e) { diff --git a/src/main/java/org/apache/maven/plugins/javadoc/JavadocReport.java b/src/main/java/org/apache/maven/plugins/javadoc/JavadocReport.java index 14e138ecf..417ffea80 100644 --- a/src/main/java/org/apache/maven/plugins/javadoc/JavadocReport.java +++ b/src/main/java/org/apache/maven/plugins/javadoc/JavadocReport.java @@ -28,8 +28,9 @@ import org.apache.maven.doxia.sink.Sink; import org.apache.maven.doxia.sink.SinkFactory; -import org.apache.maven.doxia.siterenderer.RenderingContext; +import org.apache.maven.doxia.siterenderer.DocumentRenderingContext; import org.apache.maven.doxia.siterenderer.sink.SiteRendererSink; +import org.apache.maven.doxia.tools.SiteTool; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugins.annotations.Execute; @@ -118,11 +119,6 @@ public String getDescription(Locale locale) { } /** {@inheritDoc} */ - @Override - public void generate(org.codehaus.doxia.sink.Sink sink, Locale locale) throws MavenReportException { - generate(sink, null, locale); - } - public void generate(Sink sink, Locale locale) throws MavenReportException { generate(sink, null, locale); } @@ -299,16 +295,16 @@ public void doExecute() throws MojoExecutionException, MojoFailureException { String filename = getOutputName() + ".html"; - Locale locale = Locale.getDefault(); + Locale locale = SiteTool.DEFAULT_LOCALE; try { - // TODO Replace null with real value - RenderingContext docRenderingContext = new RenderingContext(outputDirectory, filename, null); + String reportMojoInfo = mojoExecution.getPlugin().getId() + ":" + mojoExecution.getGoal(); + DocumentRenderingContext docRenderingContext = + new DocumentRenderingContext(outputDirectory, filename, reportMojoInfo); SiteRendererSink sink = new SiteRendererSink(docRenderingContext); generate(sink, null, locale); - } catch (MavenReportException | RuntimeException e) { failOnError("An error has occurred in " + getName(Locale.ENGLISH) + " report generation", e); } diff --git a/src/test/java/org/apache/maven/plugins/javadoc/AggregatorJavadocReportTest.java b/src/test/java/org/apache/maven/plugins/javadoc/AggregatorJavadocReportTest.java index 9097ab9e8..36bd7d890 100644 --- a/src/test/java/org/apache/maven/plugins/javadoc/AggregatorJavadocReportTest.java +++ b/src/test/java/org/apache/maven/plugins/javadoc/AggregatorJavadocReportTest.java @@ -62,8 +62,12 @@ protected void setUp() throws Exception { private JavadocReport lookupMojo(File testPom) throws Exception { JavadocReport mojo = (JavadocReport) lookupMojo("aggregate", testPom); - MojoExecution mojoExec = new MojoExecution(new Plugin(), "aggregate", null); - setVariableValueToObject(mojo, "mojo", mojoExec); + Plugin p = new Plugin(); + p.setGroupId("org.apache.maven.plugins"); + p.setArtifactId("maven-javadoc-plugin"); + MojoExecution mojoExecution = new MojoExecution(p, "aggregate", null); + + setVariableValueToObject(mojo, "mojoExecution", mojoExecution); MavenProject currentProject = new MavenProjectStub(); currentProject.setGroupId("GROUPID"); diff --git a/src/test/java/org/apache/maven/plugins/javadoc/JavadocJarTest.java b/src/test/java/org/apache/maven/plugins/javadoc/JavadocJarTest.java index c36668f75..66ffc989d 100644 --- a/src/test/java/org/apache/maven/plugins/javadoc/JavadocJarTest.java +++ b/src/test/java/org/apache/maven/plugins/javadoc/JavadocJarTest.java @@ -42,9 +42,12 @@ public class JavadocJarTest extends AbstractMojoTestCase { private JavadocJar lookupMojo(File testPom) throws Exception { JavadocJar mojo = (JavadocJar) lookupMojo("jar", testPom); - MojoExecution mojoExec = new MojoExecution(new Plugin(), "javadoc", null); + Plugin p = new Plugin(); + p.setGroupId("org.apache.maven.plugins"); + p.setArtifactId("maven-javadoc-plugin"); + MojoExecution mojoExecution = new MojoExecution(p, "jar", null); - setVariableValueToObject(mojo, "mojo", mojoExec); + setVariableValueToObject(mojo, "mojoExecution", mojoExecution); MavenProject currentProject = new MavenProjectStub(); currentProject.setGroupId("GROUPID"); diff --git a/src/test/java/org/apache/maven/plugins/javadoc/JavadocReportTest.java b/src/test/java/org/apache/maven/plugins/javadoc/JavadocReportTest.java index d8c836b80..e61f747e7 100644 --- a/src/test/java/org/apache/maven/plugins/javadoc/JavadocReportTest.java +++ b/src/test/java/org/apache/maven/plugins/javadoc/JavadocReportTest.java @@ -26,6 +26,7 @@ import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -101,17 +102,23 @@ protected void setUp() throws Exception { private JavadocReport lookupMojo(Path testPom) throws Exception { JavadocReport mojo = (JavadocReport) lookupMojo("javadoc", testPom.toFile()); - MojoExecution mojoExec = new MojoExecution(new Plugin(), "javadoc", null); + Plugin p = new Plugin(); + p.setGroupId("org.apache.maven.plugins"); + p.setArtifactId("maven-javadoc-plugin"); + MojoExecution mojoExecution = new MojoExecution(p, "javadoc", null); - setVariableValueToObject(mojo, "mojo", mojoExec); + setVariableValueToObject(mojo, "mojoExecution", mojoExecution); MavenProject currentProject = new MavenProjectStub(); currentProject.setGroupId("GROUPID"); currentProject.setArtifactId("ARTIFACTID"); + List reactorProjects = + mojo.getReactorProjects() != null ? mojo.getReactorProjects() : Collections.emptyList(); MavenSession session = newMavenSession(currentProject); setVariableValueToObject(mojo, "session", session); setVariableValueToObject(mojo, "repoSession", session.getRepositorySession()); + setVariableValueToObject(mojo, "reactorProjects", reactorProjects); return mojo; } @@ -1064,15 +1071,6 @@ public void testValidateOptions() throws Exception { assertTrue("No wrong charset catch", e.getMessage().contains("Unsupported option ")); } - // locale - testPom = unit.resolve("validate-options-test/wrong-locale-test-plugin-config.xml"); - mojo = lookupMojo(testPom); - try { - mojo.execute(); - fail("No wrong locale catch"); - } catch (MojoExecutionException e) { - assertTrue("No wrong locale catch", e.getMessage().contains("Unsupported option ")); - } testPom = unit.resolve("validate-options-test/wrong-locale-with-variant-test-plugin-config.xml"); mojo = lookupMojo(testPom); mojo.execute(); diff --git a/src/test/java/org/apache/maven/plugins/javadoc/TestJavadocReportTest.java b/src/test/java/org/apache/maven/plugins/javadoc/TestJavadocReportTest.java index ad2cfa663..3f8d02a67 100644 --- a/src/test/java/org/apache/maven/plugins/javadoc/TestJavadocReportTest.java +++ b/src/test/java/org/apache/maven/plugins/javadoc/TestJavadocReportTest.java @@ -43,9 +43,12 @@ public void testTestJavadoc() throws Exception { new File(getBasedir(), "src/test/resources/unit/test-javadoc-test/test-javadoc-test-plugin-config.xml"); TestJavadocReport mojo = (TestJavadocReport) lookupMojo("test-javadoc", testPom); - MojoExecution mojoExec = new MojoExecution(new Plugin(), "test-javadoc", null); + Plugin p = new Plugin(); + p.setGroupId("org.apache.maven.plugins"); + p.setArtifactId("maven-javadoc-plugin"); + MojoExecution mojoExecution = new MojoExecution(p, "test-javadoc", null); - setVariableValueToObject(mojo, "mojo", mojoExec); + setVariableValueToObject(mojo, "mojoExecution", mojoExecution); MavenProject currentProject = new MavenProjectStub(); currentProject.setGroupId("GROUPID"); diff --git a/src/test/resources/unit/validate-options-test/wrong-locale-test-plugin-config.xml b/src/test/resources/unit/validate-options-test/wrong-locale-test-plugin-config.xml deleted file mode 100644 index d94e0c8ab..000000000 --- a/src/test/resources/unit/validate-options-test/wrong-locale-test-plugin-config.xml +++ /dev/null @@ -1,52 +0,0 @@ - - - - 4.0.0 - org.apache.maven.plugins.maven-javadoc-plugin.unit - wrong-locale-options-test - jar - 1.0-SNAPSHOT - 2007 - Maven Javadoc Plugin wrong locale Test - http://maven.apache.org - - - - org.apache.maven.plugins - maven-javadoc-plugin - - - ${localRepository} - ${basedir}/target/test/unit/validate-options-test/target/site/apidocs - ${basedir}/target/test/unit/validate-options-test/target/javadoc-bundle-options - protected - - - true - true - wrong_wrong_wrong_wrong - java - true - - - - -