1 package org.apache.maven.plugins.pmd;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.IOException;
23 import java.util.ArrayList;
24 import java.util.Collections;
25 import java.util.HashMap;
26 import java.util.List;
27 import java.util.Map;
28
29 import org.codehaus.plexus.util.StringUtils;
30
31 import net.sourceforge.pmd.Report;
32 import net.sourceforge.pmd.Report.ProcessingError;
33 import net.sourceforge.pmd.Report.SuppressedViolation;
34 import net.sourceforge.pmd.RuleViolation;
35 import net.sourceforge.pmd.renderers.AbstractRenderer;
36 import net.sourceforge.pmd.util.datasource.DataSource;
37
38
39
40
41
42
43
44
45
46 @Deprecated
47 public class PmdCollectingRenderer extends AbstractRenderer
48 {
49 private List<ProcessingError> errors = Collections.synchronizedList( new ArrayList<>() );
50 private List<RuleViolation> violations = Collections.synchronizedList( new ArrayList<>() );
51 private List<SuppressedViolation> suppressed = Collections.synchronizedList( new ArrayList<> () );
52
53
54
55
56 public PmdCollectingRenderer()
57 {
58 super( PmdCollectingRenderer.class.getSimpleName(), "Collects all reports from all threads" );
59 }
60
61 @Override
62 public void renderFileReport( Report report ) throws IOException
63 {
64 violations.addAll( report.getViolations() );
65 errors.addAll( report.getProcessingErrors() );
66 suppressed.addAll( report.getSuppressedViolations() );
67 }
68
69
70
71
72
73 public boolean hasViolations()
74 {
75 return !violations.isEmpty();
76 }
77
78
79
80
81
82 public List<RuleViolation> getViolations()
83 {
84 return violations;
85 }
86
87
88
89
90
91 public boolean hasErrors()
92 {
93 return !errors.isEmpty();
94 }
95
96
97
98
99
100 public List<ProcessingError> getErrors()
101 {
102 return errors;
103 }
104
105
106
107
108
109
110 public String getErrorsAsString( boolean withDetails )
111 {
112 List<String> errorsAsString = new ArrayList<>( errors.size() );
113 for ( ProcessingError error : errors )
114 {
115 errorsAsString.add( error.getFile() + ": " + error.getMsg() );
116 if ( withDetails )
117 {
118 errorsAsString.add( error.getDetail() );
119 }
120 }
121 return StringUtils.join( errorsAsString.toArray(), System.getProperty( "line.separator" ) );
122 }
123
124
125
126
127
128 public Report asReport()
129 {
130 Report report = new Report();
131 for ( RuleViolation v : violations )
132 {
133 report.addRuleViolation( v );
134 }
135 for ( ProcessingError e : errors )
136 {
137 report.addError( e );
138 }
139 Map<Integer, String> suppressedLines = new HashMap<Integer, String>();
140 for ( SuppressedViolation s : suppressed )
141 {
142 if ( s.suppressedByNOPMD() )
143 {
144 suppressedLines.put( s.getRuleViolation().getBeginLine(), s.getUserMessage() );
145 }
146 }
147 report.suppress( suppressedLines );
148 for ( SuppressedViolation s : suppressed )
149 {
150 report.addRuleViolation( s.getRuleViolation() );
151 }
152 return report;
153 }
154
155
156
157 @Override
158 public String defaultFileExtension()
159 {
160 return null;
161 }
162 @Override
163 public void start() throws IOException
164 {
165 }
166 @Override
167 public void startFileAnalysis( DataSource dataSource )
168 {
169 }
170 @Override
171 public void end() throws IOException
172 {
173 }
174 }