Coverage Report - org.apache.maven.scm.provider.vss.commands.checkin.VssCheckInConsumer
 
Classes in this File Line Coverage Branch Coverage Complexity
VssCheckInConsumer
0 %
0/41
0 %
0/22
2,857
 
 1  
 package org.apache.maven.scm.provider.vss.commands.checkin;
 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: VssCheckInConsumer.java 1058790 2011-01-13 23:17:47Z olamy $
 36  
  * @since 1.3
 37  
  */
 38  
 public class VssCheckInConsumer
 39  
     extends AbstractConsumer
 40  
     implements StreamConsumer
 41  
 {
 42  
 
 43  
     /**
 44  
      * expecting file information
 45  
      */
 46  
     private static final int GET_UNKNOWN = 0;
 47  
 
 48  
     /**
 49  
      * expecting file information
 50  
      */
 51  
     private static final int GET_FILE = 1;
 52  
 
 53  
     /**
 54  
      * expecting file information
 55  
      */
 56  
     private static final int REPLACE_FILE = 2;
 57  
 
 58  
     /**
 59  
      * expecting file path information
 60  
      */
 61  
     private static final int GET_FILE_PATH = 3;
 62  
 
 63  
     /**
 64  
      * expecting writable copy
 65  
      */
 66  
     private static final int IS_WRITABLE_COPY = 4;
 67  
 
 68  
     /**
 69  
      * expecting working folder
 70  
      */
 71  
     private static final int SET_WORKING_FOLDER = 5;
 72  
 
 73  
     /**
 74  
      * Marks start of file data
 75  
      */
 76  
     private static final String START_FILE_PATH = "$/";
 77  
 
 78  
     /**
 79  
      * Marks getting a new File
 80  
      */
 81  
     private static final String START_GETTING = "Getting";
 82  
 
 83  
     /**
 84  
      * Marks replacing a old File
 85  
      */
 86  
     private static final String START_REPLACING = "Replacing local copy of ";
 87  
 
 88  
     /**
 89  
      * Marks a writable copy of a File / maybe a conflict
 90  
      */
 91  
     private static final String START_WRITABLE_COPY = "A writable ";
 92  
 
 93  
     /**
 94  
      * Marks "Set the default folder for project" question
 95  
      */
 96  
     private static final String CONTAINS_SET_DEFAULT_WORKING_FOLDER = "as the default folder for project";
 97  
 
 98  0
     private String currentPath = "";
 99  
 
 100  0
     private List<ScmFile> updatedFiles = new ArrayList<ScmFile>();
 101  
 
 102  
     private VssScmProviderRepository repo;
 103  
 
 104  
     public VssCheckInConsumer( VssScmProviderRepository repo, ScmLogger logger )
 105  
     {
 106  0
         super( logger );
 107  0
         this.repo = repo;
 108  0
     }
 109  
 
 110  
     /** {@inheritDoc} */
 111  
     public void consumeLine( String line )
 112  
     {
 113  0
         if ( getLogger().isDebugEnabled() )
 114  
         {
 115  0
             getLogger().debug( line );
 116  
         }
 117  
 
 118  0
         switch ( getLineStatus( line ) )
 119  
         {
 120  
             case GET_FILE_PATH:
 121  0
                 processGetFilePath( line );
 122  0
                 break;
 123  
             case GET_FILE:
 124  0
                 processGetFile( line );
 125  0
                 break;
 126  
             case REPLACE_FILE:
 127  0
                 processReplaceFile( line );
 128  0
                 break;
 129  
             case IS_WRITABLE_COPY:
 130  
                 // will be overwritten and uses REPLACE_FILE
 131  0
                 break;
 132  
             case SET_WORKING_FOLDER:
 133  
                 // to trash
 134  0
                 break;
 135  
             default:
 136  
                 break;
 137  
         }
 138  0
     }
 139  
 
 140  
     /**
 141  
      * Process the current input line in the Get File state.
 142  
      * 
 143  
      * @param line a line of text from the VSS log output
 144  
      */
 145  
     private void processGetFile( String line )
 146  
     {
 147  0
         String[] fileLine = line.split( " " );
 148  0
         updatedFiles.add( new ScmFile( currentPath + "/" + fileLine[1], ScmFileStatus.UPDATED ) );
 149  0
         if ( getLogger().isInfoEnabled() )
 150  
         {
 151  0
             getLogger().info( fileLine[0] + ": " + currentPath + "/" + fileLine[1] );
 152  
         }
 153  0
     }
 154  
 
 155  
     /**
 156  
      * Process the current input line in the Replace File state.
 157  
      * 
 158  
      * @param line a line of text from the VSS log output
 159  
      */
 160  
     private void processReplaceFile( String line )
 161  
     {
 162  0
         updatedFiles.add( new ScmFile( currentPath + "/" + line.substring( START_REPLACING.length() ),
 163  
                                        ScmFileStatus.UPDATED ) );
 164  0
         if ( getLogger().isInfoEnabled() )
 165  
         {
 166  0
             getLogger().info( START_REPLACING + currentPath + "/" + line.substring( START_REPLACING.length() ) );
 167  
         }
 168  0
     }
 169  
 
 170  
     /**
 171  
      * Process the current input line in the Get File Path state.
 172  
      * 
 173  
      * @param line a line of text from the VSS log output
 174  
      */
 175  
     private void processGetFilePath( String line )
 176  
     {
 177  0
         currentPath = line.substring( ( VssConstants.PROJECT_PREFIX + repo.getProject() ).length(), line.length() - 1 );
 178  0
     }
 179  
 
 180  
     /**
 181  
      * Identify the status of a vss get line
 182  
      * 
 183  
      * @param line The line to process
 184  
      * @return status
 185  
      */
 186  
     private int getLineStatus( String line )
 187  
     {
 188  0
         int argument = GET_UNKNOWN;
 189  0
         if ( line.startsWith( START_FILE_PATH ) )
 190  
         {
 191  0
             argument = GET_FILE_PATH;
 192  
         }
 193  0
         else if ( line.startsWith( START_GETTING ) )
 194  
         {
 195  0
             argument = GET_FILE;
 196  
         }
 197  0
         else if ( line.startsWith( START_REPLACING ) )
 198  
         {
 199  0
             argument = REPLACE_FILE;
 200  
         }
 201  0
         else if ( line.startsWith( START_WRITABLE_COPY ) )
 202  
         {
 203  0
             argument = IS_WRITABLE_COPY;
 204  
         }
 205  0
         else if ( line.indexOf( CONTAINS_SET_DEFAULT_WORKING_FOLDER ) != -1 )
 206  
         {
 207  0
             argument = SET_WORKING_FOLDER;
 208  
         }
 209  
 
 210  0
         return argument;
 211  
     }
 212  
 
 213  
     public List<ScmFile> getUpdatedFiles()
 214  
     {
 215  0
         return updatedFiles;
 216  
     }
 217  
 
 218  
 }