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 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
33
34
35
36
37
38 @Mojo( name = "distribution-management" )
39 public class DistributionManagementReport
40 extends AbstractProjectInfoReport
41 {
42
43
44
45
46 @Override
47 public boolean canGenerateReport()
48 {
49 boolean result = super.canGenerateReport();
50 if ( result && skipEmptyReport )
51 {
52 result = getProject().getDistributionManagement() != null;
53 }
54
55 return result;
56 }
57
58 @Override
59 public void executeReport( Locale locale )
60 {
61 DistributionManagementRenderer r =
62 new DistributionManagementRenderer( getSink(), getProject(), getI18N( locale ), locale );
63
64 r.render();
65 }
66
67
68 public String getOutputName()
69 {
70 return "distribution-management";
71 }
72
73 @Override
74 protected String getI18Nsection()
75 {
76 return "distributionManagement";
77 }
78
79
80
81
82
83
84
85
86 private static class DistributionManagementRenderer
87 extends AbstractProjectInfoRenderer
88 {
89 private final MavenProject project;
90
91 DistributionManagementRenderer( Sink sink, MavenProject project, I18N i18n, Locale locale )
92 {
93 super( sink, i18n, locale );
94
95 this.project = project;
96 }
97
98 @Override
99 protected String getI18Nsection()
100 {
101 return "distributionManagement";
102 }
103
104 @Override
105 public void renderBody()
106 {
107 DistributionManagement distributionManagement = project.getDistributionManagement();
108 if ( distributionManagement == null )
109 {
110 startSection( getI18nString( "overview.title" ) );
111
112 paragraph( getI18nString( "nodistributionmanagement" ) );
113
114 endSection();
115
116 return;
117 }
118
119 startSection( getI18nString( "overview.title" ) );
120 paragraph( getI18nString( "overview.intro" ) );
121
122 if ( StringUtils.isNotEmpty( distributionManagement.getDownloadUrl() ) )
123 {
124 startSection( getI18nString( "downloadURL" ) );
125 internalLink( distributionManagement.getDownloadUrl() );
126 endSection();
127 }
128
129 if ( distributionManagement.getRelocation() != null )
130 {
131 startSection( getI18nString( "relocation" ) );
132 startTable();
133 tableHeader( new String[] { getI18nString( "field" ), getI18nString( "value" ) } );
134 tableRow( new String[] { getI18nString( "relocation.groupid" ),
135 distributionManagement.getRelocation().getGroupId() } );
136 tableRow( new String[] { getI18nString( "relocation.artifactid" ),
137 distributionManagement.getRelocation().getArtifactId() } );
138 tableRow( new String[] { getI18nString( "relocation.version" ),
139 distributionManagement.getRelocation().getVersion() } );
140 tableRow( new String[] { getI18nString( "relocation.message" ),
141 distributionManagement.getRelocation().getMessage() } );
142 endTable();
143 endSection();
144 }
145
146 if ( distributionManagement.getRepository() != null
147 && StringUtils.isNotEmpty( distributionManagement.getRepository().getUrl() ) )
148 {
149 startSection( getI18nString( "repository" )
150 + getRepoName( distributionManagement.getRepository().getId() ) );
151 internalLink( distributionManagement.getRepository().getUrl() );
152 endSection();
153 }
154
155 if ( distributionManagement.getSnapshotRepository() != null
156 && StringUtils.isNotEmpty( distributionManagement.getSnapshotRepository().getUrl() ) )
157 {
158 startSection( getI18nString( "snapshotRepository" )
159 + getRepoName( distributionManagement.getSnapshotRepository().getId() ) );
160 internalLink( distributionManagement.getSnapshotRepository().getUrl() );
161 endSection();
162 }
163
164 if ( distributionManagement.getSite() != null
165 && StringUtils.isNotEmpty( distributionManagement.getSite().getUrl() ) )
166 {
167 startSection( getI18nString( "site" ) + getRepoName( distributionManagement.getSite().getId() ) );
168 internalLink( distributionManagement.getSite().getUrl() );
169 endSection();
170 }
171
172 endSection();
173 }
174
175 private void internalLink( String url )
176 {
177 if ( StringUtils.isEmpty( url ) )
178 {
179 return;
180 }
181
182 String urlLowerCase = url.trim().toLowerCase( Locale.ENGLISH );
183 if ( urlLowerCase.startsWith( "http" ) || urlLowerCase.startsWith( "https" )
184 || urlLowerCase.startsWith( "ftp" ) )
185 {
186 link( url, url );
187 }
188 else
189 {
190 paragraph( url );
191 }
192 }
193
194 private String getRepoName( String name )
195 {
196 if ( StringUtils.isNotEmpty( name ) )
197 {
198 return " - " + name;
199 }
200
201 return "";
202 }
203 }
204 }