Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JXR-188] Upgrade to Doxia 2.0.0 Milestone Stack #64

Merged
merged 2 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions maven-jxr-plugin/pom.xml
Original file line number Diff line number Diff line change
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-M12</version>
</dependency>
<dependency>
<groupId>org.apache.maven.reporting</groupId>
<artifactId>maven-reporting-impl</artifactId>
<version>3.2.0</version>
<version>4.0.0-M15</version>
</dependency>

<!-- shared utils -->
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/reports/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,28 +194,28 @@ && 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, File 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(outputDirectory.toPath());
jxr.setInputEncoding(getInputEncoding());
jxr.setLocale(locale);
jxr.setOutputEncoding(getOutputEncoding());
jxr.setRevision("HEAD");
jxr.setJavadocLinkDir(getJavadocLocation());
jxr.setJavadocLinkDir(constructJavadocLocation());
// Set include/exclude patterns on the jxr instance
if (excludes != null && !excludes.isEmpty()) {
jxr.setExcludes(excludes.toArray(new String[0]));
Expand All @@ -242,11 +234,11 @@ private void createXref(Locale locale, String destinationDirectory, List<String>
}

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

/**
* Returns the bottom text to be displayed at the lower part of the generated JXR reports.
* Returns the bottom text to be displayed at the lower part of the generated JXR report.
*/
private String getBottomText() {
int currentYear = Calendar.getInstance().get(Calendar.YEAR);
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(File 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(File 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 All @@ -473,30 +468,30 @@ public boolean isExternalReport() {
/**
* @return a String that contains the location of the javadocs
*/
private Path getJavadocLocation() throws IOException {
private Path constructJavadocLocation() throws IOException {
Path location = null;
if (linkJavadoc) {
// We don't need to do the whole translation thing like normal, because JXR does it internally.
// It probably shouldn't.
if (getJavadocDir().exists()) {
if (getJavadocLocation().exists()) {
// XRef was already generated by manual execution of a lifecycle binding
location = getJavadocDir().toPath().toAbsolutePath();
location = getJavadocLocation().toPath().toAbsolutePath();
} else {
// Not yet generated - check if the report is on its way

// Special case: using the site:stage goal
String stagingDirectory = System.getProperty("stagingDirectory");

if (stagingDirectory != null && !stagingDirectory.isEmpty()) {
String javadocDestDir = getJavadocDir().getName();
String javadocOutputDir = getJavadocLocation().getName();
boolean javadocAggregate = JxrReportUtil.isJavadocAggregated(project);
String structureProject = JxrReportUtil.getStructure(project, false);

if (isAggregate() && javadocAggregate) {
location = Paths.get(stagingDirectory, structureProject, javadocDestDir);
location = Paths.get(stagingDirectory, structureProject, javadocOutputDir);
}
if (!isAggregate() && javadocAggregate) {
location = Paths.get(stagingDirectory, javadocDestDir);
location = Paths.get(stagingDirectory, javadocOutputDir);

String hierarchy = project.getName();

Expand All @@ -505,17 +500,17 @@ private Path getJavadocLocation() throws IOException {
hierarchy = parent.getName();
parent = parent.getParent();
}
location = Paths.get(stagingDirectory, hierarchy, javadocDestDir);
location = Paths.get(stagingDirectory, hierarchy, javadocOutputDir);
}
if (isAggregate() && !javadocAggregate) {
getLog().warn("The JXR plugin is configured to build an aggregated report at the root, "
+ "not the Javadoc plugin.");
}
if (!isAggregate() && !javadocAggregate) {
location = Paths.get(stagingDirectory, structureProject, javadocDestDir);
location = Paths.get(stagingDirectory, structureProject, javadocOutputDir);
}
} else {
location = getJavadocDir().toPath();
location = getJavadocLocation().toPath();
}
}

Expand All @@ -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 report will be put
* beneath {@link #getReportOutputDirectory()}.
*
* @return a String that contains the target directory name
* @return a File for the plugin's report output directory
*/
protected abstract String getDestinationDirectory();
protected abstract File getPluginReportOutputDirectory();

/**
* Abstract method that returns the specified source directories that will be included in the JXR report generation.
Expand All @@ -551,11 +547,11 @@ private Path getJavadocLocation() throws IOException {
protected abstract List<String> getSourceRoots(MavenProject project);

/**
* Abstract method that returns the directory of the javadoc files.
* Abstract method that returns the location where (Test) Javadoc is generated for this project.
*
* @return a File for the directory of the javadocs
* @return a File for the location of (test) javadoc
*/
protected abstract File getJavadocDir();
protected abstract File getJavadocLocation();

/**
* Is the current report aggregated?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import org.apache.maven.plugins.annotations.Mojo;

/**
* Creates an html-based, cross referenced version of Java source code
* Creates an HTML-based, cross referenced version of Java source code
* for a project without forking. Note that this goal does require generation of sources before
* site generation, e.g. by invoking {@code }mvn clean deploy site}.
*
Expand Down
Loading