Coverage Report - org.apache.maven.scm.provider.clearcase.command.remove.ClearCaseRemoveCommand
 
Classes in this File Line Coverage Branch Coverage Complexity
ClearCaseRemoveCommand
32 %
12/37
16 %
3/18
7
 
 1  
 package org.apache.maven.scm.provider.clearcase.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 java.io.File;
 23  
 import java.util.List;
 24  
 
 25  
 import org.apache.maven.scm.ScmException;
 26  
 import org.apache.maven.scm.ScmFileSet;
 27  
 import org.apache.maven.scm.ScmResult;
 28  
 import org.apache.maven.scm.command.remove.AbstractRemoveCommand;
 29  
 import org.apache.maven.scm.command.status.StatusScmResult;
 30  
 import org.apache.maven.scm.log.ScmLogger;
 31  
 import org.apache.maven.scm.provider.ScmProviderRepository;
 32  
 import org.apache.maven.scm.provider.clearcase.command.ClearCaseCommand;
 33  
 import org.apache.maven.scm.provider.clearcase.command.edit.ClearCaseEditCommand;
 34  
 import org.codehaus.plexus.util.cli.CommandLineException;
 35  
 import org.codehaus.plexus.util.cli.CommandLineUtils;
 36  
 import org.codehaus.plexus.util.cli.Commandline;
 37  
 
 38  
 /**
 39  
  * @author <a href="mailto:wim.deblauwe@gmail.com">Wim Deblauwe</a>
 40  
  * @author Olivier Lamy
 41  
  * @version $Id: ClearCaseRemoveCommand.java 1056938 2011-01-09 14:27:54Z olamy $
 42  
  */
 43  0
 public class ClearCaseRemoveCommand
 44  
     extends AbstractRemoveCommand
 45  
     implements ClearCaseCommand
 46  
 {
 47  
     /** {@inheritDoc} */
 48  
     protected ScmResult executeRemoveCommand( ScmProviderRepository scmProviderRepository, ScmFileSet scmFileSet,
 49  
                                               String string )
 50  
         throws ScmException
 51  
     {
 52  0
         if ( getLogger().isDebugEnabled() )
 53  
         {
 54  0
             getLogger().debug( "executing remove command..." );
 55  
         }
 56  0
         Commandline cl = createCommandLine( getLogger(), scmFileSet );
 57  
 
 58  0
         ClearCaseRemoveConsumer consumer = new ClearCaseRemoveConsumer( getLogger() );
 59  
 
 60  0
         CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
 61  
 
 62  
         int exitCode;
 63  
         try
 64  
         {
 65  
             // First we need to 'check out' the current directory
 66  0
             Commandline checkoutCurrentDirCommandLine =
 67  
                 ClearCaseEditCommand.createCheckoutCurrentDirCommandLine( scmFileSet );
 68  
 
 69  0
             if ( getLogger().isDebugEnabled() )
 70  
             {
 71  0
                 getLogger().debug(
 72  
                                    "Executing: "
 73  
                                        + checkoutCurrentDirCommandLine.getWorkingDirectory().getAbsolutePath()
 74  
                                        + ">>" + checkoutCurrentDirCommandLine.toString() );
 75  
             }
 76  0
             exitCode =
 77  
                 CommandLineUtils.executeCommandLine( checkoutCurrentDirCommandLine,
 78  
                                                      new CommandLineUtils.StringStreamConsumer(), stderr );
 79  
 
 80  0
             if ( exitCode == 0 )
 81  
             {
 82  
                 // Then we add the file
 83  0
                 if ( getLogger().isDebugEnabled() )
 84  
                 {
 85  0
                     getLogger().debug(
 86  
                                        "Executing: " + cl.getWorkingDirectory().getAbsolutePath() + ">>"
 87  
                                            + cl.toString() );
 88  
                 }
 89  0
                 exitCode = CommandLineUtils.executeCommandLine( cl, consumer, stderr );
 90  
 
 91  0
                 if ( exitCode == 0 )
 92  
                 {
 93  
                     // Then we check in the current directory again.
 94  0
                     Commandline checkinCurrentDirCommandLine =
 95  
                         ClearCaseEditCommand.createCheckinCurrentDirCommandLine( scmFileSet );
 96  0
                     if ( getLogger().isDebugEnabled() )
 97  
                     {
 98  0
                         getLogger().debug(
 99  
                                            "Executing: "
 100  
                                                + checkinCurrentDirCommandLine.getWorkingDirectory().getAbsolutePath()
 101  
                                                + ">>" + checkinCurrentDirCommandLine.toString() );
 102  
                     }
 103  0
                     exitCode = CommandLineUtils.executeCommandLine( checkinCurrentDirCommandLine,
 104  
                                                                     new CommandLineUtils.StringStreamConsumer(),
 105  
                                                                     stderr );
 106  
                 }
 107  
             }
 108  
         }
 109  0
         catch ( CommandLineException ex )
 110  
         {
 111  0
             throw new ScmException( "Error while executing clearcase command.", ex );
 112  0
         }
 113  
 
 114  0
         if ( exitCode != 0 )
 115  
         {
 116  0
             return new StatusScmResult( cl.toString(), "The cleartool command failed.", stderr.getOutput(), false );
 117  
         }
 118  
 
 119  0
         return new StatusScmResult( cl.toString(), consumer.getRemovedFiles() );
 120  
     }
 121  
 
 122  
     // ----------------------------------------------------------------------
 123  
     //
 124  
     // ----------------------------------------------------------------------
 125  
 
 126  
     public static Commandline createCommandLine( ScmLogger logger, ScmFileSet scmFileSet )
 127  
     {
 128  1
         Commandline command = new Commandline();
 129  
 
 130  1
         File workingDirectory = scmFileSet.getBasedir();
 131  
 
 132  1
         command.setWorkingDirectory( workingDirectory.getAbsolutePath() );
 133  
 
 134  1
         command.setExecutable( "cleartool" );
 135  
 
 136  1
         command.createArg().setValue( "rmname" );
 137  
 
 138  1
         command.createArg().setValue( "-nc" );
 139  
 
 140  1
         List<File> files = scmFileSet.getFileList();
 141  1
         for ( File file : files )
 142  
         {
 143  1
             if ( logger.isInfoEnabled() )
 144  
             {
 145  1
                 logger.info( "Deleting file: " + file.getAbsolutePath() );
 146  
             }
 147  1
             command.createArg().setValue( file.getName() );
 148  
         }
 149  
 
 150  1
         return command;
 151  
     }
 152  
 }