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 java.util.Locale;
23  
24  import org.apache.maven.doxia.sink.Sink;
25  import org.apache.maven.model.DistributionManagement;
26  import org.apache.maven.project.MavenProject;
27  import org.codehaus.plexus.i18n.I18N;
28  import org.codehaus.plexus.util.StringUtils;
29  
30  /**
31   * Generates the Project Distribution Management report.
32   *
33   * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton </a>
34   * @version $Id: DistributionManagementReport.java 1036268 2010-11-17 22:49:50Z vsiveton $
35   * @since 2.3
36   * @goal distribution-management
37   */
38  public class DistributionManagementReport
39      extends AbstractProjectInfoReport
40  {
41      // ----------------------------------------------------------------------
42      // Public methods
43      // ----------------------------------------------------------------------
44  
45      @Override
46      public void executeReport( Locale locale )
47      {
48          DistributionManagementRenderer r =
49              new DistributionManagementRenderer( getSink(), getProject(), getI18N( locale ), locale );
50  
51          r.render();
52      }
53  
54      /** {@inheritDoc} */
55      public String getOutputName()
56      {
57          return "distribution-management";
58      }
59  
60      @Override
61      protected String getI18Nsection()
62      {
63          return "distributionManagement";
64      }
65  
66      // ----------------------------------------------------------------------
67      // Private
68      // ----------------------------------------------------------------------
69  
70      /**
71       * Internal renderer class
72       */
73      private static class DistributionManagementRenderer
74          extends AbstractProjectInfoRenderer
75      {
76          private final MavenProject project;
77  
78          DistributionManagementRenderer( Sink sink, MavenProject project, I18N i18n, Locale locale )
79          {
80              super( sink, i18n, locale );
81  
82              this.project = project;
83          }
84  
85          @Override
86          protected String getI18Nsection()
87          {
88              return "distributionManagement";
89          }
90  
91          @Override
92          public void renderBody()
93          {
94              DistributionManagement distributionManagement = project.getDistributionManagement();
95              if ( distributionManagement == null )
96              {
97                  startSection( getI18nString( "overview.title" ) );
98  
99                  paragraph( getI18nString( "nodistributionmanagement" ) );
100 
101                 endSection();
102 
103                 return;
104             }
105 
106             startSection( getI18nString( "overview.title" ) );
107             paragraph( getI18nString( "overview.intro" ) );
108 
109             if ( StringUtils.isNotEmpty( distributionManagement.getDownloadUrl() ) )
110             {
111                 startSection( getI18nString( "downloadURL" ) );
112                 internalLink( distributionManagement.getDownloadUrl() );
113                 endSection();
114             }
115 
116             if ( distributionManagement.getRelocation() != null )
117             {
118                 startSection( getI18nString( "relocation" ) );
119                 startTable();
120                 tableHeader( new String[] { getI18nString( "field" ), getI18nString( "value" ) } );
121                 tableRow( new String[] { getI18nString( "relocation.groupid" ),
122                     distributionManagement.getRelocation().getGroupId() } );
123                 tableRow( new String[] { getI18nString( "relocation.artifactid" ),
124                     distributionManagement.getRelocation().getArtifactId() } );
125                 tableRow( new String[] { getI18nString( "relocation.version" ),
126                     distributionManagement.getRelocation().getVersion() } );
127                 tableRow( new String[] { getI18nString( "relocation.message" ),
128                     distributionManagement.getRelocation().getMessage() } );
129                 endTable();
130                 endSection();
131             }
132 
133             if ( distributionManagement.getRepository() != null
134                 && StringUtils.isNotEmpty( distributionManagement.getRepository().getUrl() ) )
135             {
136                 startSection( getI18nString( "repository" )
137                     + getRepoName( distributionManagement.getRepository().getId() ) );
138                 internalLink( distributionManagement.getRepository().getUrl() );
139                 endSection();
140             }
141 
142             if ( distributionManagement.getSnapshotRepository() != null
143                 && StringUtils.isNotEmpty( distributionManagement.getSnapshotRepository().getUrl() ) )
144             {
145                 startSection( getI18nString( "snapshotRepository" )
146                     + getRepoName( distributionManagement.getSnapshotRepository().getId() ) );
147                 internalLink( distributionManagement.getSnapshotRepository().getUrl() );
148                 endSection();
149             }
150 
151             if ( distributionManagement.getSite() != null
152                 && StringUtils.isNotEmpty( distributionManagement.getSite().getUrl() ) )
153             {
154                 startSection( getI18nString( "site" ) + getRepoName( distributionManagement.getSite().getId() ) );
155                 internalLink( distributionManagement.getSite().getUrl() );
156                 endSection();
157             }
158 
159             endSection();
160         }
161 
162         private void internalLink( String url )
163         {
164             if ( StringUtils.isEmpty( url ) )
165             {
166                 return;
167             }
168 
169             String urlLowerCase = url.trim().toLowerCase( Locale.ENGLISH );
170             if ( urlLowerCase.startsWith( "http" ) || urlLowerCase.startsWith( "https" )
171                 || urlLowerCase.startsWith( "ftp" ) )
172             {
173                 link( url, url );
174             }
175             else
176             {
177                 paragraph( url );
178             }
179         }
180 
181         private String getRepoName( String name )
182         {
183             if ( StringUtils.isNotEmpty( name ) )
184             {
185                 return " - " + name;
186             }
187 
188             return "";
189         }
190     }
191 }