The CPD Ant task now supports an optional language attribute.
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@4311 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
@ -231,9 +231,10 @@
|
||||
<target name="cpd" description="Runs CPD">
|
||||
<taskdef name="cpd" classname="net.sourceforge.pmd.cpd.CPDTask" />
|
||||
<!-- ignoreIdentifiers="true" -->
|
||||
<cpd ignoreLiterals="true" minimumTokenCount="20" outputFile="cpd.txt" format="text">
|
||||
<fileset dir="${java-source.path}/java/lang/ref">
|
||||
<include name="**/*.java" />
|
||||
<cpd language="cpp" ignoreLiterals="true" minimumTokenCount="20" outputFile="cpd.txt" format="text">
|
||||
<fileset dir="/usr/local/src/apache_1.3.33/">
|
||||
<!--<fileset dir="${java-source.path}/java/lang/ref">-->
|
||||
<include name="**/*.c" />
|
||||
</fileset>
|
||||
</cpd>
|
||||
</target>
|
||||
|
@ -28,6 +28,7 @@ Fixed bug 1455965 - MethodReturnsInternalArray no longer flags variations on 're
|
||||
Implemented RFE 1415487 - Added a rulesets/releases/35.xml ruleset (and similar rulesets for previous releases) contains rules new to PMD v3.5
|
||||
Wouter Zelle fixed a false positive in NonThreadSafeSingleton.
|
||||
Wouter Zelle fixed a false positive in InefficientStringBuffering.
|
||||
The CPD Ant task now supports an optional language attribute.
|
||||
Fixed bug in CallSuperInConstructor; it no longer flag classes without extends clauses.
|
||||
Fixed release packaging; now entire xslt/ directory contents are included.
|
||||
Added more XSLT from Dave Corley - you can use them to filter PMD reports by priority level.
|
||||
|
@ -5,6 +5,7 @@ import net.sourceforge.pmd.Rule;
|
||||
import net.sourceforge.pmd.RuleSetNotFoundException;
|
||||
import test.net.sourceforge.pmd.testframework.SimpleAggregatorTst;
|
||||
import test.net.sourceforge.pmd.testframework.TestDescriptor;
|
||||
import junit.framework.Assert;
|
||||
|
||||
public class AvoidInstanceofChecksInCatchClauseTest extends SimpleAggregatorTst {
|
||||
private Rule rule;
|
||||
|
@ -25,7 +25,7 @@ import java.util.Properties;
|
||||
* <project name="CPDProj" default="main" basedir=".">
|
||||
* <taskdef name="cpd" classname="net.sourceforge.pmd.cpd.CPDTask" />
|
||||
* <target name="main">
|
||||
* <cpd ignoreIdentifiers="true" ignoreLiterals="true" minimumTokenCount="100" outputFile="c:\cpdrun.txt">
|
||||
* <cpd language="java" ignoreIdentifiers="true" ignoreLiterals="true" minimumTokenCount="100" outputFile="c:\cpdrun.txt">
|
||||
* <fileset dir="/path/to/my/src">
|
||||
* <include name="*.java"/>
|
||||
* </fileset>
|
||||
@ -42,6 +42,7 @@ public class CPDTask extends Task {
|
||||
private static final String CSV_FORMAT = "csv";
|
||||
|
||||
private String format = TEXT_FORMAT;
|
||||
private String language = LanguageFactory.JAVA_KEY;
|
||||
private int minimumTokenCount;
|
||||
private boolean ignoreLiterals;
|
||||
private boolean ignoreIdentifiers;
|
||||
@ -53,14 +54,7 @@ public class CPDTask extends Task {
|
||||
validateFields();
|
||||
|
||||
log("Tokenizing files", Project.MSG_INFO);
|
||||
Properties p = new Properties();
|
||||
if (ignoreLiterals) {
|
||||
p.setProperty(JavaTokenizer.IGNORE_LITERALS, "true");
|
||||
}
|
||||
if (ignoreIdentifiers) {
|
||||
p.setProperty(JavaTokenizer.IGNORE_IDENTIFIERS, "true");
|
||||
}
|
||||
CPD cpd = new CPD(minimumTokenCount, new JavaLanguage(p));
|
||||
CPD cpd = new CPD(minimumTokenCount, createLanguage());
|
||||
tokenizeFiles(cpd);
|
||||
|
||||
log("Starting to analyze code", Project.MSG_INFO);
|
||||
@ -79,6 +73,17 @@ public class CPDTask extends Task {
|
||||
}
|
||||
}
|
||||
|
||||
private Language createLanguage() {
|
||||
Properties p = new Properties();
|
||||
if (ignoreLiterals) {
|
||||
p.setProperty(JavaTokenizer.IGNORE_LITERALS, "true");
|
||||
}
|
||||
if (ignoreIdentifiers) {
|
||||
p.setProperty(JavaTokenizer.IGNORE_IDENTIFIERS, "true");
|
||||
}
|
||||
return new LanguageFactory().createLanguage(language, p);
|
||||
}
|
||||
|
||||
private void report(CPD cpd) throws ReportException {
|
||||
if (!cpd.getMatches().hasNext()) {
|
||||
log("No duplicates over " + minimumTokenCount + " tokens found", Project.MSG_INFO);
|
||||
@ -91,7 +96,6 @@ public class CPDTask extends Task {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void tokenizeFiles(CPD cpd) throws IOException {
|
||||
for (Iterator iterator = filesets.iterator(); iterator.hasNext();) {
|
||||
FileSet fileSet = (FileSet) iterator.next();
|
||||
@ -155,11 +159,21 @@ public class CPDTask extends Task {
|
||||
format = formatAttribute.getValue();
|
||||
}
|
||||
|
||||
public static class FormatAttribute extends EnumeratedAttribute {
|
||||
private String[] formats = new String[]{XML_FORMAT, TEXT_FORMAT, CSV_FORMAT};
|
||||
public void setLanguage(LanguageAttribute languageAttribute) {
|
||||
language = languageAttribute.getValue();
|
||||
}
|
||||
|
||||
public static class FormatAttribute extends EnumeratedAttribute {
|
||||
private static final String[] FORMATS = new String[]{XML_FORMAT, TEXT_FORMAT, CSV_FORMAT};
|
||||
public String[] getValues() {
|
||||
return formats;
|
||||
return FORMATS;
|
||||
}
|
||||
}
|
||||
|
||||
public static class LanguageAttribute extends EnumeratedAttribute {
|
||||
private String[] LANGUAGES = new String[]{LanguageFactory.JAVA_KEY, LanguageFactory.CPP_KEY, LanguageFactory.C_KEY, LanguageFactory.PHP_KEY, LanguageFactory.RUBY_KEY };
|
||||
public String[] getValues() {
|
||||
return LANGUAGES;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -50,7 +50,8 @@
|
||||
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. There's also a <code>ignoreIdentifiers="true"</code> option
|
||||
that does the same thing with identifiers; i.e., variable names, methods names, and so forth.
|
||||
The same guidelines apply.
|
||||
The same guidelines apply. Finally, there's an optional <code>language="cpp|java|php|ruby"</code> flag
|
||||
to select the appropriate language; the default language is "java".
|
||||
</p>
|
||||
<p>Also, you can get verbose output from this task by running ant with the <code>-v</code> flag; i.e.:</p>
|
||||
<source>
|
||||
|
@ -48,6 +48,7 @@
|
||||
</subsection>
|
||||
<subsection name="Contributors">
|
||||
<ul>
|
||||
<li>Mathieu Champlon - Added language support to the CPD Ant task</li>
|
||||
<li>Wouter Zelle - Fixed a false positive in InefficientStringBuffering, fixed a false positive in NonThreadSafeSingleton, a nice patch to clean up some of the Ant task properties and fix a TextRenderer bug, rewrote PositionLiteralsFirstInComparisons in XPath, Renderer improvement suggestions, wrote NonThreadSafeSingleton rule, wrote DefaultPackage rule, worked thru ASTMethodDeclaration.isSyntacticallyX design, reported docs bug 1292689 for UnnecessaryLocalBeforeReturn, reported leftover ExceptionTypeChecking source file, rewrote UselessOverridingMethod in Java, UselessOverridingMethod rule, ProperLogger rule, nifty code to allow variables in XPath rules, externalInfoUrl data for all rules in basic and unusedcode rulesets, some very nifty XSLT, improvements to UseCorrectExceptionLogging, designed and implemented the "externalInfoUrl" feature in the rule definitions, fixed a devious bug in RuleSetFactory, AvoidPrintStackTrace, initial implementation of SimplifyConditional</li>
|
||||
<li>Uroshnor - Reported bug in UseNotifyAllInsteadOfNotify</li>
|
||||
<li>Jan Koops - Noted missing data in MemberValuePair nodes, bug report for JBuilder plugin</li>
|
||||
|
Reference in New Issue
Block a user