You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ol...@apache.org on 2012/05/26 22:08:06 UTC
svn commit: r1342956 -
/maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/
Author: olamy
Date: Sat May 26 20:08:06 2012
New Revision: 1342956
URL: http://svn.apache.org/viewvc?rev=1342956&view=rev
Log:
code format no change
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/CpdReportGenerator.java
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/PmdFileInfo.java
maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/PmdReportListener.java
maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/PmdViolationCheckMojo.java
maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/ViolationDetails.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=1342956&r1=1342955&r2=1342956&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 Sat May 26 20:08:06 2012
@@ -19,12 +19,6 @@ package org.apache.maven.plugin.pmd;
* under the License.
*/
-import java.io.File;
-import java.io.IOException;
-import java.io.Reader;
-import java.util.ArrayList;
-import java.util.List;
-
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
@@ -32,6 +26,12 @@ import org.apache.maven.project.MavenPro
import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
+import java.io.File;
+import java.io.IOException;
+import java.io.Reader;
+import java.util.ArrayList;
+import java.util.List;
+
/**
* Base class for mojos that check if there were any PMD violations.
*
@@ -131,14 +131,12 @@ public abstract class AbstractPmdViolati
}
catch ( IOException e )
{
- throw new MojoExecutionException(
- "Unable to read PMD results xml: " + outputFile.getAbsolutePath(),
+ throw new MojoExecutionException( "Unable to read PMD results xml: " + outputFile.getAbsolutePath(),
e );
}
catch ( XmlPullParserException e )
{
- throw new MojoExecutionException(
- "Unable to read PMD results xml: " + outputFile.getAbsolutePath(),
+ throw new MojoExecutionException( "Unable to read PMD results xml: " + outputFile.getAbsolutePath(),
e );
}
finally
@@ -156,10 +154,8 @@ public abstract class AbstractPmdViolati
/**
* Method for collecting the violations found by the PMD tool
*
- * @param xpp
- * the xml parser object
- * @param tagName
- * the element that will be checked
+ * @param xpp the xml parser object
+ * @param tagName the element that will be checked
* @return an int that specifies the number of violations found
* @throws XmlPullParserException
* @throws IOException
@@ -171,8 +167,8 @@ public abstract class AbstractPmdViolati
List<D> warnings = new ArrayList<D>();
List<D> violations = getErrorDetails( analysisFile );
-
- for( D violation : violations )
+
+ for ( D violation : violations )
{
int priority = getPriority( violation );
if ( priority <= failurePriority )
@@ -184,28 +180,26 @@ public abstract class AbstractPmdViolati
warnings.add( violation );
}
}
-
+
ViolationDetails<D> details = newViolationDetailsInstance();
details.setFailureDetails( failures );
details.setWarningDetails( warnings );
return details;
}
-
+
protected abstract int getPriority( D errorDetail );
-
+
protected abstract ViolationDetails<D> newViolationDetailsInstance();
/**
* Prints the warnings and failures
*
- * @param failures
- * list of failures
- * @param warnings
- * list of warnings
+ * @param failures list of failures
+ * @param warnings list of warnings
*/
protected void printErrors( List<D> failures, List<D> warnings )
{
- for ( D warning : warnings )
+ for ( D warning : warnings )
{
printError( warning, "Warning" );
}
Modified: maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/CpdReportGenerator.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/CpdReportGenerator.java?rev=1342956&r1=1342955&r2=1342956&view=diff
==============================================================================
--- maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/CpdReportGenerator.java (original)
+++ maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/CpdReportGenerator.java Sat May 26 20:08:06 2012
@@ -19,18 +19,17 @@ package org.apache.maven.plugin.pmd;
* under the License.
*/
-import java.io.File;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.ResourceBundle;
-
import net.sourceforge.pmd.cpd.Match;
import net.sourceforge.pmd.cpd.TokenEntry;
-
import org.apache.maven.doxia.sink.Sink;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.util.StringUtils;
+import java.io.File;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.ResourceBundle;
+
/**
* Class that generated the CPD report.
*
@@ -132,8 +131,8 @@ public class CpdReportGenerator
if ( xrefLocation != null )
{
- sink.link( xrefLocation + "/" + filename.replaceAll( "\\.java$", ".html" ).replace( '\\', '/' )
- + "#" + line );
+ sink.link(
+ xrefLocation + "/" + filename.replaceAll( "\\.java$", ".html" ).replace( '\\', '/' ) + "#" + line );
}
sink.text( String.valueOf( line ) );
if ( xrefLocation != null )
@@ -165,9 +164,9 @@ public class CpdReportGenerator
while ( matches.hasNext() )
{
Match match = matches.next();
-
+
String code = match.getSourceCodeSlice();
-
+
sink.table();
sink.tableRow();
sink.tableHeaderCell();
@@ -191,11 +190,10 @@ public class CpdReportGenerator
TokenEntry mark = occurrences.next();
generateFileLine( mark );
}
-
+
// Source snippet
sink.tableRow();
-
int colspan = 2;
if ( aggregate )
{
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?rev=1342956&r1=1342955&r2=1342956&view=diff
==============================================================================
--- 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 Sat May 26 20:08:06 2012
@@ -19,11 +19,6 @@ package org.apache.maven.plugin.pmd;
* under the License.
*/
-import java.io.File;
-import java.io.FileReader;
-import java.io.IOException;
-import java.util.List;
-
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugin.pmd.model.CpdErrorDetail;
@@ -32,15 +27,20 @@ import org.apache.maven.plugin.pmd.model
import org.apache.maven.plugin.pmd.model.io.xpp3.CpdXpp3Reader;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.util.List;
+
/**
* Fail the build if there were any CPD violations in the source code.
*
- * @since 2.0
* @version $Id$
* @goal cpd-check
* @phase verify
* @execute goal="cpd"
* @threadSafe
+ * @since 2.0
*/
public class CpdViolationCheckMojo
extends AbstractPmdViolationCheckMojo<Duplication>
@@ -54,7 +54,9 @@ public class CpdViolationCheckMojo
*/
private boolean skip;
- /** {@inheritDoc} */
+ /**
+ * {@inheritDoc}
+ */
public void execute()
throws MojoExecutionException, MojoFailureException
{
@@ -64,19 +66,19 @@ public class CpdViolationCheckMojo
}
}
- /** {@inheritDoc} */
+ /**
+ * {@inheritDoc}
+ */
protected void printError( Duplication item, String severity )
{
int lines = item.getLines();
-
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() );
-
- for( CpdFile file : item.getFiles() )
+ for ( CpdFile file : item.getFiles() )
{
buff.setLength( 0 );
buff.append( " " );
@@ -89,7 +91,9 @@ public class CpdViolationCheckMojo
this.getLog().debug( item.getCodefragment() );
}
- /** {@inheritDoc} */
+ /**
+ * {@inheritDoc}
+ */
protected List<Duplication> getErrorDetails( File cpdFile )
throws XmlPullParserException, IOException
{
@@ -97,13 +101,13 @@ public class CpdViolationCheckMojo
CpdErrorDetail details = reader.read( new FileReader( cpdFile ), false );
return details.getDuplications();
}
-
+
@Override
protected int getPriority( Duplication errorDetail )
{
return 0;
}
-
+
@Override
protected ViolationDetails<Duplication> newViolationDetailsInstance()
{
Modified: maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/PmdFileInfo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/PmdFileInfo.java?rev=1342956&r1=1342955&r2=1342956&view=diff
==============================================================================
--- maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/PmdFileInfo.java (original)
+++ maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/PmdFileInfo.java Sat May 26 20:08:06 2012
@@ -19,10 +19,10 @@ package org.apache.maven.plugin.pmd;
* under the License.
*/
-import java.io.File;
-
import org.apache.maven.project.MavenProject;
+import java.io.File;
+
/**
* @version $Id$
*/
@@ -30,12 +30,12 @@ public class PmdFileInfo
{
private MavenProject project;
+
private File sourceDir;
+
private String xref;
- public PmdFileInfo( MavenProject project,
- File dir,
- String x )
+ public PmdFileInfo( MavenProject project, File dir, String x )
{
this.project = project;
if ( dir.isAbsolute() )
Modified: maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/PmdReportListener.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/PmdReportListener.java?rev=1342956&r1=1342955&r2=1342956&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 Sat May 26 20:08:06 2012
@@ -19,6 +19,13 @@ package org.apache.maven.plugin.pmd;
* under the License.
*/
+import net.sourceforge.pmd.ReportListener;
+import net.sourceforge.pmd.RuleViolation;
+import net.sourceforge.pmd.stat.Metric;
+import org.apache.maven.doxia.sink.Sink;
+import org.apache.maven.plugin.logging.Log;
+import org.codehaus.plexus.util.StringUtils;
+
import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
@@ -27,14 +34,6 @@ import java.util.List;
import java.util.Map;
import java.util.ResourceBundle;
-import net.sourceforge.pmd.ReportListener;
-import net.sourceforge.pmd.RuleViolation;
-import net.sourceforge.pmd.stat.Metric;
-
-import org.apache.maven.doxia.sink.Sink;
-import org.apache.maven.plugin.logging.Log;
-import org.codehaus.plexus.util.StringUtils;
-
/**
* Handle events from PMD, converting them into Doxia events.
*
@@ -63,7 +62,7 @@ public class PmdReportListener
// private List<Metric> metrics = new ArrayList<Metric>();
- public PmdReportListener(Log log, Sink sink, ResourceBundle bundle, boolean aggregate )
+ public PmdReportListener( Log log, Sink sink, ResourceBundle bundle, boolean aggregate )
{
this.log = log;
this.sink = sink;
@@ -96,12 +95,16 @@ public class PmdReportListener
// prepare the filename
this.currentFilename = currentFilename;
- if ( fileInfo != null && fileInfo.getSourceDirectory() != null ) {
+ if ( fileInfo != null && fileInfo.getSourceDirectory() != null )
+ {
this.currentFilename =
- StringUtils.substring( currentFilename, fileInfo.getSourceDirectory().getAbsolutePath().length() + 1 );
- } else {
- log.warn( "Unfortunately there was no PmdFileInfo available or the SourceDirectory is not known for "
- + " file " + currentFilename );
+ StringUtils.substring( currentFilename, fileInfo.getSourceDirectory().getAbsolutePath().length() + 1 );
+ }
+ else
+ {
+ log.warn(
+ "Unfortunately there was no PmdFileInfo available or the SourceDirectory is not known for " + " file "
+ + currentFilename );
}
this.currentFilename = StringUtils.replace( this.currentFilename, "\\", "/" );
@@ -179,7 +182,7 @@ public class PmdReportListener
for ( RuleViolation ruleViolation : violations )
{
String currentFn = ruleViolation.getFilename();
- PmdFileInfo fileInfo = files.get( new File ( currentFn ) );
+ PmdFileInfo fileInfo = files.get( new File( currentFn ) );
if ( !currentFn.equalsIgnoreCase( previousFilename ) && fileSectionStarted )
{
endFileSection();
@@ -205,7 +208,8 @@ public class PmdReportListener
private void outputLineLink( int line, PmdFileInfo fileInfo )
{
String xrefLocation = null;
- if ( fileInfo != null ) {
+ if ( fileInfo != null )
+ {
xrefLocation = fileInfo.getXrefLocation();
}
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=1342956&r1=1342955&r2=1342956&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 Sat May 26 20:08:06 2012
@@ -19,12 +19,6 @@ package org.apache.maven.plugin.pmd;
* under the License.
*/
-import java.io.File;
-import java.io.FileReader;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugin.pmd.model.PmdErrorDetail;
@@ -34,15 +28,21 @@ import org.apache.maven.plugin.pmd.model
import org.codehaus.plexus.util.StringUtils;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
/**
* Fail the build if there were any PMD violations in the source code.
*
- * @since 2.0
* @version $Id$
* @goal check
* @phase verify
* @execute goal="pmd"
* @threadSafe
+ * @since 2.0
*/
public class PmdViolationCheckMojo
extends AbstractPmdViolationCheckMojo<Violation>
@@ -66,7 +66,9 @@ public class PmdViolationCheckMojo
*/
private boolean skip;
- /** {@inheritDoc} */
+ /**
+ * {@inheritDoc}
+ */
public void execute()
throws MojoExecutionException, MojoFailureException
{
@@ -76,7 +78,9 @@ public class PmdViolationCheckMojo
}
}
- /** {@inheritDoc} */
+ /**
+ * {@inheritDoc}
+ */
protected void printError( Violation item, String severity )
{
@@ -103,7 +107,7 @@ public class PmdViolationCheckMojo
this.getLog().info( buff.toString() );
}
-
+
@Override
protected List<Violation> getErrorDetails( File pmdFile )
throws XmlPullParserException, IOException
@@ -112,10 +116,10 @@ public class PmdViolationCheckMojo
PmdErrorDetail details = reader.read( new FileReader( pmdFile ), false );
List<Violation> violations = new ArrayList<Violation>();
- for( PmdFile file : details.getFiles() )
+ for ( PmdFile file : details.getFiles() )
{
String fullPath = file.getName();
-
+
for ( Violation violation : file.getViolations() )
{
violation.setFileName( getFilename( fullPath, violation.getViolationPackage() ) );
@@ -124,19 +128,19 @@ public class PmdViolationCheckMojo
}
return violations;
}
-
+
@Override
protected int getPriority( Violation errorDetail )
{
return errorDetail.getPriority();
}
-
+
@Override
protected ViolationDetails<Violation> newViolationDetailsInstance()
{
return new ViolationDetails<Violation>();
}
-
+
private String getFilename( String fullpath, String pkg )
{
int index = fullpath.lastIndexOf( File.separatorChar );
Modified: maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/ViolationDetails.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/ViolationDetails.java?rev=1342956&r1=1342955&r2=1342956&view=diff
==============================================================================
--- maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/ViolationDetails.java (original)
+++ maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/ViolationDetails.java Sat May 26 20:08:06 2012
@@ -24,15 +24,15 @@ import java.util.List;
/**
* Collector of warnings and failures.
- *
+ *
+ * @param <D>
* @author Robert Scholte
- * @param <D>
* @since 2.7
*/
public class ViolationDetails<D>
{
private List<D> warningDetails = new ArrayList<D>();
-
+
private List<D> failureDetails = new ArrayList<D>();
/**