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