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 Jun 26, 2024
1 parent aa0a666 commit c85af67
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 147 deletions.
26 changes: 12 additions & 14 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 @@ -127,8 +126,8 @@ under the License.
<enforcerPluginVersion>3.4.1</enforcerPluginVersion>
<pluginPluginVersion>3.10.1</pluginPluginVersion>
<jarPluginVersion>3.3.0</jarPluginVersion>
<sitePluginVersion>3.12.1</sitePluginVersion>
<projectInfoReportsPluginVersion>3.5.0</projectInfoReportsPluginVersion>
<sitePluginVersion>4.0.0-M15</sitePluginVersion>
<projectInfoReportsPluginVersion>3.6.1</projectInfoReportsPluginVersion>
<project.build.outputTimestamp>2024-05-29T16:13:14Z</project.build.outputTimestamp>
<slf4jVersion>1.7.36</slf4jVersion>
</properties>
Expand Down Expand Up @@ -203,7 +202,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 @@ -230,21 +229,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 @@ -4250,64 +4257,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
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
Original file line number Diff line number Diff line change
Expand Up @@ -1054,15 +1054,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.

0 comments on commit c85af67

Please sign in to comment.