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 | 1 | private String remoteProjectFolder = ""; |
98 | |
|
99 | 1 | private String localFolder = ""; |
100 | |
|
101 | 1 | private int lastState = 0; |
102 | |
|
103 | 1 | 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 | 1 | super( logger ); |
114 | 1 | this.repo = repo; |
115 | 1 | this.fileSet = fileSet; |
116 | 1 | } |
117 | |
|
118 | |
|
119 | |
public void consumeLine( String line ) |
120 | |
{ |
121 | 136 | if ( getLogger().isDebugEnabled() ) |
122 | |
{ |
123 | 0 | getLogger().debug( line ); |
124 | |
} |
125 | |
|
126 | 136 | switch ( getLineStatus( line ) ) |
127 | |
{ |
128 | |
case DIFF_LOCAL_FILES_NOT_IN_PROJECT: |
129 | 1 | lastState = DIFF_LOCAL_FILES_NOT_IN_PROJECT; |
130 | 1 | break; |
131 | |
case DIFF_VSS_FILES_DIFFERENT_FROM_LOCAL_FILES: |
132 | 0 | lastState = DIFF_VSS_FILES_DIFFERENT_FROM_LOCAL_FILES; |
133 | 0 | break; |
134 | |
case DIFF_VSS_FILES_NOT_IN_CURRENT_FOLDER: |
135 | 0 | lastState = DIFF_VSS_FILES_NOT_IN_CURRENT_FOLDER; |
136 | 0 | break; |
137 | |
case DIFF_START_DIFFING_LOCAL: |
138 | 29 | lastState = DIFF_START_DIFFING_LOCAL; |
139 | 29 | processLocalFolder( line ); |
140 | 29 | break; |
141 | |
case DIFF_START_DIFFING_REMOTE: |
142 | 29 | lastState = DIFF_START_DIFFING_REMOTE; |
143 | 29 | processRemoteProjectFolder( line ); |
144 | 29 | break; |
145 | |
default: |
146 | 77 | processLastStateFiles( line ); |
147 | |
break; |
148 | |
} |
149 | 136 | } |
150 | |
|
151 | |
|
152 | |
|
153 | |
|
154 | |
|
155 | |
|
156 | |
private void processLastStateFiles( String line ) |
157 | |
{ |
158 | |
|
159 | 77 | if ( line != null && line.trim().length() > 0 ) |
160 | |
{ |
161 | 48 | if ( lastState == DIFF_START_DIFFING_LOCAL ) |
162 | |
{ |
163 | 47 | setLocalFolder( localFolder + line ); |
164 | 47 | getLogger().debug( "Local folder: " + localFolder ); |
165 | |
} |
166 | 1 | else if ( lastState == DIFF_START_DIFFING_REMOTE ) |
167 | |
{ |
168 | 0 | setRemoteProjectFolder( remoteProjectFolder + line ); |
169 | 0 | getLogger().debug( "Remote folder: " + localFolder ); |
170 | |
} |
171 | |
|
172 | 48 | String[] fileLine = line.split( " " ); |
173 | 100 | for ( int i = 0; i < fileLine.length; i++ ) |
174 | |
{ |
175 | 52 | if ( fileLine[i].trim().length() > 0 ) |
176 | |
{ |
177 | 49 | if ( lastState == DIFF_LOCAL_FILES_NOT_IN_PROJECT ) |
178 | |
{ |
179 | 2 | updatedFiles.add( new ScmFile( localFolder + fileLine[i], ScmFileStatus.ADDED ) ); |
180 | |
} |
181 | 47 | else if ( lastState == DIFF_VSS_FILES_NOT_IN_CURRENT_FOLDER ) |
182 | |
{ |
183 | 0 | updatedFiles.add( new ScmFile( localFolder + fileLine[i], ScmFileStatus.UPDATED ) ); |
184 | |
} |
185 | 47 | else if ( lastState == DIFF_VSS_FILES_DIFFERENT_FROM_LOCAL_FILES ) |
186 | |
{ |
187 | 0 | updatedFiles.add( new ScmFile( localFolder + fileLine[i], ScmFileStatus.MODIFIED ) ); |
188 | |
} |
189 | |
|
190 | 49 | if ( getLogger().isDebugEnabled() ) |
191 | |
{ |
192 | 0 | getLogger().debug( localFolder + fileLine[i] ); |
193 | |
} |
194 | |
} |
195 | |
} |
196 | 48 | } |
197 | |
else |
198 | |
{ |
199 | 29 | if ( getLogger().isDebugEnabled() ) |
200 | |
{ |
201 | 0 | getLogger().debug( "processLastStateFiles: empty line" ); |
202 | |
} |
203 | |
} |
204 | |
|
205 | 77 | } |
206 | |
|
207 | |
|
208 | |
|
209 | |
|
210 | |
|
211 | |
|
212 | |
private void processLocalFolder( String line ) |
213 | |
{ |
214 | |
|
215 | 29 | setLocalFolder( line.substring( START_DIFFING_LOCAL.length() ).trim() ); |
216 | |
|
217 | 29 | } |
218 | |
|
219 | |
|
220 | |
|
221 | |
|
222 | |
|
223 | |
|
224 | |
private void processRemoteProjectFolder( String line ) |
225 | |
{ |
226 | |
|
227 | 29 | setRemoteProjectFolder( line.substring( START_DIFFING_REMOTE.length() ).trim() ); |
228 | |
|
229 | 29 | } |
230 | |
|
231 | |
|
232 | |
|
233 | |
|
234 | |
|
235 | |
|
236 | |
|
237 | |
private int getLineStatus( String line ) |
238 | |
{ |
239 | 136 | int argument = DIFF_UNKNOWN; |
240 | 136 | if ( line.startsWith( LOCAL_FILES_NOT_IN_PROJECT ) ) |
241 | |
{ |
242 | 1 | argument = DIFF_LOCAL_FILES_NOT_IN_PROJECT; |
243 | |
} |
244 | 135 | else if ( line.startsWith( VSS_FILES_DIFFERENT_FROM_LOCAL_FILES ) ) |
245 | |
{ |
246 | 0 | argument = DIFF_VSS_FILES_DIFFERENT_FROM_LOCAL_FILES; |
247 | |
} |
248 | 135 | else if ( line.startsWith( VSS_FILES_NOT_IN_CURRENT_FOLDER ) ) |
249 | |
{ |
250 | 0 | argument = DIFF_VSS_FILES_NOT_IN_CURRENT_FOLDER; |
251 | |
} |
252 | |
|
253 | |
|
254 | |
|
255 | |
|
256 | |
|
257 | |
|
258 | 135 | else if ( line.startsWith( START_DIFFING_LOCAL ) ) |
259 | |
{ |
260 | 29 | argument = DIFF_START_DIFFING_LOCAL; |
261 | |
} |
262 | 106 | else if ( line.startsWith( START_DIFFING_REMOTE ) ) |
263 | |
{ |
264 | 29 | argument = DIFF_START_DIFFING_REMOTE; |
265 | |
} |
266 | |
|
267 | 136 | return argument; |
268 | |
} |
269 | |
|
270 | |
public List<ScmFile> getUpdatedFiles() |
271 | |
{ |
272 | 0 | return updatedFiles; |
273 | |
} |
274 | |
|
275 | |
private void setLocalFolder( String localFolder ) |
276 | |
{ |
277 | 76 | if ( localFolder != null && localFolder.trim().length() > 0 ) |
278 | |
{ |
279 | 51 | this.localFolder = localFolder.replace( java.io.File.separatorChar, '/' ) + "/"; |
280 | |
} |
281 | |
else |
282 | |
{ |
283 | 25 | this.localFolder = ""; |
284 | |
} |
285 | 76 | } |
286 | |
|
287 | |
private void setRemoteProjectFolder( String remoteProjectFolder ) |
288 | |
{ |
289 | 29 | this.remoteProjectFolder = remoteProjectFolder; |
290 | 29 | } |
291 | |
|
292 | |
} |