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