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 Nov 16, 2023
1 parent d6a03e6 commit 80e165a
Show file tree
Hide file tree
Showing 34 changed files with 291 additions and 270 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.2-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-M8</version>
</dependency>
<dependency>
<groupId>org.apache.maven.reporting</groupId>
<artifactId>maven-reporting-impl</artifactId>
<version>3.2.0</version>
<version>4.0.0-M11</version>
</dependency>

<!-- shared utils -->
Expand Down Expand Up @@ -156,7 +156,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
6 changes: 4 additions & 2 deletions maven-jxr-plugin/src/it/JXR-100_parameterlink/verify.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
* specific language governing permissions and limitations
* under the License.
*/
assert new File( basedir, 'target/site/xref/com/mycompany/app/Foo.html' ).exists()
File file = new File( basedir, 'target/site/xref/com/mycompany/app/Foo.html' );

assert 4 == new File( basedir, '/target/site/xref/com/mycompany/app/Foo.html' ).text.count( '<a name="App" href="../../../com/mycompany/app/App.html#App">App</a>' )
assert file.exists()

assert 4 == file.text.count( '<a name="App" href="../../../com/mycompany/app/App.html#App">App</a>' )
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 @@ -202,23 +194,23 @@ && hasSources(currentFile)) {
}

/**
* Creates the Xref for the Java files found in the given source directory and puts them in the given destination
* Creates the Xref for the Java files found in the given source directory and puts them in the given output
* directory.
*
* @param locale The user locale to use for the Xref generation
* @param destinationDirectory The output directory
* @param outputDirectory The output directory
* @param sourceDirs The source directories
* @throws java.io.IOException
* @throws org.apache.maven.jxr.JxrException
*/
private void createXref(Locale locale, String destinationDirectory, List<String> sourceDirs)
private void createXref(Locale locale, String outputDirectory, List<String> sourceDirs)
throws IOException, JxrException {
FileManager fileManager = new FileManager();
PackageManager packageManager = new PackageManager(fileManager);
JavaCodeTransform codeTransform = new JavaCodeTransform(packageManager, fileManager);

JXR jxr = new JXR(packageManager, codeTransform);
jxr.setDest(Paths.get(destinationDirectory));
jxr.setDest(Paths.get(outputDirectory));
jxr.setInputEncoding(getInputEncoding());
jxr.setLocale(locale);
jxr.setOutputEncoding(getOutputEncoding());
Expand All @@ -242,7 +234,7 @@ private void createXref(Locale locale, String destinationDirectory, List<String>
}

// and finally copy the stylesheet
copyRequiredResources(destinationDirectory);
copyRequiredResources(outputDirectory);
}

/**
Expand All @@ -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 @@ -293,28 +285,28 @@ private String getBottomText() {
}

/**
* Copy some required resources (like the stylesheet) to the given directory
* Copy some required resources (like the stylesheet) to the given target directory
*
* @param dir the directory to copy the resources to
* @param targetDirectory the directory to copy the resources to
*/
private void copyRequiredResources(String dir) {
private void copyRequiredResources(String targetDirectory) {
if (stylesheet != null && !stylesheet.isEmpty()) {
File stylesheetFile = new File(stylesheet);
File destStylesheetFile = new File(dir, "stylesheet.css");
File targetStylesheetFile = new File(targetDirectory, "stylesheet.css");

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

/**
* Copy styles and related resources to the given directory
*
* @param dir the directory to copy the resources to
* @param targetDirectory the target directory to copy the resources to
* @param sourceDirectory resources subdirectory to copy from
* @param files names of files to copy
*/
private void copyResources(String dir, String sourceDirectory, String... files) {
private void copyResources(String targetDirectory, String sourceDirectory, String... files) {
try {
for (String file : files) {
URL resourceUrl = this.getClass().getClassLoader().getResource(sourceDirectory + file);
File destResourceFile = new File(dir, file);
FileUtils.copyURLToFile(resourceUrl, destResourceFile);
File targetResourceFile = new File(targetDirectory, file);
FileUtils.copyURLToFile(resourceUrl, targetResourceFile);
}
} catch (IOException e) {
getLog().warn("An error occured while copying the resource to the target directory", e);
Expand All @@ -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 All @@ -386,7 +382,7 @@ protected void executeReport(Locale locale) throws MavenReportException {
setJavadocTemplatesVersion();

try {
createXref(locale, getDestinationDirectory(), constructSourceDirs());
createXref(locale, getPluginReportOutputDirectory(), constructSourceDirs());
} catch (JxrException | IOException e) {
throw new MavenReportException("Error while generating the HTML source code of the project.", e);
}
Expand Down Expand Up @@ -450,7 +446,6 @@ protected List<String> constructSourceDirs() {
@Override
public boolean canGenerateReport() {
if (skip) {
getLog().info("Skipping JXR.");
return false;
}

Expand Down Expand Up @@ -528,11 +523,12 @@ private Path getJavadocLocation() throws IOException {
}

/**
* Abstract method that returns the target directory where the generated JXR reports will be put.
* Abstract method that returns the plugin report output directory where the generated JXR reports will be put
* beneath {@link #getReportOutputDirectory()}.
*
* @return a String that contains the target directory name
*/
protected abstract String getDestinationDirectory();
protected abstract String getPluginReportOutputDirectory();

/**
* Abstract method that returns the specified source directories that will be included in the JXR report generation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,15 @@ public class JxrReport extends AbstractJxrReport {
@Parameter
private String sourcePath;

/**
* Directory where the Xref files will be copied to.
*/
@Parameter(defaultValue = "${project.reporting.outputDirectory}/xref")
private String destDir;

/**
* Directory where Javadoc is generated for this project.
*/
@Parameter(defaultValue = "${project.reporting.outputDirectory}/apidocs")
private File javadocDir;

@Override
protected String getDestinationDirectory() {
return destDir;
protected String getPluginReportOutputDirectory() {
return getReportOutputDirectory().getAbsolutePath() + "/xref";
}

@Override
Expand All @@ -80,12 +74,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 +91,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 All @@ -129,14 +123,4 @@ public String getOutputName() {
protected File getJavadocDir() {
return javadocDir;
}

@Override
public void setReportOutputDirectory(File reportOutputDirectory) {
if ((reportOutputDirectory != null)
&& (!reportOutputDirectory.getAbsolutePath().endsWith("xref"))) {
this.destDir = new File(reportOutputDirectory, "xref").getAbsolutePath();
} else {
this.destDir = reportOutputDirectory.getAbsolutePath();
}
}
}
Loading

0 comments on commit 80e165a

Please sign in to comment.