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