1 package org.apache.maven.scm.provider.cvslib.command.checkout;
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.codehaus.plexus.util.StringUtils;
26 import org.codehaus.plexus.util.cli.StreamConsumer;
27
28 import java.util.ArrayList;
29 import java.util.List;
30
31
32
33
34
35
36 public class CvsCheckOutConsumer
37 implements StreamConsumer
38 {
39 private ScmLogger logger;
40
41 private List<ScmFile> files = new ArrayList<ScmFile>();
42
43 public CvsCheckOutConsumer( ScmLogger logger )
44 {
45 this.logger = logger;
46 }
47
48
49 public void consumeLine( String line )
50 {
51 if ( logger.isDebugEnabled() )
52 {
53 logger.debug( line );
54 }
55
56 if ( line.length() < 3 )
57 {
58 if ( StringUtils.isNotEmpty( line ) )
59 {
60 if ( logger.isWarnEnabled() )
61 {
62 logger.warn( "Unable to parse output from command: line length must be bigger than 3. ("
63 + line + ")." );
64 }
65 }
66 return;
67 }
68
69 String status = line.substring( 0, 2 );
70
71 String file = line.substring( 2 );
72
73 file = file.substring( file.indexOf( '/' ) );
74
75 if ( status.equals( "U " ) )
76 {
77 files.add( new ScmFile( file, ScmFileStatus.UPDATED ) );
78 }
79 else if ( status.equals( "P " ) )
80 {
81 files.add( new ScmFile( file, ScmFileStatus.PATCHED ) );
82 }
83 else if ( status.equals( "C " ) )
84 {
85 files.add( new ScmFile( file, ScmFileStatus.CONFLICT ) );
86 }
87 else
88 {
89 if ( logger.isWarnEnabled() )
90 {
91 logger.warn( "Unknown status: '" + status + "'." );
92 }
93 }
94 }
95
96 public List<ScmFile> getCheckedOutFiles()
97 {
98 return files;
99 }
100 }