maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hbout...@apache.org
Subject svn commit: r939798 - /maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/CpdReport.java
Date Fri, 30 Apr 2010 20:02:23 GMT
Author: hboutemy
Date: Fri Apr 30 20:02:23 2010
New Revision: 939798

URL: http://svn.apache.org/viewvc?rev=939798&view=rev
Log:
[MPMD-113] added support for ignoreLiterals and ignoreIdentifiers CPD properties

Modified:
    maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/CpdReport.java

Modified: maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/CpdReport.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/CpdReport.java?rev=939798&r1=939797&r2=939798&view=diff
==============================================================================
--- maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/CpdReport.java
(original)
+++ maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/CpdReport.java
Fri Apr 30 20:02:23 2010
@@ -29,11 +29,13 @@ import java.io.Writer;
 import java.util.Iterator;
 import java.util.Locale;
 import java.util.Map;
+import java.util.Properties;
 import java.util.ResourceBundle;
 
 import net.sourceforge.pmd.cpd.CPD;
 import net.sourceforge.pmd.cpd.CSVRenderer;
 import net.sourceforge.pmd.cpd.JavaLanguage;
+import net.sourceforge.pmd.cpd.JavaTokenizer;
 import net.sourceforge.pmd.cpd.Renderer;
 import net.sourceforge.pmd.cpd.XMLRenderer;
 
@@ -72,6 +74,24 @@ public class CpdReport
      */
     private boolean skip;
 
+    /**
+     * If true, CPD ignores literal value differences when evaluating a duplicate block.
+     * This means that <code>foo=42;</code> and <code>foo=43;</code>
will be seen as equivalent.
+     * You may want to run PMD with this option off to start with and then switch it on to
see what it turns up.
+     *
+     * @parameter expression="${cpd.ignoreLiterals}" default-value="false"
+     * @since 2.5
+     */
+    private boolean ignoreLiterals;
+
+    /**
+     * Similar to <code>ignoreLiterals</code> but for identifiers; i.e., variable
names, methods names, and so forth.
+     *
+     * @parameter expression="${cpd.ignoreIdentifiers}" default-value="false"
+     * @since 2.5
+     */
+    private boolean ignoreIdentifiers;
+
     /** {@inheritDoc} */
     public String getName( Locale locale )
     {
@@ -129,7 +149,17 @@ public class CpdReport
     private CPD generateReport( Locale locale )
         throws MavenReportException
     {
-        CPD cpd = new CPD( minimumTokens, new JavaLanguage() );
+        Properties p = new Properties();
+        if ( ignoreLiterals )
+        {
+            p.setProperty( JavaTokenizer.IGNORE_LITERALS, "true" );
+        }
+        if ( ignoreIdentifiers )
+        {
+            p.setProperty( JavaTokenizer.IGNORE_IDENTIFIERS, "true" );
+        }
+        CPD cpd = new CPD( minimumTokens, new JavaLanguage( p ) );
+
         Map files = null;
         try
         {



Mime
View raw message