Skip to content

Commit

Permalink
[JXR-189] Dynamically calculate javadocLocation/testJavadocLocation
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-o committed Aug 19, 2024
1 parent 4744d81 commit c4b6a27
Show file tree
Hide file tree
Showing 14 changed files with 36 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ private void createXref(Locale locale, File outputDirectory, List<String> source
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 Down Expand Up @@ -468,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 @@ -500,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 Down Expand Up @@ -547,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 @@ -54,9 +54,11 @@ public class JxrReport extends AbstractJxrReport {

/**
* Directory where Javadoc is generated for this project.
* <br>
* <strong>Default</strong>: {@link #getReportOutputDirectory()} + {@code /apidocs}
*/
@Parameter(defaultValue = "${project.reporting.outputDirectory}/apidocs")
private File javadocDir;
@Parameter
private File javadocLocation;

@Override
protected File getPluginReportOutputDirectory() {
Expand Down Expand Up @@ -120,7 +122,7 @@ public String getOutputName() {
}

@Override
protected File getJavadocDir() {
return javadocDir;
protected File getJavadocLocation() {
return javadocLocation != null ? javadocLocation : new File(getReportOutputDirectory(), "apidocs");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,11 @@ public class JxrTestReport extends AbstractJxrReport {

/**
* Directory where Test Javadoc is generated for this project.
* <br>
* <strong>Default</strong>: {@link #getReportOutputDirectory()} + {@code /testapidocs}
*/
@Parameter(defaultValue = "${project.reporting.outputDirectory}/testapidocs")
private File testJavadocDir;
@Parameter
private File testJavadocLocation;

@Override
protected List<String> getSourceRoots() {
Expand Down Expand Up @@ -102,7 +104,7 @@ public String getOutputName() {
}

@Override
protected File getJavadocDir() {
return testJavadocDir;
protected File getJavadocLocation() {
return testJavadocLocation != null ? testJavadocLocation : new File(getReportOutputDirectory(), "testapidocs");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ under the License.
<value>${basedir}/src/test/resources/unit/aggregate-test/submodule1</value>
<value>${basedir}/src/test/resources/unit/aggregate-test/submodule2</value>
</sourceDirs>
<javadocDir>${basedir}/target/test/unit/aggregate-test/target/site/apidocs</javadocDir>
<javadocLocation>${basedir}/target/test/unit/aggregate-test/target/site/apidocs</javadocLocation>
<linkJavadoc>false</linkJavadoc>
<bottom>Copyright 2006 Apache Foundation</bottom>
<javadocVersion>1.4</javadocVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ under the License.
<sourceDirs>
<value>${basedir}/src/test/resources/unit/default-configuration</value>
</sourceDirs>
<javadocDir>${basedir}/target/test/unit/default-configuration/target/site/4/apidocs</javadocDir>
<javadocLocation>${basedir}/target/test/unit/default-configuration/target/site/4/apidocs</javadocLocation>
<linkJavadoc>true</linkJavadoc>
<bottom>Copyright 2006 Apache Foundation</bottom>
<javadocVersion>1.4</javadocVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ under the License.
<sourceDirs>
<value>${basedir}/src/test/resources/unit/default-configuration</value>
</sourceDirs>
<javadocDir>${basedir}/target/test/unit/default-configuration/target/site/6/apidocs</javadocDir>
<javadocLocation>${basedir}/target/test/unit/default-configuration/target/site/6/apidocs</javadocLocation>
<linkJavadoc>true</linkJavadoc>
<bottom>Copyright 2006 Apache Foundation</bottom>
<javadocVersion>1.6</javadocVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ under the License.
<sourceDirs>
<value>${basedir}/src/test/resources/unit/default-configuration</value>
</sourceDirs>
<javadocDir>${basedir}/target/test/unit/default-configuration/target/site/7/apidocs</javadocDir>
<javadocLocation>${basedir}/target/test/unit/default-configuration/target/site/7/apidocs</javadocLocation>
<linkJavadoc>true</linkJavadoc>
<bottom>Copyright 2006 Apache Foundation</bottom>
<javadocVersion>1.7</javadocVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ under the License.
<sourceDirs>
<value>${basedir}/src/test/resources/unit/default-configuration</value>
</sourceDirs>
<javadocDir>${basedir}/target/test/unit/default-configuration/target/site/8/apidocs</javadocDir>
<javadocLocation>${basedir}/target/test/unit/default-configuration/target/site/8/apidocs</javadocLocation>
<linkJavadoc>true</linkJavadoc>
<bottom>Copyright 2006 Apache Foundation</bottom>
<javadocVersion>1.8</javadocVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ under the License.
<sourceDirs>
<value>${basedir}/src/test/resources/unit/default-configuration</value>
</sourceDirs>
<javadocDir>${basedir}/target/test/unit/default-configuration/target/site/apidocs</javadocDir>
<javadocLocation>${basedir}/target/test/unit/default-configuration/target/site/apidocs</javadocLocation>
<linkJavadoc>true</linkJavadoc>
<bottom>Copyright 2006 Apache Foundation</bottom>
<templateDir>templates</templateDir>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ under the License.
<sourceDirs>
<value>${basedir}/src/test/resources/unit/default-configuration</value>
</sourceDirs>
<javadocDir>${basedir}/target/test/unit/default-configuration/target/site/apidocs</javadocDir>
<javadocLocation>${basedir}/target/test/unit/default-configuration/target/site/apidocs</javadocLocation>
<linkJavadoc>true</linkJavadoc>
<bottom>Copyright 2006 Apache Foundation</bottom>
<templateDir>temp</templateDir>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ under the License.
<sourceDirs>
<value>${basedir}/src/test/resources/unit/exclude-configuration</value>
</sourceDirs>
<javadocDir>${basedir}/target/test/unit/exclude-configuration/target/site/apidocs</javadocDir>
<javadocLocation>${basedir}/target/test/unit/exclude-configuration/target/site/apidocs</javadocLocation>
<linkJavadoc>true</linkJavadoc>
<bottom>Copyright 2006 Apache Foundation</bottom>
<javadocVersion>1.4</javadocVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ under the License.
<sourceDirs>
<value>${basedir}/src/test/resources/unit/include-configuration</value>
</sourceDirs>
<javadocDir>${basedir}/target/test/unit/include-configuration/target/site/apidocs</javadocDir>
<javadocLocation>${basedir}/target/test/unit/include-configuration/target/site/apidocs</javadocLocation>
<linkJavadoc>true</linkJavadoc>
<bottom>Copyright 2006 Apache Foundation</bottom>
<javadocVersion>1.4</javadocVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ under the License.
<sourceDirs>
<value>${basedir}/src/test/resources/unit/nojavadocdir-test</value>
</sourceDirs>
<javadocDir>${basedir}/target/test/unit/nojavadocdir-test/target/site/apidocs</javadocDir>
<javadocLocation>${basedir}/target/test/unit/nojavadocLocation-test/target/site/apidocs</javadocLocation>
<linkJavadoc>true</linkJavadoc>
<bottom>Copyright 2006 Apache Foundation</bottom>
<javadocVersion>1.4</javadocVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ under the License.
<sourceDirs>
<value>${basedir}/src/test/resources/unit/nojavadoclink-configuration</value>
</sourceDirs>
<javadocDir>${basedir}/target/test/unit/nojavadoclink-configuration/target/site/apidocs</javadocDir>
<javadocLocation>${basedir}/target/test/unit/nojavadoclink-configuration/target/site/apidocs</javadocLocation>
<linkJavadoc>false</linkJavadoc>
<bottom>Copyright 2006 Apache Foundation</bottom>
<javadocVersion>1.4</javadocVersion>
Expand Down

0 comments on commit c4b6a27

Please sign in to comment.