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 org.apache.maven.plugin.MojoExecutionException; |
23 | |
import org.apache.maven.scm.ChangeSet; |
24 | |
import org.apache.maven.scm.ScmBranch; |
25 | |
import org.apache.maven.scm.ScmException; |
26 | |
import org.apache.maven.scm.command.changelog.ChangeLogScmResult; |
27 | |
import org.apache.maven.scm.command.changelog.ChangeLogSet; |
28 | |
import org.apache.maven.scm.provider.ScmProvider; |
29 | |
import org.apache.maven.scm.repository.ScmRepository; |
30 | |
|
31 | |
import java.io.IOException; |
32 | |
import java.text.ParseException; |
33 | |
import java.text.SimpleDateFormat; |
34 | |
import java.util.Date; |
35 | |
import java.util.Iterator; |
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | 4 | 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 | 4 | 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 | |
public void execute() |
93 | |
throws MojoExecutionException |
94 | |
{ |
95 | 4 | super.execute(); |
96 | |
|
97 | 4 | SimpleDateFormat localFormat = new SimpleDateFormat( userDateFormat ); |
98 | |
|
99 | |
try |
100 | |
{ |
101 | 4 | ScmRepository repository = getScmRepository(); |
102 | |
|
103 | 4 | ScmProvider provider = getScmManager().getProviderByRepository( repository ); |
104 | |
|
105 | 4 | ChangeLogScmResult result = provider.changeLog( repository, getFileSet(), |
106 | |
this.parseDate( localFormat, this.startDate ), |
107 | |
this.parseDate( localFormat, this.endDate ), 0, |
108 | |
(ScmBranch) getScmVersion( scmVersionType, scmVersion ), |
109 | |
dateFormat ); |
110 | 3 | checkResult( result ); |
111 | |
|
112 | 2 | ChangeLogSet changeLogSet = result.getChangeLog(); |
113 | |
|
114 | 2 | for ( Iterator i = changeLogSet.getChangeSets().iterator(); i.hasNext(); ) |
115 | |
{ |
116 | 15 | ChangeSet changeSet = (ChangeSet) i.next(); |
117 | |
|
118 | 15 | System.out.println( changeSet.toString() ); |
119 | 15 | } |
120 | |
|
121 | |
} |
122 | 0 | catch ( IOException e ) |
123 | |
{ |
124 | 0 | throw new MojoExecutionException( "Cannot run changelog command : ", e ); |
125 | |
} |
126 | 0 | catch ( ScmException e ) |
127 | |
{ |
128 | 0 | throw new MojoExecutionException( "Cannot run changelog command : ", e ); |
129 | 2 | } |
130 | 2 | } |
131 | |
|
132 | |
|
133 | |
|
134 | |
|
135 | |
|
136 | |
|
137 | |
private Date parseDate( SimpleDateFormat format, String date ) |
138 | |
throws MojoExecutionException |
139 | |
{ |
140 | 7 | if ( date == null || date.trim().length() == 0 ) |
141 | |
{ |
142 | 4 | return null; |
143 | |
} |
144 | |
|
145 | |
try |
146 | |
{ |
147 | 3 | return format.parse( date.toString() ); |
148 | |
} |
149 | 1 | catch ( ParseException e ) |
150 | |
{ |
151 | 1 | throw new MojoExecutionException( "Please use this date pattern: " + format.toLocalizedPattern().toString(), |
152 | |
e ); |
153 | |
} |
154 | |
} |
155 | |
} |