Added new stuff to RuleFactory
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@129 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
@ -29,9 +29,9 @@
|
||||
|
||||
<target name="pmd">
|
||||
<taskdef name="pmd" classname="net.sourceforge.pmd.ant.PMDTask"/>
|
||||
<pmd reportFile="c:\pmd.html" verbose="false" rulesettype="general" format="html">
|
||||
<fileset dir="c:\data\pmd\pmd\src">
|
||||
<!--<fileset dir="c:\j2sdk1.4.0\src">-->
|
||||
<pmd reportFile="c:\jdk14.HTML" verbose="false" rulesettype="general" format="html">
|
||||
<!--<fileset dir="c:\data\pmd\pmd\src">-->
|
||||
<fileset dir="c:\j2sdk1.4.0\src">
|
||||
<include name="**/*.java"/>
|
||||
</fileset>
|
||||
</pmd>
|
||||
|
@ -1,5 +1,5 @@
|
||||
??? - 0.3:
|
||||
foo
|
||||
Added new rule: UseSingletonRule
|
||||
|
||||
June 27 2002 - 0.2:
|
||||
Added new rules: IfElseStmtsMustUseBracesRule, EmptyWhileStmtRule
|
||||
|
@ -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"));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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() {
|
||||
|
@ -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);
|
||||
|
Reference in New Issue
Block a user