Coverage Report - org.apache.maven.scm.provider.tfs.command.consumer.ChangedFileConsumer
 
Classes in this File Line Coverage Branch Coverage Complexity
ChangedFileConsumer
93 %
29/31
62 %
10/16
2,333
 
 1  
 package org.apache.maven.scm.provider.tfs.command.consumer;
 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.HashMap;
 24  
 import java.util.List;
 25  
 import java.util.Map;
 26  
 
 27  
 import org.apache.maven.scm.ScmFile;
 28  
 import org.apache.maven.scm.ScmFileStatus;
 29  
 import org.apache.maven.scm.log.ScmLogger;
 30  
 import org.codehaus.plexus.util.cli.StreamConsumer;
 31  
 
 32  
 public class ChangedFileConsumer
 33  
     implements StreamConsumer
 34  
 {
 35  
 
 36  
     private ScmLogger logger;
 37  
 
 38  
     private static final String KEY_CHANGE = "Change";
 39  
 
 40  
     private static final String KEY_LOCAL_ITEM = "Local item";
 41  
 
 42  
     private static final String CHANGE_EDIT = "edit";
 43  
 
 44  
     private static final String CHANGE_ADD = "add";
 45  
 
 46  4
     private Map<String,String> values = new HashMap<String,String>();
 47  
 
 48  4
     private List<ScmFile> changedFiles = new ArrayList<ScmFile>();
 49  
 
 50  
     public ChangedFileConsumer( ScmLogger logger )
 51  4
     {
 52  4
         this.logger = logger;
 53  4
     }
 54  
 
 55  
     public void consumeLine( String line )
 56  
     {
 57  54
         if ( line.indexOf( ':' ) >= 0 )
 58  
         {
 59  42
             String[] s = line.split( ":", 2 );
 60  42
             if ( s.length > 1 )
 61  42
                 values.put( s[0].trim(), s[1].trim() );
 62  
         }
 63  54
         if ( line.trim().equals( "" ) )
 64  
         {
 65  6
             extractChangedFile();
 66  
         }
 67  54
         logger.debug( "line -" + line );
 68  54
     }
 69  
 
 70  
     private void extractChangedFile()
 71  
     {
 72  6
         String change = getChange();
 73  6
         if ( change != null )
 74  
         {
 75  6
             ScmFileStatus stat = ScmFileStatus.UNKNOWN;
 76  6
             if ( change.equals( ChangedFileConsumer.CHANGE_EDIT ) )
 77  6
                 stat = ScmFileStatus.MODIFIED;
 78  6
             if ( change.equals( ChangedFileConsumer.CHANGE_ADD ) )
 79  0
                 stat = ScmFileStatus.ADDED;
 80  6
             changedFiles.add( new ScmFile( getLocalPath(), stat ) );
 81  6
             values.clear();
 82  
         }
 83  6
     }
 84  
 
 85  
     public List<ScmFile> getChangedFiles()
 86  
     {
 87  2
         if ( values.size() > 0 )
 88  
         {
 89  0
             extractChangedFile();
 90  
         }
 91  2
         return changedFiles;
 92  
     }
 93  
 
 94  
     private String getChange()
 95  
     {
 96  6
         return (String) values.get( KEY_CHANGE );
 97  
     }
 98  
 
 99  
     private String getLocalPath()
 100  
     {
 101  6
         String local = (String) values.get( KEY_LOCAL_ITEM );
 102  6
         if ( local != null )
 103  
         {
 104  6
             local = local.split( "]", 2 )[1].trim();
 105  
         }
 106  6
         return local;
 107  
     }
 108  
 
 109  
 }