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.io.File; |
23 | |
import java.util.HashMap; |
24 | |
import java.util.Iterator; |
25 | |
import java.util.LinkedHashMap; |
26 | |
import java.util.List; |
27 | |
import java.util.Map; |
28 | |
import java.util.ResourceBundle; |
29 | |
|
30 | |
import org.apache.commons.lang.StringUtils; |
31 | |
import org.apache.maven.doxia.sink.Sink; |
32 | |
import org.apache.maven.doxia.util.HtmlTools; |
33 | |
import org.apache.maven.plugin.logging.Log; |
34 | |
import org.apache.maven.plugins.changes.model.Action; |
35 | |
import org.apache.maven.plugins.changes.model.DueTo; |
36 | |
import org.apache.maven.plugins.changes.model.FixedIssue; |
37 | |
import org.apache.maven.plugins.changes.model.Release; |
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
public class ChangesReportGenerator |
45 | |
{ |
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
private static final String URL_TOKEN = "%URL%"; |
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
private static final String ISSUE_TOKEN = "%ISSUE%"; |
56 | |
|
57 | |
private static final String DEFAULT_ISSUE_SYSTEM_KEY = "default"; |
58 | |
|
59 | |
private ChangesXML report; |
60 | |
|
61 | |
private String url; |
62 | |
|
63 | |
private Map issueLinksPerSystem; |
64 | |
|
65 | |
private boolean addActionDate; |
66 | |
|
67 | |
public ChangesReportGenerator() |
68 | 0 | { |
69 | 0 | issueLinksPerSystem = new HashMap(); |
70 | 0 | } |
71 | |
|
72 | |
public ChangesReportGenerator( File xmlPath, Log log ) |
73 | |
{ |
74 | 0 | this(); |
75 | 0 | report = new ChangesXML( xmlPath, log ); |
76 | 0 | } |
77 | |
|
78 | |
|
79 | |
|
80 | |
|
81 | |
public void setIssueLink( String issueLink ) |
82 | |
{ |
83 | 0 | if ( this.issueLinksPerSystem == null ) |
84 | |
{ |
85 | 0 | this.issueLinksPerSystem = new HashMap(); |
86 | |
} |
87 | 0 | if ( !this.issueLinksPerSystem.containsKey( DEFAULT_ISSUE_SYSTEM_KEY ) ) |
88 | |
{ |
89 | 0 | this.issueLinksPerSystem.put( DEFAULT_ISSUE_SYSTEM_KEY, issueLink ); |
90 | |
} |
91 | 0 | } |
92 | |
|
93 | |
|
94 | |
|
95 | |
|
96 | |
public String getIssueLink() |
97 | |
{ |
98 | 0 | return (String) issueLinksPerSystem.get( DEFAULT_ISSUE_SYSTEM_KEY ); |
99 | |
} |
100 | |
|
101 | |
public void setUrl( String url ) |
102 | |
{ |
103 | 0 | this.url = url; |
104 | 0 | } |
105 | |
|
106 | |
public String getUrl() |
107 | |
{ |
108 | 0 | return url; |
109 | |
} |
110 | |
|
111 | |
public Map getIssueLinksPerSystem() |
112 | |
{ |
113 | 0 | return issueLinksPerSystem; |
114 | |
} |
115 | |
|
116 | |
public void setIssueLinksPerSystem( Map issueLinksPerSystem ) |
117 | |
{ |
118 | 0 | if ( this.issueLinksPerSystem != null && issueLinksPerSystem == null ) |
119 | |
{ |
120 | 0 | return; |
121 | |
} |
122 | 0 | this.issueLinksPerSystem = issueLinksPerSystem; |
123 | 0 | } |
124 | |
|
125 | |
public boolean isAddActionDate() |
126 | |
{ |
127 | 0 | return addActionDate; |
128 | |
} |
129 | |
|
130 | |
public void setAddActionDate( boolean addActionDate ) |
131 | |
{ |
132 | 0 | this.addActionDate = addActionDate; |
133 | 0 | } |
134 | |
|
135 | |
|
136 | |
|
137 | |
|
138 | |
|
139 | |
|
140 | |
public boolean canGenerateIssueLinks( String system ) |
141 | |
{ |
142 | 0 | if ( !this.issueLinksPerSystem.containsKey( system ) ) |
143 | |
{ |
144 | 0 | return false; |
145 | |
} |
146 | 0 | String issueLink = (String) this.issueLinksPerSystem.get( system ); |
147 | |
|
148 | |
|
149 | 0 | if ( StringUtils.isBlank( issueLink ) ) |
150 | |
{ |
151 | 0 | return false; |
152 | |
} |
153 | |
|
154 | |
|
155 | 0 | if ( issueLink.indexOf( URL_TOKEN ) >= 0 && StringUtils.isBlank( getUrl() ) ) |
156 | |
{ |
157 | 0 | return false; |
158 | |
} |
159 | 0 | return true; |
160 | |
} |
161 | |
|
162 | |
public boolean canGenerateIssueLinks() |
163 | |
{ |
164 | 0 | if ( this.issueLinksPerSystem == null || this.issueLinksPerSystem.isEmpty() ) |
165 | |
{ |
166 | 0 | return false; |
167 | |
} |
168 | 0 | return this.issueLinksPerSystem.containsKey( DEFAULT_ISSUE_SYSTEM_KEY ); |
169 | |
} |
170 | |
|
171 | |
public void doGenerateEmptyReport( ResourceBundle bundle, Sink sink, String message ) |
172 | |
{ |
173 | 0 | sinkBeginReport( sink, bundle ); |
174 | |
|
175 | 0 | sink.text( message ); |
176 | |
|
177 | 0 | sinkEndReport( sink ); |
178 | 0 | } |
179 | |
|
180 | |
public void doGenerateReport( ResourceBundle bundle, Sink sink ) |
181 | |
{ |
182 | 0 | sinkBeginReport( sink, bundle ); |
183 | |
|
184 | 0 | constructReleaseHistory( sink, bundle ); |
185 | |
|
186 | 0 | constructReleases( sink, bundle ); |
187 | |
|
188 | 0 | sinkEndReport( sink ); |
189 | 0 | } |
190 | |
|
191 | |
private void constructActions( Sink sink, List actionList, ResourceBundle bundle ) |
192 | |
{ |
193 | 0 | if ( actionList.isEmpty() ) |
194 | |
{ |
195 | 0 | sink.paragraph(); |
196 | |
|
197 | 0 | sink.text( bundle.getString( "report.changes.text.no.changes" ) ); |
198 | |
|
199 | 0 | sink.paragraph_(); |
200 | |
} |
201 | |
else |
202 | |
{ |
203 | 0 | sink.table(); |
204 | |
|
205 | 0 | sink.tableRow(); |
206 | |
|
207 | 0 | sinkHeader( sink, bundle.getString( "report.changes.label.type" ) ); |
208 | |
|
209 | 0 | sinkHeader( sink, bundle.getString( "report.changes.label.changes" ) ); |
210 | |
|
211 | 0 | sinkHeader( sink, bundle.getString( "report.changes.label.by" ) ); |
212 | |
|
213 | 0 | if ( this.isAddActionDate() ) |
214 | |
{ |
215 | 0 | sinkHeader( sink, bundle.getString( "report.changes.label.date" ) ); |
216 | |
} |
217 | 0 | sink.tableRow_(); |
218 | |
|
219 | 0 | for ( int idx = 0; idx < actionList.size(); idx++ ) |
220 | |
{ |
221 | 0 | Action action = (Action) actionList.get( idx ); |
222 | |
|
223 | 0 | sink.tableRow(); |
224 | |
|
225 | 0 | sinkShowTypeIcon( sink, action.getType() ); |
226 | |
|
227 | 0 | sink.tableCell(); |
228 | |
|
229 | 0 | sink.text( action.getAction() ); |
230 | |
|
231 | |
|
232 | 0 | if ( StringUtils.isNotEmpty( action.getIssue() ) || ( !action.getFixedIssues().isEmpty() ) ) |
233 | |
{ |
234 | 0 | sink.text( " " + bundle.getString( "report.changes.text.fixes" ) + " " ); |
235 | |
|
236 | 0 | String system = action.getSystem(); |
237 | 0 | system = StringUtils.isEmpty( system ) ? DEFAULT_ISSUE_SYSTEM_KEY : system; |
238 | 0 | if ( !canGenerateIssueLinks( system ) ) |
239 | |
{ |
240 | 0 | constructIssueText( action.getIssue(), sink, action.getFixedIssues() ); |
241 | |
} |
242 | |
else |
243 | |
{ |
244 | 0 | constructIssueLink( action.getIssue(), system, sink, action.getFixedIssues() ); |
245 | |
} |
246 | 0 | sink.text( "." ); |
247 | |
} |
248 | |
|
249 | 0 | if ( StringUtils.isNotEmpty( action.getDueTo() ) || ( !action.getDueTos().isEmpty() ) ) |
250 | |
{ |
251 | 0 | constructDueTo( sink, action, bundle, action.getDueTos() ); |
252 | |
} |
253 | |
|
254 | 0 | sink.tableCell_(); |
255 | |
|
256 | 0 | sinkCellLink( sink, action.getDev(), "team-list.html#" + action.getDev() ); |
257 | |
|
258 | 0 | if ( this.isAddActionDate() ) |
259 | |
{ |
260 | 0 | sinkCell( sink, action.getDate() ); |
261 | |
} |
262 | |
|
263 | 0 | sink.tableRow_(); |
264 | |
} |
265 | |
|
266 | 0 | sink.table_(); |
267 | |
} |
268 | 0 | } |
269 | |
|
270 | |
private void constructReleaseHistory( Sink sink, ResourceBundle bundle ) |
271 | |
{ |
272 | 0 | sink.section2(); |
273 | |
|
274 | 0 | sinkSectionTitle2Anchor( sink, bundle.getString( "report.changes.label.releasehistory" ), |
275 | |
bundle.getString( "report.changes.label.releasehistory" ) ); |
276 | |
|
277 | 0 | List releaseList = report.getReleaseList(); |
278 | |
|
279 | 0 | sink.table(); |
280 | |
|
281 | 0 | sink.tableRow(); |
282 | |
|
283 | 0 | sinkHeader( sink, bundle.getString( "report.changes.label.version" ) ); |
284 | |
|
285 | 0 | sinkHeader( sink, bundle.getString( "report.changes.label.date" ) ); |
286 | |
|
287 | 0 | sinkHeader( sink, bundle.getString( "report.changes.label.description" ) ); |
288 | |
|
289 | 0 | sink.tableRow_(); |
290 | |
|
291 | 0 | for ( int idx = 0; idx < releaseList.size(); idx++ ) |
292 | |
{ |
293 | 0 | Release release = (Release) releaseList.get( idx ); |
294 | |
|
295 | 0 | sink.tableRow(); |
296 | |
|
297 | 0 | sinkCellLink( sink, release.getVersion(), "#" + HtmlTools.encodeId( release.getVersion() ) ); |
298 | |
|
299 | 0 | sinkCell( sink, release.getDateRelease() ); |
300 | |
|
301 | 0 | sinkCell( sink, release.getDescription() ); |
302 | |
|
303 | 0 | sink.tableRow_(); |
304 | |
} |
305 | |
|
306 | 0 | sink.table_(); |
307 | |
|
308 | |
|
309 | |
|
310 | |
|
311 | |
|
312 | |
|
313 | |
|
314 | |
|
315 | |
|
316 | |
|
317 | 0 | sink.section2_(); |
318 | 0 | } |
319 | |
|
320 | |
private void constructReleases( Sink sink, ResourceBundle bundle ) |
321 | |
{ |
322 | 0 | List releaseList = report.getReleaseList(); |
323 | |
|
324 | 0 | for ( int idx = 0; idx < releaseList.size(); idx++ ) |
325 | |
{ |
326 | 0 | Release release = (Release) releaseList.get( idx ); |
327 | |
|
328 | 0 | sink.section2(); |
329 | |
|
330 | 0 | sinkSectionTitle2Anchor( sink, bundle.getString( "report.changes.label.release" ) + " " |
331 | |
+ release.getVersion() + " - " + release.getDateRelease(), HtmlTools.encodeId( release.getVersion() ) ); |
332 | |
|
333 | 0 | constructActions( sink, release.getActions(), bundle ); |
334 | |
|
335 | 0 | sink.section2_(); |
336 | |
} |
337 | 0 | } |
338 | |
|
339 | |
private String parseIssueLink( String issue, String system ) |
340 | |
{ |
341 | |
String parseLink; |
342 | 0 | String issueLink = (String) this.issueLinksPerSystem.get( system ); |
343 | 0 | parseLink = issueLink.replaceFirst( ISSUE_TOKEN, issue ); |
344 | 0 | if ( parseLink.indexOf( URL_TOKEN ) >= 0 ) |
345 | |
{ |
346 | 0 | String url = this.url.substring( 0, this.url.lastIndexOf( "/" ) ); |
347 | 0 | parseLink = parseLink.replaceFirst( URL_TOKEN, url ); |
348 | |
} |
349 | |
|
350 | 0 | return parseLink; |
351 | |
} |
352 | |
|
353 | |
private void sinkBeginReport( Sink sink, ResourceBundle bundle ) |
354 | |
{ |
355 | 0 | sink.head(); |
356 | 0 | String title = null; |
357 | 0 | if ( report.getTitle() != null ) |
358 | |
{ |
359 | 0 | title = report.getTitle(); |
360 | |
} |
361 | |
else |
362 | |
{ |
363 | 0 | title = bundle.getString( "report.changes.header" ); |
364 | |
} |
365 | 0 | sink.title(); |
366 | 0 | sink.text( title ); |
367 | 0 | sink.title_(); |
368 | |
|
369 | 0 | if ( StringUtils.isNotEmpty( report.getAuthor() ) ) |
370 | |
{ |
371 | 0 | sink.author(); |
372 | 0 | sink.text( report.getAuthor() ); |
373 | 0 | sink.author_(); |
374 | |
} |
375 | |
|
376 | 0 | sink.head_(); |
377 | |
|
378 | 0 | sink.body(); |
379 | |
|
380 | 0 | sink.section1(); |
381 | |
|
382 | 0 | sinkSectionTitle1Anchor( sink, title, title ); |
383 | 0 | } |
384 | |
|
385 | |
private void sinkCell( Sink sink, String text ) |
386 | |
{ |
387 | 0 | sink.tableCell(); |
388 | |
|
389 | 0 | sink.text( text ); |
390 | |
|
391 | 0 | sink.tableCell_(); |
392 | 0 | } |
393 | |
|
394 | |
private void sinkCellLink( Sink sink, String text, String link ) |
395 | |
{ |
396 | 0 | sink.tableCell(); |
397 | |
|
398 | 0 | sinkLink( sink, text, link ); |
399 | |
|
400 | 0 | sink.tableCell_(); |
401 | 0 | } |
402 | |
|
403 | |
private void sinkEndReport( Sink sink ) |
404 | |
{ |
405 | 0 | sink.section1_(); |
406 | |
|
407 | 0 | sink.body_(); |
408 | |
|
409 | 0 | sink.flush(); |
410 | |
|
411 | 0 | sink.close(); |
412 | 0 | } |
413 | |
|
414 | |
private void sinkFigure( String image, Sink sink, String altText ) |
415 | |
{ |
416 | 0 | sink.figure(); |
417 | |
|
418 | 0 | sink.figureGraphics( image ); |
419 | |
|
420 | 0 | sink.figureCaption(); |
421 | |
|
422 | 0 | sink.text( altText ); |
423 | |
|
424 | 0 | sink.figureCaption_(); |
425 | |
|
426 | 0 | sink.figure_(); |
427 | 0 | } |
428 | |
|
429 | |
private void sinkHeader( Sink sink, String header ) |
430 | |
{ |
431 | 0 | sink.tableHeaderCell(); |
432 | |
|
433 | 0 | sink.text( header ); |
434 | |
|
435 | 0 | sink.tableHeaderCell_(); |
436 | 0 | } |
437 | |
|
438 | |
private void sinkLink( Sink sink, String text, String link ) |
439 | |
{ |
440 | 0 | sink.link( link ); |
441 | |
|
442 | 0 | sink.text( text ); |
443 | |
|
444 | 0 | sink.link_(); |
445 | 0 | } |
446 | |
|
447 | |
private void sinkSectionTitle1Anchor( Sink sink, String text, String anchor ) |
448 | |
{ |
449 | 0 | sink.sectionTitle1(); |
450 | 0 | sink.text( text ); |
451 | 0 | sink.sectionTitle1_(); |
452 | |
|
453 | 0 | sink.anchor( anchor ); |
454 | 0 | sink.anchor_(); |
455 | 0 | } |
456 | |
|
457 | |
private void sinkSectionTitle2Anchor( Sink sink, String text, String anchor ) |
458 | |
{ |
459 | 0 | sink.sectionTitle2(); |
460 | 0 | sink.text( text ); |
461 | 0 | sink.sectionTitle2_(); |
462 | |
|
463 | 0 | sink.anchor( anchor ); |
464 | 0 | sink.anchor_(); |
465 | 0 | } |
466 | |
|
467 | |
private void sinkShowTypeIcon( Sink sink, String type ) |
468 | |
{ |
469 | 0 | String image = ""; |
470 | 0 | String altText = ""; |
471 | |
|
472 | 0 | if ( type == null ) |
473 | |
{ |
474 | 0 | image = "images/icon_help_sml.gif"; |
475 | 0 | altText = "?"; |
476 | |
} |
477 | 0 | else if ( type.equals( "fix" ) ) |
478 | |
{ |
479 | 0 | image = "images/fix.gif"; |
480 | 0 | altText = "fix"; |
481 | |
} |
482 | 0 | else if ( type.equals( "update" ) ) |
483 | |
{ |
484 | 0 | image = "images/update.gif"; |
485 | 0 | altText = "update"; |
486 | |
} |
487 | 0 | else if ( type.equals( "add" ) ) |
488 | |
{ |
489 | 0 | image = "images/add.gif"; |
490 | 0 | altText = "add"; |
491 | |
} |
492 | 0 | else if ( type.equals( "remove" ) ) |
493 | |
{ |
494 | 0 | image = "images/remove.gif"; |
495 | 0 | altText = "remove"; |
496 | |
} |
497 | |
|
498 | 0 | sink.tableCell(); |
499 | |
|
500 | 0 | sinkFigure( image, sink, altText ); |
501 | |
|
502 | 0 | sink.tableCell_(); |
503 | 0 | } |
504 | |
|
505 | |
|
506 | |
|
507 | |
|
508 | |
|
509 | |
private void constructIssueLink( String issue, String system, Sink sink, List fixes ) |
510 | |
{ |
511 | 0 | if ( StringUtils.isNotEmpty( issue ) ) |
512 | |
{ |
513 | 0 | sink.link( parseIssueLink( issue, system ) ); |
514 | |
|
515 | 0 | sink.text( issue ); |
516 | |
|
517 | 0 | sink.link_(); |
518 | |
|
519 | 0 | if ( !fixes.isEmpty() ) |
520 | |
{ |
521 | 0 | sink.text( ", " ); |
522 | |
} |
523 | |
} |
524 | |
|
525 | 0 | for ( Iterator iterator = fixes.iterator(); iterator.hasNext(); ) |
526 | |
{ |
527 | 0 | FixedIssue fixedIssue = (FixedIssue) iterator.next(); |
528 | 0 | String currentIssueId = fixedIssue.getIssue(); |
529 | 0 | if ( StringUtils.isNotEmpty( currentIssueId ) ) |
530 | |
{ |
531 | 0 | sink.link( parseIssueLink( currentIssueId, system ) ); |
532 | |
|
533 | 0 | sink.text( currentIssueId ); |
534 | |
|
535 | 0 | sink.link_(); |
536 | |
} |
537 | |
|
538 | 0 | if ( iterator.hasNext() ) |
539 | |
{ |
540 | 0 | sink.text( ", " ); |
541 | |
} |
542 | 0 | } |
543 | 0 | } |
544 | |
|
545 | |
|
546 | |
|
547 | |
|
548 | |
|
549 | |
private void constructIssueText( String issue, Sink sink, List fixes ) |
550 | |
{ |
551 | 0 | if ( StringUtils.isNotEmpty( issue ) ) |
552 | |
{ |
553 | 0 | sink.text( issue ); |
554 | |
|
555 | 0 | if ( !fixes.isEmpty() ) |
556 | |
{ |
557 | 0 | sink.text( ", " ); |
558 | |
} |
559 | |
} |
560 | |
|
561 | 0 | for ( Iterator iterator = fixes.iterator(); iterator.hasNext(); ) |
562 | |
{ |
563 | 0 | FixedIssue fixedIssue = (FixedIssue) iterator.next(); |
564 | |
|
565 | 0 | String currentIssueId = fixedIssue.getIssue(); |
566 | 0 | if ( StringUtils.isNotEmpty( currentIssueId ) ) |
567 | |
{ |
568 | 0 | sink.text( currentIssueId ); |
569 | |
} |
570 | |
|
571 | 0 | if ( iterator.hasNext() ) |
572 | |
{ |
573 | 0 | sink.text( ", " ); |
574 | |
} |
575 | 0 | } |
576 | 0 | } |
577 | |
|
578 | |
|
579 | |
|
580 | |
|
581 | |
|
582 | |
|
583 | |
private void constructDueTo( Sink sink, Action action, ResourceBundle bundle, List dueTos ) |
584 | |
{ |
585 | |
|
586 | |
|
587 | 0 | Map namesEmailMap = new LinkedHashMap(); |
588 | |
|
589 | |
|
590 | 0 | if ( StringUtils.isNotEmpty( action.getDueTo() ) || StringUtils.isNotEmpty( action.getDueToEmail() ) ) |
591 | |
{ |
592 | 0 | namesEmailMap.put( action.getDueTo(), action.getDueToEmail() ); |
593 | |
} |
594 | |
|
595 | 0 | for ( Iterator iterator = dueTos.iterator(); iterator.hasNext(); ) |
596 | |
{ |
597 | 0 | DueTo dueTo = (DueTo) iterator.next(); |
598 | 0 | namesEmailMap.put( dueTo.getName(), dueTo.getEmail() ); |
599 | 0 | } |
600 | |
|
601 | 0 | if ( namesEmailMap.isEmpty() ) |
602 | |
{ |
603 | 0 | return; |
604 | |
} |
605 | |
|
606 | 0 | sink.text( " " + bundle.getString( "report.changes.text.thanx" ) + " " ); |
607 | 0 | int i = 0; |
608 | 0 | for ( Iterator iterator = namesEmailMap.keySet().iterator(); iterator.hasNext(); ) |
609 | |
{ |
610 | 0 | String currentDueTo = (String) iterator.next(); |
611 | 0 | String currentDueToEmail = (String) namesEmailMap.get( currentDueTo ); |
612 | 0 | i++; |
613 | |
|
614 | 0 | if ( StringUtils.isNotEmpty( currentDueToEmail ) ) |
615 | |
{ |
616 | 0 | sinkLink( sink, currentDueTo, "mailto:" + currentDueToEmail ); |
617 | |
} |
618 | 0 | else if ( StringUtils.isNotEmpty( currentDueTo ) ) |
619 | |
{ |
620 | 0 | sink.text( currentDueTo ); |
621 | |
} |
622 | |
|
623 | 0 | if ( i < namesEmailMap.size() ) |
624 | |
{ |
625 | 0 | sink.text( ", " ); |
626 | |
} |
627 | 0 | } |
628 | |
|
629 | 0 | sink.text( "." ); |
630 | 0 | } |
631 | |
|
632 | |
} |