updated XML report format
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@30 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
@ -60,6 +60,6 @@ public class PMD {
|
|||||||
}
|
}
|
||||||
PMD pmd = new PMD();
|
PMD pmd = new PMD();
|
||||||
Report report = pmd.processFile(input, RuleFactory.ALL);
|
Report report = pmd.processFile(input, RuleFactory.ALL);
|
||||||
System.out.println(report.renderToXML());
|
System.out.println("<pmd>" + report.renderToXML() + "</pmd>");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,16 @@ public class PMDTask extends Task {
|
|||||||
if (ruleSetType == null) {
|
if (ruleSetType == null) {
|
||||||
throw new BuildException("No rule set type specified");
|
throw new BuildException("No rule set type specified");
|
||||||
}
|
}
|
||||||
|
if (format == null) {
|
||||||
|
throw new BuildException("No report format specified");
|
||||||
|
}
|
||||||
|
|
||||||
StringBuffer buf = new StringBuffer();
|
StringBuffer buf = new StringBuffer();
|
||||||
|
|
||||||
|
if (format.equals("xml")) {
|
||||||
|
buf.append("<pmd>" + System.getProperty("line.separator"));
|
||||||
|
}
|
||||||
|
|
||||||
for (Iterator i = filesets.iterator(); i.hasNext();) {
|
for (Iterator i = filesets.iterator(); i.hasNext();) {
|
||||||
FileSet fs = (FileSet) i.next();
|
FileSet fs = (FileSet) i.next();
|
||||||
DirectoryScanner ds = fs.getDirectoryScanner(project);
|
DirectoryScanner ds = fs.getDirectoryScanner(project);
|
||||||
@ -68,6 +77,10 @@ public class PMDTask extends Task {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (format.equals("xml")) {
|
||||||
|
buf.append("</pmd>");
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
BufferedWriter writer = new BufferedWriter(new FileWriter(new File(reportFile)));
|
BufferedWriter writer = new BufferedWriter(new FileWriter(new File(reportFile)));
|
||||||
writer.write(buf.toString(), 0, buf.length());
|
writer.write(buf.toString(), 0, buf.length());
|
||||||
|
@ -27,18 +27,12 @@ public class Report {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String renderToXML() {
|
public String renderToXML() {
|
||||||
StringBuffer buf = new StringBuffer();
|
StringBuffer buf = new StringBuffer("<file>" + System.getProperty("line.separator") + "<name>" + filename + "</name>");
|
||||||
for (Iterator iterator = violations.iterator(); iterator.hasNext();) {
|
for (Iterator iterator = violations.iterator(); iterator.hasNext();) {
|
||||||
if (buf.length() != 0) {
|
buf.append(((RuleViolation) iterator.next()).getXML());
|
||||||
buf.append(System.getProperty("line.separator"));
|
|
||||||
}
|
|
||||||
RuleViolation violation = (RuleViolation) iterator.next();
|
|
||||||
buf.append("<ruleviolation>");
|
|
||||||
buf.append("<file>" + filename + "</file>");
|
|
||||||
buf.append(violation.getXML());
|
|
||||||
buf.append("</ruleviolation>");
|
|
||||||
}
|
}
|
||||||
return "<pmd>" + System.getProperty("line.separator") + buf.toString() + System.getProperty("line.separator") + "</pmd>";
|
buf.append("</file>" + System.getProperty("line.separator"));
|
||||||
|
return buf.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean empty() {
|
public boolean empty() {
|
||||||
|
@ -27,8 +27,10 @@ public class RuleViolation {
|
|||||||
|
|
||||||
public String getXML() {
|
public String getXML() {
|
||||||
StringBuffer buf = new StringBuffer();
|
StringBuffer buf = new StringBuffer();
|
||||||
|
buf.append("<ruleviolation>");
|
||||||
buf.append("<line>" + Integer.toString(line) + "</line>");
|
buf.append("<line>" + Integer.toString(line) + "</line>");
|
||||||
buf.append("<description>" + description + "</description>");
|
buf.append("<description>" + description + "</description>");
|
||||||
|
buf.append("</ruleviolation>");
|
||||||
return buf.toString();
|
return buf.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user