Coverage Report - org.apache.maven.report.projectinfo.ProjectSummaryReport
 
Classes in this File Line Coverage Branch Coverage Complexity
ProjectSummaryReport
86%
6/7
N/A
2
ProjectSummaryReport$ProjectSummaryRenderer
79%
50/63
45%
9/20
2
 
 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  1
 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  1
         new ProjectSummaryRenderer( getSink(), locale ).render();
 51  1
     }
 52  
 
 53  
     /** {@inheritDoc} */
 54  
     public String getName( Locale locale )
 55  
     {
 56  1
         return i18n.getString( "project-info-report", locale, "report.summary.name" );
 57  
     }
 58  
 
 59  
     /** {@inheritDoc} */
 60  
     public String getDescription( Locale locale )
 61  
     {
 62  0
         return i18n.getString( "project-info-report", locale, "report.summary.description" );
 63  
     }
 64  
 
 65  
     /** {@inheritDoc} */
 66  
     public String getOutputName()
 67  
     {
 68  3
         return "project-summary";
 69  
     }
 70  
 
 71  
     // ----------------------------------------------------------------------
 72  
     // Private
 73  
     // ----------------------------------------------------------------------
 74  
 
 75  
     /**
 76  
      * Internal renderer class
 77  
      */
 78  1
     private class ProjectSummaryRenderer
 79  
         extends AbstractMavenReportRenderer
 80  
     {
 81  
         private final Locale locale;
 82  
 
 83  
         ProjectSummaryRenderer( Sink sink, Locale locale )
 84  1
         {
 85  1
             super( sink );
 86  
 
 87  1
             this.locale = locale;
 88  1
         }
 89  
 
 90  
         /** {@inheritDoc} */
 91  
         public String getTitle()
 92  
         {
 93  2
             return getReportString( "report.summary.title" );
 94  
         }
 95  
 
 96  
         /** {@inheritDoc} */
 97  
         protected void renderBody()
 98  
         {
 99  1
             startSection( getTitle() );
 100  
 
 101  
             //general information sub-section
 102  1
             String name = project.getName();
 103  1
             if ( name == null )
 104  
             {
 105  0
                 name = "";
 106  
             }
 107  1
             String description = project.getDescription();
 108  1
             if ( description == null )
 109  
             {
 110  1
                 description = "";
 111  
             }
 112  1
             String homepage = project.getUrl();
 113  1
             if ( homepage == null )
 114  
             {
 115  1
                 homepage = "";
 116  
             }
 117  
 
 118  1
             startSection( getReportString( "report.summary.general.title" ) );
 119  1
             startTable();
 120  1
             tableHeader(
 121  
                 new String[]{getReportString( "report.summary.field" ), getReportString( "report.summary.value" )} );
 122  1
             tableRow( new String[]{getReportString( "report.summary.general.name" ), name} );
 123  1
             tableRow( new String[]{getReportString( "report.summary.general.description" ), description} );
 124  1
             tableRowWithLink( new String[]{getReportString( "report.summary.general.homepage" ), homepage} );
 125  1
             endTable();
 126  1
             endSection();
 127  
 
 128  
             //organization sub-section
 129  1
             startSection( getReportString( "report.summary.organization.title" ) );
 130  1
             Organization organization = project.getOrganization();
 131  1
             if ( organization == null )
 132  
             {
 133  1
                 paragraph( getReportString( "report.summary.noorganization" ) );
 134  
             }
 135  
             else
 136  
             {
 137  0
                 if ( organization.getName() == null )
 138  
                 {
 139  0
                     organization.setName( "" );
 140  
                 }
 141  0
                 if ( organization.getUrl() == null )
 142  
                 {
 143  0
                     organization.setUrl( "" );
 144  
                 }
 145  
 
 146  0
                 startTable();
 147  0
                 tableHeader( new String[]{getReportString( "report.summary.field" ),
 148  
                     getReportString( "report.summary.value" )} );
 149  0
                 tableRow( new String[] { getReportString( "report.summary.organization.name" ),
 150  
                     organization.getName() } );
 151  0
                 tableRowWithLink(
 152  
                     new String[]{getReportString( "report.summary.organization.url" ), organization.getUrl()} );
 153  0
                 endTable();
 154  
             }
 155  1
             endSection();
 156  
 
 157  
             //build section
 158  1
             startSection( getReportString( "report.summary.build.title" ) );
 159  1
             startTable();
 160  1
             tableHeader(
 161  
                 new String[]{getReportString( "report.summary.field" ), getReportString( "report.summary.value" )} );
 162  1
             tableRow( new String[]{getReportString( "report.summary.build.groupid" ), project.getGroupId()} );
 163  1
             tableRow( new String[]{getReportString( "report.summary.build.artifactid" ), project.getArtifactId()} );
 164  1
             tableRow( new String[]{getReportString( "report.summary.build.version" ), project.getVersion()} );
 165  1
             tableRow( new String[]{getReportString( "report.summary.build.type" ), project.getPackaging()} );
 166  1
             endTable();
 167  1
             endSection();
 168  
 
 169  1
             endSection();
 170  1
         }
 171  
 
 172  
         private String getReportString( String key )
 173  
         {
 174  17
             return i18n.getString( "project-info-report", locale, key );
 175  
         }
 176  
 
 177  
         private void tableRowWithLink( String[] content )
 178  
         {
 179  1
             sink.tableRow();
 180  
 
 181  3
             for ( int ctr = 0; ctr < content.length; ctr++ )
 182  
             {
 183  2
                 String cell = content[ctr];
 184  
 
 185  2
                 sink.tableCell();
 186  
 
 187  2
                 if ( StringUtils.isEmpty( cell ) )
 188  
                 {
 189  1
                     sink.text( "-" );
 190  
                 }
 191  
                 else
 192  
                 {
 193  1
                     if ( ctr == content.length - 1 && cell.length() > 0 )
 194  
                     {
 195  0
                         sink.link( cell );
 196  0
                         sink.text( cell );
 197  0
                         sink.link_();
 198  
                     }
 199  
                     else
 200  
                     {
 201  1
                         sink.text( cell );
 202  
                     }
 203  
                 }
 204  2
                 sink.tableCell_();
 205  
             }
 206  
 
 207  1
             sink.tableRow_();
 208  1
         }
 209  
     }
 210  
 }