Coverage Report - org.apache.maven.scm.provider.tfs.command.TfsCommand
 
Classes in this File Line Coverage Branch Coverage Complexity
TfsCommand
48 %
20/41
31 %
5/16
2,25
 
 1  
 package org.apache.maven.scm.provider.tfs.command;
 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.Iterator;
 24  
 
 25  
 import org.apache.maven.scm.ScmException;
 26  
 import org.apache.maven.scm.ScmFile;
 27  
 import org.apache.maven.scm.ScmFileSet;
 28  
 import org.apache.maven.scm.log.ScmLogger;
 29  
 import org.apache.maven.scm.provider.ScmProviderRepository;
 30  
 import org.apache.maven.scm.provider.tfs.command.consumer.ErrorStreamConsumer;
 31  
 import org.apache.maven.scm.provider.tfs.command.consumer.FileListConsumer;
 32  
 import org.codehaus.plexus.util.cli.CommandLineException;
 33  
 import org.codehaus.plexus.util.cli.CommandLineUtils;
 34  
 import org.codehaus.plexus.util.cli.Commandline;
 35  
 import org.codehaus.plexus.util.cli.StreamConsumer;
 36  
 import org.codehaus.plexus.util.cli.CommandLineUtils.StringStreamConsumer;
 37  
 
 38  
 public class TfsCommand
 39  
 {
 40  
 
 41  
     private ScmLogger logger;
 42  
 
 43  
     private Commandline command;
 44  
 
 45  
     public TfsCommand( String cmd, ScmProviderRepository r, ScmFileSet f, ScmLogger logger )
 46  11
     {
 47  11
         command = new Commandline();
 48  11
         command.setExecutable( "tf" );
 49  11
         if ( f != null )
 50  
         {
 51  11
             command.setWorkingDirectory( f.getBasedir().getAbsolutePath() );
 52  
         }
 53  
         
 54  11
         command.createArg().setValue( cmd );
 55  
         
 56  11
         if ( r.getUser() != null )
 57  
         {
 58  11
             command.createArg().setValue( "-login:" + r.getUser() + "," + r.getPassword() );
 59  
         }
 60  11
         this.logger = logger;
 61  11
     }
 62  
 
 63  
     public void addArgument( ScmFileSet f )
 64  
     {
 65  5
         info( "files: " + f.getBasedir().getAbsolutePath() );
 66  5
         Iterator<File> iter = f.getFileList().iterator();
 67  10
         while ( iter.hasNext() )
 68  
         {
 69  5
             command.createArg().setValue( ( (File) iter.next() ).getPath() );
 70  
         }
 71  5
     }
 72  
 
 73  
     public void addArgument( String s )
 74  
     {
 75  23
         command.createArg().setValue( s );
 76  23
     }
 77  
 
 78  
     public int execute( StreamConsumer out, ErrorStreamConsumer err )
 79  
         throws ScmException
 80  
     {
 81  0
         info( "Command line - " + getCommandString() );
 82  
         int status;
 83  
         try
 84  
         {
 85  0
             status = CommandLineUtils.executeCommandLine( command, out, err );
 86  
         }
 87  0
         catch ( CommandLineException e )
 88  
         {
 89  0
             throw new ScmException( "Error while executing TFS command line - " + getCommandString(), e );
 90  0
         }
 91  0
         info( "err - " + err.getOutput() );
 92  0
         if ( out instanceof StringStreamConsumer )
 93  
         {
 94  0
             StringStreamConsumer sc = (StringStreamConsumer) out;
 95  0
             debug( sc.getOutput() );
 96  
         }
 97  0
         if ( out instanceof FileListConsumer )
 98  
         {
 99  0
             FileListConsumer f = (FileListConsumer) out;
 100  0
             for ( Iterator<ScmFile> i = f.getFiles().iterator(); i.hasNext(); )
 101  
             {
 102  0
                 ScmFile file = i.next();
 103  0
                 debug( file.getPath() );
 104  0
             }
 105  
         }
 106  
 
 107  0
         return status;
 108  
     }
 109  
 
 110  
     public String getCommandString()
 111  
     {
 112  0
         return command.toString();
 113  
     }
 114  
     
 115  
     public Commandline getCommandline() {
 116  11
         return command;
 117  
     }
 118  
 
 119  
     private void info( String message )
 120  
     {
 121  5
         if ( logger != null )
 122  0
             logger.info( message );
 123  5
     }
 124  
 
 125  
     private void debug( String message )
 126  
     {
 127  0
         if ( logger != null )
 128  0
             logger.debug( message );
 129  0
     }
 130  
 
 131  
 }