1 | |
package org.apache.maven.plugin.changelog; |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
import java.io.BufferedOutputStream; |
23 | |
import java.io.BufferedReader; |
24 | |
import java.io.File; |
25 | |
import java.io.FileNotFoundException; |
26 | |
import java.io.FileOutputStream; |
27 | |
import java.io.IOException; |
28 | |
import java.io.StringReader; |
29 | |
import java.io.UnsupportedEncodingException; |
30 | |
import java.io.Writer; |
31 | |
import java.text.ParseException; |
32 | |
import java.text.SimpleDateFormat; |
33 | |
import java.util.ArrayList; |
34 | |
import java.util.Collection; |
35 | |
import java.util.Collections; |
36 | |
import java.util.Comparator; |
37 | |
import java.util.Date; |
38 | |
import java.util.HashMap; |
39 | |
import java.util.Iterator; |
40 | |
import java.util.LinkedList; |
41 | |
import java.util.List; |
42 | |
import java.util.Locale; |
43 | |
import java.util.Properties; |
44 | |
import java.util.ResourceBundle; |
45 | |
import java.util.StringTokenizer; |
46 | |
import java.util.regex.Matcher; |
47 | |
import java.util.regex.Pattern; |
48 | |
|
49 | |
import org.apache.maven.doxia.sink.Sink; |
50 | |
import org.apache.maven.doxia.siterenderer.Renderer; |
51 | |
import org.apache.maven.model.Developer; |
52 | |
import org.apache.maven.plugin.MojoExecutionException; |
53 | |
import org.apache.maven.project.MavenProject; |
54 | |
import org.apache.maven.reporting.AbstractMavenReport; |
55 | |
import org.apache.maven.reporting.MavenReportException; |
56 | |
import org.apache.maven.scm.ChangeFile; |
57 | |
import org.apache.maven.scm.ChangeSet; |
58 | |
import org.apache.maven.scm.ScmBranch; |
59 | |
import org.apache.maven.scm.ScmException; |
60 | |
import org.apache.maven.scm.ScmFileSet; |
61 | |
import org.apache.maven.scm.ScmResult; |
62 | |
import org.apache.maven.scm.ScmRevision; |
63 | |
import org.apache.maven.scm.command.changelog.ChangeLogScmResult; |
64 | |
import org.apache.maven.scm.command.changelog.ChangeLogSet; |
65 | |
import org.apache.maven.scm.manager.ScmManager; |
66 | |
import org.apache.maven.scm.provider.ScmProvider; |
67 | |
import org.apache.maven.scm.provider.ScmProviderRepository; |
68 | |
import org.apache.maven.scm.provider.ScmProviderRepositoryWithHost; |
69 | |
import org.apache.maven.scm.provider.svn.repository.SvnScmProviderRepository; |
70 | |
import org.apache.maven.scm.repository.ScmRepository; |
71 | |
import org.apache.maven.settings.Server; |
72 | |
import org.apache.maven.settings.Settings; |
73 | |
import org.codehaus.plexus.util.ReaderFactory; |
74 | |
import org.codehaus.plexus.util.StringUtils; |
75 | |
import org.codehaus.plexus.util.WriterFactory; |
76 | |
|
77 | |
|
78 | |
|
79 | |
|
80 | |
|
81 | |
|
82 | |
|
83 | 68 | public class ChangeLogReport |
84 | |
extends AbstractMavenReport |
85 | |
{ |
86 | |
|
87 | |
|
88 | |
|
89 | |
|
90 | |
private static final String FILE_TOKEN = "%FILE%"; |
91 | |
|
92 | |
|
93 | |
|
94 | |
|
95 | |
|
96 | |
private static final String ISSUE_TOKEN = "%ISSUE%"; |
97 | |
|
98 | |
|
99 | |
|
100 | |
|
101 | |
|
102 | |
|
103 | |
private static final String REV_TOKEN = "%REV%"; |
104 | |
|
105 | |
|
106 | |
|
107 | |
|
108 | |
private static final int DEFAULT_RANGE = 30; |
109 | |
|
110 | |
|
111 | |
|
112 | |
|
113 | |
|
114 | |
|
115 | |
|
116 | |
|
117 | 68 | private String headingDateFormat = "yyyy-MM-dd"; |
118 | |
|
119 | |
|
120 | |
|
121 | |
|
122 | |
|
123 | |
|
124 | |
|
125 | |
private String type; |
126 | |
|
127 | |
|
128 | |
|
129 | |
|
130 | |
|
131 | |
|
132 | |
private int range; |
133 | |
|
134 | |
|
135 | |
|
136 | |
|
137 | |
|
138 | |
|
139 | |
private List dates; |
140 | |
|
141 | |
|
142 | |
|
143 | |
|
144 | |
|
145 | |
|
146 | |
private List tags; |
147 | |
|
148 | |
|
149 | |
|
150 | |
|
151 | |
|
152 | |
|
153 | |
|
154 | |
private String dateFormat; |
155 | |
|
156 | |
|
157 | |
|
158 | |
|
159 | |
|
160 | |
|
161 | |
|
162 | |
private File basedir; |
163 | |
|
164 | |
|
165 | |
|
166 | |
|
167 | |
|
168 | |
|
169 | |
|
170 | |
private File outputXML; |
171 | |
|
172 | |
|
173 | |
|
174 | |
|
175 | |
|
176 | |
|
177 | |
|
178 | |
private int outputXMLExpiration; |
179 | |
|
180 | |
|
181 | |
|
182 | |
|
183 | |
|
184 | |
|
185 | |
|
186 | |
|
187 | |
private String commentFormat; |
188 | |
|
189 | |
|
190 | |
|
191 | |
|
192 | |
|
193 | |
|
194 | |
|
195 | |
private String outputEncoding; |
196 | |
|
197 | |
|
198 | |
|
199 | |
|
200 | |
|
201 | |
|
202 | |
private String username; |
203 | |
|
204 | |
|
205 | |
|
206 | |
|
207 | |
|
208 | |
|
209 | |
private String password; |
210 | |
|
211 | |
|
212 | |
|
213 | |
|
214 | |
|
215 | |
|
216 | |
private String privateKey; |
217 | |
|
218 | |
|
219 | |
|
220 | |
|
221 | |
|
222 | |
|
223 | |
private String passphrase; |
224 | |
|
225 | |
|
226 | |
|
227 | |
|
228 | |
|
229 | |
|
230 | |
private String tagBase; |
231 | |
|
232 | |
|
233 | |
|
234 | |
|
235 | |
|
236 | |
|
237 | |
protected String scmUrl; |
238 | |
|
239 | |
|
240 | |
|
241 | |
|
242 | |
|
243 | |
|
244 | |
|
245 | |
|
246 | |
private MavenProject project; |
247 | |
|
248 | |
|
249 | |
|
250 | |
|
251 | |
|
252 | |
|
253 | |
|
254 | |
|
255 | |
private File outputDirectory; |
256 | |
|
257 | |
|
258 | |
|
259 | |
|
260 | |
private Renderer siteRenderer; |
261 | |
|
262 | |
|
263 | |
|
264 | |
|
265 | |
|
266 | |
|
267 | |
private boolean offline; |
268 | |
|
269 | |
|
270 | |
|
271 | |
|
272 | |
private ScmManager manager; |
273 | |
|
274 | |
|
275 | |
|
276 | |
|
277 | |
|
278 | |
|
279 | |
private Settings settings; |
280 | |
|
281 | |
|
282 | |
|
283 | |
|
284 | |
|
285 | |
|
286 | |
|
287 | |
|
288 | |
private String connectionType; |
289 | |
|
290 | |
|
291 | |
|
292 | |
|
293 | |
|
294 | |
|
295 | |
|
296 | |
|
297 | |
|
298 | |
|
299 | |
|
300 | |
|
301 | |
|
302 | |
|
303 | |
|
304 | |
|
305 | |
|
306 | |
|
307 | |
protected String displayFileDetailUrl; |
308 | |
|
309 | |
|
310 | |
|
311 | |
|
312 | |
|
313 | |
|
314 | |
|
315 | |
|
316 | |
|
317 | |
|
318 | |
|
319 | |
private String issueIDRegexPattern; |
320 | |
|
321 | |
|
322 | |
|
323 | |
|
324 | |
|
325 | |
|
326 | |
|
327 | |
|
328 | |
|
329 | |
|
330 | |
|
331 | |
private String issueLinkUrl; |
332 | |
|
333 | |
|
334 | |
|
335 | |
|
336 | |
|
337 | |
|
338 | |
|
339 | |
|
340 | |
|
341 | |
|
342 | |
|
343 | |
|
344 | |
|
345 | |
|
346 | |
|
347 | |
|
348 | |
|
349 | |
|
350 | |
|
351 | |
|
352 | |
|
353 | |
|
354 | |
protected String displayChangeSetDetailUrl; |
355 | |
|
356 | |
|
357 | |
|
358 | |
|
359 | |
|
360 | |
|
361 | |
|
362 | |
|
363 | |
|
364 | |
|
365 | |
|
366 | |
|
367 | |
|
368 | |
|
369 | |
|
370 | |
|
371 | |
|
372 | |
|
373 | |
|
374 | |
|
375 | |
|
376 | |
|
377 | |
|
378 | |
|
379 | |
|
380 | |
|
381 | |
|
382 | |
|
383 | |
|
384 | |
protected String displayFileRevDetailUrl; |
385 | |
|
386 | |
|
387 | |
|
388 | |
|
389 | |
|
390 | |
|
391 | |
|
392 | |
protected List developers; |
393 | |
|
394 | |
|
395 | |
private String rptRepository, rptOneRepoParam, rptMultiRepoParam; |
396 | |
|
397 | |
|
398 | |
private String connection; |
399 | |
|
400 | |
|
401 | |
private HashMap developersById; |
402 | |
|
403 | |
|
404 | |
private HashMap developersByName; |
405 | |
|
406 | |
|
407 | |
|
408 | |
|
409 | |
|
410 | |
|
411 | |
private Properties systemProperties; |
412 | |
|
413 | |
|
414 | |
public void executeReport( Locale locale ) |
415 | |
throws MavenReportException |
416 | |
{ |
417 | |
|
418 | 68 | if ( !basedir.exists() ) |
419 | |
{ |
420 | 12 | doGenerateEmptyReport( getBundle( locale ), getSink() ); |
421 | |
|
422 | 12 | return; |
423 | |
} |
424 | |
|
425 | 56 | initializeDefaultConfigurationParameters(); |
426 | |
|
427 | 56 | initializeDeveloperMaps(); |
428 | |
|
429 | 56 | verifySCMTypeParams(); |
430 | |
|
431 | 52 | if ( systemProperties != null ) |
432 | |
{ |
433 | |
|
434 | 0 | Iterator iter = systemProperties.keySet().iterator(); |
435 | |
|
436 | 0 | while ( iter.hasNext() ) |
437 | |
{ |
438 | 0 | String key = (String) iter.next(); |
439 | |
|
440 | 0 | String value = systemProperties.getProperty( key ); |
441 | |
|
442 | 0 | System.setProperty( key, value ); |
443 | |
|
444 | 0 | getLog().debug( "Setting system property: " + key + "=" + value ); |
445 | 0 | } |
446 | |
} |
447 | |
|
448 | 52 | doGenerateReport( getChangedSets(), getBundle( locale ), getSink() ); |
449 | 40 | } |
450 | |
|
451 | |
|
452 | |
|
453 | |
|
454 | |
|
455 | |
private void initializeDefaultConfigurationParameters() |
456 | |
{ |
457 | 56 | if ( displayFileRevDetailUrl == null || displayFileRevDetailUrl.length() == 0 ) |
458 | |
{ |
459 | 56 | displayFileRevDetailUrl = displayFileDetailUrl; |
460 | |
} |
461 | 56 | } |
462 | |
|
463 | |
|
464 | |
|
465 | |
|
466 | |
|
467 | |
private void initializeDeveloperMaps() |
468 | |
{ |
469 | 56 | developersById = new HashMap(); |
470 | 56 | developersByName = new HashMap(); |
471 | |
|
472 | 56 | if ( developers != null ) |
473 | |
{ |
474 | 4 | for ( Iterator i = developers.iterator(); i.hasNext(); ) |
475 | |
{ |
476 | 8 | Developer developer = (Developer) i.next(); |
477 | |
|
478 | 8 | developersById.put( developer.getId(), developer ); |
479 | 8 | developersByName.put( developer.getName(), developer ); |
480 | 8 | } |
481 | |
} |
482 | 56 | } |
483 | |
|
484 | |
|
485 | |
|
486 | |
|
487 | |
|
488 | |
|
489 | |
|
490 | |
protected List getChangedSets() |
491 | |
throws MavenReportException |
492 | |
{ |
493 | 52 | List changelogList = null; |
494 | |
|
495 | 52 | if ( !outputXML.isAbsolute() ) |
496 | |
{ |
497 | 40 | outputXML = new File( project.getBasedir(), outputXML.getPath() ); |
498 | |
} |
499 | |
|
500 | 52 | if ( outputXML.exists() ) |
501 | |
{ |
502 | 40 | if ( outputXMLExpiration > 0 |
503 | |
&& outputXMLExpiration * 60000 > System.currentTimeMillis() - outputXML.lastModified() ) |
504 | |
{ |
505 | |
try |
506 | |
{ |
507 | |
|
508 | |
|
509 | |
|
510 | 40 | getLog().info( "Using existing changelog.xml..." ); |
511 | |
|
512 | 40 | changelogList = ChangeLog.loadChangedSets( ReaderFactory.newReader( outputXML, outputEncoding ) ); |
513 | |
} |
514 | 0 | catch ( FileNotFoundException e ) |
515 | |
{ |
516 | |
|
517 | |
} |
518 | 0 | catch ( Exception e ) |
519 | |
{ |
520 | 0 | throw new MavenReportException( "An error occurred while parsing " + outputXML.getAbsolutePath(), |
521 | |
e ); |
522 | 40 | } |
523 | |
} |
524 | |
} |
525 | |
|
526 | 52 | if ( changelogList == null ) |
527 | |
{ |
528 | 12 | if ( offline ) |
529 | |
{ |
530 | 0 | throw new MavenReportException( "This report requires online mode." ); |
531 | |
} |
532 | |
|
533 | 12 | getLog().info( "Generating changed sets xml to: " + outputXML.getAbsolutePath() ); |
534 | |
|
535 | 12 | changelogList = generateChangeSetsFromSCM(); |
536 | |
|
537 | |
try |
538 | |
{ |
539 | 0 | writeChangelogXml( changelogList ); |
540 | |
} |
541 | 0 | catch ( FileNotFoundException e ) |
542 | |
{ |
543 | 0 | throw new MavenReportException( "Can't create " + outputXML.getAbsolutePath(), e ); |
544 | |
} |
545 | 0 | catch ( UnsupportedEncodingException e ) |
546 | |
{ |
547 | 0 | throw new MavenReportException( "Can't create " + outputXML.getAbsolutePath(), e ); |
548 | |
} |
549 | 0 | catch ( IOException e ) |
550 | |
{ |
551 | 0 | throw new MavenReportException( "Can't create " + outputXML.getAbsolutePath(), e ); |
552 | 0 | } |
553 | |
} |
554 | |
|
555 | 40 | return changelogList; |
556 | |
} |
557 | |
|
558 | |
private void writeChangelogXml( List changelogList ) |
559 | |
throws FileNotFoundException, UnsupportedEncodingException, IOException |
560 | |
{ |
561 | 0 | StringBuffer changelogXml = new StringBuffer(); |
562 | |
|
563 | 0 | changelogXml.append( "<?xml version=\"1.0\" encoding=\"" ).append( outputEncoding ).append( "\"?>\n" ); |
564 | 0 | changelogXml.append( "<changelog>" ); |
565 | |
|
566 | 0 | for ( Iterator sets = changelogList.iterator(); sets.hasNext(); ) |
567 | |
{ |
568 | 0 | changelogXml.append( "\n " ); |
569 | |
|
570 | 0 | ChangeLogSet changelogSet = (ChangeLogSet) sets.next(); |
571 | 0 | String changeset = changelogSet.toXML( outputEncoding ); |
572 | |
|
573 | |
|
574 | 0 | if ( changeset.startsWith( "<?xml" ) ) |
575 | |
{ |
576 | 0 | int idx = changeset.indexOf( "?>" ) + 2; |
577 | 0 | changeset = changeset.substring( idx ); |
578 | |
} |
579 | |
|
580 | 0 | changelogXml.append( changeset ); |
581 | 0 | } |
582 | |
|
583 | 0 | changelogXml.append( "\n</changelog>" ); |
584 | |
|
585 | 0 | outputXML.getParentFile().mkdirs(); |
586 | |
|
587 | |
|
588 | |
|
589 | |
|
590 | |
|
591 | |
|
592 | 0 | Writer writer = WriterFactory.newWriter( new BufferedOutputStream( new FileOutputStream( outputXML ) ), outputEncoding ); |
593 | 0 | writer.write( changelogXml.toString() ); |
594 | 0 | writer.flush(); |
595 | 0 | writer.close(); |
596 | 0 | } |
597 | |
|
598 | |
|
599 | |
|
600 | |
|
601 | |
|
602 | |
|
603 | |
|
604 | |
protected List generateChangeSetsFromSCM() |
605 | |
throws MavenReportException |
606 | |
{ |
607 | |
try |
608 | |
{ |
609 | 12 | List changeSets = new ArrayList(); |
610 | |
|
611 | 12 | ScmRepository repository = getScmRepository(); |
612 | |
|
613 | 8 | ScmProvider provider = manager.getProviderByRepository( repository ); |
614 | |
|
615 | |
ChangeLogScmResult result; |
616 | |
|
617 | 8 | if ( "range".equals( type ) ) |
618 | |
{ |
619 | 4 | result = provider.changeLog( repository, new ScmFileSet( basedir ), null, null, range, (ScmBranch) null, |
620 | |
dateFormat ); |
621 | |
|
622 | 4 | checkResult( result ); |
623 | |
|
624 | 0 | changeSets.add( result.getChangeLog() ); |
625 | |
} |
626 | 4 | else if ( "tag".equals( type ) ) |
627 | |
{ |
628 | 0 | if ( repository.getProvider().equals( "svn" ) ) |
629 | |
{ |
630 | 0 | throw new MavenReportException( "The type '" + type + "' isn't supported for svn." ); |
631 | |
} |
632 | |
|
633 | 0 | Iterator tagsIter = tags.iterator(); |
634 | |
|
635 | 0 | String startTag = (String) tagsIter.next(); |
636 | 0 | String endTag = null; |
637 | |
|
638 | 0 | if ( tagsIter.hasNext() ) |
639 | |
{ |
640 | 0 | while ( tagsIter.hasNext() ) |
641 | |
{ |
642 | 0 | endTag = (String) tagsIter.next(); |
643 | |
|
644 | 0 | result = provider.changeLog( repository, new ScmFileSet( basedir ), new ScmRevision( startTag ), |
645 | |
new ScmRevision( endTag ) ); |
646 | |
|
647 | 0 | checkResult( result ); |
648 | |
|
649 | 0 | changeSets.add( result.getChangeLog() ); |
650 | |
|
651 | 0 | startTag = endTag; |
652 | |
} |
653 | |
} |
654 | |
else |
655 | |
{ |
656 | 0 | result = provider.changeLog( repository, new ScmFileSet( basedir ), new ScmRevision( startTag ), |
657 | |
new ScmRevision( endTag ) ); |
658 | |
|
659 | 0 | checkResult( result ); |
660 | |
|
661 | 0 | changeSets.add( result.getChangeLog() ); |
662 | |
} |
663 | 0 | } |
664 | 4 | else if ( "date".equals( type ) ) |
665 | |
{ |
666 | 4 | Iterator dateIter = dates.iterator(); |
667 | |
|
668 | 4 | String startDate = (String) dateIter.next(); |
669 | 4 | String endDate = null; |
670 | |
|
671 | 4 | if ( dateIter.hasNext() ) |
672 | |
{ |
673 | 0 | while ( dateIter.hasNext() ) |
674 | |
{ |
675 | 0 | endDate = (String) dateIter.next(); |
676 | |
|
677 | 0 | result = provider.changeLog( repository, new ScmFileSet( basedir ), parseDate( startDate ), |
678 | |
parseDate( endDate ), 0, (ScmBranch) null ); |
679 | |
|
680 | 0 | checkResult( result ); |
681 | |
|
682 | 0 | changeSets.add( result.getChangeLog() ); |
683 | |
|
684 | 0 | startDate = endDate; |
685 | |
} |
686 | |
} |
687 | |
else |
688 | |
{ |
689 | 4 | result = provider.changeLog( repository, new ScmFileSet( basedir ), parseDate( startDate ), |
690 | |
parseDate( endDate ), 0, (ScmBranch) null ); |
691 | |
|
692 | 0 | checkResult( result ); |
693 | |
|
694 | 0 | changeSets.add( result.getChangeLog() ); |
695 | |
} |
696 | 0 | } |
697 | |
else |
698 | |
{ |
699 | 0 | throw new MavenReportException( "The type '" + type + "' isn't supported." ); |
700 | |
} |
701 | |
|
702 | 0 | return changeSets; |
703 | |
} |
704 | 4 | catch ( ScmException e ) |
705 | |
{ |
706 | 4 | throw new MavenReportException( "Cannot run changelog command : ", e ); |
707 | |
} |
708 | 8 | catch ( MojoExecutionException e ) |
709 | |
{ |
710 | 8 | throw new MavenReportException( "An error has occurred during changelog command : ", e ); |
711 | |
} |
712 | |
} |
713 | |
|
714 | |
|
715 | |
|
716 | |
|
717 | |
|
718 | |
|
719 | |
private Date parseDate( String date ) |
720 | |
throws MojoExecutionException |
721 | |
{ |
722 | 4 | if ( date == null || date.trim().length() == 0 ) |
723 | |
{ |
724 | 0 | return null; |
725 | |
} |
726 | |
|
727 | 4 | SimpleDateFormat formatter = new SimpleDateFormat( "yyyy-MM-dd" ); |
728 | |
|
729 | |
try |
730 | |
{ |
731 | 4 | return formatter.parse( date ); |
732 | |
} |
733 | 4 | catch ( ParseException e ) |
734 | |
{ |
735 | 4 | throw new MojoExecutionException( "Please use this date pattern: " + formatter.toLocalizedPattern(), e ); |
736 | |
} |
737 | |
} |
738 | |
|
739 | |
public ScmRepository getScmRepository() |
740 | |
throws ScmException |
741 | |
{ |
742 | |
ScmRepository repository; |
743 | |
|
744 | |
try |
745 | |
{ |
746 | 12 | repository = manager.makeScmRepository( getConnection() ); |
747 | |
|
748 | 8 | ScmProviderRepository providerRepo = repository.getProviderRepository(); |
749 | |
|
750 | 8 | if ( !StringUtils.isEmpty( username ) ) |
751 | |
{ |
752 | 0 | providerRepo.setUser( username ); |
753 | |
} |
754 | |
|
755 | 8 | if ( !StringUtils.isEmpty( password ) ) |
756 | |
{ |
757 | 0 | providerRepo.setPassword( password ); |
758 | |
} |
759 | |
|
760 | 8 | if ( repository.getProviderRepository() instanceof ScmProviderRepositoryWithHost ) |
761 | |
{ |
762 | 0 | ScmProviderRepositoryWithHost repo = (ScmProviderRepositoryWithHost) repository.getProviderRepository(); |
763 | |
|
764 | 0 | loadInfosFromSettings( repo ); |
765 | |
|
766 | 0 | if ( !StringUtils.isEmpty( username ) ) |
767 | |
{ |
768 | 0 | repo.setUser( username ); |
769 | |
} |
770 | |
|
771 | 0 | if ( !StringUtils.isEmpty( password ) ) |
772 | |
{ |
773 | 0 | repo.setPassword( password ); |
774 | |
} |
775 | |
|
776 | 0 | if ( !StringUtils.isEmpty( privateKey ) ) |
777 | |
{ |
778 | 0 | repo.setPrivateKey( privateKey ); |
779 | |
} |
780 | |
|
781 | 0 | if ( !StringUtils.isEmpty( passphrase ) ) |
782 | |
{ |
783 | 0 | repo.setPassphrase( passphrase ); |
784 | |
} |
785 | |
} |
786 | |
|
787 | 8 | if ( !StringUtils.isEmpty( tagBase ) && repository.getProvider().equals( "svn" ) ) |
788 | |
{ |
789 | 0 | SvnScmProviderRepository svnRepo = (SvnScmProviderRepository) repository.getProviderRepository(); |
790 | |
|
791 | 0 | svnRepo.setTagBase( tagBase ); |
792 | |
} |
793 | |
} |
794 | 4 | catch ( Exception e ) |
795 | |
{ |
796 | 4 | throw new ScmException( "Can't load the scm provider.", e ); |
797 | 8 | } |
798 | |
|
799 | 8 | return repository; |
800 | |
} |
801 | |
|
802 | |
|
803 | |
|
804 | |
|
805 | |
|
806 | |
|
807 | |
private void loadInfosFromSettings( ScmProviderRepositoryWithHost repo ) |
808 | |
{ |
809 | 0 | if ( username == null || password == null ) |
810 | |
{ |
811 | 0 | String host = repo.getHost(); |
812 | |
|
813 | 0 | int port = repo.getPort(); |
814 | |
|
815 | 0 | if ( port > 0 ) |
816 | |
{ |
817 | 0 | host += ":" + port; |
818 | |
} |
819 | |
|
820 | 0 | Server server = this.settings.getServer( host ); |
821 | |
|
822 | 0 | if ( server != null ) |
823 | |
{ |
824 | 0 | if ( username == null ) |
825 | |
{ |
826 | 0 | username = this.settings.getServer( host ).getUsername(); |
827 | |
} |
828 | |
|
829 | 0 | if ( password == null ) |
830 | |
{ |
831 | 0 | password = this.settings.getServer( host ).getPassword(); |
832 | |
} |
833 | |
|
834 | 0 | if ( privateKey == null ) |
835 | |
{ |
836 | 0 | privateKey = this.settings.getServer( host ).getPrivateKey(); |
837 | |
} |
838 | |
|
839 | 0 | if ( passphrase == null ) |
840 | |
{ |
841 | 0 | passphrase = this.settings.getServer( host ).getPassphrase(); |
842 | |
} |
843 | |
} |
844 | |
} |
845 | 0 | } |
846 | |
|
847 | |
public void checkResult( ScmResult result ) |
848 | |
throws MojoExecutionException |
849 | |
{ |
850 | 4 | if ( !result.isSuccess() ) |
851 | |
{ |
852 | 4 | getLog().error( "Provider message:" ); |
853 | |
|
854 | 4 | getLog().error( result.getProviderMessage() == null ? "" : result.getProviderMessage() ); |
855 | |
|
856 | 4 | getLog().error( "Command output:" ); |
857 | |
|
858 | 4 | getLog().error( result.getCommandOutput() == null ? "" : result.getCommandOutput() ); |
859 | |
|
860 | 4 | throw new MojoExecutionException( "Command failed." ); |
861 | |
} |
862 | 0 | } |
863 | |
|
864 | |
|
865 | |
|
866 | |
|
867 | |
|
868 | |
|
869 | |
|
870 | |
protected String getConnection() |
871 | |
throws MavenReportException |
872 | |
{ |
873 | 52 | if ( this.connection != null ) |
874 | |
{ |
875 | 32 | return connection; |
876 | |
} |
877 | |
|
878 | 20 | if ( project.getScm() == null ) |
879 | |
{ |
880 | 0 | throw new MavenReportException( "SCM Connection is not set." ); |
881 | |
} |
882 | |
|
883 | 20 | String scmConnection = project.getScm().getConnection(); |
884 | 20 | if ( StringUtils.isNotEmpty( scmConnection ) && "connection".equals( connectionType.toLowerCase() ) ) |
885 | |
{ |
886 | 16 | connection = scmConnection; |
887 | |
} |
888 | |
|
889 | 20 | String scmDeveloper = project.getScm().getDeveloperConnection(); |
890 | 20 | if ( StringUtils.isNotEmpty( scmDeveloper ) && "developerconnection".equals( connectionType.toLowerCase() ) ) |
891 | |
{ |
892 | 0 | connection = scmDeveloper; |
893 | |
} |
894 | |
|
895 | 20 | if ( StringUtils.isEmpty( connection ) ) |
896 | |
{ |
897 | 4 | throw new MavenReportException( "SCM Connection is not set." ); |
898 | |
} |
899 | |
|
900 | 16 | return connection; |
901 | |
} |
902 | |
|
903 | |
|
904 | |
|
905 | |
|
906 | |
|
907 | |
|
908 | |
private void verifySCMTypeParams() |
909 | |
throws MavenReportException |
910 | |
{ |
911 | 56 | if ( "range".equals( type ) ) |
912 | |
{ |
913 | 32 | if ( range == -1 ) |
914 | |
{ |
915 | 32 | range = DEFAULT_RANGE; |
916 | |
} |
917 | |
} |
918 | 24 | else if ( "date".equals( type ) ) |
919 | |
{ |
920 | 12 | if ( dates == null ) |
921 | |
{ |
922 | 0 | throw new MavenReportException( |
923 | |
"The dates parameter is required when type=\"date\"." |
924 | |
+ " The value should be the absolute date for the start of the log." ); |
925 | |
} |
926 | |
} |
927 | 12 | else if ( "tag".equals( type ) ) |
928 | |
{ |
929 | 8 | if ( tags == null ) |
930 | |
{ |
931 | 0 | throw new MavenReportException( "The tags parameter is required when type=\"tag\"." ); |
932 | |
} |
933 | |
} |
934 | |
else |
935 | |
{ |
936 | 4 | throw new MavenReportException( "The type parameter has an invalid value: " + type |
937 | |
+ ". The value should be \"range\", \"date\", or \"tag\"." ); |
938 | |
} |
939 | 52 | } |
940 | |
|
941 | |
|
942 | |
|
943 | |
|
944 | |
|
945 | |
|
946 | |
|
947 | |
protected void doGenerateEmptyReport( ResourceBundle bundle, Sink sink ) |
948 | |
{ |
949 | 4 | sink.head(); |
950 | 4 | sink.title(); |
951 | 4 | sink.text( bundle.getString( "report.changelog.header" ) ); |
952 | 4 | sink.title_(); |
953 | 4 | sink.head_(); |
954 | |
|
955 | 4 | sink.body(); |
956 | 4 | sink.section1(); |
957 | |
|
958 | 4 | sink.sectionTitle1(); |
959 | 4 | sink.text( bundle.getString( "report.changelog.mainTitle" ) ); |
960 | 4 | sink.sectionTitle1_(); |
961 | |
|
962 | 4 | sink.paragraph(); |
963 | 4 | sink.text( bundle.getString( "report.changelog.nosources" ) ); |
964 | 4 | sink.paragraph_(); |
965 | |
|
966 | 4 | sink.section1_(); |
967 | |
|
968 | 4 | sink.body_(); |
969 | 4 | sink.flush(); |
970 | 4 | sink.close(); |
971 | 4 | } |
972 | |
|
973 | |
|
974 | |
|
975 | |
|
976 | |
|
977 | |
|
978 | |
|
979 | |
|
980 | |
protected void doGenerateReport( List changeLogSets, ResourceBundle bundle, Sink sink ) |
981 | |
{ |
982 | 32 | sink.head(); |
983 | 32 | sink.title(); |
984 | 32 | sink.text( bundle.getString( "report.changelog.header" ) ); |
985 | 32 | sink.title_(); |
986 | 32 | sink.head_(); |
987 | |
|
988 | 32 | sink.body(); |
989 | 32 | sink.section1(); |
990 | |
|
991 | 32 | sink.sectionTitle1(); |
992 | 32 | sink.text( bundle.getString( "report.changelog.mainTitle" ) ); |
993 | 32 | sink.sectionTitle1_(); |
994 | |
|
995 | |
|
996 | 32 | doSummarySection( changeLogSets, bundle, sink ); |
997 | |
|
998 | 32 | for ( Iterator sets = changeLogSets.iterator(); sets.hasNext(); ) |
999 | |
{ |
1000 | 36 | ChangeLogSet changeLogSet = (ChangeLogSet) sets.next(); |
1001 | |
|
1002 | 36 | doChangedSet( changeLogSet, bundle, sink ); |
1003 | 36 | } |
1004 | |
|
1005 | 32 | sink.section1_(); |
1006 | 32 | sink.body_(); |
1007 | |
|
1008 | 32 | sink.flush(); |
1009 | 32 | sink.close(); |
1010 | 32 | } |
1011 | |
|
1012 | |
|
1013 | |
|
1014 | |
|
1015 | |
|
1016 | |
|
1017 | |
|
1018 | |
|
1019 | |
private void doSummarySection( List changeLogSets, ResourceBundle bundle, Sink sink ) |
1020 | |
{ |
1021 | 32 | sink.paragraph(); |
1022 | |
|
1023 | 32 | sink.text( bundle.getString( "report.changelog.ChangedSetsTotal" ) ); |
1024 | 32 | sink.text( ": " + changeLogSets.size() ); |
1025 | |
|
1026 | 32 | sink.paragraph_(); |
1027 | 32 | } |
1028 | |
|
1029 | |
|
1030 | |
|
1031 | |
|
1032 | |
|
1033 | |
|
1034 | |
|
1035 | |
|
1036 | |
private void doChangedSet( ChangeLogSet set, ResourceBundle bundle, Sink sink ) |
1037 | |
{ |
1038 | 36 | sink.section2(); |
1039 | |
|
1040 | 36 | doChangeSetTitle( set, bundle, sink ); |
1041 | |
|
1042 | 36 | doSummary( set, bundle, sink ); |
1043 | |
|
1044 | 36 | doChangedSetTable( set.getChangeSets(), bundle, sink ); |
1045 | |
|
1046 | 36 | sink.section2_(); |
1047 | 36 | } |
1048 | |
|
1049 | |
|
1050 | |
|
1051 | |
|
1052 | |
|
1053 | |
|
1054 | |
|
1055 | |
|
1056 | |
protected void doChangeSetTitle( ChangeLogSet set, ResourceBundle bundle, Sink sink ) |
1057 | |
{ |
1058 | 52 | sink.sectionTitle2(); |
1059 | |
|
1060 | 52 | SimpleDateFormat headingDateFormater = new SimpleDateFormat( headingDateFormat ); |
1061 | |
|
1062 | 52 | if ( "tag".equals( type ) ) |
1063 | |
{ |
1064 | 8 | if ( set.getStartVersion() == null || set.getStartVersion().getName() == null ) |
1065 | |
{ |
1066 | 8 | sink.text( bundle.getString( "report.SetTagCreation" ) ); |
1067 | 8 | if ( set.getEndVersion() != null && set.getEndVersion().getName() != null ) |
1068 | |
{ |
1069 | 0 | sink.text( " " + bundle.getString( "report.SetTagUntil" ) + " '" + set.getEndVersion() + "'" ); |
1070 | |
} |
1071 | |
} |
1072 | 0 | else if ( set.getEndVersion() == null || set.getEndVersion().getName() == null ) |
1073 | |
{ |
1074 | 0 | sink.text( bundle.getString( "report.SetTagSince" ) ); |
1075 | 0 | sink.text( " '" + set.getStartVersion() + "'" ); |
1076 | |
} |
1077 | |
else |
1078 | |
{ |
1079 | 0 | sink.text( bundle.getString( "report.SetTagBetween" ) ); |
1080 | 0 | sink.text( " '" + set.getStartVersion() + "' " + bundle.getString( "report.And" ) + " '" |
1081 | |
+ set.getEndVersion() + "'" ); |
1082 | |
} |
1083 | |
} |
1084 | 44 | else if ( set.getStartDate() == null ) |
1085 | |
{ |
1086 | 0 | sink.text( bundle.getString( "report.SetRangeUnknown" ) ); |
1087 | |
} |
1088 | 44 | else if ( set.getEndDate() == null ) |
1089 | |
{ |
1090 | 0 | sink.text( bundle.getString( "report.SetRangeSince" ) ); |
1091 | 0 | sink.text( " " + headingDateFormater.format( set.getStartDate() ) ); |
1092 | |
} |
1093 | |
else |
1094 | |
{ |
1095 | 44 | sink.text( bundle.getString( "report.SetRangeBetween" ) ); |
1096 | 44 | sink.text( " " + headingDateFormater.format( set.getStartDate() ) |
1097 | |
+ " " + bundle.getString( "report.And" ) + " " |
1098 | |
+ headingDateFormater.format( set.getEndDate() ) ); |
1099 | |
} |
1100 | 52 | sink.sectionTitle2_(); |
1101 | 52 | } |
1102 | |
|
1103 | |
|
1104 | |
|
1105 | |
|
1106 | |
|
1107 | |
|
1108 | |
|
1109 | |
|
1110 | |
protected void doSummary( ChangeLogSet set, ResourceBundle bundle, Sink sink ) |
1111 | |
{ |
1112 | 52 | sink.paragraph(); |
1113 | 52 | sink.text( bundle.getString( "report.TotalCommits" ) ); |
1114 | 52 | sink.text( ": " + set.getChangeSets().size() ); |
1115 | 52 | sink.lineBreak(); |
1116 | 52 | sink.text( bundle.getString( "report.changelog.FilesChanged" ) ); |
1117 | 52 | sink.text( ": " + countFilesChanged( set.getChangeSets() ) ); |
1118 | 52 | sink.paragraph_(); |
1119 | 52 | } |
1120 | |
|
1121 | |
|
1122 | |
|
1123 | |
|
1124 | |
|
1125 | |
|
1126 | |
|
1127 | |
protected long countFilesChanged( Collection entries ) |
1128 | |
{ |
1129 | 52 | if ( entries == null ) |
1130 | |
{ |
1131 | 0 | return 0; |
1132 | |
} |
1133 | |
|
1134 | 52 | if ( entries.isEmpty() ) |
1135 | |
{ |
1136 | 28 | return 0; |
1137 | |
} |
1138 | |
|
1139 | 24 | HashMap fileList = new HashMap(); |
1140 | |
|
1141 | 24 | for ( Iterator i = entries.iterator(); i.hasNext(); ) |
1142 | |
{ |
1143 | 48 | ChangeSet entry = (ChangeSet) i.next(); |
1144 | |
|
1145 | 48 | List files = entry.getFiles(); |
1146 | |
|
1147 | 48 | for ( Iterator fileIterator = files.iterator(); fileIterator.hasNext(); ) |
1148 | |
{ |
1149 | 72 | ChangeFile file = (ChangeFile) fileIterator.next(); |
1150 | |
|
1151 | 72 | String name = file.getName(); |
1152 | |
|
1153 | 72 | if ( fileList.containsKey( name ) ) |
1154 | |
{ |
1155 | 24 | LinkedList list = (LinkedList) fileList.get( name ); |
1156 | |
|
1157 | 24 | list.add( file ); |
1158 | 24 | } |
1159 | |
else |
1160 | |
{ |
1161 | 48 | LinkedList list = new LinkedList(); |
1162 | |
|
1163 | 48 | list.add( file ); |
1164 | |
|
1165 | 48 | fileList.put( name, list ); |
1166 | |
} |
1167 | 72 | } |
1168 | 48 | } |
1169 | |
|
1170 | 24 | return fileList.size(); |
1171 | |
} |
1172 | |
|
1173 | |
|
1174 | |
|
1175 | |
|
1176 | |
|
1177 | |
|
1178 | |
|
1179 | |
|
1180 | |
private void doChangedSetTable( Collection entries, ResourceBundle bundle, Sink sink ) |
1181 | |
{ |
1182 | 36 | sink.table(); |
1183 | |
|
1184 | 36 | sink.tableRow(); |
1185 | 36 | sink.tableHeaderCell(); |
1186 | 36 | sink.text( bundle.getString( "report.changelog.timestamp" ) ); |
1187 | 36 | sink.tableHeaderCell_(); |
1188 | 36 | sink.tableHeaderCell(); |
1189 | 36 | sink.text( bundle.getString( "report.changelog.author" ) ); |
1190 | 36 | sink.tableHeaderCell_(); |
1191 | 36 | sink.tableHeaderCell(); |
1192 | 36 | sink.text( bundle.getString( "report.changelog.details" ) ); |
1193 | 36 | sink.tableHeaderCell_(); |
1194 | 36 | sink.tableRow_(); |
1195 | |
|
1196 | 36 | initReportUrls(); |
1197 | |
|
1198 | 36 | List sortedEntries = new ArrayList( entries ); |
1199 | 36 | Collections.sort( sortedEntries, new Comparator() |
1200 | |
{ |
1201 | 36 | public int compare( Object arg0, Object arg1 ) |
1202 | |
{ |
1203 | 8 | ChangeSet changeSet0 = (ChangeSet) arg0; |
1204 | 8 | ChangeSet changeSet1 = (ChangeSet) arg1; |
1205 | 8 | return changeSet1.getDate().compareTo( changeSet0.getDate() ); |
1206 | |
} |
1207 | |
} ); |
1208 | |
|
1209 | 36 | for ( Iterator i = sortedEntries.iterator(); i.hasNext(); ) |
1210 | |
{ |
1211 | 16 | ChangeSet entry = (ChangeSet) i.next(); |
1212 | |
|
1213 | 16 | doChangedSetDetail( entry, bundle, sink ); |
1214 | 16 | } |
1215 | |
|
1216 | 36 | sink.table_(); |
1217 | 36 | } |
1218 | |
|
1219 | |
|
1220 | |
|
1221 | |
|
1222 | |
|
1223 | |
|
1224 | |
|
1225 | |
|
1226 | |
private void doChangedSetDetail( ChangeSet entry, ResourceBundle bundle, Sink sink ) |
1227 | |
{ |
1228 | 16 | sink.tableRow(); |
1229 | |
|
1230 | 16 | sink.tableCell(); |
1231 | 16 | sink.text( entry.getDateFormatted() + " " + entry.getTimeFormatted() ); |
1232 | 16 | sink.tableCell_(); |
1233 | |
|
1234 | 16 | sink.tableCell(); |
1235 | |
|
1236 | 16 | sinkAuthorDetails( sink, entry.getAuthor() ); |
1237 | |
|
1238 | 16 | sink.tableCell_(); |
1239 | |
|
1240 | 16 | sink.tableCell(); |
1241 | |
|
1242 | 16 | doChangedFiles( entry.getFiles(), sink ); |
1243 | 16 | sink.lineBreak(); |
1244 | 16 | StringReader sr = new StringReader( entry.getComment() ); |
1245 | 16 | BufferedReader br = new BufferedReader( sr ); |
1246 | |
String line; |
1247 | |
try |
1248 | |
{ |
1249 | 16 | if ( ( issueIDRegexPattern != null && issueIDRegexPattern.length() > 0 ) |
1250 | |
&& ( issueLinkUrl != null && issueLinkUrl.length() > 0 ) ) |
1251 | |
{ |
1252 | 0 | Pattern pattern = Pattern.compile( issueIDRegexPattern ); |
1253 | |
|
1254 | 0 | line = br.readLine(); |
1255 | |
|
1256 | 0 | while ( line != null ) |
1257 | |
{ |
1258 | 0 | sinkIssueLink( sink, line, pattern ); |
1259 | |
|
1260 | 0 | line = br.readLine(); |
1261 | 0 | if ( line != null ) |
1262 | |
{ |
1263 | 0 | sink.lineBreak(); |
1264 | |
} |
1265 | |
} |
1266 | 0 | } |
1267 | |
else |
1268 | |
{ |
1269 | 16 | line = br.readLine(); |
1270 | |
|
1271 | 32 | while ( line != null ) |
1272 | |
{ |
1273 | 16 | sink.text( line ); |
1274 | 16 | line = br.readLine(); |
1275 | 16 | if ( line != null ) |
1276 | |
{ |
1277 | 0 | sink.lineBreak(); |
1278 | |
} |
1279 | |
} |
1280 | |
} |
1281 | |
} |
1282 | 0 | catch ( IOException e ) |
1283 | |
{ |
1284 | 0 | getLog().warn( "Unable to read the comment of a ChangeSet as a stream." ); |
1285 | |
} |
1286 | |
finally |
1287 | |
{ |
1288 | 16 | if ( br != null ) |
1289 | |
{ |
1290 | |
try |
1291 | |
{ |
1292 | 16 | br.close(); |
1293 | |
} |
1294 | 0 | catch ( IOException e ) |
1295 | |
{ |
1296 | 0 | getLog().warn( "Unable to close a reader." ); |
1297 | 16 | } |
1298 | |
} |
1299 | 16 | if ( sr != null ) |
1300 | |
{ |
1301 | 16 | sr.close(); |
1302 | |
} |
1303 | |
} |
1304 | 16 | sink.tableCell_(); |
1305 | |
|
1306 | 16 | sink.tableRow_(); |
1307 | 16 | } |
1308 | |
|
1309 | |
private void sinkIssueLink( Sink sink, String line, Pattern pattern ) |
1310 | |
{ |
1311 | |
|
1312 | |
|
1313 | 0 | Matcher matcher = pattern.matcher( line ); |
1314 | |
|
1315 | 0 | int currLoc = 0; |
1316 | |
|
1317 | 0 | while ( matcher.find() ) |
1318 | |
{ |
1319 | 0 | String match = matcher.group(); |
1320 | |
|
1321 | |
String link; |
1322 | |
|
1323 | 0 | if ( issueLinkUrl.indexOf( ISSUE_TOKEN ) > 0 ) |
1324 | |
{ |
1325 | 0 | link = issueLinkUrl.replaceAll( ISSUE_TOKEN, match ); |
1326 | |
} |
1327 | |
else |
1328 | |
{ |
1329 | 0 | if ( issueLinkUrl.endsWith( "/" ) ) |
1330 | |
{ |
1331 | 0 | link = issueLinkUrl; |
1332 | |
} |
1333 | |
else |
1334 | |
{ |
1335 | 0 | link = issueLinkUrl + "/"; |
1336 | |
} |
1337 | |
|
1338 | 0 | link += match; |
1339 | |
} |
1340 | |
|
1341 | 0 | int startOfMatch = matcher.start(); |
1342 | |
|
1343 | 0 | String unmatchedText = line.substring( currLoc, startOfMatch ); |
1344 | |
|
1345 | 0 | currLoc = matcher.end(); |
1346 | |
|
1347 | 0 | sink.text( unmatchedText ); |
1348 | |
|
1349 | 0 | sink.link( link ); |
1350 | 0 | sink.text( match ); |
1351 | 0 | sink.link_(); |
1352 | 0 | } |
1353 | |
|
1354 | 0 | sink.text( line.substring( currLoc ) ); |
1355 | 0 | } |
1356 | |
|
1357 | |
|
1358 | |
|
1359 | |
|
1360 | |
|
1361 | |
|
1362 | |
|
1363 | |
|
1364 | |
|
1365 | |
protected void sinkAuthorDetails( Sink sink, String author ) |
1366 | |
{ |
1367 | 24 | Developer developer = (Developer) developersById.get( author ); |
1368 | |
|
1369 | 24 | if ( developer == null ) |
1370 | |
{ |
1371 | 24 | developer = (Developer) developersByName.get( author ); |
1372 | |
} |
1373 | |
|
1374 | 24 | if ( developer != null ) |
1375 | |
{ |
1376 | 8 | sink.link( "team-list.html#" + developer.getId() ); |
1377 | 8 | sink.text( developer.getName() ); |
1378 | 8 | sink.link_(); |
1379 | |
} |
1380 | |
else |
1381 | |
{ |
1382 | 16 | sink.text( author ); |
1383 | |
} |
1384 | 24 | } |
1385 | |
|
1386 | |
|
1387 | |
|
1388 | |
|
1389 | |
protected void initReportUrls() |
1390 | |
{ |
1391 | 44 | if ( scmUrl != null ) |
1392 | |
{ |
1393 | 44 | int idx = scmUrl.indexOf( '?' ); |
1394 | |
|
1395 | 44 | if ( idx > 0 ) |
1396 | |
{ |
1397 | 4 | rptRepository = scmUrl.substring( 0, idx ); |
1398 | |
|
1399 | 4 | if ( scmUrl.equals( displayFileDetailUrl ) ) |
1400 | |
{ |
1401 | 4 | String rptTmpMultiRepoParam = scmUrl.substring( rptRepository.length() ); |
1402 | |
|
1403 | 4 | rptOneRepoParam = "?" + rptTmpMultiRepoParam.substring( 1 ); |
1404 | |
|
1405 | 4 | rptMultiRepoParam = "&" + rptTmpMultiRepoParam.substring( 1 ); |
1406 | 4 | } |
1407 | |
} |
1408 | |
else |
1409 | |
{ |
1410 | 40 | rptRepository = scmUrl; |
1411 | |
|
1412 | 40 | rptOneRepoParam = ""; |
1413 | |
|
1414 | 40 | rptMultiRepoParam = ""; |
1415 | |
} |
1416 | |
} |
1417 | 44 | } |
1418 | |
|
1419 | |
|
1420 | |
|
1421 | |
|
1422 | |
|
1423 | |
|
1424 | |
|
1425 | |
private void doChangedFiles( List files, Sink sink ) |
1426 | |
{ |
1427 | 16 | for ( Iterator i = files.iterator(); i.hasNext(); ) |
1428 | |
{ |
1429 | 24 | ChangeFile file = (ChangeFile) i.next(); |
1430 | 24 | sinkLogFile( sink, file.getName(), file.getRevision() ); |
1431 | 24 | } |
1432 | 16 | } |
1433 | |
|
1434 | |
|
1435 | |
|
1436 | |
|
1437 | |
|
1438 | |
|
1439 | |
|
1440 | |
|
1441 | |
private void sinkLogFile( Sink sink, String name, String revision ) |
1442 | |
{ |
1443 | |
try |
1444 | |
{ |
1445 | 24 | String connection = getConnection(); |
1446 | |
|
1447 | 24 | generateLinks( connection, name, revision, sink ); |
1448 | |
} |
1449 | 0 | catch ( Exception e ) |
1450 | |
{ |
1451 | 0 | getLog().debug( e ); |
1452 | |
|
1453 | 0 | sink.text( name + " v " + revision ); |
1454 | 24 | } |
1455 | |
|
1456 | 24 | sink.lineBreak(); |
1457 | 24 | } |
1458 | |
|
1459 | |
|
1460 | |
|
1461 | |
|
1462 | |
|
1463 | |
|
1464 | |
|
1465 | |
|
1466 | |
protected void generateLinks( String connection, String name, Sink sink ) |
1467 | |
{ |
1468 | 16 | generateLinks( connection, name, null, sink ); |
1469 | 16 | } |
1470 | |
|
1471 | |
|
1472 | |
|
1473 | |
|
1474 | |
|
1475 | |
|
1476 | |
|
1477 | |
|
1478 | |
|
1479 | |
protected void generateLinks( String connection, String name, String revision, Sink sink ) |
1480 | |
{ |
1481 | 40 | String linkFile = null; |
1482 | 40 | String linkRev = null; |
1483 | |
|
1484 | 40 | if ( revision != null ) |
1485 | |
{ |
1486 | 24 | linkFile = displayFileRevDetailUrl; |
1487 | |
} |
1488 | |
else |
1489 | |
{ |
1490 | 16 | linkFile = displayFileDetailUrl; |
1491 | |
} |
1492 | |
|
1493 | 40 | if ( linkFile != null ) |
1494 | |
{ |
1495 | 0 | if ( !scmUrl.equals( linkFile ) ) |
1496 | |
{ |
1497 | |
|
1498 | |
|
1499 | 0 | if ( linkFile.indexOf( FILE_TOKEN ) > 0 ) |
1500 | |
{ |
1501 | 0 | linkFile = linkFile.replaceAll( FILE_TOKEN, name ); |
1502 | |
} |
1503 | |
else |
1504 | |
{ |
1505 | |
|
1506 | |
|
1507 | |
|
1508 | 0 | linkFile = linkFile + name; |
1509 | |
} |
1510 | |
|
1511 | |
|
1512 | |
|
1513 | 0 | if ( revision != null && linkFile.indexOf( REV_TOKEN ) > 0 ) |
1514 | |
{ |
1515 | 0 | linkFile = linkFile.replaceAll( REV_TOKEN, revision ); |
1516 | |
} |
1517 | |
} |
1518 | 0 | else if ( connection.startsWith( "scm:perforce" ) ) |
1519 | |
{ |
1520 | 0 | String path = getAbsolutePath( displayFileDetailUrl, name ); |
1521 | 0 | linkFile = path + "?ac=22"; |
1522 | 0 | if ( revision != null ) |
1523 | |
{ |
1524 | 0 | linkRev = path + "?ac=64&rev=" + revision; |
1525 | |
} |
1526 | 0 | } |
1527 | 0 | else if ( connection.startsWith( "scm:clearcase" ) ) |
1528 | |
{ |
1529 | 0 | String path = getAbsolutePath( displayFileDetailUrl, name ); |
1530 | 0 | linkFile = path + rptOneRepoParam; |
1531 | 0 | } |
1532 | 0 | else if ( connection.indexOf( "cvsmonitor.pl" ) > 0 ) |
1533 | |
{ |
1534 | 0 | String module = rptOneRepoParam.replaceAll( "^.*(&module=.*?(?:&|$)).*$", "$1" ); |
1535 | 0 | linkFile = displayFileDetailUrl + "?cmd=viewBrowseFile" + module + "&file=" + name; |
1536 | 0 | if ( revision != null ) |
1537 | |
{ |
1538 | 0 | linkRev = |
1539 | |
rptRepository + "?cmd=viewBrowseVersion" + module + "&file=" + name + "&version=" + revision; |
1540 | |
} |
1541 | 0 | } |
1542 | |
else |
1543 | |
{ |
1544 | 0 | String path = getAbsolutePath( displayFileDetailUrl, name ); |
1545 | 0 | linkFile = path + rptOneRepoParam; |
1546 | 0 | if ( revision != null ) |
1547 | |
{ |
1548 | 0 | linkRev = path + "?rev=" + revision + "&content-type=text/vnd.viewcvs-markup" + rptMultiRepoParam; |
1549 | |
} |
1550 | |
} |
1551 | |
} |
1552 | |
|
1553 | 40 | if ( linkFile != null ) |
1554 | |
{ |
1555 | 0 | sink.link( linkFile ); |
1556 | 0 | sinkFileName( name, sink ); |
1557 | 0 | sink.link_(); |
1558 | |
} |
1559 | |
else |
1560 | |
{ |
1561 | 40 | sinkFileName( name, sink ); |
1562 | |
} |
1563 | |
|
1564 | 40 | sink.text( " " ); |
1565 | |
|
1566 | 40 | if ( linkRev == null && revision != null && displayChangeSetDetailUrl != null ) |
1567 | |
{ |
1568 | 0 | if ( displayChangeSetDetailUrl.indexOf( REV_TOKEN ) > 0 ) |
1569 | |
{ |
1570 | 0 | linkRev = displayChangeSetDetailUrl.replaceAll( REV_TOKEN, revision ); |
1571 | |
} |
1572 | |
else |
1573 | |
{ |
1574 | 0 | linkRev = displayChangeSetDetailUrl + revision; |
1575 | |
} |
1576 | |
} |
1577 | |
|
1578 | 40 | if ( linkRev != null ) |
1579 | |
{ |
1580 | 0 | sink.link( linkRev ); |
1581 | 0 | sink.text( "v " + revision ); |
1582 | 0 | sink.link_(); |
1583 | |
} |
1584 | 40 | else if ( revision != null ) |
1585 | |
{ |
1586 | 24 | sink.text( "v " + revision ); |
1587 | |
} |
1588 | 40 | } |
1589 | |
|
1590 | |
|
1591 | |
|
1592 | |
|
1593 | |
|
1594 | |
|
1595 | |
|
1596 | |
private void sinkFileName( String name, Sink sink ) |
1597 | |
{ |
1598 | 40 | name = name.replaceAll( "\\\\", "/" ); |
1599 | 40 | int pos = name.lastIndexOf( '/' ); |
1600 | |
|
1601 | |
String head; |
1602 | |
String tail; |
1603 | 40 | if ( pos < 0 ) |
1604 | |
{ |
1605 | 0 | head = ""; |
1606 | 0 | tail = name; |
1607 | |
} |
1608 | |
else |
1609 | |
{ |
1610 | 40 | head = name.substring( 0, pos ) + "/"; |
1611 | 40 | tail = name.substring( pos + 1 ); |
1612 | |
} |
1613 | |
|
1614 | 40 | sink.text( head ); |
1615 | 40 | sink.bold(); |
1616 | 40 | sink.text( tail ); |
1617 | 40 | sink.bold_(); |
1618 | 40 | } |
1619 | |
|
1620 | |
|
1621 | |
|
1622 | |
|
1623 | |
|
1624 | |
|
1625 | |
|
1626 | |
private String getAbsolutePath( final String base, final String target ) |
1627 | |
{ |
1628 | 0 | String absPath = ""; |
1629 | |
|
1630 | 0 | StringTokenizer baseTokens = new StringTokenizer( base.replaceAll( "\\\\", "/" ), "/", true ); |
1631 | |
|
1632 | 0 | StringTokenizer targetTokens = new StringTokenizer( target.replaceAll( "\\\\", "/" ), "/" ); |
1633 | |
|
1634 | 0 | String targetRoot = targetTokens.nextToken(); |
1635 | |
|
1636 | 0 | while ( baseTokens.hasMoreTokens() ) |
1637 | |
{ |
1638 | 0 | String baseToken = baseTokens.nextToken(); |
1639 | |
|
1640 | 0 | if ( baseToken.equals( targetRoot ) ) |
1641 | |
{ |
1642 | 0 | break; |
1643 | |
} |
1644 | |
|
1645 | 0 | absPath += baseToken; |
1646 | 0 | } |
1647 | |
|
1648 | 0 | if ( !absPath.endsWith( "/" ) ) |
1649 | |
{ |
1650 | 0 | absPath += "/"; |
1651 | |
} |
1652 | |
|
1653 | 0 | String newTarget = target; |
1654 | 0 | if ( newTarget.startsWith( "/" ) ) |
1655 | |
{ |
1656 | 0 | newTarget = newTarget.substring( 1 ); |
1657 | |
} |
1658 | |
|
1659 | 0 | return absPath + newTarget; |
1660 | |
} |
1661 | |
|
1662 | |
|
1663 | |
protected MavenProject getProject() |
1664 | |
{ |
1665 | 0 | return project; |
1666 | |
} |
1667 | |
|
1668 | |
|
1669 | |
protected String getOutputDirectory() |
1670 | |
{ |
1671 | 68 | if ( !outputDirectory.isAbsolute() ) |
1672 | |
{ |
1673 | 68 | outputDirectory = new File( project.getBasedir(), outputDirectory.getPath() ); |
1674 | |
} |
1675 | |
|
1676 | 68 | return outputDirectory.getAbsolutePath(); |
1677 | |
} |
1678 | |
|
1679 | |
|
1680 | |
protected Renderer getSiteRenderer() |
1681 | |
{ |
1682 | 104 | return siteRenderer; |
1683 | |
} |
1684 | |
|
1685 | |
|
1686 | |
public String getDescription( Locale locale ) |
1687 | |
{ |
1688 | 0 | return getBundle( locale ).getString( "report.changelog.description" ); |
1689 | |
} |
1690 | |
|
1691 | |
|
1692 | |
public String getName( Locale locale ) |
1693 | |
{ |
1694 | 16 | return getBundle( locale ).getString( "report.changelog.name" ); |
1695 | |
} |
1696 | |
|
1697 | |
|
1698 | |
public String getOutputName() |
1699 | |
{ |
1700 | 52 | return "changelog"; |
1701 | |
} |
1702 | |
|
1703 | |
|
1704 | |
|
1705 | |
|
1706 | |
|
1707 | |
protected ResourceBundle getBundle( Locale locale ) |
1708 | |
{ |
1709 | 68 | return ResourceBundle.getBundle( "scm-activity", locale, this.getClass().getClassLoader() ); |
1710 | |
} |
1711 | |
|
1712 | |
|
1713 | |
public boolean canGenerateReport() |
1714 | |
{ |
1715 | 0 | if ( offline && !outputXML.exists() ) |
1716 | |
{ |
1717 | 0 | return false; |
1718 | |
} |
1719 | |
|
1720 | 0 | return true; |
1721 | |
} |
1722 | |
} |