You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by de...@apache.org on 2012/01/04 20:39:49 UTC

svn commit: r1227278 - in /maven/plugins/trunk/maven-pmd-plugin: pom.xml src/main/java/org/apache/maven/plugin/pmd/CpdReportGenerator.java src/test/java/org/apache/maven/plugin/pmd/CpdReportTest.java

Author: dennisl
Date: Wed Jan  4 19:39:49 2012
New Revision: 1227278

URL: http://svn.apache.org/viewvc?rev=1227278&view=rev
Log:
[MPMD-134] Update to PMD 4.3 -- allow target to java 7
Submitted by: Eric Barboni
Reviewed by: Dennis Lundberg

o Applied patch from Eric for CpdReportGenerator.java with lots of modifications to code style.
o Updated to PMD 4.2.6 as a first step, because it changed its behavior a bit - previously the output of duplicate code snippet came from the second file, but now it comes from the first file
o Changed one of the tests due to the changed behavior

Modified:
    maven/plugins/trunk/maven-pmd-plugin/pom.xml
    maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/CpdReportGenerator.java
    maven/plugins/trunk/maven-pmd-plugin/src/test/java/org/apache/maven/plugin/pmd/CpdReportTest.java

Modified: maven/plugins/trunk/maven-pmd-plugin/pom.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pmd-plugin/pom.xml?rev=1227278&r1=1227277&r2=1227278&view=diff
==============================================================================
--- maven/plugins/trunk/maven-pmd-plugin/pom.xml (original)
+++ maven/plugins/trunk/maven-pmd-plugin/pom.xml Wed Jan  4 19:39:49 2012
@@ -147,7 +147,7 @@ under the License.
     <dependency>
       <groupId>pmd</groupId>
       <artifactId>pmd</artifactId>
