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 May 7, 2023
1 parent 29fe6f4 commit 40bd704
Show file tree
Hide file tree
Showing 32 changed files with 230 additions and 133 deletions.
8 changes: 4 additions & 4 deletions maven-jxr-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,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 @@ -89,12 +89,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-M6</version>
</dependency>
<dependency>
<groupId>org.apache.maven.reporting</groupId>
<artifactId>maven-reporting-impl</artifactId>
<version>3.2.0</version>
<version>4.0.0-M8</version>
</dependency>

<!-- shared utils -->
Expand Down Expand Up @@ -153,7 +153,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 @@ -38,6 +38,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 @@ -76,7 +77,7 @@ public abstract class AbstractJxrReport
/**
* 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 +112,6 @@ public abstract class AbstractJxrReport
@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 @@ -282,7 +277,7 @@ private String getBottomText()
{
if ( inceptionYear.equals( year ) )
{
theBottom = StringUtils.replace( theBottom, "{inceptionYear}&#x2013;", "" );
theBottom = StringUtils.replace( theBottom, "{inceptionYear}\u2013", "" );
}
else
{
Expand All @@ -291,7 +286,7 @@ private String getBottomText()
}
else
{
theBottom = StringUtils.replace( theBottom, "{inceptionYear}&#x2013;", "" );
theBottom = StringUtils.replace( theBottom, "{inceptionYear}\u2013", "" );
}

if ( project.getOrganization() == null )
Expand Down Expand Up @@ -418,15 +413,21 @@ 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 @@ -87,14 +87,14 @@ 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 @@ -108,14 +108,14 @@ 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 @@ -65,14 +65,14 @@ 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 @@ -88,7 +88,7 @@ protected List<String> getSourceRoots( MavenProject project )

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 @@ -22,8 +22,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 @@ -125,8 +131,14 @@ protected AbstractJxrReport createReportMojo( String goal, File pluginXmlFile )
(DefaultRepositorySystemSession) legacySupport.getRepositorySession();
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 Down Expand Up @@ -156,4 +168,21 @@ protected String readFile( File xrefTestDir, String fileName ) throws IOExceptio
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 @@ -48,7 +48,7 @@ public void testDefaultConfiguration()

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 @@ -87,7 +87,7 @@ public void testJdk4Configuration()

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 @@ -102,10 +102,10 @@ public void testJdk4Configuration()

//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 @@ -126,7 +126,7 @@ public void testJdk6Configuration()

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 @@ -141,10 +141,10 @@ public void testJdk6Configuration()

//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 @@ -165,7 +165,7 @@ public void testJdk7Configuration()

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 @@ -184,10 +184,10 @@ public void testJdk7Configuration()

//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 @@ -208,7 +208,7 @@ public void testJdk8Configuration()

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 @@ -240,7 +240,7 @@ public void testJdk8Configuration()
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 @@ -260,11 +260,11 @@ public void testNoJavadocLink()

//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\"" ),
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 @@ -281,7 +281,7 @@ public void testNoJavadocLink()
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 @@ -306,16 +306,16 @@ public void testAggregate()
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 @@ -326,7 +326,7 @@ public void testNoJavadocDir()
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 @@ -345,7 +345,7 @@ public void testExclude()
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 @@ -360,7 +360,7 @@ 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" );
}
Expand All @@ -378,9 +378,14 @@ public void testExceptions()
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 40bd704

Please sign in to comment.