diff --git a/src/main/java/org/apache/maven/plugins/pmd/AbstractPmdReport.java b/src/main/java/org/apache/maven/plugins/pmd/AbstractPmdReport.java index 97cf3d47..2fab8485 100644 --- a/src/main/java/org/apache/maven/plugins/pmd/AbstractPmdReport.java +++ b/src/main/java/org/apache/maven/plugins/pmd/AbstractPmdReport.java @@ -78,22 +78,26 @@ public abstract class AbstractPmdReport extends AbstractMavenReport { protected String format = "xml"; /** - * Link the violation line numbers to the source xref. Links will be created automatically if the jxr plugin is + * Link the violation line numbers to the (Test) Source XRef. Links will be created automatically if the JXR plugin is * being used. */ @Parameter(property = "linkXRef", defaultValue = "true") private boolean linkXRef; /** - * Location of the Xrefs to link to. + * Location where Source XRef is generated for this project. + *
+ * Default: {@link #getReportOutputDirectory()} + {@code /xref} */ - @Parameter(defaultValue = "${project.reporting.outputDirectory}/xref") + @Parameter private File xrefLocation; /** - * Location of the Test Xrefs to link to. + * Location where Test Source XRef is generated for this project. + *
+ * Default: {@link #getReportOutputDirectory()} + {@code /xref-test} */ - @Parameter(defaultValue = "${project.reporting.outputDirectory}/xref-test") + @Parameter private File xrefTestLocation; /** @@ -279,18 +283,18 @@ protected MojoExecution getMojoExecution() { return mojoExecution; } - protected String constructXRefLocation(boolean test) { + protected String constructXrefLocation(boolean test) { String location = null; if (linkXRef) { - File xrefLoc = test ? xrefTestLocation : xrefLocation; + File xrefLocation = getXrefLocation(test); - String relativePath = - PathTool.getRelativePath(getReportOutputDirectory().getAbsolutePath(), xrefLoc.getAbsolutePath()); + String relativePath = PathTool.getRelativePath( + getReportOutputDirectory().getAbsolutePath(), xrefLocation.getAbsolutePath()); if (relativePath == null || relativePath.isEmpty()) { relativePath = "."; } - relativePath = relativePath + "/" + xrefLoc.getName(); - if (xrefLoc.exists()) { + relativePath = relativePath + "/" + xrefLocation.getName(); + if (xrefLocation.exists()) { // XRef was already generated by manual execution of a lifecycle binding location = relativePath; } else { @@ -300,19 +304,24 @@ protected String constructXRefLocation(boolean test) { reporting != null ? reporting.getPlugins() : Collections.emptyList(); for (ReportPlugin plugin : reportPlugins) { String artifactId = plugin.getArtifactId(); - if ("maven-jxr-plugin".equals(artifactId) || "jxr-maven-plugin".equals(artifactId)) { + if ("maven-jxr-plugin".equals(artifactId)) { location = relativePath; } } } if (location == null) { - getLog().warn("Unable to locate Source XRef to link to - DISABLED"); + getLog().warn("Unable to locate" + (test ? " Test" : "") + " Source XRef to link to - DISABLED"); } } return location; } + protected File getXrefLocation(boolean test) { + File location = test ? xrefTestLocation : xrefLocation; + return location != null ? location : new File(getReportOutputDirectory(), test ? "xref-test" : "xref"); + } + /** * Convenience method to get the list of files where the PMD tool will be executed * @@ -346,7 +355,7 @@ protected Map getFilesToProcess() throws IOException { for (String root : compileSourceRoots) { File sroot = new File(root); if (sroot.exists()) { - String sourceXref = constructXRefLocation(false); + String sourceXref = constructXrefLocation(false); directories.add(new PmdFileInfo(project, sroot, sourceXref)); } } @@ -359,7 +368,7 @@ protected Map getFilesToProcess() throws IOException { for (String root : testSourceRoots) { File sroot = new File(root); if (sroot.exists()) { - String testXref = constructXRefLocation(true); + String testXref = constructXrefLocation(true); directories.add(new PmdFileInfo(project, sroot, testXref)); } } @@ -370,7 +379,7 @@ protected Map getFilesToProcess() throws IOException { for (String root : localCompileSourceRoots) { File sroot = new File(root); if (sroot.exists()) { - String sourceXref = constructXRefLocation(false); + String sourceXref = constructXrefLocation(false); directories.add(new PmdFileInfo(localProject, sroot, sourceXref)); } } @@ -379,7 +388,7 @@ protected Map getFilesToProcess() throws IOException { for (String root : localTestCompileSourceRoots) { File sroot = new File(root); if (sroot.exists()) { - String testXref = constructXRefLocation(true); + String testXref = constructXrefLocation(true); directories.add(new PmdFileInfo(localProject, sroot, testXref)); } }