1 package org.apache.maven.scm.provider.vss.commands.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.apache.maven.scm.provider.vss.commands.VssConstants;
26 import org.apache.maven.scm.provider.vss.repository.VssScmProviderRepository;
27 import org.apache.maven.scm.util.AbstractConsumer;
28 import org.codehaus.plexus.util.cli.StreamConsumer;
29
30 import java.util.ArrayList;
31 import java.util.List;
32
33
34
35
36
37 public class VssCheckOutConsumer
38 extends AbstractConsumer
39 implements StreamConsumer
40 {
41
42
43
44
45 private static final int GET_UNKNOWN = 0;
46
47
48
49
50 private static final int GET_FILE = 1;
51
52
53
54
55 private static final int REPLACE_FILE = 2;
56
57
58
59
60 private static final int GET_FILE_PATH = 3;
61
62
63
64
65 private static final int IS_WRITABLE_COPY = 4;
66
67
68
69
70 private static final int SET_WORKING_FOLDER = 5;
71
72
73
74
75 private static String START_FILE_PATH = "$/";
76
77
78
79
80 private static final String START_GETTING = "Getting";
81
82
83
84
85 private static final String START_REPLACING = "Replacing local copy of ";
86
87
88
89
90 private static final String START_WRITABLE_COPY = "A writable ";
91
92
93
94
95 private static final String CONTAINS_SET_DEFAULT_WORKING_FOLDER = "as the default folder for project";
96
97 private String currentPath = "";
98
99 private List updatedFiles = new ArrayList();
100
101 private VssScmProviderRepository repo;
102
103 public VssCheckOutConsumer( VssScmProviderRepository repo, ScmLogger logger )
104 {
105 super( logger );
106 this.repo = repo;
107 }
108
109 public void consumeLine( String line )
110 {
111 getLogger().debug( line );
112
113 switch ( getLineStatus( line ) )
114 {
115 case GET_FILE_PATH:
116 processGetFilePath( line );
117 break;
118 case GET_FILE:
119 processGetFile( line );
120 break;
121 case REPLACE_FILE:
122 processReplaceFile( line );
123 break;
124 case IS_WRITABLE_COPY:
125
126 break;
127 case SET_WORKING_FOLDER:
128
129 break;
130 default:
131 break;
132 }
133 }
134
135
136
137
138
139
140 private void processGetFile( String line )
141 {
142 String[] fileLine = line.split( " " );
143 updatedFiles.add( new ScmFile( currentPath + "/" + fileLine[1], ScmFileStatus.UPDATED ) );
144 getLogger().info( fileLine[0] + ": " + currentPath + "/" + fileLine[1] );
145 }
146
147
148
149
150
151
152 private void processReplaceFile( String line )
153 {
154 updatedFiles.add(
155 new ScmFile( currentPath + "/" + line.substring( START_REPLACING.length() ), ScmFileStatus.UPDATED ) );
156 getLogger().info( START_REPLACING + currentPath + "/" + line.substring( START_REPLACING.length() ) );
157 }
158
159
160
161
162
163
164 private void processGetFilePath( String line )
165 {
166 currentPath = line.substring( ( VssConstants.PROJECT_PREFIX + repo.getProject() ).length(), line.length() - 1 );
167 }
168
169
170
171
172
173
174
175 private int getLineStatus( String line )
176 {
177 int argument = GET_UNKNOWN;
178 if ( line.startsWith( START_FILE_PATH ) )
179 {
180 argument = GET_FILE_PATH;
181 }
182 else if ( line.startsWith( START_GETTING ) )
183 {
184 argument = GET_FILE;
185 }
186 else if ( line.startsWith( START_REPLACING ) )
187 {
188 argument = REPLACE_FILE;
189 }
190 else if ( line.startsWith( START_WRITABLE_COPY ) )
191 {
192 argument = IS_WRITABLE_COPY;
193 }
194 else if ( line.indexOf( CONTAINS_SET_DEFAULT_WORKING_FOLDER ) != -1 )
195 {
196 argument = SET_WORKING_FOLDER;
197 }
198
199 return argument;
200 }
201
202 public List getUpdatedFiles()
203 {
204 return updatedFiles;
205 }
206
207 }