You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by hb...@apache.org on 2010/04/30 19:36:29 UTC
svn commit: r939751 - in /maven/plugins/trunk/maven-pmd-plugin/src:
main/java/org/apache/maven/plugin/pmd/ test/java/org/apache/maven/plugin/pmd/
Author: hboutemy
Date: Fri Apr 30 17:36:29 2010
New Revision: 939751
URL: http://svn.apache.org/viewvc?rev=939751&view=rev
Log:
[MPMD-91] report filename when no class name available in pmd:check output
Modified:
maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/AbstractPmdViolationCheckMojo.java
maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/PmdViolationCheckMojo.java
maven/plugins/trunk/maven-pmd-plugin/src/test/java/org/apache/maven/plugin/pmd/PmdViolationCheckMojoTest.java
Modified: maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/AbstractPmdViolationCheckMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/AbstractPmdViolationCheckMojo.java?rev=939751&r1=939750&r2=939751&view=diff
==============================================================================
--- maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/AbstractPmdViolationCheckMojo.java (original)
+++ maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/AbstractPmdViolationCheckMojo.java Fri Apr 30 17:36:29 2010
@@ -33,6 +33,7 @@ import org.apache.maven.plugin.AbstractM
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.project.MavenProject;
+import org.codehaus.plexus.util.StringUtils;
import org.codehaus.plexus.util.xml.pull.MXParser;
import org.codehaus.plexus.util.xml.pull.XmlPullParser;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
@@ -180,11 +181,23 @@ public abstract class AbstractPmdViolati
List failures = new ArrayList();
List warnings = new ArrayList();
+ String fullpath = null;
+
while ( eventType != XmlPullParser.END_DOCUMENT )
{
+ if ( eventType == XmlPullParser.START_TAG && "file".equals( xpp.getName() ) )
+ {
+ fullpath = xpp.getAttributeValue( "", "name" );
+ }
if ( eventType == XmlPullParser.START_TAG && tagName.equals( xpp.getName() ) )
{
Map details = getErrorDetails( xpp );
+
+ if ( fullpath != null )
+ {
+ details.put( "filename", getFilename( fullpath, (String) details.get( "package" ) ) );
+ }
+
try
{
int priority = Integer.parseInt( (String) details.get( "priority" ) );
@@ -199,13 +212,13 @@ public abstract class AbstractPmdViolati
}
catch ( NumberFormatException e )
{
- // i don't know what priority this is. Treat it like a
+ // I don't know what priority this is. Treat it like a
// failure
failures.add( details );
}
catch ( NullPointerException e )
{
- // i don't know what priority this is. Treat it like a
+ // I don't know what priority this is. Treat it like a
// failure
failures.add( details );
}
@@ -221,6 +234,26 @@ public abstract class AbstractPmdViolati
return map;
}
+ private String getFilename( String fullpath, String pkg )
+ {
+ int index = fullpath.lastIndexOf( File.separatorChar );
+
+ while ( StringUtils.isNotEmpty( pkg ) )
+ {
+ index = fullpath.substring( 0, index ).lastIndexOf( File.separatorChar );
+
+ int dot = pkg.indexOf( '.' );
+
+ if ( dot < 0 )
+ {
+ break;
+ }
+ pkg = pkg.substring( dot + 1 );
+ }
+
+ return fullpath.substring( index + 1 );
+ }
+
/**
* Prints the warnings and failures
*
Modified: maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/PmdViolationCheckMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/PmdViolationCheckMojo.java?rev=939751&r1=939750&r2=939751&view=diff
==============================================================================
--- maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/PmdViolationCheckMojo.java (original)
+++ maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/PmdViolationCheckMojo.java Fri Apr 30 17:36:29 2010
@@ -75,16 +75,20 @@ public class PmdViolationCheckMojo
StringBuffer buff = new StringBuffer( 100 );
buff.append( "PMD " + severity + ": " );
- if ( item.containsKey( "package" ) )
- {
- buff.append( item.get( "package" ) );
- buff.append( "." );
- }
if ( item.containsKey( "class" ) )
{
+ if ( item.containsKey( "package" ) )
+ {
+ buff.append( item.get( "package" ) );
+ buff.append( "." );
+ }
buff.append( item.get( "class" ) );
- buff.append( ":" );
}
+ else
+ {
+ buff.append( item.get( "filename" ) );
+ }
+ buff.append( ":" );
buff.append( item.get( "beginline" ) );
buff.append( " Rule:" ).append( item.get( "rule" ) );
buff.append( " Priority:" ).append( item.get( "priority" ) );
Modified: maven/plugins/trunk/maven-pmd-plugin/src/test/java/org/apache/maven/plugin/pmd/PmdViolationCheckMojoTest.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pmd-plugin/src/test/java/org/apache/maven/plugin/pmd/PmdViolationCheckMojoTest.java?rev=939751&r1=939750&r2=939751&view=diff
==============================================================================
--- maven/plugins/trunk/maven-pmd-plugin/src/test/java/org/apache/maven/plugin/pmd/PmdViolationCheckMojoTest.java (original)
+++ maven/plugins/trunk/maven-pmd-plugin/src/test/java/org/apache/maven/plugin/pmd/PmdViolationCheckMojoTest.java Fri Apr 30 17:36:29 2010
@@ -90,7 +90,7 @@ public class PmdViolationCheckMojoTest
}
catch ( MojoFailureException e )
{
- System.out.println("Caught Expected Message: "+e.getMessage());// expected
+ System.out.println( "Caught Expected Message: " + e.getMessage() );// expected
}
}