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