Skip to content

Commit

Permalink
Prepare for Doxia 2.0.0
Browse files Browse the repository at this point in the history
This also fixes JXR-169
  • Loading branch information
michael-o committed Jul 13, 2023
1 parent fb71130 commit b2c7173
Show file tree
Hide file tree
Showing 33 changed files with 232 additions and 169 deletions.
8 changes: 4 additions & 4 deletions maven-jxr-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ under the License.
<parent>
<groupId>org.apache.maven.jxr</groupId>
<artifactId>jxr</artifactId>
<version>3.3.1-SNAPSHOT</version>
<version>4.0.0-M1-SNAPSHOT</version>
</parent>

<groupId>org.apache.maven.plugins</groupId>
Expand Down Expand Up @@ -88,12 +88,12 @@ under the License.
<dependency>
<groupId>org.apache.maven.reporting</groupId>
<artifactId>maven-reporting-api</artifactId>
<version>3.1.1</version>
<version>4.0.0-M7</version>
</dependency>
<dependency>
<groupId>org.apache.maven.reporting</groupId>
<artifactId>maven-reporting-impl</artifactId>
<version>3.2.0</version>
<version>4.0.0-M9</version>
</dependency>

<!-- shared utils -->
Expand Down Expand Up @@ -152,7 +152,7 @@ under the License.
<dependency>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-http-lightweight</artifactId>
<version>3.5.1</version>
<version>3.5.3</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.apache.maven.jxr.pacman.FileManager;
import org.apache.maven.jxr.pacman.PackageManager;
import org.apache.maven.model.ReportPlugin;
import org.apache.maven.plugin.MojoExecution;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
import org.apache.maven.reporting.AbstractMavenReport;
Expand Down Expand Up @@ -73,10 +74,7 @@ public abstract class AbstractJxrReport extends AbstractMavenReport {
/**
* String used at the bottom of the Xref HTML files.
*/
@Parameter(
property = "bottom",
defaultValue =
"Copyright &#169; {inceptionYear}&#x2013;{currentYear} {organizationName}. All rights reserved.")
@Parameter(property = "bottom", defaultValue = "\u00A9 {inceptionYear}\u2013{currentYear} {organizationName}")
private String bottom;

// CHECKSTYLE_ON: LineLength
Expand Down Expand Up @@ -111,12 +109,6 @@ public abstract class AbstractJxrReport extends AbstractMavenReport {
@Parameter
private ArrayList<String> includes;

/**
* The projects in the reactor for aggregation report.
*/
@Parameter(defaultValue = "${reactorProjects}", readonly = true)
protected List<MavenProject> reactorProjects;

/**
* Whether to skip this execution.
*
Expand Down Expand Up @@ -258,12 +250,12 @@ private String getBottomText() {

if (inceptionYear != null) {
if (inceptionYear.equals(year)) {
theBottom = StringUtils.replace(theBottom, "{inceptionYear}&#x2013;", "");
theBottom = StringUtils.replace(theBottom, "{inceptionYear}\u2013", "");
} else {
theBottom = StringUtils.replace(theBottom, "{inceptionYear}", inceptionYear);
}
} else {
theBottom = StringUtils.replace(theBottom, "{inceptionYear}&#x2013;", "");
theBottom = StringUtils.replace(theBottom, "{inceptionYear}\u2013", "");
}

if (project.getOrganization() == null) {
Expand Down Expand Up @@ -359,14 +351,18 @@ protected MavenProject getProject() {
return project;
}

/**
* Returns the Maven session.
* @return Maven session
*/
protected MavenSession getSession() {
return session;
}

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

protected MojoExecution getMojoExecution() {
return mojoExecution;
}

/**
* Returns the correct resource bundle according to the locale.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,12 @@ protected List<String> getSourceRoots() {

List<String> l = new ArrayList<>();

if (!"pom".equals(getProject().getPackaging().toLowerCase(Locale.US))) {
if (!"pom".equals(getProject().getPackaging().toLowerCase(Locale.ENGLISH))) {
l.addAll(sourceDirs);
}

if (getProject().getExecutionProject() != null) {
if (!"pom".equals(getProject().getExecutionProject().getPackaging().toLowerCase(Locale.US))) {
if (!"pom".equals(getProject().getExecutionProject().getPackaging().toLowerCase(Locale.ENGLISH))) {
l.addAll(getProject().getExecutionProject().getCompileSourceRoots());
}
}
Expand All @@ -97,12 +97,12 @@ protected List<String> getSourceRoots() {
protected List<String> getSourceRoots(MavenProject project) {
List<String> l = new ArrayList<>();

if (!"pom".equals(project.getPackaging().toLowerCase(Locale.US))) {
if (!"pom".equals(project.getPackaging().toLowerCase(Locale.ENGLISH))) {
l.addAll(project.getCompileSourceRoots());
}

if (project.getExecutionProject() != null) {
if (!"pom".equals(project.getExecutionProject().getPackaging().toLowerCase(Locale.US))) {
if (!"pom".equals(project.getExecutionProject().getPackaging().toLowerCase(Locale.ENGLISH))) {
l.addAll(project.getExecutionProject().getCompileSourceRoots());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ public class JxrTestReport extends AbstractJxrReport {
protected List<String> getSourceRoots() {
List<String> l = new ArrayList<>();

if (!"pom".equals(getProject().getPackaging().toLowerCase(Locale.US))) {
if (!"pom".equals(getProject().getPackaging().toLowerCase(Locale.ENGLISH))) {
l.addAll(sourceDirs);
}

if (getProject().getExecutionProject() != null) {
if (!"pom".equals(getProject().getExecutionProject().getPackaging().toLowerCase(Locale.US))) {
if (!"pom".equals(getProject().getExecutionProject().getPackaging().toLowerCase(Locale.ENGLISH))) {
l.addAll(getProject().getExecutionProject().getTestCompileSourceRoots());
}
}
Expand All @@ -79,7 +79,7 @@ protected List<String> getSourceRoots(MavenProject project) {
List<String> l = new ArrayList<>();

if (project.getExecutionProject() != null) {
if (!"pom".equals(project.getExecutionProject().getPackaging().toLowerCase(Locale.US))) {
if (!"pom".equals(project.getExecutionProject().getPackaging().toLowerCase(Locale.ENGLISH))) {
l.addAll(project.getExecutionProject().getTestCompileSourceRoots());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,14 @@
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.Collections;
import java.util.List;

import org.apache.maven.model.Plugin;
import org.apache.maven.plugin.LegacySupport;
import org.apache.maven.plugin.MojoExecution;
import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.plugin.testing.AbstractMojoTestCase;
import org.apache.maven.plugin.testing.ArtifactStubFactory;
import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
Expand Down Expand Up @@ -112,8 +118,17 @@ protected AbstractJxrReport createReportMojo(String goal, File pluginXmlFile) th
repoSession.setLocalRepositoryManager(new SimpleLocalRepositoryManagerFactory()
.newInstance(repoSession, new LocalRepository(artifactStubFactory.getWorkingDir())));

List<MavenProject> reactorProjects =
mojo.getReactorProjects() != null ? mojo.getReactorProjects() : Collections.emptyList();

setVariableValueToObject(mojo, "mojoExecution", getMockMojoExecution());
setVariableValueToObject(mojo, "session", legacySupport.getSession());
setVariableValueToObject(mojo, "remoteRepositories", mojo.getProject().getRemoteArtifactRepositories());
setVariableValueToObject(mojo, "repoSession", legacySupport.getRepositorySession());
setVariableValueToObject(mojo, "reactorProjects", reactorProjects);
setVariableValueToObject(
mojo, "remoteProjectRepositories", mojo.getProject().getRemoteProjectRepositories());
setVariableValueToObject(
mojo, "siteDirectory", new File(mojo.getProject().getBasedir(), "src/site"));
return mojo;
}

Expand All @@ -139,4 +154,22 @@ protected File generateReport(AbstractJxrReport mojo, File pluginXmlFile) throws
protected String readFile(File xrefTestDir, String fileName) throws IOException {
return new String(Files.readAllBytes(xrefTestDir.toPath().resolve(fileName)));
}

private MojoExecution getMockMojoExecution() {
MojoDescriptor md = new MojoDescriptor();
md.setGoal(getGoal());

MojoExecution me = new MojoExecution(md);

PluginDescriptor pd = new PluginDescriptor();
Plugin p = new Plugin();
p.setGroupId("org.apache.maven.plugins");
p.setArtifactId("maven-jxr-plugin");
pd.setPlugin(p);
md.setPluginDescriptor(pd);

return me;
}

protected abstract String getGoal();
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void testDefaultConfiguration() throws Exception {

FileUtils.copyDirectory(new File(resourcesDir, "javadoc-files"), outputDir);

generateReport("jxr", "default-configuration/default-configuration-plugin-config.xml");
generateReport(getGoal(), "default-configuration/default-configuration-plugin-config.xml");

// check if xref files were generated
assertTrue(new File(xrefDir, "allclasses-frame.html").exists());
Expand Down Expand Up @@ -80,7 +80,7 @@ public void testJdk4Configuration() throws Exception {

FileUtils.copyDirectory(new File(resourcesDir, "javadoc-files"), outputDir);

generateReport("jxr", "default-configuration/default-configuration-plugin-config-4.xml");
generateReport(getGoal(), "default-configuration/default-configuration-plugin-config-4.xml");

// check if xref files were generated
assertTrue(new File(xrefDir, "allclasses-frame.html").exists());
Expand All @@ -95,10 +95,10 @@ public void testJdk4Configuration() throws Exception {

// check if there's a link to the javadoc files
String str = readFile(xrefDir, "def/configuration/AppSample.html");
assertTrue(str.toLowerCase(Locale.US).contains("/apidocs/def/configuration/appsample.html\""));
assertTrue(str.toLowerCase(Locale.ENGLISH).contains("/apidocs/def/configuration/appsample.html\""));

str = readFile(xrefDir, "def/configuration/App.html");
assertTrue(str.toLowerCase(Locale.US).contains("/apidocs/def/configuration/app.html\""));
assertTrue(str.toLowerCase(Locale.ENGLISH).contains("/apidocs/def/configuration/app.html\""));

// check if encoding is UTF-8, the default value
assertTrue(str.contains("text/html; charset=UTF-8"));
Expand All @@ -117,7 +117,7 @@ public void testJdk6Configuration() throws Exception {

FileUtils.copyDirectory(new File(resourcesDir, "javadoc-files"), outputDir);

generateReport("jxr", "default-configuration/default-configuration-plugin-config-6.xml");
generateReport(getGoal(), "default-configuration/default-configuration-plugin-config-6.xml");

// check if xref files were generated
assertTrue(new File(xrefDir, "allclasses-frame.html").exists());
Expand All @@ -132,10 +132,10 @@ public void testJdk6Configuration() throws Exception {

// check if there's a link to the javadoc files
String str = readFile(xrefDir, "def/configuration/AppSample.html");
assertTrue(str.toLowerCase(Locale.US).contains("/apidocs/def/configuration/appsample.html\""));
assertTrue(str.toLowerCase(Locale.ENGLISH).contains("/apidocs/def/configuration/appsample.html\""));

str = readFile(xrefDir, "def/configuration/App.html");
assertTrue(str.toLowerCase(Locale.US).contains("/apidocs/def/configuration/app.html\""));
assertTrue(str.toLowerCase(Locale.ENGLISH).contains("/apidocs/def/configuration/app.html\""));

// check if encoding is UTF-8, the default value
assertTrue(str.contains("text/html; charset=UTF-8"));
Expand All @@ -154,7 +154,7 @@ public void testJdk7Configuration() throws Exception {

FileUtils.copyDirectory(new File(resourcesDir, "javadoc-files"), outputDir);

generateReport("jxr", "default-configuration/default-configuration-plugin-config-7.xml");
generateReport(getGoal(), "default-configuration/default-configuration-plugin-config-7.xml");

// check if xref files were generated
assertTrue(new File(xrefDir, "allclasses-frame.html").exists());
Expand All @@ -173,10 +173,10 @@ public void testJdk7Configuration() throws Exception {

// check if there's a link to the javadoc files
String str = readFile(xrefDir, "def/configuration/AppSample.html");
assertTrue(str.toLowerCase(Locale.US).contains("/apidocs/def/configuration/appsample.html\""));
assertTrue(str.toLowerCase(Locale.ENGLISH).contains("/apidocs/def/configuration/appsample.html\""));

str = readFile(xrefDir, "def/configuration/App.html");
assertTrue(str.toLowerCase(Locale.US).contains("/apidocs/def/configuration/app.html\""));
assertTrue(str.toLowerCase(Locale.ENGLISH).contains("/apidocs/def/configuration/app.html\""));

// check if encoding is UTF-8, the default value
assertTrue(str.contains("text/html; charset=UTF-8"));
Expand All @@ -195,7 +195,7 @@ public void testJdk8Configuration() throws Exception {

FileUtils.copyDirectory(new File(resourcesDir, "javadoc-files"), outputDir);

generateReport("jxr", "default-configuration/default-configuration-plugin-config-8.xml");
generateReport(getGoal(), "default-configuration/default-configuration-plugin-config-8.xml");

// check if xref files were generated
assertTrue(new File(xrefDir, "allclasses-frame.html").exists());
Expand Down Expand Up @@ -225,7 +225,7 @@ public void testJdk8Configuration() throws Exception {
* @throws Exception
*/
public void testNoJavadocLink() throws Exception {
generateReport("jxr", "nojavadoclink-configuration/nojavadoclink-configuration-plugin-config.xml");
generateReport(getGoal(), "nojavadoclink-configuration/nojavadoclink-configuration-plugin-config.xml");

File xrefDir = new File(getBasedir(), "target/test/unit/nojavadoclink-configuration/target/site/xref");

Expand All @@ -245,10 +245,11 @@ public void testNoJavadocLink() throws Exception {

// check if there's a link to the javadoc files
String str = readFile(xrefDir, "nojavadoclink/configuration/AppSample.html");
assertEquals(str.toLowerCase(Locale.US).indexOf("/apidocs/nojavadoclink/configuration/appsample.html\""), -1);
assertEquals(
str.toLowerCase(Locale.ENGLISH).indexOf("/apidocs/nojavadoclink/configuration/appsample.html\""), -1);

str = readFile(xrefDir, "nojavadoclink/configuration/App.html");
assertEquals(str.toLowerCase(Locale.US).indexOf("/apidocs/nojavadoclink/configuration/app.html\""), -1);
assertEquals(str.toLowerCase(Locale.ENGLISH).indexOf("/apidocs/nojavadoclink/configuration/app.html\""), -1);

str = readFile(xrefDir, "nojavadoclink/configuration/sample/Sample.html");
assertEquals(str.toLowerCase().indexOf("/apidocs/nojavadoclink/configuration/sample/sample.html\""), -1);
Expand All @@ -263,7 +264,7 @@ public void testNoJavadocLink() throws Exception {
* @throws Exception
*/
public void testAggregate() throws Exception {
generateReport("jxr", "aggregate-test/aggregate-test-plugin-config.xml");
generateReport(getGoal(), "aggregate-test/aggregate-test-plugin-config.xml");

File xrefDir = new File(getBasedir(), "target/test/unit/aggregate-test/target/site/xref");

Expand All @@ -286,16 +287,16 @@ public void testAggregate() throws Exception {
* @throws Exception
*/
public void testNoJavadocDir() throws Exception {
generateReport("jxr", "nojavadocdir-test/nojavadocdir-test-plugin-config.xml");
generateReport(getGoal(), "nojavadocdir-test/nojavadocdir-test-plugin-config.xml");

File xrefDir = new File(getBasedir(), "target/test/unit/nojavadocdir-test/target/site/xref");

// check if there's a link to the javadoc files
String str = readFile(xrefDir, "nojavadocdir/test/AppSample.html");
assertTrue(str.toLowerCase(Locale.US).contains("/apidocs/nojavadocdir/test/appsample.html"));
assertTrue(str.toLowerCase(Locale.ENGLISH).contains("/apidocs/nojavadocdir/test/appsample.html"));

str = readFile(xrefDir, "nojavadocdir/test/App.html");
assertTrue(str.toLowerCase(Locale.US).contains("/apidocs/nojavadocdir/test/app.html"));
assertTrue(str.toLowerCase(Locale.ENGLISH).contains("/apidocs/nojavadocdir/test/app.html"));
}

/**
Expand All @@ -304,7 +305,7 @@ public void testNoJavadocDir() throws Exception {
* @throws Exception
*/
public void testExclude() throws Exception {
generateReport("jxr", "exclude-configuration/exclude-configuration-plugin-config.xml");
generateReport(getGoal(), "exclude-configuration/exclude-configuration-plugin-config.xml");

Path xrefDir = new File(getBasedir(), "target/test/unit/exclude-configuration/target/site/xref").toPath();

Expand All @@ -321,7 +322,7 @@ public void testExclude() throws Exception {
* @throws Exception
*/
public void testInclude() throws Exception {
generateReport("jxr", "include-configuration/include-configuration-plugin-config.xml");
generateReport(getGoal(), "include-configuration/include-configuration-plugin-config.xml");

Path xrefDir = new File(getBasedir(), "target/test/unit/include-configuration/target/site/xref").toPath();

Expand All @@ -334,7 +335,7 @@ public void testInclude() throws Exception {

public void testExceptions() {
try {
generateReport("jxr", "default-configuration/exception-test-plugin-config.xml");
generateReport(getGoal(), "default-configuration/exception-test-plugin-config.xml");

fail("Must throw exception");
} catch (Exception e) {
Expand All @@ -348,8 +349,13 @@ public void testExceptions() {
* @throws Exception
*/
public void testPom() throws Exception {
generateReport("jxr", "pom-test/pom-test-plugin-config.xml");
generateReport(getGoal(), "pom-test/pom-test-plugin-config.xml");

assertFalse(new File(getBasedir(), "target/test/unit/pom-test").exists());
}

@Override
protected String getGoal() {
return "jxr";
}
}
Loading

0 comments on commit b2c7173

Please sign in to comment.