From 79183c8ba95aba141ea1c0ac98679137f9b76179 Mon Sep 17 00:00:00 2001 From: Tom Copeland Date: Wed, 10 Jul 2002 18:20:55 +0000 Subject: [PATCH] added fixes for bug 579718 git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@279 51baf565-9d33-0410-a72c-fc3788e3496d --- pmd/etc/build.xml | 4 ++-- .../pmd/RuleSetNotFoundException.java | 12 ++++++++++ pmd/src/net/sourceforge/pmd/ant/PMDTask.java | 24 ++++++++++++++----- 3 files changed, 32 insertions(+), 8 deletions(-) create mode 100644 pmd/src/net/sourceforge/pmd/RuleSetNotFoundException.java diff --git a/pmd/etc/build.xml b/pmd/etc/build.xml index 746d809ef9..9444257f18 100644 --- a/pmd/etc/build.xml +++ b/pmd/etc/build.xml @@ -35,8 +35,8 @@ - - + + diff --git a/pmd/src/net/sourceforge/pmd/RuleSetNotFoundException.java b/pmd/src/net/sourceforge/pmd/RuleSetNotFoundException.java new file mode 100644 index 0000000000..935afe8aa8 --- /dev/null +++ b/pmd/src/net/sourceforge/pmd/RuleSetNotFoundException.java @@ -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); + } +} diff --git a/pmd/src/net/sourceforge/pmd/ant/PMDTask.java b/pmd/src/net/sourceforge/pmd/ant/PMDTask.java index 4dc136d143..299c7fc1b2 100644 --- a/pmd/src/net/sourceforge/pmd/ant/PMDTask.java +++ b/pmd/src/net/sourceforge/pmd/ant/PMDTask.java @@ -62,10 +62,15 @@ public class PMDTask extends Task { 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(); - RuleSet rules = createRuleSets(); Report report = new 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(); RuleSet ruleSet = new RuleSet(); if (ruleSetFiles.indexOf(',') == -1) { - ruleSet = ruleSetFactory.createRuleSet(getClass().getClassLoader().getResourceAsStream(ruleSetFiles)); + ruleSet = ruleSetFactory.createRuleSet(tryToGetStreamTo(ruleSetFiles)); } else { for (StringTokenizer st = new StringTokenizer(ruleSetFiles, ","); st.hasMoreTokens();) { 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); ruleSet.addRuleSet(tmpRuleSet); } } - 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; + } }