You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by dk...@apache.org on 2007/03/11 20:30:13 UTC
svn commit: r516996 - in
/maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd:
CpdViolationCheckMojo.java PmdReport.java
Author: dkulp
Date: Sun Mar 11 12:30:12 2007
New Revision: 516996
URL: http://svn.apache.org/viewvc?view=rev&rev=516996
Log:
MPMD-49
Add information for verbose mode for cdp:check
Remove calls to deprecated methods
Modified:
maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/CpdViolationCheckMojo.java
maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/PmdReport.java
Modified: maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/CpdViolationCheckMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/CpdViolationCheckMojo.java?view=diff&rev=516996&r1=516995&r2=516996
==============================================================================
--- maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/CpdViolationCheckMojo.java (original)
+++ maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/CpdViolationCheckMojo.java Sun Mar 11 12:30:12 2007
@@ -55,7 +55,7 @@
{
if ( !skip )
{
- executeCheck( "cpd.xml", "duplication", "CPD duplication", 0 );
+ executeCheck( "cpd.xml", "duplication", "CPD duplication", 10 );
}
}
@@ -66,13 +66,71 @@
*/
protected void printError( Map item, String severity )
{
- // TODO Auto-generated method stub
+ String lines = (String) item.get( "lines" );
+
+
+ StringBuffer buff = new StringBuffer( 100 );
+ buff.append( "CPD " + severity + ": Found " );
+ buff.append(lines).append(" lines of duplicated code at locations:");
+ this.getLog().info( buff.toString() );
+
+ buff.setLength(0);
+ buff.append(" ");
+ Map file = (Map)item.get( "file" );
+ buff.append( file.get( "path" ) );
+ buff.append(" line ").append( file.get("line") );
+ this.getLog().info( buff.toString() );
+
+ buff.setLength(0);
+ buff.append(" ");
+ file = (Map)item.get( "file1" );
+ buff.append( file.get( "path" ) );
+ buff.append(" line ").append( file.get("line") );
+ this.getLog().info( buff.toString() );
}
protected Map getErrorDetails( XmlPullParser xpp )
throws XmlPullParserException, IOException
{
- // TODO Auto-generated method stub
- return null;
+ int index = 0;
+ int attributeCount = 0;
+ HashMap msgs = new HashMap();
+
+ attributeCount = xpp.getAttributeCount();
+ while ( index < attributeCount )
+ {
+ msgs.put( xpp.getAttributeName( index ), xpp.getAttributeValue( index ) );
+
+ index++;
+ }
+
+ int tp = xpp.next();
+ while ( tp != XmlPullParser.END_TAG )
+ {
+ // get the tag's text
+ switch ( tp )
+ {
+ case XmlPullParser.TEXT:
+ msgs.put( "text", xpp.getText().trim() );
+ break;
+ case XmlPullParser.START_TAG:
+ {
+ String nm = xpp.getName();
+ if ( msgs.containsKey( nm ) )
+ {
+ int cnt = 1;
+ while ( msgs.containsKey( nm + cnt) )
+ {
+ ++cnt;
+ }
+ nm = nm + cnt;
+ }
+ msgs.put( nm, getErrorDetails( xpp ) );
+ break;
+ }
+ }
+ tp = xpp.next();
+ }
+ return msgs;
}
}
Modified: maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/PmdReport.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/PmdReport.java?view=diff&rev=516996&r1=516995&r2=516996
==============================================================================
--- 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 Mar 11 12:30:12 2007
@@ -28,6 +28,7 @@
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
+import java.io.StringWriter;
import java.io.UnsupportedEncodingException;
import java.io.Writer;
import java.util.Iterator;
@@ -54,7 +55,9 @@
import org.apache.maven.reporting.MavenReportException;
import org.codehaus.doxia.sink.Sink;
import org.codehaus.plexus.resource.ResourceManager;
+import org.codehaus.plexus.resource.loader.FileResourceCreationException;
import org.codehaus.plexus.resource.loader.FileResourceLoader;
+import org.codehaus.plexus.resource.loader.ResourceNotFoundException;
/**
* Implement the PMD report.
@@ -137,7 +140,6 @@
PMD pmd = getPMD();
RuleContext ruleContext = new RuleContext();
Report report = new Report();
- // TODO: use source roots instead
PmdReportListener reportSink = new PmdReportListener( sink, getBundle( locale ), aggregate );
report.addListener( reportSink );
@@ -153,7 +155,7 @@
{
String set = rulesets[idx];
getLog().debug( "Preparing ruleset: " + set );
- File ruleset = locator.resolveLocation( set, getLocationTemp( set ) );
+ File ruleset = locator.getResourceAsFile( set, getLocationTemp( set ) );
InputStream rulesInput = null;
if ( null == ruleset)
{
@@ -176,6 +178,14 @@
{
throw new MavenReportException( e.getMessage(), e );
}
+ catch (ResourceNotFoundException e)
+ {
+ throw new MavenReportException( e.getMessage(), e );
+ }
+ catch (FileResourceCreationException e)
+ {
+ throw new MavenReportException( e.getMessage(), e );
+ }
boolean hasEncoding = sourceEncoding != null;
@@ -194,7 +204,6 @@
Map.Entry entry = (Map.Entry) i.next();
File file = (File) entry.getKey();
PmdFileInfo fileInfo = (PmdFileInfo) entry.getValue();
- File sourceDir = fileInfo.getSourceDirectory();
// TODO: lazily call beginFile in case there are no rules
@@ -236,9 +245,13 @@
{
// Use the PMD renderers to render in any format aside from HTML.
Renderer r = createRenderer();
- String buffer = r.render( report );
+ StringWriter stringwriter = new StringWriter();
+
try
{
+ r.render( stringwriter, report );
+ String buffer = stringwriter.toString();
+
Writer writer = new FileWriter( new File( targetDirectory, "pmd." + format ) );
writer.write( buffer, 0, buffer.length() );
writer.close();