1 package org.apache.maven.scm.provider.vss.commands.status;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.util.ArrayList;
23 import java.util.List;
24
25 import org.apache.maven.scm.ScmFile;
26 import org.apache.maven.scm.ScmFileSet;
27 import org.apache.maven.scm.ScmFileStatus;
28 import org.apache.maven.scm.log.ScmLogger;
29 import org.apache.maven.scm.provider.vss.repository.VssScmProviderRepository;
30 import org.apache.maven.scm.util.AbstractConsumer;
31 import org.codehaus.plexus.util.cli.StreamConsumer;
32
33
34
35
36
37 public class VssStatusConsumer
38 extends AbstractConsumer
39 implements StreamConsumer
40 {
41
42
43
44
45 private static final int DIFF_UNKNOWN = 0;
46
47
48
49
50 private static final int DIFF_LOCAL_FILES_NOT_IN_PROJECT = 1;
51
52
53
54
55 private static final int DIFF_VSS_FILES_DIFFERENT_FROM_LOCAL_FILES = 2;
56
57
58
59
60 private static final int DIFF_VSS_FILES_NOT_IN_CURRENT_FOLDER = 3;
61
62
63
64
65 private static final int DIFF_START_DIFFING_REMOTE = 4;
66
67
68
69
70 private static final int DIFF_START_DIFFING_LOCAL = 5;
71
72
73
74
75 private static final String START_DIFFING_REMOTE = "Diffing:";
76
77
78
79
80 private static final String START_DIFFING_LOCAL = "Against:";
81
82
83
84
85 private static final String LOCAL_FILES_NOT_IN_PROJECT = "Local files not in the current project:";
86
87
88
89
90 private static final String VSS_FILES_DIFFERENT_FROM_LOCAL_FILES = "SourceSafe files different from local files:";
91
92
93
94
95 private static final String VSS_FILES_NOT_IN_CURRENT_FOLDER = "SourceSafe files not in the current folder:";
96
97 private String remoteProjectFolder = "";
98
99 private String localFolder = "";
100
101 private int lastState = 0;
102
103 private List<ScmFile> updatedFiles = new ArrayList<ScmFile>();
104
105 @SuppressWarnings( "unused" )
106 private VssScmProviderRepository repo;
107
108 @SuppressWarnings( "unused" )
109 private ScmFileSet fileSet;
110
111 public VssStatusConsumer( VssScmProviderRepository repo, ScmLogger logger, ScmFileSet fileSet )
112 {
113 super( logger );
114 this.repo = repo;
115 this.fileSet = fileSet;
116 }
117
118
119 public void consumeLine( String line )
120 {
121 if ( getLogger().isDebugEnabled() )
122 {
123 getLogger().debug( line );
124 }
125
126 switch ( getLineStatus( line ) )
127 {
128 case DIFF_LOCAL_FILES_NOT_IN_PROJECT:
129 lastState = DIFF_LOCAL_FILES_NOT_IN_PROJECT;
130 break;
131 case DIFF_VSS_FILES_DIFFERENT_FROM_LOCAL_FILES:
132 lastState = DIFF_VSS_FILES_DIFFERENT_FROM_LOCAL_FILES;
133 break;
134 case DIFF_VSS_FILES_NOT_IN_CURRENT_FOLDER:
135 lastState = DIFF_VSS_FILES_NOT_IN_CURRENT_FOLDER;
136 break;
137 case DIFF_START_DIFFING_LOCAL:
138 lastState = DIFF_START_DIFFING_LOCAL;
139 processLocalFolder( line );
140 break;
141 case DIFF_START_DIFFING_REMOTE:
142 lastState = DIFF_START_DIFFING_REMOTE;
143 processRemoteProjectFolder( line );
144 break;
145 default:
146 processLastStateFiles( line );
147 break;
148 }
149 }
150
151
152
153
154
155
156 private void processLastStateFiles( String line )
157 {
158
159 if ( line != null && line.trim().length() > 0 )
160 {
161 if ( lastState == DIFF_START_DIFFING_LOCAL )
162 {
163 setLocalFolder( localFolder + line );
164 getLogger().debug( "Local folder: " + localFolder );
165 }
166 else if ( lastState == DIFF_START_DIFFING_REMOTE )
167 {
168 setRemoteProjectFolder( remoteProjectFolder + line );
169 getLogger().debug( "Remote folder: " + localFolder );
170 }
171
172 String[] fileLine = line.split( " " );
173 for ( int i = 0; i < fileLine.length; i++ )
174 {
175 if ( fileLine[i].trim().length() > 0 )
176 {
177 if ( lastState == DIFF_LOCAL_FILES_NOT_IN_PROJECT )
178 {
179 updatedFiles.add( new ScmFile( localFolder + fileLine[i], ScmFileStatus.ADDED ) );
180 }
181 else if ( lastState == DIFF_VSS_FILES_NOT_IN_CURRENT_FOLDER )
182 {
183 updatedFiles.add( new ScmFile( localFolder + fileLine[i], ScmFileStatus.UPDATED ) );
184 }
185 else if ( lastState == DIFF_VSS_FILES_DIFFERENT_FROM_LOCAL_FILES )
186 {
187 updatedFiles.add( new ScmFile( localFolder + fileLine[i], ScmFileStatus.MODIFIED ) );
188 }
189
190 if ( getLogger().isDebugEnabled() )
191 {
192 getLogger().debug( localFolder + fileLine[i] );
193 }
194 }
195 }
196 }
197 else
198 {
199 if ( getLogger().isDebugEnabled() )
200 {
201 getLogger().debug( "processLastStateFiles: empty line" );
202 }
203 }
204
205 }
206
207
208
209
210
211
212 private void processLocalFolder( String line )
213 {
214
215 setLocalFolder( line.substring( START_DIFFING_LOCAL.length() ).trim() );
216
217 }
218
219
220
221
222
223
224 private void processRemoteProjectFolder( String line )
225 {
226
227 setRemoteProjectFolder( line.substring( START_DIFFING_REMOTE.length() ).trim() );
228
229 }
230
231
232
233
234
235
236
237 private int getLineStatus( String line )
238 {
239 int argument = DIFF_UNKNOWN;
240 if ( line.startsWith( LOCAL_FILES_NOT_IN_PROJECT ) )
241 {
242 argument = DIFF_LOCAL_FILES_NOT_IN_PROJECT;
243 }
244 else if ( line.startsWith( VSS_FILES_DIFFERENT_FROM_LOCAL_FILES ) )
245 {
246 argument = DIFF_VSS_FILES_DIFFERENT_FROM_LOCAL_FILES;
247 }
248 else if ( line.startsWith( VSS_FILES_NOT_IN_CURRENT_FOLDER ) )
249 {
250 argument = DIFF_VSS_FILES_NOT_IN_CURRENT_FOLDER;
251 }
252
253
254
255
256
257
258 else if ( line.startsWith( START_DIFFING_LOCAL ) )
259 {
260 argument = DIFF_START_DIFFING_LOCAL;
261 }
262 else if ( line.startsWith( START_DIFFING_REMOTE ) )
263 {
264 argument = DIFF_START_DIFFING_REMOTE;
265 }
266
267 return argument;
268 }
269
270 public List<ScmFile> getUpdatedFiles()
271 {
272 return updatedFiles;
273 }
274
275 private void setLocalFolder( String localFolder )
276 {
277 if ( localFolder != null && localFolder.trim().length() > 0 )
278 {
279 this.localFolder = localFolder.replace( java.io.File.separatorChar, '/' ) + "/";
280 }
281 else
282 {
283 this.localFolder = "";
284 }
285 }
286
287 private void setRemoteProjectFolder( String remoteProjectFolder )
288 {
289 this.remoteProjectFolder = remoteProjectFolder;
290 }
291
292 }