3737
3838import net .sourceforge .pmd .PMDVersion ;
3939import org .apache .maven .execution .MavenSession ;
40- import org .apache .maven .model .ReportPlugin ;
41- import org .apache .maven .model .Reporting ;
4240import org .apache .maven .plugin .MojoExecution ;
4341import org .apache .maven .plugins .annotations .Component ;
4442import org .apache .maven .plugins .annotations .Parameter ;
4846import org .apache .maven .toolchain .Toolchain ;
4947import org .apache .maven .toolchain .ToolchainManager ;
5048import org .codehaus .plexus .util .FileUtils ;
51- import org .codehaus .plexus .util .PathTool ;
5249import org .codehaus .plexus .util .StringUtils ;
5350
5451/**
@@ -283,45 +280,6 @@ protected MojoExecution getMojoExecution() {
283280 return mojoExecution ;
284281 }
285282
286- protected String constructXrefLocation (boolean test ) {
287- String location = null ;
288- if (linkXRef ) {
289- File xrefLocation = getXrefLocation (test );
290-
291- String relativePath = PathTool .getRelativePath (
292- getReportOutputDirectory ().getAbsolutePath (), xrefLocation .getAbsolutePath ());
293- if (relativePath == null || relativePath .isEmpty ()) {
294- relativePath = "." ;
295- }
296- relativePath = relativePath + "/" + xrefLocation .getName ();
297- if (xrefLocation .exists ()) {
298- // XRef was already generated by manual execution of a lifecycle binding
299- location = relativePath ;
300- } else {
301- // Not yet generated - check if the report is on its way
302- Reporting reporting = project .getModel ().getReporting ();
303- List <ReportPlugin > reportPlugins =
304- reporting != null ? reporting .getPlugins () : Collections .<ReportPlugin >emptyList ();
305- for (ReportPlugin plugin : reportPlugins ) {
306- String artifactId = plugin .getArtifactId ();
307- if ("maven-jxr-plugin" .equals (artifactId )) {
308- location = relativePath ;
309- }
310- }
311- }
312-
313- if (location == null ) {
314- getLog ().warn ("Unable to locate" + (test ? " Test" : "" ) + " Source XRef to link to - DISABLED" );
315- }
316- }
317- return location ;
318- }
319-
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-
325283 /**
326284 * Convenience method to get the list of files where the PMD tool will be executed
327285 *
@@ -355,7 +313,7 @@ protected Map<File, PmdFileInfo> getFilesToProcess() throws IOException {
355313 for (String root : compileSourceRoots ) {
356314 File sroot = new File (root );
357315 if (sroot .exists ()) {
358- String sourceXref = constructXrefLocation (false );
316+ String sourceXref = linkXRef ? constructXrefLocation (xrefLocation , false ) : null ;
359317 directories .add (new PmdFileInfo (project , sroot , sourceXref ));
360318 }
361319 }
@@ -368,8 +326,8 @@ protected Map<File, PmdFileInfo> getFilesToProcess() throws IOException {
368326 for (String root : testSourceRoots ) {
369327 File sroot = new File (root );
370328 if (sroot .exists ()) {
371- String testXref = constructXrefLocation (true );
372- directories .add (new PmdFileInfo (project , sroot , testXref ));
329+ String testSourceXref = linkXRef ? constructXrefLocation (xrefTestLocation , true ) : null ;
330+ directories .add (new PmdFileInfo (project , sroot , testSourceXref ));
373331 }
374332 }
375333 }
@@ -379,7 +337,7 @@ protected Map<File, PmdFileInfo> getFilesToProcess() throws IOException {
379337 for (String root : localCompileSourceRoots ) {
380338 File sroot = new File (root );
381339 if (sroot .exists ()) {
382- String sourceXref = constructXrefLocation (false );
340+ String sourceXref = linkXRef ? constructXrefLocation (xrefLocation , false ) : null ;
383341 directories .add (new PmdFileInfo (localProject , sroot , sourceXref ));
384342 }
385343 }
@@ -388,8 +346,8 @@ protected Map<File, PmdFileInfo> getFilesToProcess() throws IOException {
388346 for (String root : localTestCompileSourceRoots ) {
389347 File sroot = new File (root );
390348 if (sroot .exists ()) {
391- String testXref = constructXrefLocation (true );
392- directories .add (new PmdFileInfo (localProject , sroot , testXref ));
349+ String testSourceXref = linkXRef ? constructXrefLocation (xrefTestLocation , true ) : null ;
350+ directories .add (new PmdFileInfo (localProject , sroot , testSourceXref ));
393351 }
394352 }
395353 }
0 commit comments