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