diff --git a/pmd/bin/build.xml b/pmd/bin/build.xml
index e2683b26bb..50e18ebee2 100644
--- a/pmd/bin/build.xml
+++ b/pmd/bin/build.xml
@@ -231,9 +231,10 @@
-
-
-
+
+
+
+
diff --git a/pmd/etc/changelog.txt b/pmd/etc/changelog.txt
index 7dc29a3c5b..e67f3bdd21 100644
--- a/pmd/etc/changelog.txt
+++ b/pmd/etc/changelog.txt
@@ -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.
diff --git a/pmd/regress/test/net/sourceforge/pmd/rules/design/AvoidInstanceofChecksInCatchClauseTest.java b/pmd/regress/test/net/sourceforge/pmd/rules/design/AvoidInstanceofChecksInCatchClauseTest.java
index 26e1a91de1..ebe0531af1 100644
--- a/pmd/regress/test/net/sourceforge/pmd/rules/design/AvoidInstanceofChecksInCatchClauseTest.java
+++ b/pmd/regress/test/net/sourceforge/pmd/rules/design/AvoidInstanceofChecksInCatchClauseTest.java
@@ -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;
diff --git a/pmd/src/net/sourceforge/pmd/cpd/CPDTask.java b/pmd/src/net/sourceforge/pmd/cpd/CPDTask.java
index 544500e16f..dc1de4fefd 100644
--- a/pmd/src/net/sourceforge/pmd/cpd/CPDTask.java
+++ b/pmd/src/net/sourceforge/pmd/cpd/CPDTask.java
@@ -25,7 +25,7 @@ import java.util.Properties;
*
*
*
- *
+ *
*
*
*
@@ -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;
}
}
}
diff --git a/pmd/xdocs/cpd.xml b/pmd/xdocs/cpd.xml
index 7159da6880..e7101379c8 100644
--- a/pmd/xdocs/cpd.xml
+++ b/pmd/xdocs/cpd.xml
@@ -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 ignoreIdentifiers="true" 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 language="cpp|java|php|ruby" flag
+ to select the appropriate language; the default language is "java".
Also, you can get verbose output from this task by running ant with the -v flag; i.e.:
Mathieu Champlon - Added language support to the CPD Ant task
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
Uroshnor - Reported bug in UseNotifyAllInsteadOfNotify
Jan Koops - Noted missing data in MemberValuePair nodes, bug report for JBuilder plugin