1 package org.apache.maven.scm.provider.vss.commands.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.provider.vss.repository.VssScmProviderRepository;
26 import org.apache.maven.scm.util.AbstractConsumer;
27
28 import java.text.SimpleDateFormat;
29 import java.util.ArrayList;
30 import java.util.Collections;
31 import java.util.List;
32 import java.util.Map;
33 import java.util.TreeMap;
34 import java.util.Vector;
35
36
37
38
39
40
41 public class VssChangeLogConsumer
42 extends AbstractConsumer
43 {
44
45
46
47
48 private static final SimpleDateFormat ENTRY_KEY_TIMESTAMP_FORMAT = new SimpleDateFormat( "yyyyMMddHHmm" );
49
50
51
52
53
54
55 private static final int GET_FILE = 1;
56
57
58
59
60 private static final int GET_FILE_PATH = 2;
61
62
63
64
65 private static final int GET_AUTHOR = 3;
66
67
68
69
70 private static final int GET_COMMENT = 4;
71
72
73
74
75 private static final int GET_REVISION = 5;
76
77
78
79
80 private static final int GET_UNKNOWN = 6;
81
82
83
84
85 private static final String START_FILE = "***** ";
86
87
88
89
90 private static final String START_FILE_PATH = "$/";
91
92
93
94
95 private static final String START_REVISION = "Version";
96
97
98
99
100 private static final String START_AUTHOR = "User: ";
101
102
103
104
105 private static final String START_COMMENT = "Comment: ";
106
107
108
109
110 private Map<String, ChangeSet> entries = new TreeMap<String, ChangeSet>( Collections.reverseOrder() );
111
112 private ChangeFile currentFile;
113
114 private ChangeSet currentChangeSet;
115
116
117
118
119 private int lastStatus = GET_FILE;
120
121 private VssScmProviderRepository repo;
122
123 private String userDatePattern;
124
125 public VssChangeLogConsumer( VssScmProviderRepository repo, String userDatePattern, ScmLogger logger )
126 {
127 super( logger );
128 this.userDatePattern = userDatePattern;
129 this.repo = repo;
130 }
131
132 public List<ChangeSet> getModifications()
133 {
134 return new ArrayList<ChangeSet>( entries.values() );
135 }
136
137
138 public void consumeLine( String line )
139 {
140 switch ( getLineStatus( line ) )
141 {
142 case GET_FILE:
143 processGetFile( line );
144 break;
145 case GET_REVISION:
146 processGetRevision( line );
147 break;
148 case GET_AUTHOR:
149 processGetAuthor( line );
150 break;
151 case GET_FILE_PATH:
152 processGetFilePath( line );
153 break;
154 case GET_COMMENT:
155 processGetComment( line );
156 break;
157 default:
158 break;
159 }
160 }
161
162
163
164
165
166
167 private void processGetComment( String line )
168 {
169 String[] commentLine = line.split( ":" );
170 if ( commentLine.length == 2 )
171 {
172 currentChangeSet.setComment( commentLine[1] );
173 }
174
175 else
176 {
177 String comment = currentChangeSet.getComment();
178 comment = comment + " " + line;
179 currentChangeSet.setComment( comment );
180 }
181 }
182
183
184
185
186
187
188 private void processGetAuthor( String line )
189 {
190 String[] result = line.split( "\\s" );
191 Vector<String> vector = new Vector<String>();
192 for ( int i = 0; i < result.length; i++ )
193 {
194 if ( !result[i].equals( "" ) )
195 {
196 vector.add( result[i] );
197 }
198 }
199 currentChangeSet.setAuthor( vector.get( 1 ) );
200 currentChangeSet.setDate(
201 parseDate( vector.get( 3 ) + " " + vector.get( 5 ), userDatePattern, "dd.MM.yy HH:mm" ) );
202 }
203
204
205
206
207
208
209 private void processGetFile( String line )
210 {
211 currentChangeSet = ( new ChangeSet() );
212 String[] fileLine = line.split( " " );
213 currentFile = new ChangeFile( fileLine[2] );
214 }
215
216
217
218
219
220
221 private void processGetFilePath( String line )
222 {
223 if ( currentFile != null )
224 {
225 String fileName = currentFile.getName();
226
227 String path = line.substring( line.indexOf( '$' ), line.length() );
228 String longPath = path.substring( repo.getProject()
229 .length() + 1, path.length() ) + "/" + fileName;
230 currentFile.setName( longPath );
231 addEntry( currentChangeSet, currentFile );
232 }
233 }
234
235
236
237
238
239
240 private void processGetRevision( String line )
241 {
242 String[] revisionLine = line.split( " " );
243 currentFile.setRevision( revisionLine[1] );
244 }
245
246
247
248
249
250
251
252 private int getLineStatus( String line )
253 {
254 int argument = GET_UNKNOWN;
255 if ( line.startsWith( START_FILE ) )
256 {
257 argument = GET_FILE;
258 }
259 else if ( line.startsWith( START_REVISION ) )
260 {
261 argument = GET_REVISION;
262 }
263 else if ( line.startsWith( START_AUTHOR ) )
264 {
265 argument = GET_AUTHOR;
266 }
267 else if ( line.indexOf( START_FILE_PATH ) != -1 )
268 {
269 argument = GET_FILE_PATH;
270 }
271 else if ( line.startsWith( START_COMMENT ) )
272 {
273 argument = GET_COMMENT;
274 }
275 else if ( lastStatus == GET_COMMENT )
276 {
277
278 argument = lastStatus;
279 }
280 lastStatus = argument;
281
282 return argument;
283 }
284
285
286
287
288
289
290
291
292
293
294 private void addEntry( ChangeSet entry, ChangeFile file )
295 {
296
297 if ( entry.getAuthor() == null )
298 {
299 return;
300 }
301
302 String key = ENTRY_KEY_TIMESTAMP_FORMAT.format( entry.getDate() ) + entry.getAuthor() + entry.getComment();
303
304 if ( !entries.containsKey( key ) )
305 {
306 entry.addFile( file );
307 entries.put( key, entry );
308 }
309 else
310 {
311 ChangeSet existingEntry = (ChangeSet) entries.get( key );
312 existingEntry.addFile( file );
313 }
314 }
315 }