Coverage Report - org.apache.maven.scm.provider.perforce.command.unedit.PerforceUnEditCommand
 
Classes in this File Line Coverage Branch Coverage Complexity
PerforceUnEditCommand
25 %
6/24
25 %
2/8
4,5
 
 1  
 package org.apache.maven.scm.provider.perforce.command.unedit;
 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.unedit.AbstractUnEditCommand;
 26  
 import org.apache.maven.scm.command.unedit.UnEditScmResult;
 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: PerforceUnEditCommand.java 1306867 2012-03-29 13:45:10Z olamy $
 42  
  */
 43  0
 public class PerforceUnEditCommand
 44  
     extends AbstractUnEditCommand
 45  
     implements PerforceCommand
 46  
 {
 47  
 
 48  
     /** {@inheritDoc} */
 49  
     protected ScmResult executeUnEditCommand( ScmProviderRepository repo, ScmFileSet files )
 50  
         throws ScmException
 51  
     {
 52  0
         Commandline cl = createCommandLine( (PerforceScmProviderRepository) repo, files.getBasedir(), files );
 53  0
         PerforceUnEditConsumer consumer = new PerforceUnEditConsumer();
 54  
         try
 55  
         {
 56  0
             CommandLineUtils.StringStreamConsumer err = new CommandLineUtils.StringStreamConsumer();
 57  0
             int exitCode = CommandLineUtils.executeCommandLine( cl, consumer, err );
 58  
 
 59  0
             if ( exitCode != 0 )
 60  
             {
 61  0
                 String cmdLine = CommandLineUtils.toString( cl.getCommandline() );
 62  
 
 63  0
                 StringBuilder msg = new StringBuilder( "Exit code: " + exitCode + " - " + err.getOutput() );
 64  0
                 msg.append( '\n' );
 65  0
                 msg.append( "Command line was:" + cmdLine );
 66  
 
 67  0
                 throw new CommandLineException( msg.toString() );
 68  
             }
 69  
         }
 70  0
         catch ( CommandLineException e )
 71  
         {
 72  0
             if ( getLogger().isErrorEnabled() )
 73  
             {
 74  0
                 getLogger().error( "CommandLineException " + e.getMessage(), e );
 75  
             }
 76  0
         }
 77  
 
 78  0
         if ( consumer.isSuccess() )
 79  
         {
 80  0
             return new UnEditScmResult( cl.toString(), consumer.getEdits() );
 81  
         }
 82  
 
 83  0
         return new UnEditScmResult( cl.toString(), "Unable to revert", consumer.getOutput(), consumer.isSuccess() );
 84  
     }
 85  
 
 86  
     public static Commandline createCommandLine( PerforceScmProviderRepository repo, File workingDirectory,
 87  
                                                  ScmFileSet files )
 88  
     {
 89  1
         Commandline command = PerforceScmProvider.createP4Command( repo, workingDirectory );
 90  
 
 91  1
         command.createArg().setValue( "revert" );
 92  
 
 93  1
         List<File> fs = files.getFileList();
 94  1
         for ( File file : fs )
 95  
         {
 96  2
             command.createArg().setValue( file.getName() );
 97  
         }
 98  1
         return command;
 99  
     }
 100  
 }