1 package org.apache.maven.report.projectinfo;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
32
33
34
35
36
37
38 public class DistributionManagementReport
39 extends AbstractProjectInfoReport
40 {
41
42
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
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
68
69
70
71
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 }