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