From 8c264ca01f7f926f1023686519edd1d8a0ae3d74 Mon Sep 17 00:00:00 2001 From: Tom Copeland Date: Fri, 28 Jun 2002 17:44:42 +0000 Subject: [PATCH] Added new stuff to RuleFactory git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@129 51baf565-9d33-0410-a72c-fc3788e3496d --- pmd/etc/build.xml | 6 +++--- pmd/etc/changelog.txt | 2 +- .../net/sourceforge/pmd/RuleFactoryTest.java | 10 +++++++++ pmd/src/net/sourceforge/pmd/RuleFactory.java | 21 +++++++++++++++---- pmd/src/net/sourceforge/pmd/ant/PMDTask.java | 5 +++-- 5 files changed, 34 insertions(+), 10 deletions(-) diff --git a/pmd/etc/build.xml b/pmd/etc/build.xml index 03250c7090..a0c0f2cc90 100644 --- a/pmd/etc/build.xml +++ b/pmd/etc/build.xml @@ -29,9 +29,9 @@ - - - + + + diff --git a/pmd/etc/changelog.txt b/pmd/etc/changelog.txt index 5b4a668341..c057eaf843 100644 --- a/pmd/etc/changelog.txt +++ b/pmd/etc/changelog.txt @@ -1,5 +1,5 @@ ??? - 0.3: -foo +Added new rule: UseSingletonRule June 27 2002 - 0.2: Added new rules: IfElseStmtsMustUseBracesRule, EmptyWhileStmtRule diff --git a/pmd/regress/test/net/sourceforge/pmd/RuleFactoryTest.java b/pmd/regress/test/net/sourceforge/pmd/RuleFactoryTest.java index 6f573351d7..6d64a34611 100644 --- a/pmd/regress/test/net/sourceforge/pmd/RuleFactoryTest.java +++ b/pmd/regress/test/net/sourceforge/pmd/RuleFactoryTest.java @@ -44,4 +44,14 @@ public class RuleFactoryTest extends TestCase { throw new RuntimeException("Should have thrown RuntimeException"); } + public void testConcatenatedList() { + String list = RuleFactory.getConcatenatedRuleSetList(); + assertTrue(list.indexOf("design") != -1); + } + + public void testContains() { + assertTrue(RuleFactory.containsRuleSet("all")); + assertTrue(!RuleFactory.containsRuleSet("foo")); + } + } diff --git a/pmd/src/net/sourceforge/pmd/RuleFactory.java b/pmd/src/net/sourceforge/pmd/RuleFactory.java index a408abf5bc..7e1850d55a 100644 --- a/pmd/src/net/sourceforge/pmd/RuleFactory.java +++ b/pmd/src/net/sourceforge/pmd/RuleFactory.java @@ -26,19 +26,32 @@ public class RuleFactory { ruleSets.add(DESIGN); } - public static List createRules(String ruleSetType) { - if (!ruleSets.contains(ruleSetType)) { - throw new RuntimeException("Unknown rule set type " + ruleSetType); + public static String getConcatenatedRuleSetList() { + StringBuffer buf = new StringBuffer(); + for (Iterator i = ruleSets.iterator(); i.hasNext();) { + if (buf.length() != 0) { + buf.append(","); + } + buf.append(i.next()); } + return buf.toString(); + } + public static boolean containsRuleSet(String ruleSet) { + return ruleSets.contains(ruleSet); + } + + public static List createRules(String ruleSetType) { if (ruleSetType.equals(ALL)) { return createAllRules(); } else if (ruleSetType.equals(GENERAL)) { return createGeneralRules(); } else if (ruleSetType.equals(DESIGN)) { return createDesignRules(); + } else if (ruleSetType.equals(COUGAAR)) { + return createCougaarRules(); } - return createCougaarRules(); + throw new RuntimeException("Unknown rule set type " + ruleSetType); } private static List createAllRules() { diff --git a/pmd/src/net/sourceforge/pmd/ant/PMDTask.java b/pmd/src/net/sourceforge/pmd/ant/PMDTask.java index 5bef8f73ca..ff96a2a204 100644 --- a/pmd/src/net/sourceforge/pmd/ant/PMDTask.java +++ b/pmd/src/net/sourceforge/pmd/ant/PMDTask.java @@ -12,6 +12,7 @@ import net.sourceforge.pmd.ast.ASTCompilationUnit; import net.sourceforge.pmd.PMD; import net.sourceforge.pmd.Report; import net.sourceforge.pmd.RuleContext; +import net.sourceforge.pmd.RuleFactory; public class PMDTask extends Task { @@ -45,8 +46,8 @@ public class PMDTask extends Task { if (reportFile == null) { throw new BuildException("No report file specified"); } - if (ruleSetType == null) { - throw new BuildException("Rule set type must be 'general', 'all', or 'cougaar'; you specified " + ruleSetType); + if (ruleSetType == null || !RuleFactory.containsRuleSet(ruleSetType)) { + throw new BuildException("Rule set type must be one of: " + RuleFactory.getConcatenatedRuleSetList() + "; you specified " + ruleSetType); } if (format == null || (!format.equals("text") && !format.equals("xml") && !format.equals("html"))) { throw new BuildException("Report format must be either 'text', 'xml', or 'html'; you specified " + format);