forked from phoedos/pmd
added fixes for bug 579718
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@279 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
@ -35,8 +35,8 @@
|
|||||||
|
|
||||||
<target name="pmd">
|
<target name="pmd">
|
||||||
<taskdef name="pmd" classname="net.sourceforge.pmd.ant.PMDTask"/>
|
<taskdef name="pmd" classname="net.sourceforge.pmd.ant.PMDTask"/>
|
||||||
<!--<pmd reportFile="c:\jdk14.html" rulesetfiles="rulesets/ticbuild.xml,rulesets/unusedcode.xml,rulesets/design.xml" format="html">-->
|
<pmd reportFile="c:\jdk14.html" rulesetfiles="rulesets/basic.xml,rulesets/foo.xml" format="html">
|
||||||
<pmd reportFile="c:\jdk14.html" rulesetfiles="rulesets/new_for_0_4.xml,rulesets/ticbuild.xml,rulesets/unusedcode.xml,rulesets/design.xml" format="html" verbose="true">
|
<!--<pmd reportFile="c:\jdk14.html" rulesetfiles="rulesets/new_for_0_4.xml,rulesets/ticbuild.xml,rulesets/unusedcode.xml,rulesets/design.xml" format="html" verbose="true">-->
|
||||||
<fileset dir="c:\data\pmd\pmd\src">
|
<fileset dir="c:\data\pmd\pmd\src">
|
||||||
<!--<fileset dir="c:\j2sdk1.4.0\src">-->
|
<!--<fileset dir="c:\j2sdk1.4.0\src">-->
|
||||||
<include name="**/*.java"/>
|
<include name="**/*.java"/>
|
||||||
|
12
pmd/src/net/sourceforge/pmd/RuleSetNotFoundException.java
Normal file
12
pmd/src/net/sourceforge/pmd/RuleSetNotFoundException.java
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
/*
|
||||||
|
* User: tom
|
||||||
|
* Date: Jul 10, 2002
|
||||||
|
* Time: 2:11:53 PM
|
||||||
|
*/
|
||||||
|
package net.sourceforge.pmd;
|
||||||
|
|
||||||
|
public class RuleSetNotFoundException extends Exception {
|
||||||
|
public RuleSetNotFoundException(String msg) {
|
||||||
|
super(msg);
|
||||||
|
}
|
||||||
|
}
|
@ -62,10 +62,15 @@ public class PMDTask extends Task {
|
|||||||
throw new BuildException("Renderer format must be either 'xml' or 'html'; you specified " + format);
|
throw new BuildException("Renderer format must be either 'xml' or 'html'; you specified " + format);
|
||||||
}
|
}
|
||||||
|
|
||||||
PMD pmd = new PMD();
|
RuleSet rules = null;
|
||||||
|
try {
|
||||||
|
createRuleSets();
|
||||||
|
} catch (RuleSetNotFoundException rsnfe) {
|
||||||
|
throw new BuildException(rsnfe.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
PMD pmd = new PMD();
|
||||||
RuleContext ctx = new RuleContext();
|
RuleContext ctx = new RuleContext();
|
||||||
RuleSet rules = createRuleSets();
|
|
||||||
Report report = new Report();
|
Report report = new Report();
|
||||||
ctx.setReport(report);
|
ctx.setReport(report);
|
||||||
|
|
||||||
@ -109,21 +114,28 @@ public class PMDTask extends Task {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private RuleSet createRuleSets() {
|
private RuleSet createRuleSets() throws RuleSetNotFoundException {
|
||||||
RuleSetFactory ruleSetFactory = new RuleSetFactory();
|
RuleSetFactory ruleSetFactory = new RuleSetFactory();
|
||||||
RuleSet ruleSet = new RuleSet();
|
RuleSet ruleSet = new RuleSet();
|
||||||
|
|
||||||
if (ruleSetFiles.indexOf(',') == -1) {
|
if (ruleSetFiles.indexOf(',') == -1) {
|
||||||
ruleSet = ruleSetFactory.createRuleSet(getClass().getClassLoader().getResourceAsStream(ruleSetFiles));
|
ruleSet = ruleSetFactory.createRuleSet(tryToGetStreamTo(ruleSetFiles));
|
||||||
} else {
|
} else {
|
||||||
for (StringTokenizer st = new StringTokenizer(ruleSetFiles, ","); st.hasMoreTokens();) {
|
for (StringTokenizer st = new StringTokenizer(ruleSetFiles, ","); st.hasMoreTokens();) {
|
||||||
String ruleSetName = st.nextToken();
|
String ruleSetName = st.nextToken();
|
||||||
RuleSet tmpRuleSet = ruleSetFactory.createRuleSet(getClass().getClassLoader().getResourceAsStream(ruleSetName));
|
RuleSet tmpRuleSet = ruleSetFactory.createRuleSet(tryToGetStreamTo(ruleSetName));
|
||||||
if (verbose) System.out.println("Adding " + tmpRuleSet.size() + " rules from ruleset " + ruleSetName);
|
if (verbose) System.out.println("Adding " + tmpRuleSet.size() + " rules from ruleset " + ruleSetName);
|
||||||
ruleSet.addRuleSet(tmpRuleSet);
|
ruleSet.addRuleSet(tmpRuleSet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ruleSet;
|
return ruleSet;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private InputStream tryToGetStreamTo(String name) throws RuleSetNotFoundException {
|
||||||
|
InputStream in = getClass().getClassLoader().getResourceAsStream(name);
|
||||||
|
if (in == null) {
|
||||||
|
throw new RuleSetNotFoundException("Can't find ruleset " + name + "; make sure that path is on the CLASSPATH");
|
||||||
|
}
|
||||||
|
return in;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user