View Javadoc

1   package org.apache.maven.plugin.dependency;
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.Iterator;
23  import java.util.ResourceBundle;
24  
25  import org.apache.maven.artifact.Artifact;
26  import org.apache.maven.doxia.sink.Sink;
27  import org.apache.maven.shared.dependency.analyzer.ProjectDependencyAnalysis;
28  
29  /**
30   * This is the view part of the analyze-report mojo. It generates the HTML report for the project website. The HTML
31   * output is same as the CLI output.
32   */
33  public class AnalyzeReportView
34  {
35      /**
36       * Generates the HTML report.
37       */
38      public void generateReport( ProjectDependencyAnalysis analysis, Sink sink, ResourceBundle bundle )
39      {
40          sink.head();
41          sink.title();
42          sink.text( bundle.getString( "analyze.report.header" ) );
43          sink.title_();
44          sink.head_();
45          sink.body();
46  
47          // Generate title
48          sink.section1();
49          sink.sectionTitle1();
50          sink.text( bundle.getString( "analyze.report.mainTitle" ) );
51          sink.sectionTitle1_();
52  
53          // Generate Used Declared dependencies:
54          sink.section2();
55          sink.sectionTitle2();
56          sink.text( bundle.getString( "analyze.report.UsedDeclaredDependencies" ) );
57          sink.sectionTitle2_();
58          if ( analysis.getUsedDeclaredArtifacts().isEmpty() )
59          {
60              sink.paragraph();
61              sink.text( bundle.getString( "analyze.report.noDependency" ) );
62              sink.paragraph_();
63              sink.horizontalRule();
64          }
65          else
66          {
67              Iterator<Artifact> iter = analysis.getUsedDeclaredArtifacts().iterator();
68              generateDependenciesTable( sink, iter );
69          }
70          sink.section2_();
71  
72          // Generate Used Undeclared dependencies:
73          sink.section2();
74          sink.sectionTitle2();
75          sink.text( bundle.getString( "analyze.report.UsedUndeclaredDependencies" ) );
76          sink.sectionTitle2_();
77          if ( analysis.getUsedUndeclaredArtifacts().isEmpty() )
78          {
79              sink.paragraph();
80              sink.text( bundle.getString( "analyze.report.noDependency" ) );
81              sink.paragraph_();
82              sink.horizontalRule();
83          }
84          else
85          {
86              Iterator<Artifact> iter = analysis.getUsedUndeclaredArtifacts().iterator();
87              generateDependenciesTable( sink, iter );
88          }
89          sink.section2_();
90  
91          // Generate Unused declared dependencies:
92          sink.section2();
93          sink.sectionTitle2();
94          sink.text( bundle.getString( "analyze.report.UnusedDeclaredDependencies" ) );
95          sink.sectionTitle2_();
96          if ( analysis.getUnusedDeclaredArtifacts().isEmpty() )
97          {
98              sink.paragraph();
99              sink.text( bundle.getString( "analyze.report.noDependency" ) );
100             sink.paragraph_();
101             sink.horizontalRule();
102         }
103         else
104         {
105             Iterator<Artifact> iter = analysis.getUnusedDeclaredArtifacts().iterator();
106             generateDependenciesTable( sink, iter );
107         }
108         sink.section2_();
109 
110         sink.section1_();
111 
112         // Closing the report
113         sink.body_();
114         sink.flush();
115         sink.close();
116     }
117 
118     /**
119      * Generate a table for the given dependencies iterator.
120      */
121     public void generateDependenciesTable( Sink sink, Iterator<Artifact> iter )
122     {
123         sink.table();
124 
125         sink.tableRow();
126         sink.tableCell();
127         sink.bold();
128         sink.text( "GroupId" );
129         sink.bold_();
130         sink.tableCell_();
131 
132         sink.tableCell();
133         sink.bold();
134         sink.text( "ArtifactId" );
135         sink.bold_();
136         sink.tableCell_();
137 
138         sink.tableCell();
139         sink.bold();
140         sink.text( "Version" );
141         sink.bold_();
142         sink.tableCell_();
143 
144         sink.tableCell();
145         sink.bold();
146         sink.text( "Scope" );
147         sink.bold_();
148         sink.tableCell_();
149 
150         sink.tableCell();
151         sink.bold();
152         sink.text( "Classifier" );
153         sink.bold_();
154         sink.tableCell_();
155 
156         sink.tableCell();
157         sink.bold();
158         sink.text( "Type" );
159         sink.bold_();
160         sink.tableCell_();
161 
162         sink.tableCell();
163         sink.bold();
164         sink.text( "Optional" );
165         sink.bold_();
166         sink.tableCell_();
167 
168         sink.tableRow_();
169         while ( iter.hasNext() )
170         {
171             Artifact artifact = iter.next();
172 
173             sink.tableRow();
174             sink.tableCell();
175             sink.text( artifact.getGroupId() );
176             sink.tableCell_();
177             sink.tableCell();
178             sink.text( artifact.getArtifactId() );
179             sink.tableCell_();
180             sink.tableCell();
181             sink.text( artifact.getVersion() );
182             sink.tableCell_();
183             sink.tableCell();
184             sink.text( artifact.getScope() );
185             sink.tableCell_();
186             sink.tableCell();
187             sink.text( artifact.getClassifier() );
188             sink.tableCell_();
189             sink.tableCell();
190             sink.text( artifact.getType() );
191             sink.tableCell_();
192             sink.tableCell();
193             if ( artifact.isOptional() )
194             {
195                 sink.text( "" );
196             }
197             else
198             {
199                 sink.text( "false" );
200             }
201 
202             sink.tableCell_();
203             sink.tableRow_();
204         }
205 
206         sink.table_();
207         sink.horizontalRule();
208     }
209 }