View Javadoc

1   package org.apache.maven.report.projectinfo;
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 org.apache.maven.doxia.sink.Sink;
23  import org.apache.maven.model.Organization;
24  import org.apache.maven.reporting.AbstractMavenReportRenderer;
25  import org.apache.maven.reporting.MavenReportException;
26  import org.codehaus.plexus.util.StringUtils;
27  
28  import java.util.Locale;
29  
30  /**
31   * Generates the project information reports summary.
32   *
33   * @author Edwin Punzalan
34   * @version $Id: ProjectSummaryReport.java 728546 2008-12-21 22:56:51Z bentmann $
35   * @since 2.0
36   * @goal summary
37   * @plexus.component
38   */
39  public class ProjectSummaryReport
40      extends AbstractProjectInfoReport
41  {
42      // ----------------------------------------------------------------------
43      // Public methods
44      // ----------------------------------------------------------------------
45  
46      /** {@inheritDoc} */
47      protected void executeReport( Locale locale )
48          throws MavenReportException
49      {
50          new ProjectSummaryRenderer( getSink(), locale ).render();
51      }
52  
53      /** {@inheritDoc} */
54      public String getName( Locale locale )
55      {
56          return i18n.getString( "project-info-report", locale, "report.summary.name" );
57      }
58  
59      /** {@inheritDoc} */
60      public String getDescription( Locale locale )
61      {
62          return i18n.getString( "project-info-report", locale, "report.summary.description" );
63      }
64  
65      /** {@inheritDoc} */
66      public String getOutputName()
67      {
68          return "project-summary";
69      }
70  
71      // ----------------------------------------------------------------------
72      // Private
73      // ----------------------------------------------------------------------
74  
75      /**
76       * Internal renderer class
77       */
78      private class ProjectSummaryRenderer
79          extends AbstractMavenReportRenderer
80      {
81          private final Locale locale;
82  
83          ProjectSummaryRenderer( Sink sink, Locale locale )
84          {
85              super( sink );
86  
87              this.locale = locale;
88          }
89  
90          /** {@inheritDoc} */
91          public String getTitle()
92          {
93              return getReportString( "report.summary.title" );
94          }
95  
96          /** {@inheritDoc} */
97          protected void renderBody()
98          {
99              startSection( getTitle() );
100 
101             //general information sub-section
102             String name = project.getName();
103             if ( name == null )
104             {
105                 name = "";
106             }
107             String description = project.getDescription();
108             if ( description == null )
109             {
110                 description = "";
111             }
112             String homepage = project.getUrl();
113             if ( homepage == null )
114             {
115                 homepage = "";
116             }
117 
118             startSection( getReportString( "report.summary.general.title" ) );
119             startTable();
120             tableHeader(
121                 new String[]{getReportString( "report.summary.field" ), getReportString( "report.summary.value" )} );
122             tableRow( new String[]{getReportString( "report.summary.general.name" ), name} );
123             tableRow( new String[]{getReportString( "report.summary.general.description" ), description} );
124             tableRowWithLink( new String[]{getReportString( "report.summary.general.homepage" ), homepage} );
125             endTable();
126             endSection();
127 
128             //organization sub-section
129             startSection( getReportString( "report.summary.organization.title" ) );
130             Organization organization = project.getOrganization();
131             if ( organization == null )
132             {
133                 paragraph( getReportString( "report.summary.noorganization" ) );
134             }
135             else
136             {
137                 if ( organization.getName() == null )
138                 {
139                     organization.setName( "" );
140                 }
141                 if ( organization.getUrl() == null )
142                 {
143                     organization.setUrl( "" );
144                 }
145 
146                 startTable();
147                 tableHeader( new String[]{getReportString( "report.summary.field" ),
148                     getReportString( "report.summary.value" )} );
149                 tableRow( new String[] { getReportString( "report.summary.organization.name" ),
150                     organization.getName() } );
151                 tableRowWithLink(
152                     new String[]{getReportString( "report.summary.organization.url" ), organization.getUrl()} );
153                 endTable();
154             }
155             endSection();
156 
157             //build section
158             startSection( getReportString( "report.summary.build.title" ) );
159             startTable();
160             tableHeader(
161                 new String[]{getReportString( "report.summary.field" ), getReportString( "report.summary.value" )} );
162             tableRow( new String[]{getReportString( "report.summary.build.groupid" ), project.getGroupId()} );
163             tableRow( new String[]{getReportString( "report.summary.build.artifactid" ), project.getArtifactId()} );
164             tableRow( new String[]{getReportString( "report.summary.build.version" ), project.getVersion()} );
165             tableRow( new String[]{getReportString( "report.summary.build.type" ), project.getPackaging()} );
166             endTable();
167             endSection();
168 
169             endSection();
170         }
171 
172         private String getReportString( String key )
173         {
174             return i18n.getString( "project-info-report", locale, key );
175         }
176 
177         private void tableRowWithLink( String[] content )
178         {
179             sink.tableRow();
180 
181             for ( int ctr = 0; ctr < content.length; ctr++ )
182             {
183                 String cell = content[ctr];
184 
185                 sink.tableCell();
186 
187                 if ( StringUtils.isEmpty( cell ) )
188                 {
189                     sink.text( "-" );
190                 }
191                 else
192                 {
193                     if ( ctr == content.length - 1 && cell.length() > 0 )
194                     {
195                         sink.link( cell );
196                         sink.text( cell );
197                         sink.link_();
198                     }
199                     else
200                     {
201                         sink.text( cell );
202                     }
203                 }
204                 sink.tableCell_();
205             }
206 
207             sink.tableRow_();
208         }
209     }
210 }