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 Oct 15, 2023
1 parent 6fa9c86 commit 3023f89
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 159 deletions.
28 changes: 13 additions & 15 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.6.1-SNAPSHOT</version>
<version>3.7.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-M13</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.51.v20230217</jetty.version>
<!-- for ITs -->
<sitePluginVersion>3.12.1</sitePluginVersion>
<projectInfoReportsPluginVersion>3.4.2</projectInfoReportsPluginVersion>
<sitePluginVersion>4.0.0-M11</sitePluginVersion>
<projectInfoReportsPluginVersion>4.0.0-M1-SNAPSHOT</projectInfoReportsPluginVersion>
<project.build.outputTimestamp>2023-09-12T05:45:11Z</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-M8</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
Expand All @@ -235,21 +234,20 @@ under the License.
<dependency>
<groupId>org.apache.maven.doxia</groupId>
<artifactId>doxia-sink-api</artifactId>
<version>${doxiaVersion}</version>
<version>2.0.0-M8</version>
</dependency>

<!-- Doxia-sitetools -->
<dependency>
<groupId>org.apache.maven.doxia</groupId>
<artifactId>doxia-site-renderer</artifactId>
<version>${doxia-sitetoolsVersion}</version>
<exclusions>
<exclusion>
<!-- MJAVADOC-726 -->
<groupId>org.apache.velocity</groupId>
<artifactId>velocity-tools</artifactId>
</exclusion>
</exclusions>
<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
Binary file added src/it/mrm/3rdparty/_doclet-1.0.jar
Binary file not shown.
Binary file added src/it/mrm/repository/_mjavadoc450-static.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -269,6 +270,12 @@ public abstract class AbstractJavadocMojo extends AbstractMojo {
// Mojo components
// ----------------------------------------------------------------------

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

/**
* Archiver manager
*
Expand Down Expand Up @@ -328,8 +335,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 plugin should operate in offline mode. If maven is run in offline
Expand Down Expand Up @@ -421,8 +428,8 @@ public abstract class AbstractJavadocMojo extends AbstractMojo {
/**
* The projects in the reactor for aggregation report.
*/
@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 @@ -1827,7 +1834,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 @@ -1837,7 +1844,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 @@ -4249,64 +4256,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 <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 + "'");
}
if (StringUtils.isNotEmpty(this.locale)) {
this.locale = siteTool.getSiteLocales(locale).get(0).toString();
}
}

Expand Down Expand Up @@ -6029,6 +5980,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 @@ -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);
}
Expand Down Expand Up @@ -298,16 +294,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 @@ -46,9 +46,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 @@ -27,6 +27,7 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -113,17 +114,23 @@ protected void tearDown() 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 @@ -1045,15 +1052,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
Loading

0 comments on commit 3023f89

Please sign in to comment.