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