1 package org.apache.maven.scm.provider.vss.commands.edit;
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 VssEditConsumer
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 CURRENTLY_CHECKED_OUT_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 @SuppressWarnings( "unused" )
81 private static final String START_GETTING = "Getting";
82
83
84
85
86 private static final String START_CURRENTLY_CHECKED_OUT = "You currently have file";
87
88
89
90
91 private static final String START_WRITABLE_COPY = "A writable ";
92
93
94
95
96 private static final String CONTAINS_SET_DEFAULT_WORKING_FOLDER = "as the default folder for project";
97
98 private String currentPath = "";
99
100 private List<ScmFile> updatedFiles = new ArrayList<ScmFile>();
101
102 private VssScmProviderRepository repo;
103
104 public VssEditConsumer( VssScmProviderRepository repo, ScmLogger logger )
105 {
106 super( logger );
107 this.repo = repo;
108 }
109
110
111 public void consumeLine( String line )
112 {
113 if ( getLogger().isDebugEnabled() )
114 {
115 getLogger().debug( line );
116 }
117
118 switch ( getLineStatus( line ) )
119 {
120 case GET_FILE_PATH:
121 processGetFilePath( line );
122 break;
123 case GET_FILE:
124 processGetFile( line );
125 break;
126 case CURRENTLY_CHECKED_OUT_FILE:
127 processReplaceFile( line );
128 break;
129 case IS_WRITABLE_COPY:
130
131 break;
132 case SET_WORKING_FOLDER:
133
134 break;
135 default:
136 break;
137 }
138 }
139
140
141
142
143
144
145 private void processGetFile( String line )
146 {
147 String[] fileLine = line.split( " " );
148 updatedFiles.add( new ScmFile( currentPath + "/" + fileLine[1], ScmFileStatus.EDITED ) );
149 if ( getLogger().isInfoEnabled() )
150 {
151 getLogger().info( fileLine[0] + ": " + currentPath + "/" + fileLine[1] );
152 }
153 }
154
155
156
157
158
159
160 private void processReplaceFile( String line )
161 {
162
163
164 if ( getLogger().isInfoEnabled() )
165 {
166 getLogger().info(
167 START_CURRENTLY_CHECKED_OUT + currentPath + "/"
168 + line.substring( START_CURRENTLY_CHECKED_OUT.length() ) );
169 }
170 }
171
172
173
174
175
176
177 private void processGetFilePath( String line )
178 {
179 currentPath = line.substring( ( VssConstants.PROJECT_PREFIX + repo.getProject() ).length(), line.length() - 1 );
180 }
181
182
183
184
185
186
187
188 private int getLineStatus( String line )
189 {
190 int argument = GET_UNKNOWN;
191 if ( line.startsWith( START_FILE_PATH ) )
192 {
193 argument = GET_FILE_PATH;
194 }
195 else if ( line.startsWith( START_CURRENTLY_CHECKED_OUT ) )
196 {
197 argument = CURRENTLY_CHECKED_OUT_FILE;
198 }
199 else if ( line.startsWith( START_WRITABLE_COPY ) )
200 {
201 argument = IS_WRITABLE_COPY;
202 }
203 else if ( line.indexOf( CONTAINS_SET_DEFAULT_WORKING_FOLDER ) != -1 )
204 {
205 argument = SET_WORKING_FOLDER;
206 }
207
208 return argument;
209 }
210
211 public List<ScmFile> getUpdatedFiles()
212 {
213 return updatedFiles;
214 }
215
216 }