View Javadoc

1   package org.codehaus.mojo.dashboard.report.plugin.beans;
2   
3   /*
4    * Copyright 2006 David Vicente
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *      http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  import java.util.ArrayList;
20  import java.util.Date;
21  import java.util.Iterator;
22  import java.util.List;
23  
24  /**
25   * <ul>
26   * <li>Add "CheckStyle Violations" graph written by <a href="mailto:srivollet@objectif-informatique.fr">Sylvain
27   * Rivollet</a></li>
28   * </ul>
29   * 
30   * @author <a href="dvicente72@gmail.com">David Vicente</a>
31   * 
32   */
33  public class CheckstyleReportBean extends AbstractReportBean
34  {
35      /**
36       * 
37       */
38      private int nbClasses;
39  
40      /**
41       * 
42       */
43      private int nbInfos;
44  
45      /**
46       * 
47       */
48      private int nbWarnings;
49  
50      /**
51       * 
52       */
53      private int nbErrors;
54  
55      /**
56       * 
57       */
58      private int nbTotal;
59  
60      /**
61       * List:CheckstyleError Fixes MOJO-679. Written by <a href="srivollet@objectif-informatique.fr">Sylvain Rivollet</a>.
62       */
63      private List errors;
64  
65      /**
66       * Default constructor
67       * 
68       */
69      public CheckstyleReportBean()
70      {
71          this.errors = new ArrayList();
72      }
73  
74      /**
75       * 
76       * @param dateGeneration
77       */
78      public CheckstyleReportBean( Date dateGeneration )
79      {
80          super( dateGeneration );
81          this.errors = new ArrayList();
82      }
83  
84      /**
85       * 
86       * @return int
87       */
88      public int getNbClasses()
89      {
90          return nbClasses;
91      }
92  
93      /**
94       * 
95       * @param nbClasses
96       */
97      public void setNbClasses( int nbClasses )
98      {
99          this.nbClasses = nbClasses;
100     }
101 
102     /**
103      * 
104      * @return
105      */
106     public int getNbErrors()
107     {
108         return nbErrors;
109     }
110 
111     /**
112      * 
113      * @param nbErrors
114      */
115     public void setNbErrors( int nbErrors )
116     {
117         this.nbErrors = nbErrors;
118     }
119 
120     /**
121      * 
122      * @return
123      */
124     public int getNbInfos()
125     {
126         return nbInfos;
127     }
128 
129     /**
130      * 
131      * @param nbInfos
132      */
133     public void setNbInfos( int nbInfos )
134     {
135         this.nbInfos = nbInfos;
136     }
137 
138     /**
139      * 
140      * @return
141      */
142     public int getNbTotal()
143     {
144         return nbTotal;
145     }
146 
147     /**
148      * 
149      * @param nbTotal
150      */
151     public void setNbTotal( int nbTotal )
152     {
153         this.nbTotal = nbTotal;
154     }
155 
156     /**
157      * 
158      * @return
159      */
160     public int getNbWarnings()
161     {
162         return nbWarnings;
163     }
164 
165     /**
166      * 
167      * @param nbWarnings
168      */
169     public void setNbWarnings( int nbWarnings )
170     {
171         this.nbWarnings = nbWarnings;
172     }
173 
174     /**
175      * get the checkstyleError list. Fixes MOJO-679 . Written by <a
176      * href="mailto:srivollet@objectif-informatique.fr">Sylvain Rivollet</a>.
177      * 
178      * @return CheckstyleError list
179      */
180     public List getErrors()
181     {
182         return this.errors;
183     }
184 
185     /**
186      * 
187      * Fixes MOJO-679 . Written by <a href="mailto:srivollet@objectif-informatique.fr">Sylvain Rivollet</a>.
188      * 
189      * @param errorsList
190      *            CheckstyleError list
191      */
192     public void setErrors( List errorsList )
193     {
194         this.errors = errorsList;
195     }
196 
197     /**
198      * 
199      * @param error
200      */
201     public void addError( CheckstyleError error )
202     {
203         if ( this.errors.isEmpty() )
204         {
205             this.errors.add( error );
206         }
207         else
208         {
209             if ( ( this.errors.contains( error ) ) )
210             {
211 
212                 int index = this.errors.indexOf( error );
213                 // Fixes MOJO-814. Correction of percentage and rendering bug on "Show Checkstyle categories"
214                 int nbIter = ( (CheckstyleError) this.errors.get( index ) ).getNbIteration();
215                 ( (CheckstyleError) this.errors.get( index ) ).setNbIteration( nbIter + error.getNbIteration() );
216             }
217             else
218             {
219                 this.errors.add( error );
220             }
221         }
222     }
223 
224     /**
225      * Fixes MOJO-679 . Written by <a href="mailto:srivollet@objectif-informatique.fr">Sylvain Rivollet</a>.
226      * 
227      * @param error
228      */
229     public void addAllError( List errorsList )
230     {
231         if ( this.errors.isEmpty() )
232         {
233             Iterator iter = errorsList.iterator();
234             while ( iter.hasNext() )
235             {
236                 CheckstyleError error = (CheckstyleError) iter.next();
237                 this.errors.add( (CheckstyleError) ( error.clone() ) );
238             }
239         }
240         else
241         {
242             Iterator iter = errorsList.iterator();
243             while ( iter.hasNext() )
244             {
245                 CheckstyleError error = (CheckstyleError) iter.next();
246                 this.addError( (CheckstyleError) ( error.clone() ) );
247             }
248         }
249     }
250 
251     /**
252      * Fixes MOJO-679 . Written by <a href="mailto:srivollet@objectif-informatique.fr">Sylvain Rivollet</a>.
253      * 
254      * @param dashboardReport
255      */
256     public void merge( IDashBoardReportBean dashboardReport )
257     {
258         if ( dashboardReport != null && dashboardReport instanceof CheckstyleReportBean )
259         {
260             this.nbClasses = this.nbClasses + ( (CheckstyleReportBean) dashboardReport ).getNbClasses();
261 
262             this.nbInfos = this.nbInfos + ( (CheckstyleReportBean) dashboardReport ).getNbInfos();
263 
264             this.nbWarnings = this.nbWarnings + ( (CheckstyleReportBean) dashboardReport ).getNbWarnings();
265 
266             this.nbErrors = this.nbErrors + ( (CheckstyleReportBean) dashboardReport ).getNbErrors();
267 
268             this.nbTotal = this.nbTotal + ( (CheckstyleReportBean) dashboardReport ).getNbTotal();
269             // error management . Fixes MOJO-679 .
270             // Written by <a href="mailto:srivollet@objectif-informatique.fr">Sylvain Rivollet</a>.
271             this.addAllError( ( (CheckstyleReportBean) dashboardReport ).getErrors() );
272         }
273     }
274 
275     /**
276      * 
277      */
278     protected Object clone()
279     {
280         CheckstyleReportBean clone = new CheckstyleReportBean( this.getDateGeneration() );
281         clone.setNbClasses( this.nbClasses );
282         clone.setNbInfos( this.nbInfos );
283         clone.setNbWarnings( this.nbWarnings );
284         clone.setNbErrors( this.nbErrors );
285         clone.setNbTotal( this.nbTotal );
286         clone.addAllError( this.getErrors() );
287         return clone;
288     }
289 
290     public double getPercentInfos()
291     {
292         return getPercentageValue( this.nbInfos, this.nbTotal );
293     }
294 
295     public double getPercentErrors()
296     {
297         return getPercentageValue( this.nbErrors, this.nbTotal );
298     }
299 
300     public double getPercentWarnings()
301     {
302         return getPercentageValue( this.nbWarnings, this.nbTotal );
303     }
304 
305 }