1 |
| |
2 |
| |
3 |
| |
4 |
| package net.sourceforge.pmd.renderers; |
5 |
| |
6 |
| import net.sourceforge.pmd.IRuleViolation; |
7 |
| import net.sourceforge.pmd.PMD; |
8 |
| import net.sourceforge.pmd.Report; |
9 |
| import net.sourceforge.pmd.util.StringUtil; |
10 |
| |
11 |
| import java.io.IOException; |
12 |
| import java.io.Writer; |
13 |
| import java.util.Iterator; |
14 |
| |
15 |
| public class CSVRenderer extends AbstractRenderer { |
16 |
| |
17 |
5
| public void render(Writer writer, Report report) throws IOException {
|
18 |
5
| StringBuffer buf = new StringBuffer(300);
|
19 |
5
| quoteAndCommify(buf, "Problem");
|
20 |
5
| quoteAndCommify(buf, "Package");
|
21 |
5
| quoteAndCommify(buf, "File");
|
22 |
5
| quoteAndCommify(buf, "Priority");
|
23 |
5
| quoteAndCommify(buf, "Line");
|
24 |
5
| quoteAndCommify(buf, "Description");
|
25 |
5
| quoteAndCommify(buf, "Rule set");
|
26 |
5
| quote(buf, "Rule");
|
27 |
5
| buf.append(PMD.EOL);
|
28 |
5
| writer.write(buf.toString());
|
29 |
| |
30 |
5
| addViolations(writer, report, buf);
|
31 |
| } |
32 |
| |
33 |
5
| private void addViolations(Writer writer, Report report, StringBuffer buf) throws IOException {
|
34 |
5
| int violationCount = 1;
|
35 |
5
| IRuleViolation rv;
|
36 |
5
| for (Iterator i = report.iterator(); i.hasNext();) {
|
37 |
3
| buf.setLength(0);
|
38 |
3
| rv = (IRuleViolation) i.next();
|
39 |
3
| quoteAndCommify(buf, Integer.toString(violationCount));
|
40 |
3
| quoteAndCommify(buf, rv.getPackageName());
|
41 |
3
| quoteAndCommify(buf, rv.getFilename());
|
42 |
3
| quoteAndCommify(buf, Integer.toString(rv.getRule().getPriority()));
|
43 |
3
| quoteAndCommify(buf, Integer.toString(rv.getBeginLine()));
|
44 |
3
| quoteAndCommify(buf, StringUtil.replaceString(rv.getDescription(), '\"', "'"));
|
45 |
3
| quoteAndCommify(buf, rv.getRule().getRuleSetName());
|
46 |
3
| quote(buf, rv.getRule().getName());
|
47 |
3
| buf.append(PMD.EOL);
|
48 |
3
| writer.write(buf.toString());
|
49 |
3
| violationCount++;
|
50 |
| } |
51 |
| } |
52 |
| |
53 |
64
| private void quote(StringBuffer sb, String d) {
|
54 |
64
| sb.append('"').append(d).append('"');
|
55 |
| } |
56 |
| |
57 |
56
| private void quoteAndCommify(StringBuffer sb, String d) {
|
58 |
56
| quote(sb, d);
|
59 |
56
| sb.append(',');
|
60 |
| } |
61 |
| } |