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.Configuration; |
24 | |
import com.puppycrawl.tools.checkstyle.api.SeverityLevel; |
25 | |
|
26 | |
import java.util.HashMap; |
27 | |
import java.util.Iterator; |
28 | |
import java.util.LinkedList; |
29 | |
import java.util.List; |
30 | |
import java.util.Map; |
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
public class CheckstyleResults |
40 | |
{ |
41 | |
private Map files; |
42 | |
|
43 | |
private Configuration configuration; |
44 | |
|
45 | |
public CheckstyleResults() |
46 | 0 | { |
47 | 0 | files = new HashMap(); |
48 | 0 | } |
49 | |
|
50 | |
public List getFileViolations( String file ) |
51 | |
{ |
52 | |
List violations; |
53 | |
|
54 | 0 | if ( this.files.containsKey( file ) ) |
55 | |
{ |
56 | 0 | violations = (List) this.files.get( file ); |
57 | |
} |
58 | |
else |
59 | |
{ |
60 | 0 | violations = new LinkedList(); |
61 | 0 | this.files.put( file, violations ); |
62 | |
} |
63 | |
|
64 | 0 | return violations; |
65 | |
} |
66 | |
|
67 | |
public void setFileViolations( String file, List violations ) |
68 | |
{ |
69 | 0 | this.files.put( file, violations ); |
70 | 0 | } |
71 | |
|
72 | |
public Map getFiles() |
73 | |
{ |
74 | 0 | return files; |
75 | |
} |
76 | |
|
77 | |
public void setFiles( Map files ) |
78 | |
{ |
79 | 0 | this.files = files; |
80 | 0 | } |
81 | |
|
82 | |
public int getFileCount() |
83 | |
{ |
84 | 0 | return this.files.size(); |
85 | |
} |
86 | |
|
87 | |
public long getSeverityCount( SeverityLevel level ) |
88 | |
{ |
89 | 0 | long count = 0; |
90 | |
|
91 | 0 | Iterator it = this.files.values().iterator(); |
92 | |
|
93 | 0 | while ( it.hasNext() ) |
94 | |
{ |
95 | 0 | List errors = (List) it.next(); |
96 | |
|
97 | 0 | count = count + getSeverityCount( errors, level ); |
98 | 0 | } |
99 | |
|
100 | 0 | return count; |
101 | |
} |
102 | |
|
103 | |
public long getSeverityCount( String file, SeverityLevel level ) |
104 | |
{ |
105 | 0 | long count = 0; |
106 | |
|
107 | 0 | if ( !this.files.containsKey( file ) ) |
108 | |
{ |
109 | 0 | return count; |
110 | |
} |
111 | |
|
112 | 0 | List violations = (List) this.files.get( file ); |
113 | |
|
114 | 0 | count = getSeverityCount( violations, level ); |
115 | |
|
116 | 0 | return count; |
117 | |
} |
118 | |
|
119 | |
public long getSeverityCount( List violations, SeverityLevel level ) |
120 | |
{ |
121 | 0 | long count = 0; |
122 | |
|
123 | 0 | Iterator it = violations.iterator(); |
124 | |
|
125 | 0 | while ( it.hasNext() ) |
126 | |
{ |
127 | 0 | AuditEvent event = (AuditEvent) it.next(); |
128 | |
|
129 | 0 | if ( event.getSeverityLevel().equals( level ) ) |
130 | |
{ |
131 | 0 | count++; |
132 | |
} |
133 | 0 | } |
134 | |
|
135 | 0 | return count; |
136 | |
} |
137 | |
|
138 | |
public Configuration getConfiguration() |
139 | |
{ |
140 | 0 | return configuration; |
141 | |
} |
142 | |
|
143 | |
public void setConfiguration( Configuration configuration ) |
144 | |
{ |
145 | 0 | this.configuration = configuration; |
146 | 0 | } |
147 | |
} |