Coverage Report - org.apache.maven.scm.provider.vss.commands.status.VssStatusConsumer
 
Classes in this File Line Coverage Branch Coverage Complexity
VssStatusConsumer
80 %
56/70
72 %
32/44
3,667
 
 1  
 package org.apache.maven.scm.provider.vss.commands.status;
 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 java.util.ArrayList;
 23  
 import java.util.List;
 24  
 
 25  
 import org.apache.maven.scm.ScmFile;
 26  
 import org.apache.maven.scm.ScmFileSet;
 27  
 import org.apache.maven.scm.ScmFileStatus;
 28  
 import org.apache.maven.scm.log.ScmLogger;
 29  
 import org.apache.maven.scm.provider.vss.repository.VssScmProviderRepository;
 30  
 import org.apache.maven.scm.util.AbstractConsumer;
 31  
 import org.codehaus.plexus.util.cli.StreamConsumer;
 32  
 
 33  
 /**
 34  
  * @author <a href="mailto:triek@thrx.de">Thorsten Riek</a>
 35  
  * @version $Id: VssStatusConsumer.java 1056991 2011-01-09 18:09:10Z olamy $
 36  
  */
 37  
 public class VssStatusConsumer
 38  
     extends AbstractConsumer
 39  
     implements StreamConsumer
 40  
 {
 41  
 
 42  
     /**
 43  
      * expecting file information
 44  
      */
 45  
     private static final int DIFF_UNKNOWN = 0;
 46  
 
 47  
     /**
 48  
      * expecting files to checkin
 49  
      */
 50  
     private static final int DIFF_LOCAL_FILES_NOT_IN_PROJECT = 1;
 51  
 
 52  
     /**
 53  
      * expecting commit
 54  
      */
 55  
     private static final int DIFF_VSS_FILES_DIFFERENT_FROM_LOCAL_FILES = 2;
 56  
 
 57  
     /**
 58  
      * expecting update / checkout
 59  
      */
 60  
     private static final int DIFF_VSS_FILES_NOT_IN_CURRENT_FOLDER = 3;
 61  
 
 62  
     /**
 63  
      * expecting setting akt remote folder
 64  
      */
 65  
     private static final int DIFF_START_DIFFING_REMOTE = 4;
 66  
 
 67  
     /**
 68  
      * expecting setting akt local folder
 69  
      */
 70  
     private static final int DIFF_START_DIFFING_LOCAL = 5;
 71  
 
 72  
     /**
 73  
      * Marks Diffing remote project folder
 74  
      */
 75  
     private static final String START_DIFFING_REMOTE = "Diffing:";
 76  
 
 77  
     /**
 78  
      * Marks Diffing local project folder
 79  
      */
 80  
     private static final String START_DIFFING_LOCAL = "Against:";
 81  
 
 82  
     /**
 83  
      * Marks Local files not in the current project
 84  
      */
 85  
     private static final String LOCAL_FILES_NOT_IN_PROJECT = "Local files not in the current project:";
 86  
 
 87  
     /**
 88  
      * Marks SourceSafe files different from local files
 89  
      */
 90  
     private static final String VSS_FILES_DIFFERENT_FROM_LOCAL_FILES = "SourceSafe files different from local files:";
 91  
 
 92  
     /**
 93  
      * Marks SourceSafe files not in the current folder
 94  
      */
 95  
     private static final String VSS_FILES_NOT_IN_CURRENT_FOLDER = "SourceSafe files not in the current folder:";
 96  
 
 97  1
     private String remoteProjectFolder = "";
 98  
 
 99  1
     private String localFolder = "";
 100  
 
 101  1
     private int lastState = 0;
 102  
 
 103  1
     private List<ScmFile> updatedFiles = new ArrayList<ScmFile>();
 104  
 
 105  
     @SuppressWarnings( "unused" )
 106  
     private VssScmProviderRepository repo;
 107  
 
 108  
     @SuppressWarnings( "unused" )
 109  
     private ScmFileSet fileSet;
 110  
 
 111  
     public VssStatusConsumer( VssScmProviderRepository repo, ScmLogger logger, ScmFileSet fileSet )
 112  
     {
 113  1
         super( logger );
 114  1
         this.repo = repo;
 115  1
         this.fileSet = fileSet;
 116  1
     }
 117  
 
 118  
     /** {@inheritDoc} */
 119  
     public void consumeLine( String line )
 120  
     {
 121  136
         if ( getLogger().isDebugEnabled() )
 122  
         {
 123  0
             getLogger().debug( line );
 124  
         }
 125  
 
 126  136
         switch ( getLineStatus( line ) )
 127  
         {
 128  
             case DIFF_LOCAL_FILES_NOT_IN_PROJECT:
 129  1
                 lastState = DIFF_LOCAL_FILES_NOT_IN_PROJECT;
 130  1
                 break;
 131  
             case DIFF_VSS_FILES_DIFFERENT_FROM_LOCAL_FILES:
 132  0
                 lastState = DIFF_VSS_FILES_DIFFERENT_FROM_LOCAL_FILES;
 133  0
                 break;
 134  
             case DIFF_VSS_FILES_NOT_IN_CURRENT_FOLDER:
 135  0
                 lastState = DIFF_VSS_FILES_NOT_IN_CURRENT_FOLDER;
 136  0
                 break;
 137  
             case DIFF_START_DIFFING_LOCAL:
 138  29
                 lastState = DIFF_START_DIFFING_LOCAL;
 139  29
                 processLocalFolder( line );
 140  29
                 break;
 141  
             case DIFF_START_DIFFING_REMOTE:
 142  29
                 lastState = DIFF_START_DIFFING_REMOTE;
 143  29
                 processRemoteProjectFolder( line );
 144  29
                 break;
 145  
             default:
 146  77
                 processLastStateFiles( line );
 147  
                 break;
 148  
         }
 149  136
     }
 150  
 
 151  
     /**
 152  
      * Process the current input line in the Get File state.
 153  
      * 
 154  
      * @param line a line of text from the VSS log output
 155  
      */
 156  
     private void processLastStateFiles( String line )
 157  
     {
 158  
 
 159  77
         if ( line != null && line.trim().length() > 0 )
 160  
         {
 161  48
             if ( lastState == DIFF_START_DIFFING_LOCAL )
 162  
             {
 163  47
                 setLocalFolder( localFolder + line );
 164  47
                 getLogger().debug( "Local folder: " + localFolder );
 165  
             }
 166  1
             else if ( lastState == DIFF_START_DIFFING_REMOTE )
 167  
             {
 168  0
                 setRemoteProjectFolder( remoteProjectFolder + line );
 169  0
                 getLogger().debug( "Remote folder: " + localFolder );
 170  
             }
 171  
 
 172  48
             String[] fileLine = line.split( " " );
 173  100
             for ( int i = 0; i < fileLine.length; i++ )
 174  
             {
 175  52
                 if ( fileLine[i].trim().length() > 0 )
 176  
                 {
 177  49
                     if ( lastState == DIFF_LOCAL_FILES_NOT_IN_PROJECT )
 178  
                     {
 179  2
                         updatedFiles.add( new ScmFile( localFolder + fileLine[i], ScmFileStatus.ADDED ) );
 180  
                     }
 181  47
                     else if ( lastState == DIFF_VSS_FILES_NOT_IN_CURRENT_FOLDER )
 182  
                     {
 183  0
                         updatedFiles.add( new ScmFile( localFolder + fileLine[i], ScmFileStatus.UPDATED ) );
 184  
                     }
 185  47
                     else if ( lastState == DIFF_VSS_FILES_DIFFERENT_FROM_LOCAL_FILES )
 186  
                     {
 187  0
                         updatedFiles.add( new ScmFile( localFolder + fileLine[i], ScmFileStatus.MODIFIED ) );
 188  
                     }
 189  
 
 190  49
                     if ( getLogger().isDebugEnabled() )
 191  
                     {
 192  0
                         getLogger().debug( localFolder + fileLine[i] );
 193  
                     }
 194  
                 }
 195  
             }
 196  48
         }
 197  
         else
 198  
         {
 199  29
             if ( getLogger().isDebugEnabled() )
 200  
             {
 201  0
                 getLogger().debug( "processLastStateFiles:  empty line" );
 202  
             }
 203  
         }
 204  
 
 205  77
     }
 206  
 
 207  
     /**
 208  
      * Process the current input line in the Get File Path state.
 209  
      * 
 210  
      * @param line a line of text from the VSS log output
 211  
      */
 212  
     private void processLocalFolder( String line )
 213  
     {
 214  
 
 215  29
         setLocalFolder( line.substring( START_DIFFING_LOCAL.length() ).trim() );
 216  
 
 217  29
     }
 218  
 
 219  
     /**
 220  
      * Process the current input line in the Get File Path state.
 221  
      * 
 222  
      * @param line a line of text from the VSS log output
 223  
      */
 224  
     private void processRemoteProjectFolder( String line )
 225  
     {
 226  
 
 227  29
         setRemoteProjectFolder( line.substring( START_DIFFING_REMOTE.length() ).trim() );
 228  
 
 229  29
     }
 230  
 
 231  
     /**
 232  
      * Identify the status of a vss get line
 233  
      * 
 234  
      * @param line The line to process
 235  
      * @return status
 236  
      */
 237  
     private int getLineStatus( String line )
 238  
     {
 239  136
         int argument = DIFF_UNKNOWN;
 240  136
         if ( line.startsWith( LOCAL_FILES_NOT_IN_PROJECT ) )
 241  
         {
 242  1
             argument = DIFF_LOCAL_FILES_NOT_IN_PROJECT;
 243  
         }
 244  135
         else if ( line.startsWith( VSS_FILES_DIFFERENT_FROM_LOCAL_FILES ) )
 245  
         {
 246  0
             argument = DIFF_VSS_FILES_DIFFERENT_FROM_LOCAL_FILES;
 247  
         }
 248  135
         else if ( line.startsWith( VSS_FILES_NOT_IN_CURRENT_FOLDER ) )
 249  
         {
 250  0
             argument = DIFF_VSS_FILES_NOT_IN_CURRENT_FOLDER;
 251  
         }
 252  
         //        else if ( line.startsWith( VSS_FILES_NOT_IN_CURRENT_FOLDER ) )
 253  
         //        {
 254  
         //            Project $/com.fum/fum-utilities/src/main/java/com/fum/utilities/protocol has no
 255  
         //            corresponding folder
 256  
         //            argument = DIFF_VSS_FILES_NOT_IN_CURRENT_FOLDER;
 257  
         //        }
 258  135
         else if ( line.startsWith( START_DIFFING_LOCAL ) )
 259  
         {
 260  29
             argument = DIFF_START_DIFFING_LOCAL;
 261  
         }
 262  106
         else if ( line.startsWith( START_DIFFING_REMOTE ) )
 263  
         {
 264  29
             argument = DIFF_START_DIFFING_REMOTE;
 265  
         }
 266  
 
 267  136
         return argument;
 268  
     }
 269  
 
 270  
     public List<ScmFile> getUpdatedFiles()
 271  
     {
 272  0
         return updatedFiles;
 273  
     }
 274  
 
 275  
     private void setLocalFolder( String localFolder )
 276  
     {
 277  76
         if ( localFolder != null && localFolder.trim().length() > 0 )
 278  
         {
 279  51
             this.localFolder = localFolder.replace( java.io.File.separatorChar, '/' ) + "/";
 280  
         }
 281  
         else
 282  
         {
 283  25
             this.localFolder = "";
 284  
         }
 285  76
     }
 286  
 
 287  
     private void setRemoteProjectFolder( String remoteProjectFolder )
 288  
     {
 289  29
         this.remoteProjectFolder = remoteProjectFolder;
 290  29
     }
 291  
 
 292  
 }