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 | 0 | 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 | 0 | 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 | 0 | 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 | 0 | super( logger ); |
128 | 0 | this.userDatePattern = userDatePattern; |
129 | 0 | this.repo = repo; |
130 | 0 | } |
131 | |
|
132 | |
public List<ChangeSet> getModifications() |
133 | |
{ |
134 | 0 | return new ArrayList<ChangeSet>( entries.values() ); |
135 | |
} |
136 | |
|
137 | |
|
138 | |
public void consumeLine( String line ) |
139 | |
{ |
140 | 0 | switch ( getLineStatus( line ) ) |
141 | |
{ |
142 | |
case GET_FILE: |
143 | 0 | processGetFile( line ); |
144 | 0 | break; |
145 | |
case GET_REVISION: |
146 | 0 | processGetRevision( line ); |
147 | 0 | break; |
148 | |
case GET_AUTHOR: |
149 | 0 | processGetAuthor( line ); |
150 | 0 | break; |
151 | |
case GET_FILE_PATH: |
152 | 0 | processGetFilePath( line ); |
153 | 0 | break; |
154 | |
case GET_COMMENT: |
155 | 0 | processGetComment( line ); |
156 | 0 | break; |
157 | |
default: |
158 | |
break; |
159 | |
} |
160 | 0 | } |
161 | |
|
162 | |
|
163 | |
|
164 | |
|
165 | |
|
166 | |
|
167 | |
private void processGetComment( String line ) |
168 | |
{ |
169 | 0 | String[] commentLine = line.split( ":" ); |
170 | 0 | if ( commentLine.length == 2 ) |
171 | |
{ |
172 | 0 | currentChangeSet.setComment( commentLine[1] ); |
173 | |
} |
174 | |
|
175 | |
else |
176 | |
{ |
177 | 0 | String comment = currentChangeSet.getComment(); |
178 | 0 | comment = comment + " " + line; |
179 | 0 | currentChangeSet.setComment( comment ); |
180 | |
} |
181 | 0 | } |
182 | |
|
183 | |
|
184 | |
|
185 | |
|
186 | |
|
187 | |
|
188 | |
private void processGetAuthor( String line ) |
189 | |
{ |
190 | 0 | String[] result = line.split( "\\s" ); |
191 | 0 | Vector<String> vector = new Vector<String>(); |
192 | 0 | for ( int i = 0; i < result.length; i++ ) |
193 | |
{ |
194 | 0 | if ( !result[i].equals( "" ) ) |
195 | |
{ |
196 | 0 | vector.add( result[i] ); |
197 | |
} |
198 | |
} |
199 | 0 | currentChangeSet.setAuthor( vector.get( 1 ) ); |
200 | 0 | currentChangeSet.setDate( |
201 | |
parseDate( vector.get( 3 ) + " " + vector.get( 5 ), userDatePattern, "dd.MM.yy HH:mm" ) ); |
202 | 0 | } |
203 | |
|
204 | |
|
205 | |
|
206 | |
|
207 | |
|
208 | |
|
209 | |
private void processGetFile( String line ) |
210 | |
{ |
211 | 0 | currentChangeSet = ( new ChangeSet() ); |
212 | 0 | String[] fileLine = line.split( " " ); |
213 | 0 | currentFile = new ChangeFile( fileLine[2] ); |
214 | 0 | } |
215 | |
|
216 | |
|
217 | |
|
218 | |
|
219 | |
|
220 | |
|
221 | |
private void processGetFilePath( String line ) |
222 | |
{ |
223 | 0 | if ( currentFile != null ) |
224 | |
{ |
225 | 0 | String fileName = currentFile.getName(); |
226 | |
|
227 | 0 | String path = line.substring( line.indexOf( '$' ), line.length() ); |
228 | 0 | String longPath = path.substring( repo.getProject() |
229 | |
.length() + 1, path.length() ) + "/" + fileName; |
230 | 0 | currentFile.setName( longPath ); |
231 | 0 | addEntry( currentChangeSet, currentFile ); |
232 | |
} |
233 | 0 | } |
234 | |
|
235 | |
|
236 | |
|
237 | |
|
238 | |
|
239 | |
|
240 | |
private void processGetRevision( String line ) |
241 | |
{ |
242 | 0 | String[] revisionLine = line.split( " " ); |
243 | 0 | currentFile.setRevision( revisionLine[1] ); |
244 | 0 | } |
245 | |
|
246 | |
|
247 | |
|
248 | |
|
249 | |
|
250 | |
|
251 | |
|
252 | |
private int getLineStatus( String line ) |
253 | |
{ |
254 | 0 | int argument = GET_UNKNOWN; |
255 | 0 | if ( line.startsWith( START_FILE ) ) |
256 | |
{ |
257 | 0 | argument = GET_FILE; |
258 | |
} |
259 | 0 | else if ( line.startsWith( START_REVISION ) ) |
260 | |
{ |
261 | 0 | argument = GET_REVISION; |
262 | |
} |
263 | 0 | else if ( line.startsWith( START_AUTHOR ) ) |
264 | |
{ |
265 | 0 | argument = GET_AUTHOR; |
266 | |
} |
267 | 0 | else if ( line.indexOf( START_FILE_PATH ) != -1 ) |
268 | |
{ |
269 | 0 | argument = GET_FILE_PATH; |
270 | |
} |
271 | 0 | else if ( line.startsWith( START_COMMENT ) ) |
272 | |
{ |
273 | 0 | argument = GET_COMMENT; |
274 | |
} |
275 | 0 | else if ( lastStatus == GET_COMMENT ) |
276 | |
{ |
277 | |
|
278 | 0 | argument = lastStatus; |
279 | |
} |
280 | 0 | lastStatus = argument; |
281 | |
|
282 | 0 | return argument; |
283 | |
} |
284 | |
|
285 | |
|
286 | |
|
287 | |
|
288 | |
|
289 | |
|
290 | |
|
291 | |
|
292 | |
|
293 | |
|
294 | |
private void addEntry( ChangeSet entry, ChangeFile file ) |
295 | |
{ |
296 | |
|
297 | 0 | if ( entry.getAuthor() == null ) |
298 | |
{ |
299 | 0 | return; |
300 | |
} |
301 | |
|
302 | 0 | String key = ENTRY_KEY_TIMESTAMP_FORMAT.format( entry.getDate() ) + entry.getAuthor() + entry.getComment(); |
303 | |
|
304 | 0 | if ( !entries.containsKey( key ) ) |
305 | |
{ |
306 | 0 | entry.addFile( file ); |
307 | 0 | entries.put( key, entry ); |
308 | |
} |
309 | |
else |
310 | |
{ |
311 | 0 | ChangeSet existingEntry = (ChangeSet) entries.get( key ); |
312 | 0 | existingEntry.addFile( file ); |
313 | |
} |
314 | 0 | } |
315 | |
} |