1 | |
package org.kuali.maven.plugin.ksite.mojo; |
2 | |
|
3 | |
import org.apache.commons.lang.StringUtils; |
4 | |
import org.apache.maven.model.DistributionManagement; |
5 | |
import org.apache.maven.model.Site; |
6 | |
import org.apache.maven.plugin.AbstractMojo; |
7 | |
import org.apache.maven.plugin.MojoExecutionException; |
8 | |
import org.apache.maven.plugin.MojoFailureException; |
9 | |
import org.apache.maven.project.MavenProject; |
10 | |
import org.kuali.maven.common.SiteContext; |
11 | |
import org.kuali.maven.common.UrlBuilder; |
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | 0 | public class KualiSiteMojo extends AbstractMojo implements SiteContext { |
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
private String downloadSnapshotPrefix; |
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
private String downloadReleasePrefix; |
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
private String publishUrlProtocol; |
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
private String publicUrlProtocol; |
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
private String downloadPrefix; |
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | |
private String organizationGroupId; |
63 | |
|
64 | |
|
65 | |
|
66 | |
|
67 | |
|
68 | |
|
69 | |
|
70 | |
private String bucket; |
71 | |
|
72 | |
|
73 | |
|
74 | |
|
75 | |
|
76 | |
|
77 | |
|
78 | |
private String hostname; |
79 | |
|
80 | |
|
81 | |
|
82 | |
|
83 | |
|
84 | |
|
85 | |
|
86 | |
|
87 | |
private MavenProject project; |
88 | |
|
89 | |
@Override |
90 | |
public void execute() throws MojoExecutionException, MojoFailureException { |
91 | 0 | UrlBuilder builder = new UrlBuilder(); |
92 | |
|
93 | |
|
94 | 0 | String publicUrl = builder.getPublicUrl(getProject(), this); |
95 | 0 | String publishUrl = builder.getPublishUrl(getProject(), this); |
96 | 0 | String downloadUrl = builder.getDownloadUrl(getProject(), this); |
97 | |
|
98 | |
|
99 | 0 | MavenProject project = getProject(); |
100 | 0 | DistributionManagement dm = project.getDistributionManagement(); |
101 | 0 | Site site = dm.getSite(); |
102 | |
|
103 | |
|
104 | 0 | handlePublicUrl(publicUrl, project); |
105 | 0 | handlePublishUrl(publishUrl, site); |
106 | 0 | handleDownloadUrl(downloadUrl, dm); |
107 | |
|
108 | 0 | } |
109 | |
|
110 | |
|
111 | |
|
112 | |
|
113 | |
protected boolean isReplace(final String s, final String token) { |
114 | 0 | if (StringUtils.isEmpty(s)) { |
115 | 0 | return true; |
116 | |
} |
117 | 0 | int pos = s.indexOf(token); |
118 | 0 | if (pos != -1) { |
119 | 0 | return true; |
120 | |
} |
121 | 0 | return false; |
122 | |
} |
123 | |
|
124 | |
protected void warn(final String pomString, final String calculatedString, final String propertyDescription) { |
125 | 0 | getLog().warn("****************************************"); |
126 | 0 | getLog().warn(propertyDescription + " mismatch"); |
127 | 0 | getLog().warn("Value from the POM: " + pomString); |
128 | 0 | getLog().warn(" Calculated value: " + calculatedString); |
129 | 0 | getLog().warn("****************************************"); |
130 | 0 | } |
131 | |
|
132 | |
|
133 | |
|
134 | |
|
135 | |
protected boolean isUrlMatch(final String url1, final String url2) { |
136 | 0 | if (url1.equals(url2)) { |
137 | 0 | return true; |
138 | |
} |
139 | 0 | if ((url1 + "/").equals(url2)) { |
140 | 0 | return true; |
141 | |
} |
142 | 0 | if (url1.equals(url2 + "/")) { |
143 | 0 | return true; |
144 | |
} |
145 | 0 | return false; |
146 | |
} |
147 | |
|
148 | |
protected void handleDownloadUrl(final String downloadUrl, final DistributionManagement dm) { |
149 | 0 | if (isReplace(dm.getDownloadUrl(), "${kuali.site.download.url}")) { |
150 | 0 | getLog().info("Setting download url to " + downloadUrl + " (was " + dm.getDownloadUrl() + ")"); |
151 | 0 | dm.setDownloadUrl(downloadUrl); |
152 | 0 | return; |
153 | |
} |
154 | 0 | if (!isUrlMatch(downloadUrl, dm.getDownloadUrl())) { |
155 | 0 | warn(dm.getDownloadUrl(), downloadUrl, "Download url"); |
156 | |
} |
157 | 0 | getLog().info("Using download url from the POM " + dm.getDownloadUrl()); |
158 | 0 | } |
159 | |
|
160 | |
protected void handlePublishUrl(final String publishUrl, final Site site) { |
161 | 0 | if (isReplace(site.getUrl(), "${kuali.site.publish.url}")) { |
162 | 0 | getLog().info("Setting site publication url to " + publishUrl + " (was " + site.getUrl() + ")"); |
163 | 0 | site.setUrl(publishUrl); |
164 | 0 | return; |
165 | |
} |
166 | 0 | if (!isUrlMatch(publishUrl, site.getUrl())) { |
167 | 0 | warn(site.getUrl(), publishUrl, "Site publication url"); |
168 | |
} |
169 | 0 | getLog().info("Using site publication url from the POM " + site.getUrl()); |
170 | 0 | } |
171 | |
|
172 | |
protected void handlePublicUrl(final String publicUrl, final MavenProject project) { |
173 | 0 | if (isReplace(project.getUrl(), "${kuali.site.public.url}")) { |
174 | 0 | getLog().info("Setting public url to " + publicUrl + " (was " + project.getUrl() + ")"); |
175 | 0 | project.setUrl(publicUrl); |
176 | 0 | return; |
177 | |
} |
178 | 0 | if (!isUrlMatch(publicUrl, project.getUrl())) { |
179 | 0 | warn(project.getUrl(), publicUrl, "Public url"); |
180 | |
} |
181 | 0 | getLog().info("Using public url from the POM " + project.getUrl()); |
182 | 0 | } |
183 | |
|
184 | |
|
185 | |
|
186 | |
|
187 | |
public MavenProject getProject() { |
188 | 0 | return project; |
189 | |
} |
190 | |
|
191 | |
|
192 | |
|
193 | |
|
194 | |
|
195 | |
public void setProject(final MavenProject project) { |
196 | 0 | this.project = project; |
197 | 0 | } |
198 | |
|
199 | |
|
200 | |
|
201 | |
|
202 | |
@Override |
203 | |
public String getBucket() { |
204 | 0 | return bucket; |
205 | |
} |
206 | |
|
207 | |
|
208 | |
|
209 | |
|
210 | |
|
211 | |
public void setBucket(final String bucket) { |
212 | 0 | this.bucket = bucket; |
213 | 0 | } |
214 | |
|
215 | |
|
216 | |
|
217 | |
|
218 | |
@Override |
219 | |
public String getHostname() { |
220 | 0 | return hostname; |
221 | |
} |
222 | |
|
223 | |
|
224 | |
|
225 | |
|
226 | |
|
227 | |
public void setHostname(final String hostname) { |
228 | 0 | this.hostname = hostname; |
229 | 0 | } |
230 | |
|
231 | |
|
232 | |
|
233 | |
|
234 | |
@Override |
235 | |
public String getDownloadPrefix() { |
236 | 0 | return downloadPrefix; |
237 | |
} |
238 | |
|
239 | |
|
240 | |
|
241 | |
|
242 | |
|
243 | |
public void setDownloadPrefix(final String downloadPrefix) { |
244 | 0 | this.downloadPrefix = downloadPrefix; |
245 | 0 | } |
246 | |
|
247 | |
|
248 | |
|
249 | |
|
250 | |
@Override |
251 | |
public String getOrganizationGroupId() { |
252 | 0 | return organizationGroupId; |
253 | |
} |
254 | |
|
255 | |
|
256 | |
|
257 | |
|
258 | |
|
259 | |
public void setOrganizationGroupId(final String parentGroupId) { |
260 | 0 | this.organizationGroupId = parentGroupId; |
261 | 0 | } |
262 | |
|
263 | |
|
264 | |
|
265 | |
|
266 | |
@Override |
267 | |
public String getPublishUrlProtocol() { |
268 | 0 | return publishUrlProtocol; |
269 | |
} |
270 | |
|
271 | |
|
272 | |
|
273 | |
|
274 | |
|
275 | |
public void setPublishUrlProtocol(final String publishUrlProtocol) { |
276 | 0 | this.publishUrlProtocol = publishUrlProtocol; |
277 | 0 | } |
278 | |
|
279 | |
|
280 | |
|
281 | |
|
282 | |
@Override |
283 | |
public String getPublicUrlProtocol() { |
284 | 0 | return publicUrlProtocol; |
285 | |
} |
286 | |
|
287 | |
|
288 | |
|
289 | |
|
290 | |
|
291 | |
public void setPublicUrlProtocol(final String publicUrlProtocol) { |
292 | 0 | this.publicUrlProtocol = publicUrlProtocol; |
293 | 0 | } |
294 | |
|
295 | |
|
296 | |
|
297 | |
|
298 | |
@Override |
299 | |
public String getDownloadSnapshotPrefix() { |
300 | 0 | return downloadSnapshotPrefix; |
301 | |
} |
302 | |
|
303 | |
|
304 | |
|
305 | |
|
306 | |
|
307 | |
public void setDownloadSnapshotPrefix(final String downloadSnapshotPrefix) { |
308 | 0 | this.downloadSnapshotPrefix = downloadSnapshotPrefix; |
309 | 0 | } |
310 | |
|
311 | |
|
312 | |
|
313 | |
|
314 | |
@Override |
315 | |
public String getDownloadReleasePrefix() { |
316 | 0 | return downloadReleasePrefix; |
317 | |
} |
318 | |
|
319 | |
|
320 | |
|
321 | |
|
322 | |
|
323 | |
public void setDownloadReleasePrefix(final String downloadReleasePrefix) { |
324 | 0 | this.downloadReleasePrefix = downloadReleasePrefix; |
325 | 0 | } |
326 | |
|
327 | |
} |