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