Coverage Report - org.apache.maven.scm.provider.cvslib.command.status.CvsStatusConsumer
 
Classes in this File Line Coverage Branch Coverage Complexity
CvsStatusConsumer
0 %
0/34
0 %
0/28
7
 
 1  
 package org.apache.maven.scm.provider.cvslib.command.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.io.File;
 23  
 import java.util.ArrayList;
 24  
 import java.util.List;
 25  
 
 26  
 import org.apache.maven.scm.ScmFile;
 27  
 import org.apache.maven.scm.ScmFileStatus;
 28  
 import org.apache.maven.scm.log.ScmLogger;
 29  
 import org.codehaus.plexus.util.StringUtils;
 30  
 import org.codehaus.plexus.util.cli.StreamConsumer;
 31  
 
 32  
 /**
 33  
  * @author <a href="mailto:brett@apache.org">Brett Porter</a>
 34  
  * @version $Id: CvsStatusConsumer.java 1055646 2011-01-05 21:22:58Z olamy $
 35  
  */
 36  
 public class CvsStatusConsumer
 37  
     implements StreamConsumer
 38  
 {
 39  
     private ScmLogger logger;
 40  
 
 41  
     private File workingDirectory;
 42  
 
 43  0
     private List<ScmFile> changedFiles = new ArrayList<ScmFile>();
 44  
 
 45  
     // ----------------------------------------------------------------------
 46  
     //
 47  
     // ----------------------------------------------------------------------
 48  
 
 49  
     public CvsStatusConsumer( ScmLogger logger, File workingDirectory )
 50  0
     {
 51  0
         this.logger = logger;
 52  
 
 53  0
         this.workingDirectory = workingDirectory;
 54  0
     }
 55  
 
 56  
     // ----------------------------------------------------------------------
 57  
     // StreamConsumer Implementation
 58  
     // ----------------------------------------------------------------------
 59  
 
 60  
     /** {@inheritDoc} */
 61  
     public void consumeLine( String line )
 62  
     {
 63  0
         if ( logger.isDebugEnabled() )
 64  
         {
 65  0
             logger.debug( line );
 66  
         }
 67  
 
 68  0
         if ( line.length() < 3 )
 69  
         {
 70  0
             if ( StringUtils.isNotEmpty( line ) )
 71  
             {
 72  0
                 if ( logger.isWarnEnabled() )
 73  
                 {
 74  0
                     logger.warn( "Unable to parse output from command: line length must be bigger than 3. ("
 75  
                         + line + ")." );
 76  
                 }
 77  
             }
 78  0
             return;
 79  
         }
 80  
 
 81  0
         String statusString = line.substring( 0, 1 );
 82  
 
 83  0
         String file = line.substring( 2 );
 84  
 
 85  
         ScmFileStatus status;
 86  
 
 87  0
         if ( statusString.equals( "A" ) )
 88  
         {
 89  0
             status = ScmFileStatus.ADDED;
 90  
         }
 91  0
         else if ( statusString.equals( "M" ) )
 92  
         {
 93  0
             status = ScmFileStatus.MODIFIED;
 94  
         }
 95  0
         else if ( statusString.equals( "D" ) )
 96  
         {
 97  0
             status = ScmFileStatus.DELETED;
 98  
         }
 99  0
         else if ( statusString.equals( "C" ) )
 100  
         {
 101  0
             status = ScmFileStatus.CONFLICT;
 102  
         }
 103  0
         else if ( statusString.equals( "?" ) )
 104  
         {
 105  0
             status = ScmFileStatus.UNKNOWN;
 106  
         }
 107  0
         else if ( statusString.equals( "U" ) || statusString.equals( "P" ) )
 108  
         {
 109  
             // skip remote changes
 110  0
             return;
 111  
         }
 112  
         else
 113  
         {
 114  0
             if ( logger.isInfoEnabled() )
 115  
             {
 116  0
                 logger.info( "Unknown file status: '" + statusString + "'." );
 117  
             }
 118  
 
 119  0
             return;
 120  
         }
 121  
 
 122  
         // If the file isn't a file; don't add it.
 123  0
         if ( !status.equals( ScmFileStatus.DELETED ) && !new File( workingDirectory, file ).isFile() )
 124  
         {
 125  0
             return;
 126  
         }
 127  
 
 128  0
         changedFiles.add( new ScmFile( file, status ) );
 129  0
     }
 130  
 
 131  
     public List<ScmFile> getChangedFiles()
 132  
     {
 133  0
         return changedFiles;
 134  
     }
 135  
 }