Skip to content

Commit

Permalink
[MPLUGIN-442] Generate goal documentation leveraging Sink API (#225)
Browse files Browse the repository at this point in the history
Drop XDoc intermediate format
  • Loading branch information
kwin authored Oct 8, 2023
1 parent b7138b0 commit 679d822
Show file tree
Hide file tree
Showing 25 changed files with 1,235 additions and 1,621 deletions.
10 changes: 6 additions & 4 deletions maven-plugin-report-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,6 @@
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-tools-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-tools-generators</artifactId>
</dependency>

<!-- doxia -->
<dependency>
Expand All @@ -95,6 +91,12 @@
<artifactId>maven-reporting-impl</artifactId>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.8.1</version>
<!--same version as used by doxia site renderer -->
</dependency>
<!-- plexus -->
<dependency>
<groupId>org.codehaus.plexus</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
File pluginInfo = new File( basedir, "target/site/plugin-info.html" );
assert pluginInfo.isFile()

File touchMojo = new File( basedir, "target/generated-site/xdoc/touch-mojo.xml" );
File touchMojo = new File( basedir, "target/site/touch-mojo.html" );
assert touchMojo.isFile()

return true;
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
* specific language governing permissions and limitations
* under the License.
*/
assert new File( basedir, 'target/generated-site' ).exists()
assert new File( basedir, 'target/site/noop-mojo.html' ).exists()

content = new File( basedir, 'target/generated-site/xdoc/noop-mojo.xml' ).text
content = new File( basedir, 'target/site/noop-mojo.html' ).text

assert content.contains( '<li>Since version: <code>1.0</code></li>' )
assert content.contains( '<li>Since version: <code>1.0</code>.</li>' )
assert content.contains( '<td><code>-</code></td>' )
assert content.contains( '<td><code>1.1</code></td>' )
assert content.contains( '<li><strong>Since</strong>: <code>1.1</code></li>' )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

generated = new File( basedir, "target/generated-site/xdoc/test-mojo.xml").getText("UTF-8")
generated = new File( basedir, "target/site/test-mojo.html").getText("UTF-8")

assert generated.contains("Mojo-Description with some non-ASCII characters: €àáâãäåæòóôõöø")
assert generated.contains("Parameter-Description with some non-ASCII characters: ÈÉÊË€")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ def mojoDoc = new File( basedir, 'target/site/test-mojo.html' )

assert mojoDoc.isFile()

assert mojoDoc.text.contains('<b>See also:</b> <a class="externalLink" href="https://docs.oracle.com/javase/8/docs/api/java/util/Collections.html">java.util.Collections</a></div>') // mojo description see javadoc tag
assert mojoDoc.text.contains('<strong>See also:</strong> <a href="https://docs.oracle.com/javase/8/docs/api/java/util/Collections.html">java.util.Collections</a>') // mojo description see javadoc tag

assert mojoDoc.text.contains('beans parameter leveraging <a href="apidocs/org/SimpleBean.html"><code>SimpleBean</code></a>.') // parameter description
assert mojoDoc.text.contains('<td><code><a href="apidocs/org/SimpleBean.html">Collection&lt;SimpleBean&gt;</a></code></td>') // type link in parameter overview
assert mojoDoc.text.contains('<li><b>Type</b>: <code><a href="apidocs/org/SimpleBean.html">java.util.Collection&lt;org.SimpleBean&gt;</a></code></li>') // type link in parameter details
assert mojoDoc.text.contains('<td><a href="apidocs/org/SimpleBean.html"><code>Collection&lt;SimpleBean&gt;</code></a></td>') // type link in parameter overview
assert mojoDoc.text.contains('<li><strong>Type</strong>: <a href="apidocs/org/SimpleBean.html"><code>java.util.Collection&lt;org.SimpleBean&gt;</code></a></li>') // type link in parameter details

assert mojoDoc.text.contains('<div>invalid javadoc reference <code>org.apache.maven.artifact.Artifact</code>.</div>') // second parameter description with link being removed (as no javadoc site associated)
assert mojoDoc.text.contains('invalid javadoc reference <code>org.apache.maven.artifact.Artifact</code>') // second parameter description with link being removed (as no javadoc site associated)

// the third parameter contains an invalid link (as the internal link validation has been switched off)
assert mojoDoc.text.contains(' <code><a href="apidocs/org/internal/PrivateBean.html">org.internal.PrivateBean</a></code>')
assert mojoDoc.text.contains(' <a href="apidocs/org/internal/PrivateBean.html"><code>org.internal.PrivateBean</code></a>')
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* 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.plugin.plugin.report;

import java.util.Locale;

import org.apache.maven.doxia.sink.Sink;
import org.apache.maven.project.MavenProject;
import org.apache.maven.reporting.AbstractMavenReportRenderer;
import org.codehaus.plexus.i18n.I18N;

/** Base class for all reports generated by the plugin report plugin. */
public abstract class AbstractPluginReportRenderer extends AbstractMavenReportRenderer {

private static final String RESOURCE_BASENAME = "plugin-report";

private final I18N i18n;

protected final Locale locale;

protected final MavenProject project;

protected AbstractPluginReportRenderer(Sink sink, Locale locale, I18N i18n, MavenProject project) {
super(sink);
this.i18n = i18n;
this.locale = locale;
this.project = project;
}

@Override
public String getTitle() {
return getI18nString("title");
}

/**
* Returns
* @param key The key .
* @return The translated string.
*/
protected String getI18nString(String key) {
return getI18nString(getI18nSection(), key);
}

/**
* @param section The section.
* @param key The key to translate.
* @return the translated key.
*/
protected String getI18nString(String section, String key) {
return i18n.getString(RESOURCE_BASENAME, locale, "report." + section + '.' + key);
}

/**
*
* @return the key prefix to be used with every key. Is prepended by {@code report.}.
*/
protected abstract String getI18nSection();
}
Loading

0 comments on commit 679d822

Please sign in to comment.