diff --git a/pmd/etc/build.xml b/pmd/etc/build.xml index 44e53b5985..f0ba90e31d 100644 --- a/pmd/etc/build.xml +++ b/pmd/etc/build.xml @@ -60,7 +60,7 @@ - + diff --git a/pmd/etc/changelog.txt b/pmd/etc/changelog.txt index 6a1268db49..26f1c3666e 100644 --- a/pmd/etc/changelog.txt +++ b/pmd/etc/changelog.txt @@ -1,5 +1,5 @@ ????? - 1.06: -Removed "verbose" attribute from CPD Ant task; now it uses built in logging so you can do a "ant -verbose cpd". Thanks to Philippe T'Seyen for the code. +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. TODO - fix it so tests and rules don't duplicate the xpath expressions April 17 - 1.05: diff --git a/pmd/regress/test/net/sourceforge/pmd/ant/PMDTaskTest.java b/pmd/regress/test/net/sourceforge/pmd/ant/PMDTaskTest.java index d56ef5c674..df1beb2080 100644 --- a/pmd/regress/test/net/sourceforge/pmd/ant/PMDTaskTest.java +++ b/pmd/regress/test/net/sourceforge/pmd/ant/PMDTaskTest.java @@ -39,16 +39,4 @@ public class PMDTaskTest extends TestCase { } } - public void testBogusRuleSet() { - PMDTask task = new PMDTask(); - task.setPrintToConsole(true); - task.setRuleSetFiles("fiddlesticks"); - try { - task.execute(); - throw new RuntimeException("Should have thrown a BuildException - bogus rulesets"); - } catch (BuildException be) { - // cool - } - } - } diff --git a/pmd/src/net/sourceforge/pmd/ant/PMDTask.java b/pmd/src/net/sourceforge/pmd/ant/PMDTask.java index e8445b2051..155d61de4a 100644 --- a/pmd/src/net/sourceforge/pmd/ant/PMDTask.java +++ b/pmd/src/net/sourceforge/pmd/ant/PMDTask.java @@ -14,6 +14,7 @@ import org.apache.tools.ant.BuildException; import org.apache.tools.ant.DirectoryScanner; import org.apache.tools.ant.Task; import org.apache.tools.ant.AntClassLoader; +import org.apache.tools.ant.Project; import org.apache.tools.ant.types.FileSet; import org.apache.tools.ant.types.Path; import org.apache.tools.ant.types.Reference; @@ -33,7 +34,6 @@ public class PMDTask extends Task { private List formatters = new ArrayList(); private List filesets = new ArrayList(); private boolean shortFilenames; - private boolean verbose; private boolean printToConsole; private String ruleSetFiles; private boolean failOnError; @@ -56,10 +56,6 @@ public class PMDTask extends Task { this.failOnRuleViolation = fail; } - public void setVerbose(boolean verbose) { - this.verbose = verbose; - } - public void setPrintToConsole(boolean printToConsole) { this.printToConsole = printToConsole; } @@ -91,21 +87,17 @@ public class PMDTask extends Task { try { RuleSetFactory ruleSetFactory = new RuleSetFactory(); if (classpath == null) { - printIfVerbose("Using the normal ClassLoader"); + log("Using the normal ClassLoader", Project.MSG_VERBOSE); rules = ruleSetFactory.createRuleSet(ruleSetFiles); } else { - printIfVerbose("Using the AntClassLoader"); + log("Using the AntClassLoader", Project.MSG_VERBOSE); rules = ruleSetFactory.createRuleSet(ruleSetFiles, new AntClassLoader(project, classpath)); } - } catch (RuleSetNotFoundException rsnfe) { - throw new BuildException(rsnfe.getMessage()); + } catch (RuleSetNotFoundException e) { + throw new BuildException(e.getMessage()); } - printIfVerbose("Using these rulesets: " + ruleSetFiles); - for (Iterator i = rules.getRules().iterator();i.hasNext();) { - Rule rule = (Rule)i.next(); - printIfVerbose("Using rule " + rule.getName()); - } + logRulesUsed(rules); PMD pmd = new PMD(); RuleContext ctx = new RuleContext(); @@ -116,7 +108,7 @@ public class PMDTask extends Task { String[] srcFiles = ds.getIncludedFiles(); for (int j = 0; j < srcFiles.length; j++) { File file = new File(ds.getBasedir() + System.getProperty("file.separator") + srcFiles[j]); - printIfVerbose("Processing file " + file.getAbsoluteFile().toString()); + log("Processing file " + file.getAbsoluteFile().toString(), Project.MSG_VERBOSE); ctx.setSourceCodeFilename(shortFilenames ? srcFiles[j] : file.getAbsolutePath()); try { pmd.processFile(new FileInputStream(file), rules, ctx); @@ -125,9 +117,7 @@ public class PMDTask extends Task { throw new BuildException(fnfe); } } catch (PMDException pmde) { - if (verbose) { - pmde.printStackTrace(); - } + log(pmde.toString(), Project.MSG_VERBOSE); if (failOnError) { throw new BuildException(pmde); } @@ -136,7 +126,7 @@ public class PMDTask extends Task { } } - printIfVerbose("Problems found: " + ctx.getReport().size()); + log(ctx.getReport().size() + " problems found", Project.MSG_VERBOSE); if (!ctx.getReport().isEmpty()) { for (Iterator i = formatters.iterator(); i.hasNext();) { @@ -153,7 +143,7 @@ public class PMDTask extends Task { if (printToConsole) { Renderer r = new TextRenderer(); - log(r.render(ctx.getReport())); + log(r.render(ctx.getReport()), Project.MSG_INFO); } if (failOnRuleViolation) { @@ -162,6 +152,14 @@ public class PMDTask extends Task { } } + private void logRulesUsed(RuleSet rules) { + log("Using these rulesets: " + ruleSetFiles, Project.MSG_VERBOSE); + for (Iterator i = rules.getRules().iterator();i.hasNext();) { + Rule rule = (Rule)i.next(); + log("Using rule " + rule.getName(), Project.MSG_VERBOSE); + } + } + private void validate() throws BuildException { if (formatters.isEmpty() && !printToConsole) { throw new BuildException("No formatter specified; and printToConsole was false"); @@ -179,12 +177,6 @@ public class PMDTask extends Task { } } - private void printIfVerbose(String in) { - if (verbose) { - log(in); - } - } - private Path createClasspath() { if (classpath == null) { classpath = new Path(project);