1 | |
package org.apache.maven.plugin.changes; |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
import java.util.HashMap; |
23 | |
import java.util.Iterator; |
24 | |
import java.util.LinkedHashMap; |
25 | |
import java.util.List; |
26 | |
import java.util.Map; |
27 | |
import java.util.ResourceBundle; |
28 | |
|
29 | |
import org.apache.commons.lang.StringUtils; |
30 | |
import org.apache.maven.doxia.sink.Sink; |
31 | |
import org.apache.maven.doxia.util.HtmlTools; |
32 | |
import org.apache.maven.plugin.issues.AbstractIssuesReportGenerator; |
33 | |
import org.apache.maven.plugins.changes.model.Action; |
34 | |
import org.apache.maven.plugins.changes.model.DueTo; |
35 | |
import org.apache.maven.plugins.changes.model.FixedIssue; |
36 | |
import org.apache.maven.plugins.changes.model.Release; |
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
public class ChangesReportGenerator extends AbstractIssuesReportGenerator |
44 | |
{ |
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
private static final String URL_TOKEN = "%URL%"; |
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
private static final String ISSUE_TOKEN = "%ISSUE%"; |
55 | |
|
56 | |
static final String DEFAULT_ISSUE_SYSTEM_KEY = "default"; |
57 | |
|
58 | |
private static final String NO_TEAMLIST = "none"; |
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
private String system; |
67 | |
|
68 | |
private String teamlist; |
69 | |
|
70 | |
private String url; |
71 | |
|
72 | |
private Map issueLinksPerSystem; |
73 | |
|
74 | |
private boolean addActionDate; |
75 | |
|
76 | |
|
77 | |
|
78 | |
|
79 | |
private boolean escapeHTML; |
80 | |
|
81 | |
|
82 | |
|
83 | |
|
84 | |
private List releaseList; |
85 | |
|
86 | |
public ChangesReportGenerator() |
87 | 0 | { |
88 | 0 | issueLinksPerSystem = new HashMap(); |
89 | 0 | } |
90 | |
|
91 | |
public ChangesReportGenerator( List releaseList ) |
92 | |
{ |
93 | 0 | this(); |
94 | 0 | this.releaseList = releaseList; |
95 | 0 | } |
96 | |
|
97 | |
|
98 | |
|
99 | |
|
100 | |
public boolean isEscapeHTML() |
101 | |
{ |
102 | 0 | return escapeHTML; |
103 | |
} |
104 | |
|
105 | |
|
106 | |
|
107 | |
|
108 | |
public void setEscapeHTML( boolean escapeHTML ) |
109 | |
{ |
110 | 0 | this.escapeHTML = escapeHTML; |
111 | 0 | } |
112 | |
|
113 | |
|
114 | |
|
115 | |
|
116 | |
public String getSystem() |
117 | |
{ |
118 | 0 | return system; |
119 | |
} |
120 | |
|
121 | |
|
122 | |
|
123 | |
|
124 | |
public void setSystem( String system ) |
125 | |
{ |
126 | 0 | this.system = system; |
127 | 0 | } |
128 | |
|
129 | |
public void setTeamlist( final String teamlist ) |
130 | |
{ |
131 | 0 | this.teamlist = teamlist; |
132 | 0 | } |
133 | |
|
134 | |
public String getTeamlist() |
135 | |
{ |
136 | 0 | return teamlist; |
137 | |
} |
138 | |
|
139 | |
public void setUrl( String url ) |
140 | |
{ |
141 | 0 | this.url = url; |
142 | 0 | } |
143 | |
|
144 | |
public String getUrl() |
145 | |
{ |
146 | 0 | return url; |
147 | |
} |
148 | |
|
149 | |
public Map getIssueLinksPerSystem() |
150 | |
{ |
151 | 0 | return issueLinksPerSystem; |
152 | |
} |
153 | |
|
154 | |
public void setIssueLinksPerSystem( Map issueLinksPerSystem ) |
155 | |
{ |
156 | 0 | if ( this.issueLinksPerSystem != null && issueLinksPerSystem == null ) |
157 | |
{ |
158 | 0 | return; |
159 | |
} |
160 | 0 | this.issueLinksPerSystem = issueLinksPerSystem; |
161 | 0 | } |
162 | |
|
163 | |
public boolean isAddActionDate() |
164 | |
{ |
165 | 0 | return addActionDate; |
166 | |
} |
167 | |
|
168 | |
public void setAddActionDate( boolean addActionDate ) |
169 | |
{ |
170 | 0 | this.addActionDate = addActionDate; |
171 | 0 | } |
172 | |
|
173 | |
|
174 | |
|
175 | |
|
176 | |
|
177 | |
|
178 | |
|
179 | |
public boolean canGenerateIssueLinks( String system ) |
180 | |
{ |
181 | 0 | if ( !this.issueLinksPerSystem.containsKey( system ) ) |
182 | |
{ |
183 | 0 | return false; |
184 | |
} |
185 | 0 | String issueLink = (String) this.issueLinksPerSystem.get( system ); |
186 | |
|
187 | |
|
188 | 0 | if ( StringUtils.isBlank( issueLink ) ) |
189 | |
{ |
190 | 0 | return false; |
191 | |
} |
192 | |
|
193 | |
|
194 | 0 | if ( issueLink.indexOf( URL_TOKEN ) >= 0 && StringUtils.isBlank( getUrl() ) ) |
195 | |
{ |
196 | 0 | return false; |
197 | |
} |
198 | 0 | return true; |
199 | |
} |
200 | |
|
201 | |
public void doGenerateEmptyReport( ResourceBundle bundle, Sink sink, String message ) |
202 | |
{ |
203 | 0 | sinkBeginReport( sink, bundle ); |
204 | |
|
205 | 0 | sink.text( message ); |
206 | |
|
207 | 0 | sinkEndReport( sink ); |
208 | 0 | } |
209 | |
|
210 | |
public void doGenerateReport( ResourceBundle bundle, Sink sink ) |
211 | |
{ |
212 | 0 | sinkBeginReport( sink, bundle ); |
213 | |
|
214 | 0 | constructReleaseHistory( sink, bundle, releaseList ); |
215 | |
|
216 | 0 | constructReleases( sink, bundle, releaseList ); |
217 | |
|
218 | 0 | sinkEndReport( sink ); |
219 | 0 | } |
220 | |
|
221 | |
private void constructActions( Sink sink, List actionList, ResourceBundle bundle ) |
222 | |
{ |
223 | 0 | if ( actionList.isEmpty() ) |
224 | |
{ |
225 | 0 | sink.paragraph(); |
226 | |
|
227 | 0 | sink.text( bundle.getString( "report.changes.text.no.changes" ) ); |
228 | |
|
229 | 0 | sink.paragraph_(); |
230 | |
} |
231 | |
else |
232 | |
{ |
233 | 0 | sink.table(); |
234 | |
|
235 | 0 | sink.tableRow(); |
236 | |
|
237 | 0 | sinkHeader( sink, bundle.getString( "report.issues.label.type" ) ); |
238 | |
|
239 | 0 | sinkHeader( sink, bundle.getString( "report.issues.label.summary" ) ); |
240 | |
|
241 | 0 | sinkHeader( sink, bundle.getString( "report.issues.label.assignee" ) ); |
242 | |
|
243 | 0 | if ( this.isAddActionDate() ) |
244 | |
{ |
245 | 0 | sinkHeader( sink, bundle.getString( "report.issues.label.updated" ) ); |
246 | |
} |
247 | 0 | sink.tableRow_(); |
248 | |
|
249 | 0 | for ( int idx = 0; idx < actionList.size(); idx++ ) |
250 | |
{ |
251 | 0 | Action action = (Action) actionList.get( idx ); |
252 | |
|
253 | 0 | sink.tableRow(); |
254 | |
|
255 | 0 | sinkShowTypeIcon( sink, action.getType() ); |
256 | |
|
257 | 0 | sink.tableCell(); |
258 | |
|
259 | 0 | if ( escapeHTML ) |
260 | |
{ |
261 | 0 | sink.text( action.getAction() ); |
262 | |
} |
263 | |
else |
264 | |
{ |
265 | 0 | sink.rawText( action.getAction() ); |
266 | |
} |
267 | |
|
268 | |
|
269 | 0 | if ( StringUtils.isNotEmpty( action.getIssue() ) || ( !action.getFixedIssues().isEmpty() ) ) |
270 | |
{ |
271 | 0 | sink.text( " " + bundle.getString( "report.changes.text.fixes" ) + " " ); |
272 | |
|
273 | |
|
274 | 0 | String system = action.getSystem(); |
275 | |
|
276 | 0 | if ( StringUtils.isEmpty( system ) ) |
277 | |
{ |
278 | 0 | system = this.system; |
279 | |
} |
280 | |
|
281 | 0 | if ( StringUtils.isEmpty( system ) ) |
282 | |
{ |
283 | 0 | system = DEFAULT_ISSUE_SYSTEM_KEY; |
284 | |
} |
285 | 0 | if ( !canGenerateIssueLinks( system ) ) |
286 | |
{ |
287 | 0 | constructIssueText( action.getIssue(), sink, action.getFixedIssues() ); |
288 | |
} |
289 | |
else |
290 | |
{ |
291 | 0 | constructIssueLink( action.getIssue(), system, sink, action.getFixedIssues() ); |
292 | |
} |
293 | 0 | sink.text( "." ); |
294 | |
} |
295 | |
|
296 | 0 | if ( StringUtils.isNotEmpty( action.getDueTo() ) || ( !action.getDueTos().isEmpty() ) ) |
297 | |
{ |
298 | 0 | constructDueTo( sink, action, bundle, action.getDueTos() ); |
299 | |
} |
300 | |
|
301 | 0 | sink.tableCell_(); |
302 | |
|
303 | 0 | if ( NO_TEAMLIST.equals( teamlist ) ) |
304 | |
{ |
305 | 0 | sinkCell( sink, action.getDev() ); |
306 | |
} |
307 | |
else |
308 | |
{ |
309 | 0 | sinkCellLink( sink, action.getDev(), teamlist + "#" + action.getDev() ); |
310 | |
} |
311 | |
|
312 | 0 | if ( this.isAddActionDate() ) |
313 | |
{ |
314 | 0 | sinkCell( sink, action.getDate() ); |
315 | |
} |
316 | |
|
317 | 0 | sink.tableRow_(); |
318 | |
} |
319 | |
|
320 | 0 | sink.table_(); |
321 | |
} |
322 | 0 | } |
323 | |
|
324 | |
|
325 | |
|
326 | |
|
327 | |
|
328 | |
|
329 | |
|
330 | |
|
331 | |
|
332 | |
private void constructDueTo( Sink sink, Action action, ResourceBundle bundle, List dueTos ) |
333 | |
{ |
334 | |
|
335 | |
|
336 | 0 | Map namesEmailMap = new LinkedHashMap(); |
337 | |
|
338 | |
|
339 | 0 | if ( StringUtils.isNotEmpty( action.getDueTo() ) || StringUtils.isNotEmpty( action.getDueToEmail() ) ) |
340 | |
{ |
341 | 0 | namesEmailMap.put( action.getDueTo(), action.getDueToEmail() ); |
342 | |
} |
343 | |
|
344 | 0 | for ( Iterator iterator = dueTos.iterator(); iterator.hasNext(); ) |
345 | |
{ |
346 | 0 | DueTo dueTo = (DueTo) iterator.next(); |
347 | 0 | namesEmailMap.put( dueTo.getName(), dueTo.getEmail() ); |
348 | 0 | } |
349 | |
|
350 | 0 | if ( namesEmailMap.isEmpty() ) |
351 | |
{ |
352 | 0 | return; |
353 | |
} |
354 | |
|
355 | 0 | sink.text( " " + bundle.getString( "report.changes.text.thanx" ) + " " ); |
356 | 0 | int i = 0; |
357 | 0 | for ( Iterator iterator = namesEmailMap.keySet().iterator(); iterator.hasNext(); ) |
358 | |
{ |
359 | 0 | String currentDueTo = (String) iterator.next(); |
360 | 0 | String currentDueToEmail = (String) namesEmailMap.get( currentDueTo ); |
361 | 0 | i++; |
362 | |
|
363 | 0 | if ( StringUtils.isNotEmpty( currentDueToEmail ) ) |
364 | |
{ |
365 | 0 | sinkLink( sink, currentDueTo, "mailto:" + currentDueToEmail ); |
366 | |
} |
367 | 0 | else if ( StringUtils.isNotEmpty( currentDueTo ) ) |
368 | |
{ |
369 | 0 | sink.text( currentDueTo ); |
370 | |
} |
371 | |
|
372 | 0 | if ( i < namesEmailMap.size() ) |
373 | |
{ |
374 | 0 | sink.text( ", " ); |
375 | |
} |
376 | 0 | } |
377 | |
|
378 | 0 | sink.text( "." ); |
379 | 0 | } |
380 | |
|
381 | |
|
382 | |
|
383 | |
|
384 | |
|
385 | |
|
386 | |
|
387 | |
|
388 | |
|
389 | |
private void constructIssueLink( String issue, String system, Sink sink, List fixes ) |
390 | |
{ |
391 | 0 | if ( StringUtils.isNotEmpty( issue ) ) |
392 | |
{ |
393 | 0 | sink.link( parseIssueLink( issue, system ) ); |
394 | |
|
395 | 0 | sink.text( issue ); |
396 | |
|
397 | 0 | sink.link_(); |
398 | |
|
399 | 0 | if ( !fixes.isEmpty() ) |
400 | |
{ |
401 | 0 | sink.text( ", " ); |
402 | |
} |
403 | |
} |
404 | |
|
405 | 0 | for ( Iterator iterator = fixes.iterator(); iterator.hasNext(); ) |
406 | |
{ |
407 | 0 | FixedIssue fixedIssue = (FixedIssue) iterator.next(); |
408 | 0 | String currentIssueId = fixedIssue.getIssue(); |
409 | 0 | if ( StringUtils.isNotEmpty( currentIssueId ) ) |
410 | |
{ |
411 | 0 | sink.link( parseIssueLink( currentIssueId, system ) ); |
412 | |
|
413 | 0 | sink.text( currentIssueId ); |
414 | |
|
415 | 0 | sink.link_(); |
416 | |
} |
417 | |
|
418 | 0 | if ( iterator.hasNext() ) |
419 | |
{ |
420 | 0 | sink.text( ", " ); |
421 | |
} |
422 | 0 | } |
423 | 0 | } |
424 | |
|
425 | |
|
426 | |
|
427 | |
|
428 | |
|
429 | |
|
430 | |
|
431 | |
|
432 | |
|
433 | |
private void constructIssueText( String issue, Sink sink, List fixes ) |
434 | |
{ |
435 | 0 | if ( StringUtils.isNotEmpty( issue ) ) |
436 | |
{ |
437 | 0 | sink.text( issue ); |
438 | |
|
439 | 0 | if ( !fixes.isEmpty() ) |
440 | |
{ |
441 | 0 | sink.text( ", " ); |
442 | |
} |
443 | |
} |
444 | |
|
445 | 0 | for ( Iterator iterator = fixes.iterator(); iterator.hasNext(); ) |
446 | |
{ |
447 | 0 | FixedIssue fixedIssue = (FixedIssue) iterator.next(); |
448 | |
|
449 | 0 | String currentIssueId = fixedIssue.getIssue(); |
450 | 0 | if ( StringUtils.isNotEmpty( currentIssueId ) ) |
451 | |
{ |
452 | 0 | sink.text( currentIssueId ); |
453 | |
} |
454 | |
|
455 | 0 | if ( iterator.hasNext() ) |
456 | |
{ |
457 | 0 | sink.text( ", " ); |
458 | |
} |
459 | 0 | } |
460 | 0 | } |
461 | |
|
462 | |
private void constructReleaseHistory( Sink sink, ResourceBundle bundle, List releaseList ) |
463 | |
{ |
464 | 0 | sink.section2(); |
465 | |
|
466 | 0 | sinkSectionTitle2Anchor( sink, bundle.getString( "report.changes.label.releasehistory" ), |
467 | |
bundle.getString( "report.changes.label.releasehistory" ) ); |
468 | |
|
469 | 0 | sink.table(); |
470 | |
|
471 | 0 | sink.tableRow(); |
472 | |
|
473 | 0 | sinkHeader( sink, bundle.getString( "report.issues.label.fixVersion" ) ); |
474 | |
|
475 | 0 | sinkHeader( sink, bundle.getString( "report.changes.label.releaseDate" ) ); |
476 | |
|
477 | 0 | sinkHeader( sink, bundle.getString( "report.changes.label.releaseDescription" ) ); |
478 | |
|
479 | 0 | sink.tableRow_(); |
480 | |
|
481 | 0 | for ( int idx = 0; idx < releaseList.size(); idx++ ) |
482 | |
{ |
483 | 0 | Release release = (Release) releaseList.get( idx ); |
484 | |
|
485 | 0 | sink.tableRow(); |
486 | |
|
487 | 0 | sinkCellLink( sink, release.getVersion(), "#" + HtmlTools.encodeId( release.getVersion() ) ); |
488 | |
|
489 | 0 | sinkCell( sink, release.getDateRelease() ); |
490 | |
|
491 | 0 | sinkCell( sink, release.getDescription() ); |
492 | |
|
493 | 0 | sink.tableRow_(); |
494 | |
} |
495 | |
|
496 | 0 | sink.table_(); |
497 | |
|
498 | |
|
499 | |
|
500 | |
|
501 | |
|
502 | |
|
503 | |
|
504 | |
|
505 | |
|
506 | |
|
507 | 0 | sink.section2_(); |
508 | 0 | } |
509 | |
|
510 | |
private void constructReleases( Sink sink, ResourceBundle bundle, List releaseList ) |
511 | |
{ |
512 | |
|
513 | 0 | for ( int idx = 0; idx < releaseList.size(); idx++ ) |
514 | |
{ |
515 | 0 | Release release = (Release) releaseList.get( idx ); |
516 | |
|
517 | 0 | sink.section2(); |
518 | |
|
519 | 0 | final String date = ( release.getDateRelease() == null ) ? "" : " - " + release.getDateRelease(); |
520 | |
|
521 | 0 | sinkSectionTitle2Anchor( sink, bundle.getString( "report.changes.label.release" ) + " " |
522 | |
+ release.getVersion() + date, release.getVersion() ); |
523 | |
|
524 | 0 | constructActions( sink, release.getActions(), bundle ); |
525 | |
|
526 | 0 | sink.section2_(); |
527 | |
} |
528 | 0 | } |
529 | |
|
530 | |
|
531 | |
|
532 | |
|
533 | |
|
534 | |
|
535 | |
|
536 | |
|
537 | |
private String parseIssueLink( String issue, String system ) |
538 | |
{ |
539 | |
String parseLink; |
540 | 0 | String issueLink = (String) this.issueLinksPerSystem.get( system ); |
541 | 0 | parseLink = issueLink.replaceFirst( ISSUE_TOKEN, issue ); |
542 | 0 | if ( parseLink.indexOf( URL_TOKEN ) >= 0 ) |
543 | |
{ |
544 | 0 | String url = this.url.substring( 0, this.url.lastIndexOf( "/" ) ); |
545 | 0 | parseLink = parseLink.replaceFirst( URL_TOKEN, url ); |
546 | |
} |
547 | |
|
548 | 0 | return parseLink; |
549 | |
} |
550 | |
|
551 | |
} |