Skip to content

Commit

Permalink
[JXR-110] Use equivalent css/images of javadoc
Browse files Browse the repository at this point in the history
  • Loading branch information
judby authored and rfscholte committed Sep 21, 2018
1 parent 4b3d27c commit fb8790d
Show file tree
Hide file tree
Showing 51 changed files with 3,381 additions and 28 deletions.
4 changes: 4 additions & 0 deletions maven-jxr-plugin/pom.xml
Expand Up @@ -137,6 +137,10 @@ under the License.
<artifactId>doxia-site-renderer</artifactId>
<version>${doxia-sitetoolsVersion}</version>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-java</artifactId>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
Expand Down
3 changes: 3 additions & 0 deletions maven-jxr-plugin/src/it/JXR-100_parameterlink/pom.xml
Expand Up @@ -30,6 +30,9 @@ under the License.
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jxr-plugin</artifactId>
<version>@project.version@</version>
<configuration>
<javadocVersion>1.4</javadocVersion>
</configuration>
</plugin>
</plugins>
</pluginManagement>
Expand Down
3 changes: 3 additions & 0 deletions maven-jxr-plugin/src/it/JXR-135_innerclasses/pom.xml
Expand Up @@ -30,6 +30,9 @@ under the License.
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jxr-plugin</artifactId>
<version>@project.version@</version>
<configuration>
<javadocVersion>1.4</javadocVersion>
</configuration>
</plugin>
</plugins>
</pluginManagement>
Expand Down
5 changes: 4 additions & 1 deletion maven-jxr-plugin/src/it/aggregate/pom.xml
Expand Up @@ -56,12 +56,15 @@ under the License.
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jxr-plugin</artifactId>
<version>@project.version@</version>
<configuration>
<javadocVersion>1.4</javadocVersion>
</configuration>
<reportSets>
<reportSet>
<id>aggregate</id>
<reports>
<report>aggregate</report>
<report>test-aggregate</report>
<report>test-aggregate</report>
</reports>
</reportSet>
</reportSets>
Expand Down
8 changes: 7 additions & 1 deletion maven-jxr-plugin/src/it/mixed-plugin-report/pom.xml
Expand Up @@ -57,7 +57,10 @@ under the License.
<phase>site</phase>
</execution>
</executions>
</plugin>
<configuration>
<javadocVersion>1.4</javadocVersion>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
Expand Down Expand Up @@ -93,6 +96,9 @@ under the License.
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jxr-plugin</artifactId>
<version>@project.version@</version>
<configuration>
<javadocVersion>1.4</javadocVersion>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down
2 changes: 1 addition & 1 deletion maven-jxr-plugin/src/it/mixed-plugin-report/verify.groovy
Expand Up @@ -40,5 +40,5 @@ assert content.contains( 'App2.html' );
content = new File( basedir, 'target/site/xref/org/apache/maven/jxr/it2/App.html' ).text;
assert content.contains( 'App2.html' );
content = new File( basedir, 'target/site/xref/index.html' ).text;
assert content.contains( '<!-- this is a JXR report set -->' );
assert content.contains( '<!-- this is a JXR report set (jdk4) -->' );
return true;
3 changes: 3 additions & 0 deletions maven-jxr-plugin/src/it/new-site-config/pom.xml
Expand Up @@ -51,6 +51,9 @@ under the License.
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jxr-plugin</artifactId>
<version>@project.version@</version>
<configuration>
<javadocVersion>1.4</javadocVersion>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down
5 changes: 4 additions & 1 deletion maven-jxr-plugin/src/it/simple-project/pom.xml
Expand Up @@ -45,7 +45,7 @@ under the License.
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jxr-plugin</artifactId>
<version>@project.version@</version>
</plugin>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
Expand All @@ -61,6 +61,9 @@ under the License.
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jxr-plugin</artifactId>
<version>@project.version@</version>
<configuration>
<javadocVersion>1.4</javadocVersion>
</configuration>
</plugin>
</plugins>
</reporting>
Expand Down
Expand Up @@ -41,6 +41,7 @@
import org.apache.maven.project.MavenProject;
import org.apache.maven.reporting.AbstractMavenReport;
import org.apache.maven.reporting.MavenReportException;
import org.codehaus.plexus.languages.java.version.JavaVersion;
import org.codehaus.plexus.util.FileUtils;
import org.codehaus.plexus.util.ReaderFactory;
import org.codehaus.plexus.util.StringUtils;
Expand Down Expand Up @@ -107,14 +108,14 @@ public abstract class AbstractJxrReport
* Directory where Velocity templates can be found to generate overviews, frames and summaries. Should not be used.
* If used, should be an absolute path, like <code>"${basedir}/myTemplates"</code>.
*/
@Parameter( defaultValue = "templates" )
@Parameter
private String templateDir;

/**
* Style sheet used for the Xref HTML files. Should not be used. If used, should be an absolute path, like
* <code>"${basedir}/myStyles.css"</code>.
*/
@Parameter( defaultValue = "stylesheet.css" )
@Parameter
private String stylesheet;

/**
Expand Down Expand Up @@ -154,6 +155,19 @@ public abstract class AbstractJxrReport
@Parameter( defaultValue = "true" )
private boolean linkJavadoc;

/**
* Version of the Javadoc templates to use.
* The value should reflect `java.specification.version`, "1.4", "1.8", "9", "10",
* by default this system property is used.
*/
@Parameter( property = "javadocVersion" )
private String javadocVersion;

/**
* Version of the Javadoc templates to use.
*/
private JavaVersion javadocTemplatesVersion;

