View Javadoc
1 /*** 2 * BSD-style license; for more info see http://pmd.sourceforge.net/license.html 3 */ 4 package net.sourceforge.pmd.renderers; 5 6 import net.sourceforge.pmd.PMD; 7 import net.sourceforge.pmd.Report; 8 import net.sourceforge.pmd.RuleViolation; 9 import net.sourceforge.pmd.util.StringUtil; 10 11 import java.util.Iterator; 12 13 public class CSVRenderer implements Renderer { 14 public String render(Report report) { 15 StringBuffer buf = new StringBuffer(quoteAndCommify("Problem")); 16 buf.append(quoteAndCommify("File")); 17 buf.append(quoteAndCommify("Line")); 18 buf.append(quote("Description")); 19 buf.append(PMD.EOL); 20 21 int violationCount = 1; 22 for (Iterator i = report.iterator(); i.hasNext();) { 23 RuleViolation rv = (RuleViolation) i.next(); 24 buf.append(quoteAndCommify(Integer.toString(violationCount))); 25 buf.append(quoteAndCommify(rv.getFilename())); 26 buf.append(quoteAndCommify(Integer.toString(rv.getLine()))); 27 buf.append(quote(StringUtil.replaceString(rv.getDescription(), '\"', "'"))); 28 buf.append(PMD.EOL); 29 violationCount++; 30 } 31 return buf.toString(); 32 } 33 34 private String quote(String d) { 35 return "\"" + d + "\""; 36 } 37 38 private String quoteAndCommify(String d) { 39 return quote(d) + ","; 40 } 41 42 }

This page was automatically generated by Maven