Coverage Report - org.apache.maven.scm.provider.vss.commands.add.VssAddCommand
 
Classes in this File Line Coverage Branch Coverage Complexity
VssAddCommand
60 %
26/43
20 %
2/10
4,667
 
 1  
 package org.apache.maven.scm.provider.vss.commands.add;
 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.ScmResult;
 25  
 import org.apache.maven.scm.command.add.AbstractAddCommand;
 26  
 import org.apache.maven.scm.command.add.AddScmResult;
 27  
 import org.apache.maven.scm.command.changelog.ChangeLogScmResult;
 28  
 import org.apache.maven.scm.provider.ScmProviderRepository;
 29  
 import org.apache.maven.scm.provider.vss.commands.VssCommandLineUtils;
 30  
 import org.apache.maven.scm.provider.vss.commands.VssConstants;
 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:brett@apache.org">Brett Porter</a>
 37  
  * @version $Id: VssAddCommand.java 1054126 2010-12-31 15:18:11Z olamy $
 38  
  */
 39  2
 public class VssAddCommand
 40  
     extends AbstractAddCommand
 41  
 {
 42  
     /** {@inheritDoc} */
 43  
     protected ScmResult executeAddCommand( ScmProviderRepository repository, ScmFileSet fileSet, String message,
 44  
                                            boolean binary )
 45  
         throws ScmException
 46  
     {
 47  0
         VssScmProviderRepository repo = (VssScmProviderRepository) repository;
 48  
 
 49  0
         if ( fileSet.getFileList().isEmpty() )
 50  
         {
 51  0
             throw new ScmException( "You must provide at least one file/directory to add" );
 52  
         }
 53  
 
 54  0
         Commandline cl = buildCmdLine( repo, fileSet );
 55  
 
 56  0
         VssAddConsumer consumer = new VssAddConsumer( getLogger() );
 57  
 
 58  0
         CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
 59  
 
 60  0
         if ( getLogger().isInfoEnabled() )
 61  
         {
 62  0
             getLogger().info( "Executing: " + cl );
 63  0
             getLogger().info( "Working directory: " + cl.getWorkingDirectory().getAbsolutePath() );
 64  
         }
 65  
 
 66  0
         int exitCode = VssCommandLineUtils.executeCommandline( cl, consumer, stderr, getLogger() );
 67  
 
 68  0
         if ( exitCode != 0 )
 69  
         {
 70  0
             return new ChangeLogScmResult( cl.toString(), "The vss command failed.", stderr.getOutput(), false );
 71  
         }
 72  
 
 73  0
         return new AddScmResult( cl.toString(), consumer.getAddedFiles() );
 74  
     }
 75  
 
 76  
     public Commandline buildCmdLine( VssScmProviderRepository repo, ScmFileSet fileSet )
 77  
         throws ScmException
 78  
     {
 79  1
         Commandline command = new Commandline();
 80  
 
 81  1
         command.setWorkingDirectory( fileSet.getBasedir().getAbsolutePath() );
 82  
 
 83  
         try
 84  
         {
 85  1
             command.addSystemEnvironment();
 86  
         }
 87  0
         catch ( Exception e )
 88  
         {
 89  0
             throw new ScmException( "Can't add system environment.", e );
 90  1
         }
 91  
 
 92  1
         command.addEnvironment( "SSDIR", repo.getVssdir() );
 93  
 
 94  1
         String ssDir = VssCommandLineUtils.getSsDir();
 95  
 
 96  1
         command.setExecutable( ssDir + VssConstants.SS_EXE );
 97  
 
 98  1
         command.createArg().setValue( VssConstants.COMMAND_ADD );
 99  
 
 100  1
         VssCommandLineUtils.addFiles( command, fileSet );
 101  
 
 102  
         //        command.createArg().setValue( VssConstants.PROJECT_PREFIX + repo.getProject() );
 103  
 
 104  
         //User identification to get access to vss repository
 105  1
         if ( repo.getUserPassword() != null )
 106  
         {
 107  1
             command.createArg().setValue( VssConstants.FLAG_LOGIN + repo.getUserPassword() );
 108  
         }
 109  
 
 110  
         //Ignore: Do not ask for input under any circumstances.
 111  1
         command.createArg().setValue( VssConstants.FLAG_AUTORESPONSE_DEF );
 112  
 
 113  1
         return command;
 114  
     }
 115  
 
 116  
     public Commandline buildSetCurrentProjectCmdLine( VssScmProviderRepository repo )
 117  
         throws ScmException
 118  
     {
 119  1
         Commandline command = new Commandline();
 120  
 
 121  
         try
 122  
         {
 123  1
             command.addSystemEnvironment();
 124  
         }
 125  0
         catch ( Exception e )
 126  
         {
 127  0
             throw new ScmException( "Can't add system environment.", e );
 128  1
         }
 129  
 
 130  1
         command.addEnvironment( "SSDIR", repo.getVssdir() );
 131  
 
 132  1
         String ssDir = VssCommandLineUtils.getSsDir();
 133  
 
 134  1
         command.setExecutable( ssDir + VssConstants.SS_EXE );
 135  
 
 136  1
         command.createArg().setValue( VssConstants.COMMAND_CP );
 137  
 
 138  1
         command.createArg().setValue( VssConstants.PROJECT_PREFIX + repo.getProject() );
 139  
 
 140  
         //User identification to get access to vss repository
 141  1
         if ( repo.getUserPassword() != null )
 142  
         {
 143  1
             command.createArg().setValue( VssConstants.FLAG_LOGIN + repo.getUserPassword() );
 144  
         }
 145  
 
 146  
         //Ignore: Do not ask for input under any circumstances.
 147  1
         command.createArg().setValue( VssConstants.FLAG_AUTORESPONSE_DEF );
 148  
 
 149  1
         return command;
 150  
     }
 151  
 
 152  
 }