Author: mperham Date: Sun Jan 8 15:27:28 2006 New Revision: 367128 URL: http://svn.apache.org/viewcvs?rev=367128&view=rev Log: MPMD-9 Submitted by: Nick Giles Add JXR support to PMD report
Modified: maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/PmdReport.java maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/PmdReportListener.java maven/plugins/trunk/maven-pmd-plugin/src/site/apt/howto.apt Modified: maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/PmdReport.java URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/PmdReport.java?rev=367128&r1=367127&r2=367128&view=diff ============================================================================== --- maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/PmdReport.java (original) +++ maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/PmdReport.java Sun Jan 8 15:27:28 2006 @@ -102,6 +102,20 @@ private String[] rulesets = new String[] { "controversial" }; /** + * Link the violation line numbers to the source xref. + * @parameter + * + * TODO Can we automagically determine if xfer is being run and enable this? + */ + private boolean linkXref; + + /** + * The location of the xref pages relative to the location of the pmd report. + * @parameter + */ + private String xrefLocation = "xref"; + + /** * @see org.apache.maven.reporting.MavenReport#getName(java.util.Locale) */ public String getName( Locale locale ) @@ -160,6 +174,11 @@ // TODO: use source roots instead String sourceDirectory = getProject().getBuild().getSourceDirectory(); PmdReportListener reportSink = new PmdReportListener( sink, sourceDirectory, getBundle( locale ) ); + if ( linkXref ) + { + reportSink.setXrefLocation( xrefLocation ); + } + report.addListener( reportSink ); ruleContext.setReport( report ); reportSink.beginDocument(); Modified: maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/PmdReportListener.java URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/PmdReportListener.java?rev=367128&r1=367127&r2=367128&view=diff ============================================================================== --- maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/PmdReportListener.java (original) +++ maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/PmdReportListener.java Sun Jan 8 15:27:28 2006 @@ -50,6 +50,8 @@ private ResourceBundle bundle; + private String xrefLocation; + private List violations = new ArrayList(); private List metrics = new ArrayList(); @@ -111,8 +113,18 @@ sink.text( ruleViolation.getDescription() ); sink.tableCell_(); sink.tableCell(); - // TODO: xref link the line number + + if ( getXrefLocation() != null ) + { + sink.link( getXrefLocation() + "/" + currentFilename.replaceAll( "\\.java$", ".html" ) + "#" + + ruleViolation.getLine() ); + } sink.text( String.valueOf( ruleViolation.getLine() ) ); + if ( getXrefLocation() != null ) + { + sink.link_(); + } + sink.tableCell_(); sink.tableRow_(); } @@ -121,9 +133,10 @@ public void metricAdded( Metric metric ) { - if (metric.getCount() != 0) { + if ( metric.getCount() != 0 ) + { // Skip metrics which have no data - metrics.add(metric); + metrics.add( metric ); } } @@ -239,5 +252,15 @@ sink.flush(); sink.close(); + } + + public String getXrefLocation() + { + return xrefLocation; + } + + public void setXrefLocation( String xrefLocation ) + { + this.xrefLocation = xrefLocation; } } Modified: maven/plugins/trunk/maven-pmd-plugin/src/site/apt/howto.apt URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-pmd-plugin/src/site/apt/howto.apt?rev=367128&r1=367127&r2=367128&view=diff ============================================================================== --- maven/plugins/trunk/maven-pmd-plugin/src/site/apt/howto.apt (original) +++ maven/plugins/trunk/maven-pmd-plugin/src/site/apt/howto.apt Sun Jan 8 15:27:28 2006 @@ -18,6 +18,9 @@ PMD rulesets and output the report in XML format. The rulesets are assumed to reside in /rulesets/[name].xml in the classpath. Note that HTML is always generated in addition to any other alternate format. Legal formats are "html", "csv", "xml" and "txt". + + The PMD report will link directly to the cross-referenced source if you enable this with the linkXref parameter. + See the {{{http://mojo.codehaus.org/jxr-maven-plugin/}JXR}} plugin for more details. +-------- <reporting> @@ -31,6 +34,7 @@ <ruleset>controversial</ruleset> </rulesets> <format>xml</format> + <linkXref>true</linkXref> </configuration> </plugin> </plugins>