Coverage Report - org.apache.maven.scm.provider.perforce.command.add.PerforceAddCommand
 
Classes in this File Line Coverage Branch Coverage Complexity
PerforceAddCommand
23 %
5/21
33 %
2/6
3,5
 
 1  
 package org.apache.maven.scm.provider.perforce.command.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 java.io.File;
 23  
 
 24  
 import org.apache.maven.scm.ScmException;
 25  
 import org.apache.maven.scm.ScmFileSet;
 26  
 import org.apache.maven.scm.ScmResult;
 27  
 import org.apache.maven.scm.command.add.AbstractAddCommand;
 28  
 import org.apache.maven.scm.command.add.AddScmResult;
 29  
 import org.apache.maven.scm.provider.ScmProviderRepository;
 30  
 import org.apache.maven.scm.provider.perforce.PerforceScmProvider;
 31  
 import org.apache.maven.scm.provider.perforce.command.PerforceCommand;
 32  
 import org.apache.maven.scm.provider.perforce.repository.PerforceScmProviderRepository;
 33  
 import org.codehaus.plexus.util.cli.CommandLineException;
 34  
 import org.codehaus.plexus.util.cli.CommandLineUtils;
 35  
 import org.codehaus.plexus.util.cli.Commandline;
 36  
 
 37  
 /**
 38  
  * @author Mike Perham
 39  
  * @version $Id: PerforceAddCommand.java 1306867 2012-03-29 13:45:10Z olamy $
 40  
  */
 41  0
 public class PerforceAddCommand
 42  
     extends AbstractAddCommand
 43  
     implements PerforceCommand
 44  
 {
 45  
     /** {@inheritDoc} */
 46  
     protected ScmResult executeAddCommand( ScmProviderRepository repo, ScmFileSet files, String message,
 47  
                                            boolean binary )
 48  
         throws ScmException
 49  
     {
 50  0
         Commandline cl = createCommandLine( (PerforceScmProviderRepository) repo, files.getBasedir(), files );
 51  0
         PerforceAddConsumer consumer = new PerforceAddConsumer();
 52  
         try
 53  
         {
 54  0
             CommandLineUtils.StringStreamConsumer err = new CommandLineUtils.StringStreamConsumer();
 55  0
             int exitCode = CommandLineUtils.executeCommandLine( cl, consumer, err );
 56  
 
 57  0
             if ( exitCode != 0 )
 58  
             {
 59  0
                 String cmdLine = CommandLineUtils.toString( cl.getCommandline() );
 60  
 
 61  0
                 StringBuilder msg = new StringBuilder( "Exit code: " + exitCode + " - " + err.getOutput() );
 62  0
                 msg.append( '\n' );
 63  0
                 msg.append( "Command line was:" + cmdLine );
 64  
 
 65  0
                 throw new CommandLineException( msg.toString() );
 66  
             }
 67  
         }
 68  0
         catch ( CommandLineException e )
 69  
         {
 70  0
             if ( getLogger().isErrorEnabled() )
 71  
             {
 72  0
                 getLogger().error( "CommandLineException " + e.getMessage(), e );
 73  
             }
 74  0
         }
 75  
 
 76  0
         return new AddScmResult( cl.toString(), consumer.getAdditions() );
 77  
     }
 78  
 
 79  
     public static Commandline createCommandLine( PerforceScmProviderRepository repo, File workingDirectory,
 80  
                                                  ScmFileSet files )
 81  
     {
 82  3
         Commandline command = PerforceScmProvider.createP4Command( repo, workingDirectory );
 83  3
         command.createArg().setValue( "add" );
 84  
 
 85  3
         for ( File file : files.getFileList() )
 86  
         {
 87  6
             command.createArg().setValue( file.getName() );
 88  
         }
 89  3
         return command;
 90  
     }
 91  
 }