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 final 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 | 0 | private String currentPath = ""; |
98 | |
|
99 | 0 | private List<ScmFile> updatedFiles = new ArrayList<ScmFile>(); |
100 | |
|
101 | |
private VssScmProviderRepository repo; |
102 | |
|
103 | |
public VssCheckOutConsumer( VssScmProviderRepository repo, ScmLogger logger ) |
104 | |
{ |
105 | 0 | super( logger ); |
106 | 0 | this.repo = repo; |
107 | 0 | } |
108 | |
|
109 | |
|
110 | |
public void consumeLine( String line ) |
111 | |
{ |
112 | 0 | if ( getLogger().isDebugEnabled() ) |
113 | |
{ |
114 | 0 | getLogger().debug( line ); |
115 | |
} |
116 | |
|
117 | 0 | switch ( getLineStatus( line ) ) |
118 | |
{ |
119 | |
case GET_FILE_PATH: |
120 | 0 | processGetFilePath( line ); |
121 | 0 | break; |
122 | |
case GET_FILE: |
123 | 0 | processGetFile( line ); |
124 | 0 | break; |
125 | |
case REPLACE_FILE: |
126 | 0 | processReplaceFile( line ); |
127 | 0 | break; |
128 | |
case IS_WRITABLE_COPY: |
129 | |
|
130 | 0 | break; |
131 | |
case SET_WORKING_FOLDER: |
132 | |
|
133 | 0 | break; |
134 | |
default: |
135 | |
break; |
136 | |
} |
137 | 0 | } |
138 | |
|
139 | |
|
140 | |
|
141 | |
|
142 | |
|
143 | |
|
144 | |
private void processGetFile( String line ) |
145 | |
{ |
146 | 0 | String[] fileLine = line.split( " " ); |
147 | 0 | updatedFiles.add( new ScmFile( currentPath + "/" + fileLine[1], ScmFileStatus.UPDATED ) ); |
148 | 0 | if ( getLogger().isInfoEnabled() ) |
149 | |
{ |
150 | 0 | getLogger().info( fileLine[0] + ": " + currentPath + "/" + fileLine[1] ); |
151 | |
} |
152 | 0 | } |
153 | |
|
154 | |
|
155 | |
|
156 | |
|
157 | |
|
158 | |
|
159 | |
private void processReplaceFile( String line ) |
160 | |
{ |
161 | 0 | updatedFiles.add( |
162 | |
new ScmFile( currentPath + "/" + line.substring( START_REPLACING.length() ), ScmFileStatus.UPDATED ) ); |
163 | 0 | if ( getLogger().isInfoEnabled() ) |
164 | |
{ |
165 | 0 | getLogger().info( START_REPLACING + currentPath + "/" + line.substring( START_REPLACING.length() ) ); |
166 | |
} |
167 | 0 | } |
168 | |
|
169 | |
|
170 | |
|
171 | |
|
172 | |
|
173 | |
|
174 | |
private void processGetFilePath( String line ) |
175 | |
{ |
176 | 0 | currentPath = line.substring( ( VssConstants.PROJECT_PREFIX + repo.getProject() ).length(), line.length() - 1 ); |
177 | 0 | } |
178 | |
|
179 | |
|
180 | |
|
181 | |
|
182 | |
|
183 | |
|
184 | |
|
185 | |
private int getLineStatus( String line ) |
186 | |
{ |
187 | 0 | int argument = GET_UNKNOWN; |
188 | 0 | if ( line.startsWith( START_FILE_PATH ) ) |
189 | |
{ |
190 | 0 | argument = GET_FILE_PATH; |
191 | |
} |
192 | 0 | else if ( line.startsWith( START_GETTING ) ) |
193 | |
{ |
194 | 0 | argument = GET_FILE; |
195 | |
} |
196 | 0 | else if ( line.startsWith( START_REPLACING ) ) |
197 | |
{ |
198 | 0 | argument = REPLACE_FILE; |
199 | |
} |
200 | 0 | else if ( line.startsWith( START_WRITABLE_COPY ) ) |
201 | |
{ |
202 | 0 | argument = IS_WRITABLE_COPY; |
203 | |
} |
204 | 0 | else if ( line.indexOf( CONTAINS_SET_DEFAULT_WORKING_FOLDER ) != -1 ) |
205 | |
{ |
206 | 0 | argument = SET_WORKING_FOLDER; |
207 | |
} |
208 | |
|
209 | 0 | return argument; |
210 | |
} |
211 | |
|
212 | |
public List<ScmFile> getUpdatedFiles() |
213 | |
{ |
214 | 0 | return updatedFiles; |
215 | |
} |
216 | |
|
217 | |
} |