Coverage Report - org.apache.maven.scm.provider.vss.commands.checkout.VssCheckOutCommand
 
Classes in this File Line Coverage Branch Coverage Complexity
VssCheckOutCommand
44 %
17/38
12 %
2/16
6,5
 
 1  
 package org.apache.maven.scm.provider.vss.commands.checkout;
 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.ScmException;
 23  
 import org.apache.maven.scm.ScmFileSet;
 24  
 import org.apache.maven.scm.ScmVersion;
 25  
 import org.apache.maven.scm.command.checkout.AbstractCheckOutCommand;
 26  
 import org.apache.maven.scm.command.checkout.CheckOutScmResult;
 27  
 import org.apache.maven.scm.provider.ScmProviderRepository;
 28  
 import org.apache.maven.scm.provider.vss.commands.VssCommandLineUtils;
 29  
 import org.apache.maven.scm.provider.vss.commands.VssConstants;
 30  
 import org.apache.maven.scm.provider.vss.repository.VssScmProviderRepository;
 31  
 import org.codehaus.plexus.util.cli.CommandLineUtils;
 32  
 import org.codehaus.plexus.util.cli.Commandline;
 33  
 
 34  
 /**
 35  
  * @author <a href="mailto:triek@thrx.de">Thorsten Riek</a>
 36  
  * @version $Id: VssCheckOutCommand.java 02.06.2006 00:05:51
 37  
  */
 38  1
 public class VssCheckOutCommand
 39  
     extends AbstractCheckOutCommand
 40  
 {
 41  
 
 42  
     /** {@inheritDoc} */
 43  
     protected CheckOutScmResult executeCheckOutCommand( ScmProviderRepository repository, ScmFileSet fileSet,
 44  
                                                         ScmVersion version, boolean recursive )
 45  
         throws ScmException
 46  
     {
 47  0
         if ( getLogger().isDebugEnabled() )
 48  
         {
 49  0
             getLogger().debug( "executing checkout command..." );
 50  
         }
 51  
 
 52  0
         VssScmProviderRepository repo = (VssScmProviderRepository) repository;
 53  
 
 54  0
         Commandline cl = buildCmdLine( repo, fileSet, version );
 55  
 
 56  0
         VssCheckOutConsumer consumer = new VssCheckOutConsumer( repo, getLogger() );
 57  
 
 58  
         //      TODO handle deleted files from VSS
 59  0
         CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
 60  
 
 61  
         int exitCode;
 62  
 
 63  0
         if ( getLogger().isDebugEnabled() )
 64  
         {
 65  0
             getLogger().debug( "Executing: " + cl.getWorkingDirectory().getAbsolutePath() + ">>" + cl.toString() );
 66  
         }
 67  
 
 68  0
         exitCode = VssCommandLineUtils.executeCommandline( cl, consumer, stderr, getLogger() );
 69  
 
 70  0
         if ( exitCode != 0 )
 71  
         {
 72  0
             String error = stderr.getOutput();
 73  
 
 74  0
             if ( getLogger().isDebugEnabled() )
 75  
             {
 76  0
                 getLogger().debug( "VSS returns error: [" + error + "] return code: [" + exitCode + "]" );
 77  
             }
 78  0
             if ( error.indexOf( "A writable copy of" ) < 0 )
 79  
             {
 80  0
                 return new CheckOutScmResult( cl.toString(), "The vss command failed.", error, false );
 81  
             }
 82  
             // print out the writable copy for manual handling
 83  0
             if ( getLogger().isWarnEnabled() )
 84  
             {
 85  0
                 getLogger().warn( error );
 86  
             }
 87  
         }
 88  
 
 89  0
         return new CheckOutScmResult( cl.toString(), consumer.getUpdatedFiles() );
 90  
     }
 91  
 
 92  
     public Commandline buildCmdLine( VssScmProviderRepository repo, ScmFileSet fileSet, ScmVersion version )
 93  
         throws ScmException
 94  
     {
 95  
 
 96  1
         Commandline command = new Commandline();
 97  
 
 98  1
         command.setWorkingDirectory( fileSet.getBasedir().getAbsolutePath() );
 99  
 
 100  
         try
 101  
         {
 102  1
             command.addSystemEnvironment();
 103  
         }
 104  0
         catch ( Exception e )
 105  
         {
 106  0
             throw new ScmException( "Can't add system environment.", e );
 107  1
         }
 108  
 
 109  1
         command.addEnvironment( "SSDIR", repo.getVssdir() );
 110  
 
 111  1
         String ssDir = VssCommandLineUtils.getSsDir();
 112  
 
 113  1
         command.setExecutable( ssDir + VssConstants.SS_EXE );
 114  
 
 115  1
         command.createArg().setValue( VssConstants.COMMAND_GET );
 116  
 
 117  1
         command.createArg().setValue( VssConstants.PROJECT_PREFIX + repo.getProject() );
 118  
 
 119  
         //User identification to get access to vss repository
 120  1
         if ( repo.getUserPassword() != null )
 121  
         {
 122  1
             command.createArg().setValue( VssConstants.FLAG_LOGIN + repo.getUserPassword() );
 123  
         }
 124  
 
 125  
         //Display the history of an entire project list
 126  1
         command.createArg().setValue( VssConstants.FLAG_RECURSION );
 127  
 
 128  
         //Ignore: Do not ask for input under any circumstances.
 129  1
         command.createArg().setValue( VssConstants.FLAG_AUTORESPONSE_DEF );
 130  
 
 131  
         //Ignore: Do not touch local writable files.
 132  1
         command.createArg().setValue( VssConstants.FLAG_REPLACE_WRITABLE );
 133  
 
 134  1
         if ( version != null )
 135  
         {
 136  0
             command.createArg().setValue( VssConstants.FLAG_VERSION_LABEL + '"' + version + '"' );
 137  
         }
 138  
 
 139  1
         return command;
 140  
     }
 141  
 }