Information Technology Reference
In-Depth Information
LISTING 7-6
Using CPD Ant Task
1 <property name="reports.pmd.dir"
value="${reports.dir}/pmd-reports" />
2 <property name="reports.cpd.dir" value="${reports.pmd.dir}" />
3 <property name="cpd.output.type" value="text"
description="csv,xml,text"/>
4 <property name="cpd.output.filename"
value="cpd-results.${cpd.output.type}" />
5 <property name="cpd.output.dir" value="${build.dir}" />
6 <property name="cpd.outputfile"
value="${cpd.output.dir}/${cpd.output.filename}" />
7 <target name="run-cpd">
8 <taskdef name="cpd"
classname="net.sourceforge.pmd.cpd.CPDTask"
classpathref="pmd.classpath" />
9 <cpd minimumTokenCount="20"
outputFile="${cpd.outputfile}"
format="${cpd.output.type}"
ignoreLiterals="true"
ignoreIdentifiers="true">
10 <fileset dir="${src.dir}">
11 <patternset refid="non.test.sources.pattern" />
12 </fileset>
13 </cpd>
14 </target>
Line 2 —Assigns the CPD report directory to the same directory
where PMD reports are placed.
Line 3 —In this example, a text report is created. You can also
create a comma-separated report or an XML report.
Line 9 —Invokes the CPD task. The attribute minimumTokenCount
is used to determine how many tokens must match to be consid-
ered duplicated code. The ignoreLiterals="true" causes
CPD to ignore string literals when evaluating a duplicate block.
Likewise, the ignoreIdentifiers="true" does the same, but
for identifiers (variables, methods).
Lines 10-11 —Specify the source code to check for duplication.
Using Simian
Another tool used to seek out copied-and-pasted code is Simian. Sim-
ian works with .NET 1.1 and later, and Java 1.4 and later. Listing 7-7
demonstrates how to use Simian in Ant.
Search WWH ::




Custom Search