View Javadoc
1   package org.codehaus.mojo.javancss;
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 java.util.List;
23  import java.util.Locale;
24  import java.util.ResourceBundle;
25  
26  import org.apache.maven.plugin.logging.Log;
27  import org.apache.maven.doxia.sink.Sink;
28  import org.dom4j.Document;
29  import org.dom4j.Node;
30  
31  /**
32   * Generates the JavaNCSS aggregate report.
33   *
34   * @author <a href="mperham AT gmail.com">Mike Perham</a>
35   * @version $Id$
36   */
37  public class NcssAggregateReportGenerator
38      extends AbstractNcssReportGenerator
39  {
40  
41      /**
42       * @param sink the sink that will be used for reporting.
43       * @param bundle the correct RessourceBundle to be used for reporting.
44       * @param log the logger to output log with.
45       */
46      public NcssAggregateReportGenerator( Sink sink, ResourceBundle bundle, Log log )
47      {
48          super( sink, bundle, log );
49      }
50  
51      /**
52       * Generates the JavaNCSS report.
53       *
54       * @param locale the Locale used for this report.
55       * @param moduleReports the javancss raw reports to aggregate, List of ModuleReport.
56       * @param lineThreshold the maximum number of lines to keep in major reports.
57       */
58      public void doReport( Locale locale, List<ModuleReport> moduleReports, int lineThreshold )
59      {
60          // HEADER
61          getSink().head();
62          getSink().title();
63          getSink().text( getString( "report.javancss.title" ) );
64          getSink().title_();
65          getSink().head_();
66          // BODY
67          getSink().body();
68          doIntro( false );
69          // packages
70          startSection( "report.javancss.module.link", "report.javancss.module.title" );
71          doModuleAnalysis( moduleReports );
72          endSection();
73          getSink().body_();
74          getSink().close();
75      }
76  
77      private void doModuleAnalysis( List<ModuleReport> reports )
78      {
79          getSink().table();
80          getSink().tableRow();
81          headerCellHelper( getString( "report.javancss.header.module" ) );
82          headerCellHelper( getString( "report.javancss.header.packages" ) );
83          headerCellHelper( getString( "report.javancss.header.classetotal" ) );
84          headerCellHelper( getString( "report.javancss.header.functiontotal" ) );
85          headerCellHelper( getString( "report.javancss.header.ncsstotal" ) );
86          headerCellHelper( getString( "report.javancss.header.javadoc" ) );
87          headerCellHelper( getString( "report.javancss.header.javadoc_line" ) );
88          headerCellHelper( getString( "report.javancss.header.single_comment" ) );
89          headerCellHelper( getString( "report.javancss.header.multi_comment" ) );
90          getSink().tableRow_();
91  
92          int packages = 0;
93          int classes = 0;
94          int methods = 0;
95          int ncss = 0;
96          int javadocs = 0;
97          int jdlines = 0;
98          int single = 0;
99          int multi = 0;
100         for ( ModuleReport report : reports )
101         {
102             Document document = report.getJavancssDocument();
103             getSink().tableRow();
104             getLog().debug( "Aggregating " + report.getModule().getArtifactId() );
105             tableCellHelper( report.getModule().getArtifactId() );
106             int packageSize = document.selectNodes( "//javancss/packages/package" ).size();
107             packages += packageSize;
108             tableCellHelper( String.valueOf( packageSize ) );
109 
110             Node node = document.selectSingleNode( "//javancss/packages/total" );
111 
112             String classSize = node.valueOf( "classes" );
113             tableCellHelper( classSize );
114             classes += Integer.parseInt( classSize );
115 
116             String methodSize = node.valueOf( "functions" );
117             tableCellHelper( methodSize );
118             methods += Integer.parseInt( methodSize );
119 
120             String ncssSize = node.valueOf( "ncss" );
121             tableCellHelper( ncssSize );
122             ncss += Integer.parseInt( ncssSize );
123 
124             String javadocSize = node.valueOf( "javadocs" );
125             tableCellHelper( javadocSize );
126             javadocs += Integer.parseInt( javadocSize );
127 
128             String jdlineSize = node.valueOf( "javadoc_lines" );
129             tableCellHelper( jdlineSize );
130             jdlines += Integer.parseInt( jdlineSize );
131 
132             String singleSize = node.valueOf( "single_comment_lines" );
133             tableCellHelper( singleSize );
134             single += Integer.parseInt( singleSize );
135 
136             String multiSize = node.valueOf( "multi_comment_lines" );
137             tableCellHelper( multiSize );
138             multi += Integer.parseInt( multiSize );
139 
140             getSink().tableRow_();
141         }
142 
143         // Totals row
144         getSink().tableRow();
145         tableCellHelper( getString( "report.javancss.header.totals" ) );
146         tableCellHelper( String.valueOf( packages ) );
147         tableCellHelper( String.valueOf( classes ) );
148         tableCellHelper( String.valueOf( methods ) );
149         tableCellHelper( String.valueOf( ncss ) );
150         tableCellHelper( String.valueOf( javadocs ) );
151         tableCellHelper( String.valueOf( jdlines ) );
152         tableCellHelper( String.valueOf( single ) );
153         tableCellHelper( String.valueOf( multi ) );
154         getSink().tableRow_();
155 
156         getSink().table_();
157     }
158 
159 }