Skip to content

Commit

Permalink
[MJAVADOC-784] Upgrade to Doxia 2.0.0 Milestone Stack
Browse files Browse the repository at this point in the history
This closes #204
  • Loading branch information
michael-o committed Aug 20, 2024
1 parent a11b921 commit 9d33925
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 248 deletions.
28 changes: 13 additions & 15 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,7 @@ under the License.
<properties>
<javaVersion>8</javaVersion>
<mavenVersion>3.6.3</mavenVersion>
<doxiaVersion>1.11.1</doxiaVersion>
<doxia-sitetoolsVersion>1.11.1</doxia-sitetoolsVersion>
<doxiaSitetoolsVersion>2.0.0-M19</doxiaSitetoolsVersion>
<wagonVersion>3.5.3</wagonVersion>
<resolverVersion>1.4.1</resolverVersion>
<!-- https://cwiki.apache.org/confluence/x/VIHOCg#MavenEcosystemCleanup-ResolverandMaven -->
Expand All @@ -123,10 +122,10 @@ under the License.
<compilerPluginVersion>3.11.0</compilerPluginVersion>
<sourcePluginVersion>3.3.0</sourcePluginVersion>
<enforcerPluginVersion>3.4.1</enforcerPluginVersion>
<pluginPluginVersion>3.10.1</pluginPluginVersion>
<pluginPluginVersion>3.14.0</pluginPluginVersion>
<jarPluginVersion>3.3.0</jarPluginVersion>
<sitePluginVersion>3.12.1</sitePluginVersion>
<projectInfoReportsPluginVersion>3.5.0</projectInfoReportsPluginVersion>
<sitePluginVersion>3.20.0</sitePluginVersion>
<projectInfoReportsPluginVersion>3.7.0</projectInfoReportsPluginVersion>
<project.build.outputTimestamp>2024-07-17T13:27:38Z</project.build.outputTimestamp>
<slf4jVersion>1.7.36</slf4jVersion>
</properties>
Expand Down Expand Up @@ -201,7 +200,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-M12</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
Expand All @@ -228,21 +227,20 @@ under the License.
<dependency>
<groupId>org.apache.maven.doxia</groupId>
<artifactId>doxia-sink-api</artifactId>
<version>${doxiaVersion}</version>
<version>2.0.0-M12</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
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 @@ -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 <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 @@ -5902,8 +5853,7 @@ private boolean isJavadocVMInitError(String output) {

/**
* @param p not null
* @return the javadoc link based on the project url i.e. <code>${project.url}/${destDir}</code> where
* <code>destDir</code> is configued in the Javadoc plugin configuration (<code>apidocs</code> by default).
* @return the javadoc link based on the project url i.e. <code>${project.url}/apidocs</code>.
* @since 2.6
*/
private static String getJavadocLink(MavenProject p) {
Expand All @@ -5912,15 +5862,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";
}

/**
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
19 changes: 6 additions & 13 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 @@ -236,9 +232,6 @@ public boolean canGenerateReport() {

canGenerate = canGenerateReport(files);
}
if (getLog().isDebugEnabled()) {
getLog().debug(" canGenerateReport = " + canGenerate + " for project " + this.project);
}
return canGenerate;
}

Expand Down Expand Up @@ -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);
}
Expand Down
3 changes: 0 additions & 3 deletions src/site/apt/examples/alternate-doclet.apt.vm
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,6 @@ Using Alternate Doclet In Addition To The Javadoc Doclet
<additionalOption>\${project.build.directory}/site/doccheck</additionalOption>
</additionalOptions>

<!-- Other dir than apidocs -->
<destDir>doccheck</destDir>

<!-- For the project-reports page-->
<name>DocCheck</name>
<description>DocCheck documentation.</description>
Expand Down
11 changes: 5 additions & 6 deletions src/site/apt/examples/output-configuration.apt.vm
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ Using Alternative Output Directory
<artifactId>maven-javadoc-plugin</artifactId>
<version>${project.version}</version>
<configuration>
<reportOutputDirectory>\${project.reporting.outputDirectory}/myoutput</reportOutputDirectory>
<destDir>myapidocs</destDir>
<reportOutputDirectory>\${project.build.directory}/myoutput</reportOutputDirectory>
...
</configuration>
</plugin>
Expand All @@ -53,8 +52,8 @@ Using Alternative Output Directory
+-----+

Running <<<mvn javadoc:javadoc>>> 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>>>.

<<Note>>: Running <mvn site> will automatically use the <$\{project.reporting.outputDirectory\}> directory and
in this case, <reportOutputDirectory> has no effect. Only, <testDestDir> and <destDir> could be used.
<<Note>>: Running <<<mvn site>>> will automatically use the <<<$\{project.reporting.outputDirectory\}>>>
directory and in this case, <<<\<reportOutputDirectory /\>>>> has no effect.
Original file line number Diff line number Diff line change
Expand Up @@ -1056,15 +1056,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

This file was deleted.

Loading

0 comments on commit 9d33925

Please sign in to comment.