1 package org.apache.maven.scm.provider.jazz.command.status;
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.ScmFile;
23 import org.apache.maven.scm.ScmFileStatus;
24 import org.apache.maven.scm.log.ScmLogger;
25 import org.apache.maven.scm.provider.ScmProviderRepository;
26 import org.apache.maven.scm.provider.jazz.command.consumer.AbstractRepositoryConsumer;
27 import org.apache.maven.scm.provider.jazz.repository.JazzScmProviderRepository;
28
29 import java.util.ArrayList;
30 import java.util.List;
31 import java.util.regex.Matcher;
32 import java.util.regex.Pattern;
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51 public class JazzStatusConsumer
52 extends AbstractRepositoryConsumer
53 {
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169 private static final Pattern WORKSPACE_PATTERN =
170 Pattern.compile( "\\((\\d+)\\) \"(.*)\" <-> \\((\\d+)\\) \"(.*)\"" );
171
172
173 private static final Pattern COMPONENT_PATTERN1 = Pattern.compile( "\\((\\d+)\\) \"(.*)\"" );
174
175
176
177 private static final Pattern COMPONENT_PATTERN2 = Pattern.compile( "\\((\\d+)\\) \"(.*)\" <.*>" );
178
179
180 private static final Pattern BASELINE_PATTERN = Pattern.compile( "\\((\\d+)\\) (\\d+) \"(.*)\"" );
181
182
183 private static final Pattern CHANGESET_PATTERN = Pattern.compile( "\\((\\d+)\\) (.*)" );
184
185
186
187
188
189
190
191
192 public static final String STATUS_CMD_WORKSPACE = "Workspace:";
193
194
195
196
197 public static final String STATUS_CMD_COMPONENT = "Component:";
198
199
200
201
202 public static final String STATUS_CMD_BASELINE = "Baseline:";
203
204
205
206
207 public static final String STATUS_CMD_OUTGOING = "Outgoing:";
208
209
210
211
212 public static final String STATUS_CMD_INCOMING = "Incoming:";
213
214
215
216
217
218 public static final String STATUS_CMD_CHANGE_SETS = "Change sets:";
219
220
221
222
223 public static final String STATUS_CMD_BASELINES = "Baselines:";
224
225
226
227
228
229
230 public static final String STATUS_CMD_ADD_FLAG = "a-";
231
232
233
234
235
236 public static final String STATUS_CMD_CHANGE_FLAG = "-c";
237
238
239
240
241 public static final String STATUS_CMD_DELETE_FLAG = "d-";
242
243
244
245
246 public static final String STATUS_CMD_MOVED_FLAG = "m-";
247
248
249
250
251 private List<ScmFile> fChangedFiles = new ArrayList<ScmFile>();
252
253
254
255
256 private boolean seenOutgoingChangeSets = false;
257
258
259
260
261 private boolean seenIncomingChangeSets = false;
262
263
264
265
266
267
268
269 public JazzStatusConsumer( ScmProviderRepository repo, ScmLogger logger )
270 {
271 super( repo, logger );
272 }
273
274
275
276
277
278
279
280 public void consumeLine( String line )
281 {
282 super.consumeLine( line );
283 if ( containsWorkspace( line ) )
284 {
285 extractWorkspace( line );
286 }
287 if ( containsComponent( line ) )
288 {
289 extractComponent( line );
290 }
291 if ( containsBaseline( line ) )
292 {
293 extractBaseline( line );
294 }
295 if ( containsStatusFlag( line ) )
296 {
297 extractChangedFile( line );
298 }
299 if ( containsOutgoing( line ) )
300 {
301
302 seenOutgoingChangeSets = true;
303 seenIncomingChangeSets = false;
304 }
305 if ( containsIncoming( line ) )
306 {
307
308 seenOutgoingChangeSets = false;
309 seenIncomingChangeSets = true;
310 }
311 if ( containsBaselines( line ) )
312 {
313
314 seenOutgoingChangeSets = false;
315 seenIncomingChangeSets = false;
316 }
317 if ( seenOutgoingChangeSets )
318 {
319 Integer changeSetAlias = extractChangeSetAlias( line );
320 if ( changeSetAlias != null )
321 {
322
323
324
325
326
327
328 JazzScmProviderRepository jazzRepository = (JazzScmProviderRepository) getRepository();
329 jazzRepository.getOutgoingChangeSetAliases().add( new Integer( changeSetAlias ) );
330 }
331 }
332 if ( seenIncomingChangeSets )
333 {
334 Integer changeSetAlias = extractChangeSetAlias( line );
335 if ( changeSetAlias != null )
336 {
337
338
339
340
341
342
343 JazzScmProviderRepository jazzRepository = (JazzScmProviderRepository) getRepository();
344 jazzRepository.getIncomingChangeSetAliases().add( new Integer( changeSetAlias ) );
345 }
346 }
347 }
348
349 private boolean containsWorkspace( String line )
350 {
351 return line.trim().startsWith( STATUS_CMD_WORKSPACE );
352 }
353
354 private void extractWorkspace( String line )
355 {
356
357
358
359
360
361 Matcher matcher = WORKSPACE_PATTERN.matcher( line );
362 if ( matcher.find() )
363 {
364 JazzScmProviderRepository jazzRepository = (JazzScmProviderRepository) getRepository();
365
366 int workspaceAlias = Integer.parseInt( matcher.group( 1 ) );
367 String workspace = matcher.group( 2 );
368 int streamAlias = Integer.parseInt( matcher.group( 3 ) );
369 String stream = matcher.group( 4 );
370 if ( getLogger().isDebugEnabled() )
371 {
372 getLogger().debug( "Successfully parsed \"Workspace:\" line:" );
373 getLogger().debug( " workspaceAlias = " + workspaceAlias );
374 getLogger().debug( " workspace = " + workspace );
375 getLogger().debug( " streamAlias = " + streamAlias );
376 getLogger().debug( " stream = " + stream );
377 }
378 jazzRepository.setWorkspaceAlias( workspaceAlias );
379 jazzRepository.setWorkspace( workspace );
380 jazzRepository.setFlowTargetAlias( streamAlias );
381 jazzRepository.setFlowTarget( stream );
382 }
383 }
384
385 private boolean containsComponent( String line )
386 {
387 return line.trim().startsWith( STATUS_CMD_COMPONENT );
388 }
389
390 private void extractComponent( String line )
391 {
392
393
394
395
396
397
398
399 Matcher matcher = COMPONENT_PATTERN1.matcher( line );
400 if ( matcher.find() )
401 {
402
403 JazzScmProviderRepository jazzRepository = (JazzScmProviderRepository) getRepository();
404 int componentAlias = Integer.parseInt( matcher.group( 1 ) );
405 String component = matcher.group( 2 );
406 if ( getLogger().isDebugEnabled() )
407 {
408 getLogger().debug( "Successfully parsed \"Component:\" line:" );
409 getLogger().debug( " componentAlias = " + componentAlias );
410 getLogger().debug( " component = " + component );
411 }
412 jazzRepository.setComponent( component );
413 }
414
415 matcher = COMPONENT_PATTERN2.matcher( line );
416 if ( matcher.find() )
417 {
418
419 JazzScmProviderRepository jazzRepository = (JazzScmProviderRepository) getRepository();
420 int componentAlias = Integer.parseInt( matcher.group( 1 ) );
421 String component = matcher.group( 2 );
422 if ( getLogger().isDebugEnabled() )
423 {
424 getLogger().debug( "Successfully parsed \"Component:\" line:" );
425 getLogger().debug( " componentAlias = " + componentAlias );
426 getLogger().debug( " component = " + component );
427 }
428 jazzRepository.setComponent( component );
429 }
430 }
431
432 private boolean containsBaseline( String line )
433 {
434 return line.trim().startsWith( STATUS_CMD_BASELINE );
435 }
436
437 private void extractBaseline( String line )
438 {
439
440
441 Matcher matcher = BASELINE_PATTERN.matcher( line );
442 if ( matcher.find() )
443 {
444 JazzScmProviderRepository jazzRepository = (JazzScmProviderRepository) getRepository();
445
446 int baselineAlias = Integer.parseInt( matcher.group( 1 ) );
447 int baselineId = Integer.parseInt( matcher.group( 2 ) );
448 String baseline = matcher.group( 3 );
449 if ( getLogger().isDebugEnabled() )
450 {
451 getLogger().debug( "Successfully parsed \"Baseline:\" line:" );
452 getLogger().debug( " baselineAlias = " + baselineAlias );
453 getLogger().debug( " baselineId = " + baselineId );
454 getLogger().debug( " baseline = " + baseline );
455 }
456 jazzRepository.setBaseline( baseline );
457 }
458 }
459
460 private boolean containsStatusFlag( String line )
461 {
462 boolean containsStatusFlag = false;
463
464 if ( line.trim().length() > 2 )
465 {
466 String flag = line.trim().substring( 0, 2 );
467 if ( STATUS_CMD_ADD_FLAG.equals( flag ) || STATUS_CMD_CHANGE_FLAG.equals( flag )
468 || STATUS_CMD_DELETE_FLAG.equals( flag ) )
469 {
470 containsStatusFlag = true;
471 }
472 }
473 return containsStatusFlag;
474 }
475
476 private void extractChangedFile( String line )
477 {
478 String flag = line.trim().substring( 0, 2 );
479 String filePath = line.trim().substring( 3 ).trim();
480 ScmFileStatus status = ScmFileStatus.UNKNOWN;
481
482 if ( STATUS_CMD_ADD_FLAG.equals( flag ) )
483 {
484 status = ScmFileStatus.ADDED;
485 }
486
487 if ( STATUS_CMD_CHANGE_FLAG.equals( flag ) )
488 {
489 status = ScmFileStatus.MODIFIED;
490 }
491
492 if ( STATUS_CMD_DELETE_FLAG.equals( flag ) )
493 {
494 status = ScmFileStatus.DELETED;
495 }
496
497 if ( getLogger().isDebugEnabled() )
498 {
499 getLogger().debug( " Extracted filePath : '" + filePath + "'" );
500 getLogger().debug( " Extracted flag : '" + flag + "'" );
501 getLogger().debug( " Extracted status : '" + status + "'" );
502 }
503
504 fChangedFiles.add( new ScmFile( filePath, status ) );
505 }
506
507 public List<ScmFile> getChangedFiles()
508 {
509 return fChangedFiles;
510 }
511
512 private boolean containsOutgoing( String line )
513 {
514 return line.trim().startsWith( STATUS_CMD_OUTGOING );
515 }
516
517 private boolean containsIncoming( String line )
518 {
519 return line.trim().startsWith( STATUS_CMD_INCOMING );
520 }
521
522 private boolean containsBaselines( String line )
523 {
524 return line.trim().startsWith( STATUS_CMD_BASELINES );
525 }
526
527
528
529
530
531
532
533 private Integer extractChangeSetAlias( String line )
534 {
535
536
537 Matcher matcher = CHANGESET_PATTERN.matcher( line );
538 if ( matcher.find() )
539 {
540 int changeSetAlias = Integer.parseInt( matcher.group( 1 ) );
541 if ( getLogger().isDebugEnabled() )
542 {
543 getLogger().debug( "Successfully parsed post \"Change sets:\" line:" );
544 getLogger().debug( " changeSetAlias = " + changeSetAlias );
545 }
546 return new Integer( changeSetAlias );
547 }
548 else
549 {
550 return null;
551 }
552 }
553 }