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 void executeReport( Locale locale )
48 {
49 DistributionManagementRenderer r =
50 new DistributionManagementRenderer( getSink(), getProject(), getI18N( locale ), locale );
51
52 r.render();
53 }
54
55
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
69
70
71
72
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 }