diff --git a/pmd/etc/changelog.txt b/pmd/etc/changelog.txt
index 26f1c3666e..f57fe02d2c 100644
--- a/pmd/etc/changelog.txt
+++ b/pmd/etc/changelog.txt
@@ -1,5 +1,6 @@
????? - 1.06:
Removed "verbose" attribute from PMD and CPD Ant tasks; now they use built in logging so you can do a "ant -verbose cpd" or "ant -verbose pmd". Thanks to Philippe T'Seyen for the code.
+Added "excludes" feature to rulesets; thanks to Gael Marziou for the suggestion.
TODO - fix it so tests and rules don't duplicate the xpath expressions
April 17 - 1.05:
diff --git a/pmd/etc/doing_the_next_pmd_release.txt b/pmd/etc/doing_the_next_pmd_release.txt
index 306f3f4c0f..0f9bf2b93a 100644
--- a/pmd/etc/doing_the_next_pmd_release.txt
+++ b/pmd/etc/doing_the_next_pmd_release.txt
@@ -1,4 +1,6 @@
--------> Update ant docs - remove verbose attribute and make a note about -verbose
+--------> Update custom ruleset docs - add exclude example
+
update run.bat to point to pmd-1.05.jar
update run.sh to point to pmd-1.05.jar
update cpdgui.bat to point to pmd-1.05.jar
diff --git a/pmd/regress/test/net/sourceforge/pmd/ExternalRuleIDTest.java b/pmd/regress/test/net/sourceforge/pmd/ExternalRuleIDTest.java
index 4268d9a971..20f1480002 100644
--- a/pmd/regress/test/net/sourceforge/pmd/ExternalRuleIDTest.java
+++ b/pmd/regress/test/net/sourceforge/pmd/ExternalRuleIDTest.java
@@ -4,11 +4,8 @@ import junit.framework.TestCase;
import net.sourceforge.pmd.ExternalRuleID;
public class ExternalRuleIDTest extends TestCase {
- public ExternalRuleIDTest(String name) {
- super(name);
- }
- public void testParse() {
+ public void testSimpleRef() {
String xrefString = "rulesets/basic.xml/EmptyCatchBlock";
ExternalRuleID xref = new ExternalRuleID(xrefString);
assertEquals("Filename mismatch!", "rulesets/basic.xml", xref.getFilename());
diff --git a/pmd/regress/test/net/sourceforge/pmd/RuleSetFactoryTest.java b/pmd/regress/test/net/sourceforge/pmd/RuleSetFactoryTest.java
index 21111ead15..5d8551e6d9 100644
--- a/pmd/regress/test/net/sourceforge/pmd/RuleSetFactoryTest.java
+++ b/pmd/regress/test/net/sourceforge/pmd/RuleSetFactoryTest.java
@@ -102,7 +102,6 @@ public class RuleSetFactoryTest extends TestCase {
"3" + EOL +
"";
-
public void testSingleRuleWithPriority() {
RuleSetFactory rsf = new RuleSetFactory();
RuleSet rs = rsf.createRuleSet(new ByteArrayInputStream(SINGLE_RULE_SET_WITH_PRIORITY.getBytes()));
diff --git a/pmd/src/net/sourceforge/pmd/RuleSetFactory.java b/pmd/src/net/sourceforge/pmd/RuleSetFactory.java
index a1fa2b0d1f..2a798aa535 100644
--- a/pmd/src/net/sourceforge/pmd/RuleSetFactory.java
+++ b/pmd/src/net/sourceforge/pmd/RuleSetFactory.java
@@ -15,6 +15,8 @@ import java.util.Iterator;
import java.util.List;
import java.util.Properties;
import java.util.StringTokenizer;
+import java.util.Set;
+import java.util.HashSet;
public class RuleSetFactory {
@@ -114,15 +116,48 @@ public class RuleSetFactory {
ruleSet.addRule(rule);
}
+ /**
+ * Here's how to exclude rules:
+ *
+ *
+ *
+ *
+ *
+ *
+ */
private void parseExternallyDefinedRule(RuleSet ruleSet, Node ruleNode) throws RuleSetNotFoundException {
String referenceValue = ruleNode.getAttributes().getNamedItem("ref").getNodeValue();
- if (!referenceValue.endsWith("xml")) {
- ExternalRuleID externalRuleID = new ExternalRuleID(referenceValue);
- RuleSetFactory rsf = new RuleSetFactory();
- RuleSet externalRuleSet = rsf.createRuleSet(ResourceLoader.loadResourceAsStream(externalRuleID.getFilename()));
- ruleSet.addRule(externalRuleSet.getRuleByName(externalRuleID.getRuleName()));
+ if (referenceValue.endsWith("xml")) {
+ parseWithExcludes(ruleNode, referenceValue, ruleSet);
+ } else {
+ parseSimpleReference(referenceValue, ruleSet);
+ }
+ }
+
+ private void parseSimpleReference(String referenceValue, RuleSet ruleSet) throws RuleSetNotFoundException {
+ RuleSetFactory rsf = new RuleSetFactory();
+ ExternalRuleID externalRuleID = new ExternalRuleID(referenceValue);
+ RuleSet externalRuleSet = rsf.createRuleSet(ResourceLoader.loadResourceAsStream(externalRuleID.getFilename()));
+ ruleSet.addRule(externalRuleSet.getRuleByName(externalRuleID.getRuleName()));
+ }
+
+ private void parseWithExcludes(Node ruleNode, String referenceValue, RuleSet ruleSet) throws RuleSetNotFoundException {
+ NodeList excludeNodes = ruleNode.getChildNodes();
+ Set excludes = new HashSet();
+ for (int i=0; i
+ - Gael Marziou - "exclude" rule feature request, bug reports
- Philippe T'Seyen - refactoring and cleanup of the CPD Ant task, an XML renderer (with unit tests!) for CPD
- Michael Montuori - bug reports on the Gel IDE plugin
- Michael Hosier - bug reports on the Gel IDE plugin
@@ -52,7 +53,6 @@
- Radim Kubacki - bug reports, pmd-netbeans feedback
- Stefan Bodewig - bug report
- Paul Kendall - enhanced EmptyCatchBlock rule
- - Gael Marziou - bug reports
- Sean Sullivan - rule suggestions
- Dale Vissar - rule suggestions
- Alina Copeland - pmd-web formulas, pmd-dcpd optimizations