1 | |
package org.apache.maven.plugin.checkstyle; |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
import com.puppycrawl.tools.checkstyle.api.AuditEvent; |
23 | |
import com.puppycrawl.tools.checkstyle.api.AuditListener; |
24 | |
import com.puppycrawl.tools.checkstyle.api.AutomaticBean; |
25 | |
import com.puppycrawl.tools.checkstyle.api.SeverityLevel; |
26 | |
import org.codehaus.plexus.util.StringUtils; |
27 | |
|
28 | |
import java.io.File; |
29 | |
import java.util.ArrayList; |
30 | |
import java.util.Iterator; |
31 | |
import java.util.List; |
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
public class CheckstyleReportListener |
41 | |
extends AutomaticBean |
42 | |
implements AuditListener |
43 | |
{ |
44 | |
private List sourceDirectories; |
45 | |
|
46 | |
private CheckstyleResults results; |
47 | |
|
48 | |
private String currentFile; |
49 | |
|
50 | |
private List events; |
51 | |
|
52 | |
private SeverityLevel severityLevel; |
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
public CheckstyleReportListener( File sourceDirectory ) |
58 | 24 | { |
59 | 24 | this.sourceDirectories = new ArrayList(); |
60 | 24 | this.sourceDirectories.add( sourceDirectory ); |
61 | 24 | } |
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
public void addSourceDirectory( File sourceDirectory ) |
67 | |
{ |
68 | 0 | this.sourceDirectories.add( sourceDirectory ); |
69 | 0 | } |
70 | |
|
71 | |
|
72 | |
|
73 | |
|
74 | |
public void setSeverityLevelFilter( SeverityLevel severityLevel ) |
75 | |
{ |
76 | 8 | this.severityLevel = severityLevel; |
77 | 8 | } |
78 | |
|
79 | |
|
80 | |
|
81 | |
|
82 | |
public SeverityLevel getSeverityLevelFilter() |
83 | |
{ |
84 | 8 | return severityLevel; |
85 | |
} |
86 | |
|
87 | |
|
88 | |
|
89 | |
|
90 | |
public void auditStarted( AuditEvent event ) |
91 | |
{ |
92 | 24 | setResults( new CheckstyleResults() ); |
93 | 24 | } |
94 | |
|
95 | |
|
96 | |
|
97 | |
|
98 | |
public void auditFinished( AuditEvent event ) |
99 | |
{ |
100 | |
|
101 | 24 | } |
102 | |
|
103 | |
|
104 | |
|
105 | |
|
106 | |
public void fileStarted( AuditEvent event ) |
107 | |
{ |
108 | 76 | for ( Iterator it = sourceDirectories.iterator(); it.hasNext(); ) |
109 | |
{ |
110 | 76 | File sourceDirectory = (File) it.next(); |
111 | |
|
112 | 76 | currentFile = StringUtils.substring( event.getFileName(), sourceDirectory.getPath().length() + 1 ); |
113 | 76 | currentFile = StringUtils.replace( currentFile, "\\", "/" ); |
114 | |
|
115 | 76 | events = getResults().getFileViolations( currentFile ); |
116 | |
} |
117 | |
|
118 | 76 | if ( events == null ) |
119 | |
{ |
120 | 0 | events = new ArrayList(); |
121 | |
} |
122 | 76 | } |
123 | |
|
124 | |
|
125 | |
|
126 | |
|
127 | |
public void fileFinished( AuditEvent event ) |
128 | |
{ |
129 | 76 | getResults().setFileViolations( currentFile, events ); |
130 | 76 | currentFile = null; |
131 | 76 | } |
132 | |
|
133 | |
|
134 | |
|
135 | |
|
136 | |
public void addError( AuditEvent event ) |
137 | |
{ |
138 | 164 | if ( SeverityLevel.IGNORE.equals( event.getSeverityLevel() ) ) |
139 | |
{ |
140 | 32 | return; |
141 | |
} |
142 | |
|
143 | 132 | if ( severityLevel == null || severityLevel.equals( event.getSeverityLevel() ) ) |
144 | |
{ |
145 | 96 | events.add( event ); |
146 | |
} |
147 | 132 | } |
148 | |
|
149 | |
|
150 | |
|
151 | |
|
152 | |
public void addException( AuditEvent event, Throwable throwable ) |
153 | |
{ |
154 | |
|
155 | 0 | } |
156 | |
|
157 | |
|
158 | |
|
159 | |
|
160 | |
public CheckstyleResults getResults() |
161 | |
{ |
162 | 174 | return results; |
163 | |
} |
164 | |
|
165 | |
|
166 | |
|
167 | |
|
168 | |
public void setResults( CheckstyleResults results ) |
169 | |
{ |
170 | 24 | this.results = results; |
171 | 24 | } |
172 | |
} |
173 | |
|