1 package org.apache.maven.scm.provider.clearcase.command.changelog;
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.scm.ChangeFile;
23 import org.apache.maven.scm.ChangeSet;
24 import org.apache.maven.scm.log.ScmLogger;
25 import org.apache.maven.scm.util.AbstractConsumer;
26
27 import java.util.ArrayList;
28 import java.util.List;
29
30
31
32
33
34
35
36 public class ClearCaseChangeLogConsumer
37 extends AbstractConsumer
38 {
39
40
41
42 private static final String CLEARCASE_TIMESTAMP_PATTERN = "yyyyMMdd.HHmmss";
43
44 private static final String NAME_TAG = "NAME:";
45
46 private static final String USER_TAG = "USER:";
47
48 private static final String DATE_TAG = "DATE:";
49
50 private static final String COMMENT_TAG = "COMM:";
51
52 private static final String REVISION_TAG = "REVI:";
53
54 private List<ChangeSet> entries = new ArrayList<ChangeSet>();
55
56
57
58
59
60
61 private static final int GET_FILE = 1;
62
63
64
65
66 private static final int GET_DATE = 2;
67
68
69
70
71 private static final int GET_COMMENT = 3;
72
73
74
75
76 private static final int GET_REVISION = 4;
77
78
79
80
81 private int status = GET_FILE;
82
83
84
85
86 private ChangeSet currentChange = null;
87
88
89
90
91 private ChangeFile currentFile = null;
92
93 private String userDatePattern;
94
95
96
97
98
99 public ClearCaseChangeLogConsumer( ScmLogger logger, String userDatePattern )
100 {
101 super( logger );
102
103 this.userDatePattern = userDatePattern;
104 }
105
106
107
108
109
110 public List<ChangeSet> getModifications()
111 {
112 return entries;
113 }
114
115
116
117
118
119
120 public void consumeLine( String line )
121 {
122 switch ( getStatus() )
123 {
124 case GET_FILE:
125 processGetFile( line );
126 break;
127 case GET_DATE:
128 processGetDate( line );
129 break;
130 case GET_COMMENT:
131 processGetCommentAndUser( line );
132 break;
133 case GET_REVISION:
134 processGetRevision( line );
135 break;
136 default:
137 if ( getLogger().isWarnEnabled() )
138 {
139 getLogger().warn( "Unknown state: " + status );
140 }
141 }
142 }
143
144
145
146
147
148
149
150
151
152
153 private void processGetFile( String line )
154 {
155 if ( line.startsWith( NAME_TAG ) )
156 {
157 setCurrentChange( new ChangeSet() );
158 setCurrentFile( new ChangeFile( line.substring( NAME_TAG.length(), line.length() ) ) );
159 setStatus( GET_DATE );
160 }
161 }
162
163
164
165
166
167
168 private void processGetDate( String line )
169 {
170 if ( line.startsWith( DATE_TAG ) )
171 {
172 getCurrentChange().setDate(
173 parseDate( line.substring( DATE_TAG.length() ), userDatePattern, CLEARCASE_TIMESTAMP_PATTERN ) );
174
175 setStatus( GET_COMMENT );
176 }
177 }
178
179
180
181
182
183
184 private void processGetCommentAndUser( String line )
185 {
186 if ( line.startsWith( COMMENT_TAG ) )
187 {
188 String comm = line.substring( COMMENT_TAG.length() );
189
190 getCurrentChange().setComment( getCurrentChange().getComment() + comm + "\n" );
191 }
192 else if ( line.startsWith( USER_TAG ) )
193 {
194 getCurrentChange().setAuthor( line.substring( USER_TAG.length() ) );
195
196
197 getCurrentChange().addFile( getCurrentFile() );
198
199 entries.add( getCurrentChange() );
200
201 setStatus( GET_REVISION );
202 }
203 else
204 {
205
206 getCurrentChange().setComment( getCurrentChange().getComment() + line + "\n" );
207 }
208 }
209
210
211
212
213
214
215 private void processGetRevision( String line )
216 {
217 if ( line.startsWith( REVISION_TAG ) )
218 {
219 getCurrentChange().setRevision( line.substring( REVISION_TAG.length() ) );
220
221 setStatus( GET_FILE );
222 }
223 }
224
225
226
227
228
229
230 private ChangeFile getCurrentFile()
231 {
232 return currentFile;
233 }
234
235
236
237
238
239
240 private void setCurrentFile( ChangeFile currentFile )
241 {
242 this.currentFile = currentFile;
243 }
244
245
246
247
248
249
250 private ChangeSet getCurrentChange()
251 {
252 return currentChange;
253 }
254
255
256
257
258
259
260 private void setCurrentChange( ChangeSet currentChange )
261 {
262 this.currentChange = currentChange;
263 }
264
265
266
267
268
269
270 private int getStatus()
271 {
272 return status;
273 }
274
275
276
277
278
279
280 private void setStatus( int status )
281 {
282 this.status = status;
283 }
284 }