View Javadoc

1   package org.apache.maven.scm.provider.vss.commands.update;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   * http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
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   * @author <a href="mailto:triek@thrx.de">Thorsten Riek</a>
35   * @version $Id: VssUpdateConsumer.java 483105 2006-12-06 15:07:54Z evenisse $
36   */
37  public class VssUpdateConsumer
38      extends AbstractConsumer
39      implements StreamConsumer
40  {
41  
42      /**
43       * expecting file information
44       */
45      private static final int GET_UNKNOWN = 0;
46  
47      /**
48       * expecting file information
49       */
50      private static final int GET_FILE = 1;
51  
52      /**
53       * expecting file information
54       */
55      private static final int REPLACE_FILE = 2;
56  
57      /**
58       * expecting file path information
59       */
60      private static final int GET_FILE_PATH = 3;
61  
62      /**
63       * expecting writable copy
64       */
65      private static final int IS_WRITABLE_COPY = 4;
66  
67      /**
68       * expecting working folder
69       */
70      private static final int SET_WORKING_FOLDER = 5;
71  
72      /**
73       * Marks start of file data
74       */
75      private static String START_FILE_PATH = "$/";
76  
77      /**
78       * Marks getting a new File
79       */
80      private static final String START_GETTING = "Getting";
81  
82      /**
83       * Marks replacing a old File
84       */
85      private static final String START_REPLACING = "Replacing local copy of ";
86  
87      /**
88       * Marks a writable copy of a File / maybe a conflict
89       */
90      private static final String START_WRITABLE_COPY = "A writable ";
91  
92      /**
93       * Marks "Set the default folder for project" question
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 VssUpdateConsumer( 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                 // FIXME is actually in error stream if command is build without -G-
126                 processWritableFile( line );
127                 break;
128             case SET_WORKING_FOLDER:
129                 // to trash
130                 break;
131             default:
132                 break;
133         }
134     }
135 
136     /**
137      * Process the current input line in the Get File state.
138      *
139      * @param line a line of text from the VSS log output
140      */
141     private void processGetFile( String line )
142     {
143         String[] fileLine = line.split( " " );
144         updatedFiles.add( new ScmFile( currentPath + "/" + fileLine[1], ScmFileStatus.UPDATED ) );
145         getLogger().info( fileLine[0] + ": " + currentPath + "/" + fileLine[1] );
146 
147     }
148 
149     /**
150      * Process the current input line in the Replace File state.
151      *
152      * @param line a line of text from the VSS log output
153      */
154     private void processReplaceFile( String line )
155     {
156 
157         updatedFiles.add(
158             new ScmFile( currentPath + "/" + line.substring( START_REPLACING.length() ), ScmFileStatus.UPDATED ) );
159         getLogger().info( START_REPLACING + currentPath + "/" + line.substring( START_REPLACING.length() ) );
160 
161 
162     }
163 
164     /**
165      * Process the current input line in the Get File Path state.
166      *
167      * @param line a line of text from the VSS log output
168      */
169     private void processGetFilePath( String line )
170     {
171         currentPath = line.substring( ( VssConstants.PROJECT_PREFIX + repo.getProject() ).length(), line.length() - 1 );
172     }
173 
174     /**
175      * Process the current input line in the writable File state.
176      *
177      * @param line a line of text from the VSS log output
178      */
179     private void processWritableFile( String line )
180     {
181         // FIXME extract file name
182         //        String[] fileLine = line.split( " " );
183         //        updatedFiles.add( new ScmFile( currentPath + "/" + fileLine[1], ScmFileStatus.MODIFIED ) );
184         //        getLogger().info( fileLine[0] + ": " + currentPath + "/" + fileLine[1] );
185 
186     }
187 
188     /**
189      * Identify the status of a vss get line
190      *
191      * @param line The line to process
192      * @return status
193      */
194     private int getLineStatus( String line )
195     {
196         int argument = GET_UNKNOWN;
197         if ( line.startsWith( START_FILE_PATH ) )
198         {
199             argument = GET_FILE_PATH;
200         }
201         else if ( line.startsWith( START_GETTING ) )
202         {
203             argument = GET_FILE;
204         }
205         else if ( line.startsWith( START_REPLACING ) )
206         {
207             argument = REPLACE_FILE;
208         }
209         else if ( line.startsWith( START_WRITABLE_COPY ) )
210         {
211             argument = IS_WRITABLE_COPY;
212         }
213         else if ( line.indexOf( CONTAINS_SET_DEFAULT_WORKING_FOLDER ) != -1 )
214         {
215             argument = SET_WORKING_FOLDER;
216         }
217 
218         return argument;
219     }
220 
221     public List getUpdatedFiles()
222     {
223         return updatedFiles;
224     }
225 
226 }