Coverage Report - org.apache.maven.plugin.checkstyle.CheckstyleResults
 
Classes in this File Line Coverage Branch Coverage Complexity
CheckstyleResults
0%
0/38
0%
0/10
1.545
 
 1  
 package org.apache.maven.plugin.checkstyle;
 2  
 
 3  
 /*
 4  
  * Licensed to the Apache Software Foundation (ASF) under one
 5  
  * or more contributor license agreements.  See the NOTICE file
 6  
  * distributed with this work for additional information
 7  
  * regarding copyright ownership.  The ASF licenses this file
 8  
  * to you under the Apache License, Version 2.0 (the
 9  
  * "License"); you may not use this file except in compliance
 10  
  * with the License.  You may obtain a copy of the License at
 11  
  *
 12  
  *   http://www.apache.org/licenses/LICENSE-2.0
 13  
  *
 14  
  * Unless required by applicable law or agreed to in writing,
 15  
  * software distributed under the License is distributed on an
 16  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 17  
  * KIND, either express or implied.  See the License for the
 18  
  * specific language governing permissions and limitations
 19  
  * under the License.
 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.Iterator;
 28  
 import java.util.LinkedList;
 29  
 import java.util.List;
 30  
 import java.util.Map;
 31  
 
 32  
 /**
 33  
  * Object holding the references to the CheckstyleResults.
 34  
  *
 35  
  * @author <a href="mailto:joakim@erdfelt.net">Joakim Erdfelt</a>
 36  
  * @version $Id: org.apache.maven.plugin.checkstyle.CheckstyleResults.html 816658 2012-05-08 13:56:19Z hboutemy $
 37  
  * @todo provide fallback to disk based storage if too many results.
 38  
  */
 39  
 public class CheckstyleResults
 40  
 {
 41  
     private Map files;
 42  
     
 43  
     private Configuration configuration;
 44  
 
 45  
     public CheckstyleResults()
 46  0
     {
 47  0
         files = new HashMap();
 48  0
     }
 49  
 
 50  
     public List getFileViolations( String file )
 51  
     {
 52  
         List violations;
 53  
 
 54  0
         if ( this.files.containsKey( file ) )
 55  
         {
 56  0
             violations = (List) this.files.get( file );
 57  
         }
 58  
         else
 59  
         {
 60  0
             violations = new LinkedList();
 61  0
             this.files.put( file, violations );
 62  
         }
 63  
 
 64  0
         return violations;
 65  
     }
 66  
 
 67  
     public void setFileViolations( String file, List violations )
 68  
     {
 69  0
         this.files.put( file, violations );
 70  0
     }
 71  
 
 72  
     public Map getFiles()
 73  
     {
 74  0
         return files;
 75  
     }
 76  
 
 77  
     public void setFiles( Map files )
 78  
     {
 79  0
         this.files = files;
 80  0
     }
 81  
 
 82  
     public int getFileCount()
 83  
     {
 84  0
         return this.files.size();
 85  
     }
 86  
 
 87  
     public long getSeverityCount( SeverityLevel level )
 88  
     {
 89  0
         long count = 0;
 90  
 
 91  0
         Iterator it = this.files.values().iterator();
 92  
 
 93  0
         while ( it.hasNext() )
 94  
         {
 95  0
             List errors = (List) it.next();
 96  
 
 97  0
             count = count + getSeverityCount( errors, level );
 98  0
         }
 99  
 
 100  0
         return count;
 101  
     }
 102  
 
 103  
     public long getSeverityCount( String file, SeverityLevel level )
 104  
     {
 105  0
         long count = 0;
 106  
 
 107  0
         if ( !this.files.containsKey( file ) )
 108  
         {
 109  0
             return count;
 110  
         }
 111  
 
 112  0
         List violations = (List) this.files.get( file );
 113  
 
 114  0
         count = getSeverityCount( violations, level );
 115  
 
 116  0
         return count;
 117  
     }
 118  
 
 119  
     public long getSeverityCount( List violations, SeverityLevel level )
 120  
     {
 121  0
         long count = 0;
 122  
 
 123  0
         Iterator it = violations.iterator();
 124  
 
 125  0
         while ( it.hasNext() )
 126  
         {
 127  0
             AuditEvent event = (AuditEvent) it.next();
 128  
 
 129  0
             if ( event.getSeverityLevel().equals( level ) )
 130  
             {
 131  0
                 count++;
 132  
             }
 133  0
         }
 134  
 
 135  0
         return count;
 136  
     }
 137  
 
 138  
     public Configuration getConfiguration()
 139  
     {
 140  0
         return configuration;
 141  
     }
 142  
 
 143  
     public void setConfiguration( Configuration configuration )
 144  
     {
 145  0
         this.configuration = configuration;
 146  0
     }
 147  
 }