1 | |
package org.apache.maven.scm.plugin; |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
import java.io.IOException; |
23 | |
import java.text.ParseException; |
24 | |
import java.text.SimpleDateFormat; |
25 | |
import java.util.Date; |
26 | |
|
27 | |
import org.apache.maven.plugin.MojoExecutionException; |
28 | |
import org.apache.maven.scm.ChangeSet; |
29 | |
import org.apache.maven.scm.ScmBranch; |
30 | |
import org.apache.maven.scm.ScmException; |
31 | |
import org.apache.maven.scm.command.changelog.ChangeLogScmResult; |
32 | |
import org.apache.maven.scm.command.changelog.ChangeLogSet; |
33 | |
import org.apache.maven.scm.provider.ScmProvider; |
34 | |
import org.apache.maven.scm.repository.ScmRepository; |
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | 0 | public class ChangeLogMojo |
46 | |
extends AbstractScmMojo |
47 | |
{ |
48 | |
private static final String DEFAULT_DATE_FORMAT = "yyyy-MM-dd"; |
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
private String startDate; |
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | |
private String endDate; |
63 | |
|
64 | |
|
65 | |
|
66 | |
|
67 | |
|
68 | |
|
69 | |
private String dateFormat; |
70 | |
|
71 | |
|
72 | |
|
73 | |
|
74 | |
|
75 | |
|
76 | 0 | private String userDateFormat = DEFAULT_DATE_FORMAT; |
77 | |
|
78 | |
|
79 | |
|
80 | |
|
81 | |
|
82 | |
|
83 | |
private String scmVersionType; |
84 | |
|
85 | |
|
86 | |
|
87 | |
|
88 | |
|
89 | |
|
90 | |
private String scmVersion; |
91 | |
|
92 | |
|
93 | |
public void execute() |
94 | |
throws MojoExecutionException |
95 | |
{ |
96 | 0 | super.execute(); |
97 | |
|
98 | 0 | SimpleDateFormat localFormat = new SimpleDateFormat( userDateFormat ); |
99 | |
|
100 | |
try |
101 | |
{ |
102 | 0 | ScmRepository repository = getScmRepository(); |
103 | |
|
104 | 0 | ScmProvider provider = getScmManager().getProviderByRepository( repository ); |
105 | |
|
106 | 0 | ChangeLogScmResult result = provider.changeLog( repository, getFileSet(), |
107 | |
this.parseDate( localFormat, this.startDate ), |
108 | |
this.parseDate( localFormat, this.endDate ), 0, |
109 | |
(ScmBranch) getScmVersion( scmVersionType, scmVersion ), |
110 | |
dateFormat ); |
111 | 0 | checkResult( result ); |
112 | |
|
113 | 0 | ChangeLogSet changeLogSet = result.getChangeLog(); |
114 | |
|
115 | 0 | for ( ChangeSet changeSet : changeLogSet.getChangeSets() ) |
116 | |
{ |
117 | 0 | getLog().info( changeSet.toString() ); |
118 | |
} |
119 | |
|
120 | |
} |
121 | 0 | catch ( IOException e ) |
122 | |
{ |
123 | 0 | throw new MojoExecutionException( "Cannot run changelog command : ", e ); |
124 | |
} |
125 | 0 | catch ( ScmException e ) |
126 | |
{ |
127 | 0 | throw new MojoExecutionException( "Cannot run changelog command : ", e ); |
128 | 0 | } |
129 | 0 | } |
130 | |
|
131 | |
|
132 | |
|
133 | |
|
134 | |
|
135 | |
|
136 | |
private Date parseDate( SimpleDateFormat format, String date ) |
137 | |
throws MojoExecutionException |
138 | |
{ |
139 | 0 | if ( date == null || date.trim().length() == 0 ) |
140 | |
{ |
141 | 0 | return null; |
142 | |
} |
143 | |
|
144 | |
try |
145 | |
{ |
146 | 0 | return format.parse( date.toString() ); |
147 | |
} |
148 | 0 | catch ( ParseException e ) |
149 | |
{ |
150 | 0 | throw new MojoExecutionException( "Please use this date pattern: " + format.toLocalizedPattern().toString(), |
151 | |
e ); |
152 | |
} |
153 | |
} |
154 | |
} |