From 80ea9f3ae095219d5880884243b0ad218abc2ced Mon Sep 17 00:00:00 2001 From: Michael Osipov Date: Sun, 30 Apr 2023 11:25:56 +0200 Subject: [PATCH] [MJAVADOC-784] Upgrade to Doxia 2.0.0 Milestone Stack This closes #204 --- pom.xml | 30 ++++--- .../plugins/javadoc/AbstractJavadocMojo.java | 79 +++--------------- .../maven/plugins/javadoc/JavadocJar.java | 4 +- .../maven/plugins/javadoc/JavadocReport.java | 19 ++--- src/site/apt/examples/alternate-doclet.apt.vm | 3 - .../apt/examples/output-configuration.apt.vm | 11 ++- .../plugins/javadoc/JavadocReportTest.java | 9 --- ...adocJarInvalidDestdirMavenProjectStub.java | 81 ------------------- .../wrong-locale-test-plugin-config.xml | 51 ------------ 9 files changed, 38 insertions(+), 249 deletions(-) delete mode 100644 src/test/java/org/apache/maven/plugins/javadoc/stubs/JavadocJarInvalidDestdirMavenProjectStub.java 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 616b5f21a..feee7d6ad 100644 --- a/pom.xml +++ b/pom.xml @@ -112,8 +112,7 @@ under the License. 8 3.6.3 - 1.11.1 - 1.11.1 + 2.0.0-M19 3.5.3 1.4.1 @@ -123,12 +122,12 @@ under the License. 3.11.0 3.3.0 - 3.2.2 + 3.3.1 3.4.1 - 3.10.1 + 3.13.1 3.3.0 - 3.12.1 - 3.5.0 + 4.0.0-M16 + 3.6.2 2024-07-17T13:27:38Z 1.7.36 @@ -203,7 +202,7 @@ under the License. org.apache.maven.reporting maven-reporting-api - 3.1.1 + 4.0.0-M12 org.apache.maven @@ -230,21 +229,20 @@ under the License. org.apache.maven.doxia doxia-sink-api - ${doxiaVersion} + 2.0.0-M12 org.apache.maven.doxia doxia-site-renderer - ${doxia-sitetoolsVersion} - - - - org.apache.velocity - velocity-tools - - + ${doxiaSitetoolsVersion} + + + + org.apache.maven.doxia + doxia-integration-tools + ${doxiaSitetoolsVersion} 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 f32a49ce2..640cffa95 100644 --- a/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java +++ b/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java @@ -65,6 +65,7 @@ import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager; 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; @@ -269,6 +270,12 @@ public abstract class AbstractJavadocMojo extends AbstractMojo { // Mojo components // ---------------------------------------------------------------------- + /** + * SiteTool. + */ + @Component + protected SiteTool siteTool; + /** * Archiver manager * @@ -4264,64 +4271,8 @@ private void validateJavadocOptions() throws MavenReportException { } // locale - if (this.locale != null && !this.locale.isEmpty()) { - 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 + "'"); - } + if (StringUtils.isNotEmpty(this.locale)) { + this.locale = siteTool.getSiteLocales(locale).get(0).toString(); } } @@ -5901,8 +5852,7 @@ private boolean isJavadocVMInitError(String output) { /** * @param p not null - * @return the javadoc link based on the project url i.e. ${project.url}/${destDir} where - * destDir is configued in the Javadoc plugin configuration (apidocs by default). + * @return the javadoc link based on the project url i.e. ${project.url}/apidocs. * @since 2.6 */ private static String getJavadocLink(MavenProject p) { @@ -5911,15 +5861,8 @@ private static String getJavadocLink(MavenProject p) { } String url = cleanUrl(p.getUrl()); - String destDir = "apidocs"; // see JavadocReport#destDir - - final String pluginId = "org.apache.maven.plugins:maven-javadoc-plugin"; - String destDirConfigured = getPluginParameter(p, pluginId, "destDir"); - if (destDirConfigured != null) { - destDir = destDirConfigured; - } - return url + "/" + destDir; + return url + "/apidocs"; } /** 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 0d857831e..b5058fcce 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; @@ -117,11 +118,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); } @@ -236,9 +232,6 @@ public boolean canGenerateReport() { canGenerate = canGenerateReport(files); } - if (getLog().isDebugEnabled()) { - getLog().debug(" canGenerateReport = " + canGenerate + " for project " + this.project); - } return canGenerate; } @@ -293,16 +286,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/site/apt/examples/alternate-doclet.apt.vm b/src/site/apt/examples/alternate-doclet.apt.vm index 72bfedad5..bab74c72b 100644 --- a/src/site/apt/examples/alternate-doclet.apt.vm +++ b/src/site/apt/examples/alternate-doclet.apt.vm @@ -97,9 +97,6 @@ Using Alternate Doclet In Addition To The Javadoc Doclet \${project.build.directory}/site/doccheck - - doccheck - DocCheck DocCheck documentation. diff --git a/src/site/apt/examples/output-configuration.apt.vm b/src/site/apt/examples/output-configuration.apt.vm index c5f1633ce..2c58afcf1 100644 --- a/src/site/apt/examples/output-configuration.apt.vm +++ b/src/site/apt/examples/output-configuration.apt.vm @@ -40,8 +40,7 @@ Using Alternative Output Directory maven-javadoc-plugin ${project.version} - \${project.reporting.outputDirectory}/myoutput - myapidocs + \${project.build.directory}/myoutput ... @@ -53,8 +52,8 @@ Using Alternative Output Directory +-----+ Running <<>> will output the Javadoc in the - <$\{project.reporting.outputDirectory\}/myoutput/myapidocs> instead of the default directory, i.e. - <$\{project.reporting.outputDirectory\}/apidocs>. + <<<$\{project.build.directory\}/myoutput/apidocs>>> instead of the default directory, i.e. + <<<$\{project.build.directory\}/reports/apidocs>>>. - <>: Running will automatically use the <$\{project.reporting.outputDirectory\}> directory and - in this case, has no effect. Only, and could be used. + <>: Running <<>> will automatically use the <<<$\{project.reporting.outputDirectory\}>>> + directory and in this case, <<<\>>> has no effect. 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 abcea9af4..20d837758 100644 --- a/src/test/java/org/apache/maven/plugins/javadoc/JavadocReportTest.java +++ b/src/test/java/org/apache/maven/plugins/javadoc/JavadocReportTest.java @@ -1056,15 +1056,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/stubs/JavadocJarInvalidDestdirMavenProjectStub.java b/src/test/java/org/apache/maven/plugins/javadoc/stubs/JavadocJarInvalidDestdirMavenProjectStub.java deleted file mode 100644 index a9ac06737..000000000 --- a/src/test/java/org/apache/maven/plugins/javadoc/stubs/JavadocJarInvalidDestdirMavenProjectStub.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.maven.plugins.javadoc.stubs; - -import java.io.File; -import java.util.ArrayList; -import java.util.List; - -import org.apache.maven.artifact.Artifact; -import org.apache.maven.model.Build; -import org.apache.maven.model.Scm; -import org.apache.maven.plugin.testing.stubs.MavenProjectStub; - -/** - * @author Maria Odea Ching - */ -public class JavadocJarInvalidDestdirMavenProjectStub extends MavenProjectStub { - private Scm scm; - - public JavadocJarInvalidDestdirMavenProjectStub() { - readModel(new File(getBasedir(), "javadocjar-invalid-destdir-plugin-config.xml")); - - setGroupId(getModel().getGroupId()); - setArtifactId(getModel().getArtifactId()); - setVersion(getModel().getVersion()); - setName(getModel().getName()); - setUrl(getModel().getUrl()); - setPackaging(getModel().getPackaging()); - - Scm scm = new Scm(); - scm.setConnection("scm:svn:http://svn.apache.org/maven/sample/trunk"); - setScm(scm); - - Artifact artifact = new JavadocPluginArtifactStub(getGroupId(), getArtifactId(), getVersion(), getPackaging()); - artifact.setArtifactHandler(new DefaultArtifactHandlerStub()); - setArtifact(artifact); - - Build build = new Build(); - build.setFinalName("javadocjar-invalid-destdir"); - build.setDirectory(super.getBasedir() + "/target/test/unit/javadocjar-invalid-destdir/target"); - setBuild(build); - - List compileSourceRoots = new ArrayList<>(); - compileSourceRoots.add(getBasedir().getAbsolutePath()); - setCompileSourceRoots(compileSourceRoots); - } - - /** {@inheritDoc} */ - @Override - public Scm getScm() { - return scm; - } - - /** {@inheritDoc} */ - @Override - public void setScm(Scm scm) { - this.scm = scm; - } - - /** {@inheritDoc} */ - @Override - public File getBasedir() { - return new File(super.getBasedir() + "/src/test/resources/unit/javadocjar-invalid-destdir/"); - } -} 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 f8c564af9..000000000 --- a/src/test/resources/unit/validate-options-test/wrong-locale-test-plugin-config.xml +++ /dev/null @@ -1,51 +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 - - - ${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 - - - - -