mirror of https://github.com/apache/maven.git
upgrade to PMD 3.0, improve error handling
git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@168513 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
b8dbe29701
commit
3e936447a5
|
@ -29,8 +29,9 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>pmd</groupId>
|
<groupId>pmd</groupId>
|
||||||
<artifactId>pmd</artifactId>
|
<artifactId>pmd</artifactId>
|
||||||
<version>2.3</version>
|
<version>3.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<!-- TODO: should be in PMD pom -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>jaxen</groupId>
|
<groupId>jaxen</groupId>
|
||||||
<artifactId>jaxen</artifactId>
|
<artifactId>jaxen</artifactId>
|
||||||
|
|
|
@ -32,7 +32,7 @@ import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.FileReader;
|
import java.io.FileReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Collections;
|
import java.io.InputStream;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -45,33 +45,23 @@ import java.util.List;
|
||||||
public class PmdReport
|
public class PmdReport
|
||||||
extends AbstractMavenReport
|
extends AbstractMavenReport
|
||||||
{
|
{
|
||||||
protected static final String[] DEFAULT_EXCLUDES = {
|
protected static final String[] DEFAULT_EXCLUDES = {// Miscellaneous typical temporary files
|
||||||
// Miscellaneous typical temporary files
|
"**/*~", "**/#*#", "**/.#*", "**/%*%", "**/._*",
|
||||||
"**/*~",
|
|
||||||
"**/#*#",
|
|
||||||
"**/.#*",
|
|
||||||
"**/%*%",
|
|
||||||
"**/._*",
|
|
||||||
|
|
||||||
// CVS
|
// CVS
|
||||||
"**/CVS",
|
"**/CVS", "**/CVS/**", "**/.cvsignore",
|
||||||
"**/CVS/**",
|
|
||||||
"**/.cvsignore",
|
|
||||||
|
|
||||||
// SCCS
|
// SCCS
|
||||||
"**/SCCS",
|
"**/SCCS", "**/SCCS/**",
|
||||||
"**/SCCS/**",
|
|
||||||
|
|
||||||
// Visual SourceSafe
|
// Visual SourceSafe
|
||||||
"**/vssver.scc",
|
"**/vssver.scc",
|
||||||
|
|
||||||
// Subversion
|
// Subversion
|
||||||
"**/.svn",
|
"**/.svn", "**/.svn/**",
|
||||||
"**/.svn/**",
|
|
||||||
|
|
||||||
// Mac
|
// Mac
|
||||||
"**/.DS_Store"
|
"**/.DS_Store"};
|
||||||
};
|
|
||||||
|
|
||||||
public void execute()
|
public void execute()
|
||||||
throws MavenReportException
|
throws MavenReportException
|
||||||
|
@ -81,7 +71,7 @@ public class PmdReport
|
||||||
{
|
{
|
||||||
sink = getSink();
|
sink = getSink();
|
||||||
}
|
}
|
||||||
catch( IOException e )
|
catch ( IOException e )
|
||||||
{
|
{
|
||||||
throw new MavenReportException( "Can't obtain sink for PMD report.", e );
|
throw new MavenReportException( "Can't obtain sink for PMD report.", e );
|
||||||
}
|
}
|
||||||
|
@ -94,8 +84,8 @@ public class PmdReport
|
||||||
ruleContext.setReport( report );
|
ruleContext.setReport( report );
|
||||||
|
|
||||||
RuleSetFactory ruleSetFactory = new RuleSetFactory();
|
RuleSetFactory ruleSetFactory = new RuleSetFactory();
|
||||||
RuleSet ruleSet = ruleSetFactory.createRuleSet(
|
InputStream rulesInput = pmd.getClass().getResourceAsStream( "/rulesets/controversial.xml" );
|
||||||
pmd.getClass().getResourceAsStream( "/rulesets/controversial.xml" ) );
|
RuleSet ruleSet = ruleSetFactory.createRuleSet( rulesInput );
|
||||||
|
|
||||||
reportSink.beginDocument();
|
reportSink.beginDocument();
|
||||||
|
|
||||||
|
@ -104,7 +94,7 @@ public class PmdReport
|
||||||
{
|
{
|
||||||
files = getFilesToProcess( "**/*.java", null );
|
files = getFilesToProcess( "**/*.java", null );
|
||||||
}
|
}
|
||||||
catch( IOException e )
|
catch ( IOException e )
|
||||||
{
|
{
|
||||||
throw new MavenReportException( "Can't parse " + getConfiguration().getSourceDirectory(), e );
|
throw new MavenReportException( "Can't parse " + getConfiguration().getSourceDirectory(), e );
|
||||||
}
|
}
|
||||||
|
@ -132,7 +122,12 @@ public class PmdReport
|
||||||
}
|
}
|
||||||
catch ( PMDException e )
|
catch ( PMDException e )
|
||||||
{
|
{
|
||||||
throw new MavenReportException( "Failure executing PMD for: " + file, e );
|
Exception ex = e;
|
||||||
|
if ( e.getReason() != null )
|
||||||
|
{
|
||||||
|
ex = e.getReason();
|
||||||
|
}
|
||||||
|
throw new MavenReportException( "Failure executing PMD for: " + file, ex );
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
|
@ -160,7 +155,7 @@ public class PmdReport
|
||||||
StringBuffer excludesStr = new StringBuffer();
|
StringBuffer excludesStr = new StringBuffer();
|
||||||
if ( StringUtils.isNotEmpty( excludes ) )
|
if ( StringUtils.isNotEmpty( excludes ) )
|
||||||
{
|
{
|
||||||
excludesStr.append(excludes);
|
excludesStr.append( excludes );
|
||||||
}
|
}
|
||||||
for ( int i = 0; i < DEFAULT_EXCLUDES.length; i++ )
|
for ( int i = 0; i < DEFAULT_EXCLUDES.length; i++ )
|
||||||
{
|
{
|
||||||
|
@ -171,6 +166,7 @@ public class PmdReport
|
||||||
excludesStr.append( DEFAULT_EXCLUDES[i] );
|
excludesStr.append( DEFAULT_EXCLUDES[i] );
|
||||||
}
|
}
|
||||||
|
|
||||||
return FileUtils.getFiles( new File( getConfiguration().getSourceDirectory() ), includes, excludesStr.toString() );
|
return FileUtils.getFiles( new File( getConfiguration().getSourceDirectory() ), includes,
|
||||||
|
excludesStr.toString() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue