1 package org.apache.maven.scm.provider.cvslib.command.status;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.File;
23 import java.util.ArrayList;
24 import java.util.List;
25
26 import org.apache.maven.scm.ScmFile;
27 import org.apache.maven.scm.ScmFileStatus;
28 import org.apache.maven.scm.log.ScmLogger;
29 import org.codehaus.plexus.util.StringUtils;
30 import org.codehaus.plexus.util.cli.StreamConsumer;
31
32
33
34
35
36 public class CvsStatusConsumer
37 implements StreamConsumer
38 {
39 private ScmLogger logger;
40
41 private File workingDirectory;
42
43 private List<ScmFile> changedFiles = new ArrayList<ScmFile>();
44
45
46
47
48
49 public CvsStatusConsumer( ScmLogger logger, File workingDirectory )
50 {
51 this.logger = logger;
52
53 this.workingDirectory = workingDirectory;
54 }
55
56
57
58
59
60
61 public void consumeLine( String line )
62 {
63 if ( logger.isDebugEnabled() )
64 {
65 logger.debug( line );
66 }
67
68 if ( line.length() < 3 )
69 {
70 if ( StringUtils.isNotEmpty( line ) )
71 {
72 if ( logger.isWarnEnabled() )
73 {
74 logger.warn( "Unable to parse output from command: line length must be bigger than 3. ("
75 + line + ")." );
76 }
77 }
78 return;
79 }
80
81 String statusString = line.substring( 0, 1 );
82
83 String file = line.substring( 2 );
84
85 ScmFileStatus status;
86
87 if ( statusString.equals( "A" ) )
88 {
89 status = ScmFileStatus.ADDED;
90 }
91 else if ( statusString.equals( "M" ) )
92 {
93 status = ScmFileStatus.MODIFIED;
94 }
95 else if ( statusString.equals( "D" ) )
96 {
97 status = ScmFileStatus.DELETED;
98 }
99 else if ( statusString.equals( "C" ) )
100 {
101 status = ScmFileStatus.CONFLICT;
102 }
103 else if ( statusString.equals( "?" ) )
104 {
105 status = ScmFileStatus.UNKNOWN;
106 }
107 else if ( statusString.equals( "U" ) || statusString.equals( "P" ) )
108 {
109
110 return;
111 }
112 else
113 {
114 if ( logger.isInfoEnabled() )
115 {
116 logger.info( "Unknown file status: '" + statusString + "'." );
117 }
118
119 return;
120 }
121
122
123 if ( !status.equals( ScmFileStatus.DELETED ) && !new File( workingDirectory, file ).isFile() )
124 {
125 return;
126 }
127
128 changedFiles.add( new ScmFile( file, status ) );
129 }
130
131 public List<ScmFile> getChangedFiles()
132 {
133 return changedFiles;
134 }
135 }