/**
* Gets the effective reporting output files encoding.
*
Expand Down Expand Up @@ -248,7 +262,7 @@ && hasSources( currentFile ) )
* @throws org.apache.maven.jxr.JxrException
*/
private void createXref( Locale locale, String destinationDirectory, List<String> sourceDirs )
throws IOException, JxrException
throws IOException, JxrException, MavenReportException
{
JXR jxr = new JXR();
jxr.setDest( Paths.get( destinationDirectory ) );
Expand Down Expand Up @@ -279,7 +293,7 @@ private void createXref( Locale locale, String destinationDirectory, List<String
try
{
Thread.currentThread().setContextClassLoader( getClass().getClassLoader() );
jxr.xref( sourceDirs, templateDir, windowTitle, docTitle, getBottomText() );
jxr.xref( sourceDirs, getTemplateDir(), windowTitle, docTitle, getBottomText() );
}
finally
{
Expand Down Expand Up @@ -356,26 +370,84 @@ private String getBottomText()
*/
private void copyRequiredResources( String dir )
{
File stylesheetFile = new File( stylesheet );
File destStylesheetFile = new File( dir, "stylesheet.css" );
if ( StringUtils.isNotEmpty( stylesheet ) )
{
File stylesheetFile = new File( stylesheet );
File destStylesheetFile = new File( dir, "stylesheet.css" );

try
try
{
if ( stylesheetFile.isAbsolute() )
{
FileUtils.copyFile( stylesheetFile, destStylesheetFile );
}
else
{
URL stylesheetUrl = this.getClass().getClassLoader().getResource( stylesheet );
FileUtils.copyURLToFile( stylesheetUrl, destStylesheetFile );
}
}
catch ( IOException e )
{
getLog().warn( "An error occured while copying the stylesheet to the target directory", e );
}
}
else
{
if ( stylesheetFile.isAbsolute() )
if ( javadocTemplatesVersion.isAtLeast( "1.8" ) )
{
copyResources( dir, "jdk8/", "stylesheet.css" );
}
else if ( javadocTemplatesVersion.isAtLeast( "1.7" ) )
{
String[] jdk7Resources =
{
"stylesheet.css",
"resources/background.gif",
"resources/tab.gif",
"resources/titlebar.gif",
"resources/titlebar_end.gif"
};
copyResources( dir, "jdk7/", jdk7Resources );
}
else if ( javadocTemplatesVersion.isAtLeast( "1.6" ) )
{
FileUtils.copyFile( stylesheetFile, destStylesheetFile );
copyResources( dir, "jdk6/", "stylesheet.css" );
}
else if ( javadocTemplatesVersion.isAtLeast( "1.4" ) )
{
copyResources( dir, "jdk4/", "stylesheet.css" );
}
else
{
URL stylesheetUrl = this.getClass().getClassLoader().getResource( stylesheet );
FileUtils.copyURLToFile( stylesheetUrl, destStylesheetFile );
// Fallback to the original stylesheet
copyResources( dir, "", "stylesheet.css" );
}
}
}

/**
* Copy styles and related resources to the given directory
*
* @param dir the directory to copy the resources to
* @param sourceFolder resources subfolder to copy from
* @param files names of files to copy
*/
private void copyResources( String dir, String sourceFolder, String... files )
{
try
{
for ( String file : files )
{
URL resourceUrl = this.getClass().getClassLoader().getResource( sourceFolder + file );
File destResourceFile = new File( dir, file );
FileUtils.copyURLToFile( resourceUrl, destResourceFile );
}
}
catch ( IOException e )
{
getLog().warn( "An error occured while copying the stylesheet to the target directory", e );
getLog().warn( "An error occured while copying the resource to the target directory", e );
}

}

@Override
Expand Down Expand Up @@ -464,6 +536,9 @@ protected void executeReport( Locale locale )
// init some attributes -- TODO (javadoc)
init();

// determine version of templates to use
setJavadocTemplatesVersion();

try
{
createXref( locale, getDestinationDirectory(), sourceDirs );
Expand All @@ -479,6 +554,57 @@ protected void executeReport( Locale locale )
}
}


/**
* Determine the templateDir to use, given javadocTemplatesVersion
*
* @return
* @throws org.apache.maven.reporting.MavenReportException if javadocTemplatesVersion cannot be parsed
*/
private String getTemplateDir()
{
// Check if overridden
if ( StringUtils.isEmpty( templateDir ) )
{
if ( javadocTemplatesVersion.isAtLeast( "1.8" ) )
{
return "templates/jdk8";
}
else if ( javadocTemplatesVersion.isAtLeast( "1.7" ) )
{
return "templates/jdk7";
}
else if ( javadocTemplatesVersion.isAtLeast( "1.4" ) )
{
return "templates/jdk4";
}
else
{
getLog().warn( "Unsupported javadocVersion: " + javadocTemplatesVersion + ". Fallback to original" );
return "templates";
}
}
// use value specified by user
return templateDir;
}

/**
* Set a new value for <code>javadocTemplatesVersion</code>
*/
private void setJavadocTemplatesVersion()
{
JavaVersion javaVersion = JavaVersion.JAVA_SPECIFICATION_VERSION;

if ( StringUtils.isNotEmpty( javadocVersion ) )
{
javadocTemplatesVersion = JavaVersion.parse( javadocVersion );
}
else
{
javadocTemplatesVersion = javaVersion;
}
}

/**
* Gets the list of the source directories to be included in the JXR report generation
*
Expand Down

0 comments on commit fb8790d

Please sign in to comment.