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