I have added the CPD (copy paste detection) report to the existing PMD plugin. I believe this was the approach preferred previously on the list. For more on CPD please take a look at:
http://pmd.sourceforge.net/cpd.html
Two properties have been added:
# enable/disable CPD maven.pmd.cpd.enable = false
# minimum length of token sequences considered equal maven.pmd.cpd.minimumtokencount = 100
The attached patch was made against maven-plugins head and works for me with rc1. Please feel free to commit this with appropriate modifications.
Regards
Morten
Index: plugin.jelly
===================================================================
retrieving revision 1.10
diff -u -r1.10 plugin.jelly
--- plugin.jelly 20 Nov 2003 15:35:16 -0000 1.10
+++ plugin.jelly 28 Dec 2003 16:34:46 -0000
@@ -19,6 +19,11 @@
pluginName="pmd"
description="Verification of coding rules."
link="pmd-report"/>
+ <doc:registerReport
+ name="CPD Report"
+ pluginName=""
+ description="Detection of copy-paste code."
+ link="cpd-report"/>
</j:if>
</goal>
@@ -30,6 +35,7 @@
<goal name="maven-pmd-plugin:deregister">
<j:if test="${sourcesPresent}">
<doc:deregisterReport name="PMD Report"/>
+ <doc:deregisterReport name="CPD Report"/>
</j:if>
</goal>
@@ -118,6 +124,63 @@
prettyPrint="true"
/>
+ <!-- Generate CPD report if it is enabled -->
+ <j:set var="enable" value="${maven.pmd.cpd.enable}"/>
+
+ <j:if test="${enable == 'true'}">
+ <attainGoal name="pmd:cpd-report"/>
+ </j:if>
</goal>
-
+
+ <!--
+ ========================================================================
+ Generate the CPD report.
+ ========================================================================
+ -->
+ <goal name="pmd:cpd-report"
+ description="Generate duplicate source code report with CPD">
+
+ <!-- Define a CPD task from the PMD jar -->
+ <taskdef name="cpd"
+ classpath="${plugin.getDependencyPath('pmd:pmd')}"
+ classname="net.sourceforge.pmd.cpd.CPDTask"/>
+
+ <!-- Run the CPD task -->
+ <echo>Running the CPD task with minimumTokenCount =
${maven.pmd.cpd.minimumtokencount} ...</echo>
+
+ <cpd minimumTokenCount="${maven.pmd.cpd.minimumtokencount}"
+ outputFile="${maven.build.dir}/cpd-raw-report.txt">
+ <!-- cut and paste from pmd:report -->
+ <fileset dir="${pom.build.sourceDirectory}"
+ includes="${maven.pmd.includes}"
+ excludes="${maven.pmd.excludes}">
+
+ <!-- FIXME: This is a bad cut and paste -->
+ <!-- handle source modifications -->
+ <j:forEach var="sm" items="${pom.build.sourceModifications}">
+ <available property="classPresent" classname="${sm.className}"/>
+ <j:if test="${classPresent != 'true'}">
+ <j:forEach var="exclude" items="${sm.excludes}">
+ <exclude name="${exclude}"/>
+ </j:forEach>
+ <j:forEach var="include" items="${sm.includes}">
+ <include name="${include}"/>
+ </j:forEach>
+ </j:if>
+ </j:forEach>
+ </fileset>
+ </cpd>
+
+ <!-- Convert raw text report into XDOC -->
+
+ <j:set var="genDocs" value="${maven.gen.docs}" />
+ <doc:text-xdoc
+ title="CPD Report"
+ section="CPD Report"
+ inputFile="${maven.build.dir}/cpd-raw-report.txt"
+ output="${genDocs}/cpd-report.xml"
+ />
+
+ </goal>
+
</project>
Index: plugin.properties
===================================================================
retrieving revision 1.4
diff -u -r1.4 plugin.properties
--- plugin.properties 22 Jul 2003 16:13:27 -0000 1.4
+++ plugin.properties 28 Dec 2003 16:34:46 -0000
@@ -15,3 +15,11 @@
maven.pmd.includes = **/*.java
maven.pmd.excludes =
+
+# enable/disable CPD
+
+maven.pmd.cpd.enable = false
+
+# minimum length of token sequences considered equal
+
+maven.pmd.cpd.minimumtokencount = 100
Index: xdocs/properties.xml
===================================================================
retrieving revision 1.2
diff -u -r1.2 properties.xml
--- xdocs/properties.xml 22 Jul 2003 16:13:26 -0000 1.2
+++ xdocs/properties.xml 28 Dec 2003 16:34:47 -0000
@@ -54,6 +54,21 @@
exclude any files.
</td>
</tr>
+ <tr>
+ <td>maven.pmd.cpd.enable</td>
+ <td>Yes</td>
+ <td>
+ Enable/disable the CPD report. Defaults to "false".
+ </td>
+ </tr>
+ <tr>
+ <td>maven.pmd.cpd.minimumtokencount</td>
+ <td>Yes</td>
+ <td>
+ Specifies the minimal number required to consider two sequences of
+ tokens identical. Defaults to "100".
+ </td>
+ </tr>
</table>
</section>
</body>--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
