Skip to content

Commit 2498240

Browse files
committed
[MPMD-390] Dynamically calculate xrefLocation/xrefTestLocation
1 parent c31b29a commit 2498240

File tree

1 file changed

+26
-17
lines changed

1 file changed

+26
-17
lines changed

src/main/java/org/apache/maven/plugins/pmd/AbstractPmdReport.java

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -78,22 +78,26 @@ public abstract class AbstractPmdReport extends AbstractMavenReport {
7878
protected String format = "xml";
7979

8080
/**
81-
* Link the violation line numbers to the source xref. Links will be created automatically if the jxr plugin is
81+
* Link the violation line numbers to the (Test) Source XRef. Links will be created automatically if the JXR plugin is
8282
* being used.
8383
*/
8484
@Parameter(property = "linkXRef", defaultValue = "true")
8585
private boolean linkXRef;
8686

8787
/**
88-
* Location of the Xrefs to link to.
88+
* Location where Source XRef is generated for this project.
89+
* <br>
90+
* <strong>Default</strong>: {@link #getReportOutputDirectory()} + {@code /xref}
8991
*/
90-
@Parameter(defaultValue = "${project.reporting.outputDirectory}/xref")
92+
@Parameter
9193
private File xrefLocation;
9294

9395
/**
94-
* Location of the Test Xrefs to link to.
96+
* Location where Test Source XRef is generated for this project.
97+
* <br>
98+
* <strong>Default</strong>: {@link #getReportOutputDirectory()} + {@code /xref-test}
9599
*/
96-
@Parameter(defaultValue = "${project.reporting.outputDirectory}/xref-test")
100+
@Parameter
97101
private File xrefTestLocation;
98102

99103
/**
@@ -279,18 +283,18 @@ protected MojoExecution getMojoExecution() {
279283
return mojoExecution;
280284
}
281285

282-
protected String constructXRefLocation(boolean test) {
286+
protected String constructXrefLocation(boolean test) {
283287
String location = null;
284288
if (linkXRef) {
285-
File xrefLoc = test ? xrefTestLocation : xrefLocation;
289+
File xrefLocation = getXrefLocation(test);
286290

287-
String relativePath =
288-
PathTool.getRelativePath(getReportOutputDirectory().getAbsolutePath(), xrefLoc.getAbsolutePath());
291+
String relativePath = PathTool.getRelativePath(
292+
getReportOutputDirectory().getAbsolutePath(), xrefLocation.getAbsolutePath());
289293
if (relativePath == null || relativePath.isEmpty()) {
290294
relativePath = ".";
291295
}
292-
relativePath = relativePath + "/" + xrefLoc.getName();
293-
if (xrefLoc.exists()) {
296+
relativePath = relativePath + "/" + xrefLocation.getName();
297+
if (xrefLocation.exists()) {
294298
// XRef was already generated by manual execution of a lifecycle binding
295299
location = relativePath;
296300
} else {
@@ -300,19 +304,24 @@ protected String constructXRefLocation(boolean test) {
300304
reporting != null ? reporting.getPlugins() : Collections.<ReportPlugin>emptyList();
301305
for (ReportPlugin plugin : reportPlugins) {
302306
String artifactId = plugin.getArtifactId();
303-
if ("maven-jxr-plugin".equals(artifactId) || "jxr-maven-plugin".equals(artifactId)) {
307+
if ("maven-jxr-plugin".equals(artifactId)) {
304308
location = relativePath;
305309
}
306310
}
307311
}
308312

309313
if (location == null) {
310-
getLog().warn("Unable to locate Source XRef to link to - DISABLED");
314+
getLog().warn("Unable to locate" + (test ? " Test" : "") + " Source XRef to link to - DISABLED");
311315
}
312316
}
313317
return location;
314318
}
315319

320+
protected File getXrefLocation(boolean test) {
321+
File location = test ? xrefTestLocation : xrefLocation;
322+
return location != null ? location : new File(getReportOutputDirectory(), test ? "xref-test" : "xref");
323+
}
324+
316325
/**
317326
* Convenience method to get the list of files where the PMD tool will be executed
318327
*
@@ -346,7 +355,7 @@ protected Map<File, PmdFileInfo> getFilesToProcess() throws IOException {
346355
for (String root : compileSourceRoots) {
347356
File sroot = new File(root);
348357
if (sroot.exists()) {
349-
String sourceXref = constructXRefLocation(false);
358+
String sourceXref = constructXrefLocation(false);
350359
directories.add(new PmdFileInfo(project, sroot, sourceXref));
351360
}
352361
}
@@ -359,7 +368,7 @@ protected Map<File, PmdFileInfo> getFilesToProcess() throws IOException {
359368
for (String root : testSourceRoots) {
360369
File sroot = new File(root);
361370
if (sroot.exists()) {
362-
String testXref = constructXRefLocation(true);
371+
String testXref = constructXrefLocation(true);
363372
directories.add(new PmdFileInfo(project, sroot, testXref));
364373
}
365374
}
@@ -370,7 +379,7 @@ protected Map<File, PmdFileInfo> getFilesToProcess() throws IOException {
370379
for (String root : localCompileSourceRoots) {
371380
File sroot = new File(root);
372381
if (sroot.exists()) {
373-
String sourceXref = constructXRefLocation(false);
382+
String sourceXref = constructXrefLocation(false);
374383
directories.add(new PmdFileInfo(localProject, sroot, sourceXref));
375384
}
376385
}
@@ -379,7 +388,7 @@ protected Map<File, PmdFileInfo> getFilesToProcess() throws IOException {
379388
for (String root : localTestCompileSourceRoots) {
380389
File sroot = new File(root);
381390
if (sroot.exists()) {
382-
String testXref = constructXRefLocation(true);
391+
String testXref = constructXrefLocation(true);
383392
directories.add(new PmdFileInfo(localProject, sroot, testXref));
384393
}
385394
}

0 commit comments

Comments
 (0)