diff --git a/pmd/etc/build.xml b/pmd/etc/build.xml index bbed4a9bba..5faebc850b 100644 --- a/pmd/etc/build.xml +++ b/pmd/etc/build.xml @@ -58,8 +58,10 @@ - - + + + + diff --git a/pmd/etc/changelog.txt b/pmd/etc/changelog.txt index ff3ab6a0f6..eec12fbb03 100644 --- a/pmd/etc/changelog.txt +++ b/pmd/etc/changelog.txt @@ -1,7 +1,8 @@ -???? ?? 2002 - 1.02: +???? ?? ???? - 1.02: Added new rule: ImportFromSamePackageRule Updated LooseCouplingRule to check for usage of Vector; thx to Vladimir for the good catch. Updated AvoidDuplicateLiteralsRule to report the line number of the first occurrence of the duplicate String. +Modified Ant task to use a formatter element; this lets you render a report in several formats without having to rerun PMD. November 07 2002 - 1.01: Fixed bug 633879: EmptyFinallyBlockRule now handles multiple catch blocks followed by a finally block. diff --git a/pmd/src/net/sourceforge/pmd/ant/PMDTask.java b/pmd/src/net/sourceforge/pmd/ant/PMDTask.java index 2114a4ea74..e6baa3b8bf 100644 --- a/pmd/src/net/sourceforge/pmd/ant/PMDTask.java +++ b/pmd/src/net/sourceforge/pmd/ant/PMDTask.java @@ -27,12 +27,28 @@ import java.util.List; public class PMDTask extends Task { + public static class Formatter { + private Renderer renderer; + private String toFile; + public void setType(String type) { + if (type.equals("xml")) { + renderer = new XMLRenderer(); + } else if (type.equals("html")) { + renderer = new HTMLRenderer(); + } else { + throw new BuildException("Formatter type must be either 'xml' or 'html'; you specified " + type); + } + } + public void setToFile(String toFile) {this.toFile = toFile;} + public Renderer getRenderer() {return renderer;} + public String getToFile() {return toFile;} + } + + private List formatters = new ArrayList(); private List filesets = new ArrayList(); - private String reportFile; private boolean verbose; private boolean printToConsole; private String ruleSetFiles; - private String format; private boolean failOnError; /** @@ -60,21 +76,13 @@ public class PMDTask extends Task { filesets.add(set); } - public void setReportFile(String reportFile) { - this.reportFile = reportFile; - } - - public void setFormat(String format) { - this.format = format; + public void addFormatter(Formatter f) { + formatters.add(f); } public void execute() throws BuildException { - if (reportFile == null) { - throw new BuildException("No report file specified"); - } - - if (format == null || (!format.equals("xml") && !format.equals("html"))) { - throw new BuildException("Renderer format must be either 'xml' or 'html'; you specified " + format); + if (formatters.isEmpty()) { + throw new BuildException("No formatter specified"); } RuleSet rules = null; @@ -97,7 +105,7 @@ public class PMDTask extends Task { for (int j=0; j
-

Runs a set of static code analysis rules on some Java source code files and generates a list of problems found.

+

Runs a set of static code analysis rules on Java source code files and generates a list of problems found.

@@ -20,27 +20,17 @@ - - + + - - - - - - - - - - @@ -51,6 +41,11 @@ + + + + +
Required
reportfileThe file to which the report is written.formatterSpecifies formats and files to which the report is written. Can be of type 'xml' or 'html'. See example below. Yes
verboseVerbose output - names of files processed, rule counts, etc.No
rulesetfiles A comma delimited list of ruleset files ('rulesets/basic.xml,rulesets/design.xml'). If you write your own ruleset files, you can put them on the classpath and plug them in here. Yes
formatThe report format (xml, html)Yes
failonerror Whether or not to fail the build if PMD finds any problemsWhether or not to print any problems found to the Ant log/console No
verboseVerbose output - names of files processed, rule counts, etc.No
@@ -59,7 +54,8 @@ - + + @@ -68,7 +64,8 @@ - + +