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