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