01: /**
02: * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
03: */package net.sourceforge.pmd.renderers;
04:
05: import net.sourceforge.pmd.IRuleViolation;
06: import net.sourceforge.pmd.PMD;
07: import net.sourceforge.pmd.Report;
08:
09: import java.io.IOException;
10: import java.io.Writer;
11: import java.util.Iterator;
12:
13: public class TextRenderer extends OnTheFlyRenderer {
14:
15: private boolean empty;
16:
17: public void start() throws IOException {
18: empty = true;
19: }
20:
21: public void renderFileViolations(Iterator<IRuleViolation> violations)
22: throws IOException {
23: Writer writer = getWriter();
24: StringBuffer buf = new StringBuffer();
25:
26: empty = !violations.hasNext();
27: while (violations.hasNext()) {
28: buf.setLength(0);
29: IRuleViolation rv = violations.next();
30: buf.append(PMD.EOL).append(rv.getFilename());
31: buf.append(':').append(Integer.toString(rv.getBeginLine()));
32: buf.append('\t').append(rv.getDescription());
33: writer.write(buf.toString());
34: }
35: }
36:
37: public void end() throws IOException {
38: Writer writer = getWriter();
39: StringBuffer buf = new StringBuffer();
40: if (!errors.isEmpty()) {
41: empty = false;
42:
43: for (Report.ProcessingError error : errors) {
44: buf.setLength(0);
45: buf.append(PMD.EOL).append(error.getFile());
46: buf.append("\t-\t").append(error.getMsg());
47: writer.write(buf.toString());
48: }
49: }
50:
51: for (Report.SuppressedViolation excluded : suppressed) {
52: buf.setLength(0);
53: buf.append(PMD.EOL);
54: buf.append(excluded.getRuleViolation().getRule().getName());
55: buf.append(" rule violation suppressed by ");
56: buf.append(excluded.suppressedByNOPMD() ? "//NOPMD"
57: : "Annotation");
58: buf.append(" in ").append(
59: excluded.getRuleViolation().getFilename());
60: writer.write(buf.toString());
61: }
62:
63: if (empty) {
64: getWriter().write("No problems found!");
65: }
66: }
67:
68: }
|