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