From a98701d18b240f2bd65c7c04f21a972dfe77396a Mon Sep 17 00:00:00 2001 From: Tom Copeland Date: Mon, 24 Jun 2002 19:25:55 +0000 Subject: [PATCH] updated XML report format git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@30 51baf565-9d33-0410-a72c-fc3788e3496d --- pmd/src/net/sourceforge/pmd/PMD.java | 2 +- pmd/src/net/sourceforge/pmd/PMDTask.java | 13 +++++++++++++ pmd/src/net/sourceforge/pmd/Report.java | 14 ++++---------- pmd/src/net/sourceforge/pmd/RuleViolation.java | 2 ++ 4 files changed, 20 insertions(+), 11 deletions(-) diff --git a/pmd/src/net/sourceforge/pmd/PMD.java b/pmd/src/net/sourceforge/pmd/PMD.java index 47e9e08221..0a1865ac98 100644 --- a/pmd/src/net/sourceforge/pmd/PMD.java +++ b/pmd/src/net/sourceforge/pmd/PMD.java @@ -60,6 +60,6 @@ public class PMD { } PMD pmd = new PMD(); Report report = pmd.processFile(input, RuleFactory.ALL); - System.out.println(report.renderToXML()); + System.out.println("" + report.renderToXML() + ""); } } diff --git a/pmd/src/net/sourceforge/pmd/PMDTask.java b/pmd/src/net/sourceforge/pmd/PMDTask.java index 7f3fba5065..a05d3a47f2 100644 --- a/pmd/src/net/sourceforge/pmd/PMDTask.java +++ b/pmd/src/net/sourceforge/pmd/PMDTask.java @@ -45,7 +45,16 @@ public class PMDTask extends Task { if (ruleSetType == null) { throw new BuildException("No rule set type specified"); } + if (format == null) { + throw new BuildException("No report format specified"); + } + StringBuffer buf = new StringBuffer(); + + if (format.equals("xml")) { + buf.append("" + System.getProperty("line.separator")); + } + for (Iterator i = filesets.iterator(); i.hasNext();) { FileSet fs = (FileSet) i.next(); DirectoryScanner ds = fs.getDirectoryScanner(project); @@ -68,6 +77,10 @@ public class PMDTask extends Task { } } + if (format.equals("xml")) { + buf.append(""); + } + try { BufferedWriter writer = new BufferedWriter(new FileWriter(new File(reportFile))); writer.write(buf.toString(), 0, buf.length()); diff --git a/pmd/src/net/sourceforge/pmd/Report.java b/pmd/src/net/sourceforge/pmd/Report.java index 278a65f768..31bf3da712 100644 --- a/pmd/src/net/sourceforge/pmd/Report.java +++ b/pmd/src/net/sourceforge/pmd/Report.java @@ -27,18 +27,12 @@ public class Report { } public String renderToXML() { - StringBuffer buf = new StringBuffer(); + StringBuffer buf = new StringBuffer("" + System.getProperty("line.separator") + "" + filename + ""); for (Iterator iterator = violations.iterator(); iterator.hasNext();) { - if (buf.length() != 0) { - buf.append(System.getProperty("line.separator")); - } - RuleViolation violation = (RuleViolation) iterator.next(); - buf.append(""); - buf.append("" + filename + ""); - buf.append(violation.getXML()); - buf.append(""); + buf.append(((RuleViolation) iterator.next()).getXML()); } - return "" + System.getProperty("line.separator") + buf.toString() + System.getProperty("line.separator") + ""; + buf.append("" + System.getProperty("line.separator")); + return buf.toString(); } public boolean empty() { diff --git a/pmd/src/net/sourceforge/pmd/RuleViolation.java b/pmd/src/net/sourceforge/pmd/RuleViolation.java index a2ed5b644d..b82e55e6a4 100644 --- a/pmd/src/net/sourceforge/pmd/RuleViolation.java +++ b/pmd/src/net/sourceforge/pmd/RuleViolation.java @@ -27,8 +27,10 @@ public class RuleViolation { public String getXML() { StringBuffer buf = new StringBuffer(); + buf.append(""); buf.append("" + Integer.toString(line) + ""); buf.append("" + description + ""); + buf.append(""); return buf.toString(); } }