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