-      <version>4.2.5</version>
+      <version>4.2.6</version>
     </dependency>
 
     <!-- misc -->

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=1227278&r1=1227277&r2=1227278&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 Wed Jan  4 19:39:49 2012
@@ -25,6 +25,7 @@ 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;
@@ -103,6 +104,48 @@ public class CpdReportGenerator
     }
 
     /**
+     * Method that generates a line of CPD report according to a TokenEntry.
+     */
+    private void generateFileLine( TokenEntry tokenEntry )
+    {
+        // Get information for report generation
+        String filename = tokenEntry.getTokenSrcID();
+        File file = new File( filename );
+        PmdFileInfo fileInfo = (PmdFileInfo) fileMap.get( file );
+        File sourceDirectory = fileInfo.getSourceDirectory();
+        filename = StringUtils.substring( filename, sourceDirectory.getAbsolutePath().length() + 1 );
+        String xrefLocation = fileInfo.getXrefLocation();
+        MavenProject projectFile = fileInfo.getProject();
+        int line = tokenEntry.getBeginLine();
+
+        sink.tableRow();
+        sink.tableCell();
+        sink.text( filename );
+        sink.tableCell_();
+        if ( aggregate )
+        {
+            sink.tableCell();
+            sink.text( projectFile.getName() );
+            sink.tableCell_();
+        }
+        sink.tableCell();
+
+        if ( xrefLocation != null )
+        {
+            sink.link( xrefLocation + "/" + filename.replaceAll( "\\.java$", ".html" ).replace( '\\', '/' )
+                    + "#" + line );
+        }
+        sink.text( String.valueOf(line) );
+        if ( xrefLocation != null )
+        {
+            sink.link_();
+        }
+
+        sink.tableCell_();
+        sink.tableRow_();
+    }
+
+    /**
      * Method that generates the contents of the CPD report
      *
      * @param matches
@@ -121,28 +164,9 @@ public class CpdReportGenerator
         while ( matches.hasNext() )
         {
             Match match = matches.next();
-            String filename1 = match.getFirstMark().getTokenSrcID();
-
-            File file = new File( filename1 );
-            PmdFileInfo fileInfo = (PmdFileInfo) fileMap.get( file );
-            File sourceDirectory = fileInfo.getSourceDirectory();
-            String xrefLocation = fileInfo.getXrefLocation();
-            MavenProject projectFile1 = fileInfo.getProject();
-
-            filename1 = StringUtils.substring( filename1, sourceDirectory.getAbsolutePath().length() + 1 );
-
-            String filename2 = match.getSecondMark().getTokenSrcID();
-            file = new File( filename2 );
-            fileInfo = (PmdFileInfo) fileMap.get( file );
-            sourceDirectory = fileInfo.getSourceDirectory();
-            String xrefLocation2 = fileInfo.getXrefLocation();
-            filename2 = StringUtils.substring( filename2, sourceDirectory.getAbsolutePath().length() + 1 );
-            MavenProject projectFile2 = fileInfo.getProject();
-
+            
             String code = match.getSourceCodeSlice();
-            int line1 = match.getFirstMark().getBeginLine();
-            int line2 = match.getSecondMark().getBeginLine();
-
+            
             sink.table();
             sink.tableRow();
             sink.tableHeaderCell();
@@ -159,59 +183,14 @@ public class CpdReportGenerator
             sink.tableHeaderCell_();
             sink.tableRow_();
 
-            // File 1
-            sink.tableRow();
-            sink.tableCell();
-            sink.text( filename1 );
-            sink.tableCell_();
-            if ( aggregate )
-            {
-                sink.tableCell();
-                sink.text( projectFile1.getName() );
-                sink.tableCell_();
-            }
-            sink.tableCell();
-
-            if ( xrefLocation != null )
-            {
-                sink.link( xrefLocation + "/" + filename1.replaceAll( "\\.java$", ".html" ).replace( '\\', '/' )
-                           + "#" + line1 );
-            }
-            sink.text( String.valueOf( line1 ) );
-            if ( xrefLocation != null )
-            {
-                sink.link_();
-            }
-
-            sink.tableCell_();
-            sink.tableRow_();
-
-            // File 2
-            sink.tableRow();
-            sink.tableCell();
-            sink.text( filename2 );
-            sink.tableCell_();
-            if ( aggregate )
+            // Iterating on every token entry
+            for ( Iterator<TokenEntry> occurrences = match.iterator(); occurrences.hasNext(); )
             {
-                sink.tableCell();
-                sink.text( projectFile2.getName() );
-                sink.tableCell_();
-            }
-            sink.tableCell();
 
-            if ( xrefLocation != null )
-            {
-                sink.link( xrefLocation2 + "/" + filename2.replaceAll( "\\.java$", ".html" ).replace( '\\', '/' )
-                           + "#" + line2 );
+                TokenEntry mark = occurrences.next();
+                generateFileLine( mark );
             }
-            sink.text( String.valueOf( line2 ) );
-            if ( xrefLocation != null )
-            {
-                sink.link_();
-            }
-            sink.tableCell_();
-            sink.tableRow_();
-
+           
             // Source snippet
             sink.tableRow();
 

Modified: maven/plugins/trunk/maven-pmd-plugin/src/test/java/org/apache/maven/plugin/pmd/CpdReportTest.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pmd-plugin/src/test/java/org/apache/maven/plugin/pmd/CpdReportTest.java?rev=1227278&r1=1227277&r2=1227278&view=diff
==============================================================================
--- maven/plugins/trunk/maven-pmd-plugin/src/test/java/org/apache/maven/plugin/pmd/CpdReportTest.java (original)
+++ maven/plugins/trunk/maven-pmd-plugin/src/test/java/org/apache/maven/plugin/pmd/CpdReportTest.java Wed Jan  4 19:39:49 2012
@@ -130,7 +130,7 @@ public class CpdReportTest
         assertTrue( str.toLowerCase().indexOf( "public static void main( String[] args )".toLowerCase() ) != -1 );
 
         str = readFile( new File( getBasedir(), "target/test/unit/custom-configuration/target/site/cpd.html" ) );
-        assertTrue( str.toLowerCase().indexOf( "private String unusedMethod( String unusedParam )".toLowerCase() ) != -1 );
+        assertTrue( str.toLowerCase().indexOf( "private String unusedMethod(".toLowerCase() ) != -1 );
 
     }