1   
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  package org.apache.maven.plugins.checkstyle.exec;
20  
21  import java.util.HashMap;
22  import java.util.LinkedList;
23  import java.util.List;
24  import java.util.Map;
25  
26  import com.puppycrawl.tools.checkstyle.api.AuditEvent;
27  import com.puppycrawl.tools.checkstyle.api.Configuration;
28  import com.puppycrawl.tools.checkstyle.api.SeverityLevel;
29  
30  
31  
32  
33  
34  
35  
36  
37  public class CheckstyleResults {
38      private Map<String, List<AuditEvent>> files;
39  
40      private Configuration configuration;
41  
42      public CheckstyleResults() {
43          files = new HashMap<>();
44      }
45  
46      public List<AuditEvent> getFileViolations(String file) {
47          List<AuditEvent> violations;
48  
49          if (this.files.containsKey(file)) {
50              violations = this.files.get(file);
51          } else {
52              violations = new LinkedList<>();
53              if (file != null) {
54                  this.files.put(file, violations);
55              }
56          }
57  
58          return violations;
59      }
60  
61      public void setFileViolations(String file, List<AuditEvent> violations) {
62          if (file != null) {
63              this.files.put(file, violations);
64          }
65      }
66  
67      public Map<String, List<AuditEvent>> getFiles() {
68          return files;
69      }
70  
71      public void setFiles(Map<String, List<AuditEvent>> files) {
72          this.files = files;
73      }
74  
75      public int getFileCount() {
76          return this.files.size();
77      }
78  
79      public long getSeverityCount(SeverityLevel level) {
80          long count = 0;
81  
82          for (List<AuditEvent> errors : this.files.values()) {
83              count = count + getSeverityCount(errors, level);
84          }
85  
86          return count;
87      }
88  
89      public long getSeverityCount(String file, SeverityLevel level) {
90          long count = 0;
91  
92          if (!this.files.containsKey(file)) {
93              return count;
94          }
95  
96          List<AuditEvent> violations = this.files.get(file);
97  
98          count = getSeverityCount(violations, level);
99  
100         return count;
101     }
102 
103     public long getSeverityCount(List<AuditEvent> violations, SeverityLevel level) {
104         long count = 0;
105 
106         for (AuditEvent event : violations) {
107             if (event.getSeverityLevel().equals(level)) {
108                 count++;
109             }
110         }
111 
112         return count;
113     }
114 
115     public Configuration getConfiguration() {
116         return configuration;
117     }
118 
119     public void setConfiguration(Configuration configuration) {
120         this.configuration = configuration;
121     }
122 }