Skip to content

Commit

Permalink
Prepare for Doxia 2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-o committed Apr 30, 2023
1 parent 6f72300 commit b8ff115
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 154 deletions.
23 changes: 14 additions & 9 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ under the License.
</parent>

<artifactId>maven-javadoc-plugin</artifactId>
<version>3.5.1-SNAPSHOT</version>
<version>3.6.0-SNAPSHOT</version>
<packaging>maven-plugin</packaging>

<name>Apache Maven Javadoc Plugin</name>
Expand Down Expand Up @@ -112,16 +112,15 @@ under the License.
<properties>
<javaVersion>8</javaVersion>
<mavenVersion>3.2.5</mavenVersion>
<doxiaVersion>1.11.1</doxiaVersion>
<doxia-sitetoolsVersion>1.11.1</doxia-sitetoolsVersion>
<doxiaSitetoolsVersion>2.0.0-M10</doxiaSitetoolsVersion>
<wagonVersion>2.4</wagonVersion>
<aetherVersion>1.0.0.v20140518</aetherVersion>
<!-- https://cwiki.apache.org/confluence/x/VIHOCg#MavenEcosystemCleanup-ResolverandMaven -->
<plexus-java.version>1.1.2</plexus-java.version>
<jetty.version>9.4.50.v20221201</jetty.version>
<!-- for ITs -->
<sitePluginVersion>3.12.1</sitePluginVersion>
<projectInfoReportsPluginVersion>3.4.2</projectInfoReportsPluginVersion>
<sitePluginVersion>4.0.0-M8</sitePluginVersion>
<projectInfoReportsPluginVersion>4.0.0-M1-SNAPSHOT</projectInfoReportsPluginVersion>
<project.build.outputTimestamp>2023-02-12T17:50:15Z</project.build.outputTimestamp>
<slf4jVersion>1.7.36</slf4jVersion>
</properties>
Expand Down Expand Up @@ -209,7 +208,7 @@ under the License.
<dependency>
<groupId>org.apache.maven.reporting</groupId>
<artifactId>maven-reporting-api</artifactId>
<version>3.1.1</version>
<version>4.0.0-M6</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
Expand All @@ -231,14 +230,20 @@ under the License.
<dependency>
<groupId>org.apache.maven.doxia</groupId>
<artifactId>doxia-sink-api</artifactId>
<version>${doxiaVersion}</version>
<version>2.0.0-M6</version>
</dependency>

<!-- Doxia-sitetools -->
<dependency>
<groupId>org.apache.maven.doxia</groupId>
<artifactId>doxia-site-renderer</artifactId>
<version>${doxia-sitetoolsVersion}</version>
<version>${doxiaSitetoolsVersion}</version>
</dependency>
<!-- Doxia-sitetools -->
<dependency>
<groupId>org.apache.maven.doxia</groupId>
<artifactId>doxia-integration-tools</artifactId>
<version>${doxiaSitetoolsVersion}</version>
</dependency>

<!-- wagon -->
Expand Down Expand Up @@ -285,7 +290,7 @@ under the License.
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
<version>3.5.0</version>
<version>3.5.1</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -271,6 +272,12 @@ public abstract class AbstractJavadocMojo extends AbstractMojo {
// Mojo components
// ----------------------------------------------------------------------

/**
* SiteTool.
*/
@Component
protected SiteTool siteTool;

/**
* Archiver manager
*
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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<MavenProject> reactorProjects;
@Parameter(defaultValue = "${reactorProjects}", required = true, readonly = true)
protected List<MavenProject> reactorProjects;

/**
* Set this to <code>true</code> to debug the Javadoc plugin. With this, <code>javadoc.bat(or.sh)</code>,
Expand Down Expand Up @@ -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(
Expand All @@ -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 "
Expand Down Expand Up @@ -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 <locale/> '" + 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 <locale/> '" + 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 <locale/> '" + 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 <locale/> '" + this.locale + "', should be language_country_variant.");
}

this.locale = localeObject.toString();
final List<Locale> availableLocalesList = Arrays.asList(Locale.getAvailableLocales());
if (StringUtils.isNotEmpty(localeObject.getVariant()) && !availableLocalesList.contains(localeObject)) {
StringBuilder sb = new StringBuilder();
sb.append("Unsupported option <locale/> with variant '").append(this.locale);
sb.append("'");

localeObject = new Locale(localeObject.getLanguage(), localeObject.getCountry());
this.locale = localeObject.toString();

sb.append(", trying to use <locale/> without variant, i.e. '")
.append(this.locale)
.append("'");
if (getLog().isWarnEnabled()) {
getLog().warn(sb.toString());
}
}

if (!availableLocalesList.contains(localeObject)) {
throw new MavenReportException("Unsupported option <locale/> '" + this.locale + "'");
}
this.locale = siteTool.getSiteLocales(locale).get(0).toString();
}
}

Expand Down Expand Up @@ -6009,6 +5960,10 @@ protected void logError(String message, Throwable t) {
}
}

protected List<MavenProject> getReactorProjects() {
return reactorProjects;
}

/**
* @param prefix The prefix of the exception.
* @param e The exception.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
16 changes: 6 additions & 10 deletions src/main/java/org/apache/maven/plugins/javadoc/JavadocReport.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<MavenProject> 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;
}

Expand Down Expand Up @@ -1064,15 +1071,6 @@ public void testValidateOptions() throws Exception {
assertTrue("No wrong charset catch", e.getMessage().contains("Unsupported option <charset/>"));
}

// 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 <locale/>"));
}
testPom = unit.resolve("validate-options-test/wrong-locale-with-variant-test-plugin-config.xml");
mojo = lookupMojo(testPom);
mojo.execute();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit b8ff115

Please sign in to comment.