Coverage Report - org.apache.maven.scm.provider.clearcase.command.unedit.ClearCaseUnEditCommand
 
Classes in this File Line Coverage Branch Coverage Complexity
ClearCaseUnEditCommand
40 %
10/25
25 %
2/8
4,5
 
 1  
 package org.apache.maven.scm.provider.clearcase.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 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.status.StatusScmResult;
 29  
 import org.apache.maven.scm.command.unedit.AbstractUnEditCommand;
 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.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 <a href="mailto:wim.deblauwe@gmail.com">Wim Deblauwe</a>
 39  
  * @author Olivier Lamy
 40  
  * @version $Id: ClearCaseUnEditCommand.java 1056960 2011-01-09 15:03:50Z olamy $
 41  
  */
 42  0
 public class ClearCaseUnEditCommand
 43  
     extends AbstractUnEditCommand
 44  
     implements ClearCaseCommand
 45  
 {
 46  
     /** {@inheritDoc} */
 47  
     protected ScmResult executeUnEditCommand( ScmProviderRepository repository, ScmFileSet fileSet )
 48  
         throws ScmException
 49  
     {
 50  0
         if ( getLogger().isDebugEnabled() )
 51  
         {
 52  0
             getLogger().debug( "executing unedit command..." );
 53  
         }
 54  0
         Commandline cl = createCommandLine( getLogger(), fileSet );
 55  
 
 56  0
         ClearCaseUnEditConsumer consumer = new ClearCaseUnEditConsumer( getLogger() );
 57  
 
 58  0
         CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
 59  
 
 60  
         int exitCode;
 61  
 
 62  
         try
 63  
         {
 64  0
             if ( getLogger().isDebugEnabled() )
 65  
             {
 66  0
                 getLogger().debug( "Executing: " + cl.getWorkingDirectory().getAbsolutePath() + ">>" + cl.toString() );
 67  
             }
 68  0
             exitCode = CommandLineUtils.executeCommandLine( cl, consumer, stderr );
 69  
         }
 70  0
         catch ( CommandLineException ex )
 71  
         {
 72  0
             throw new ScmException( "Error while executing clearcase command.", ex );
 73  0
         }
 74  
 
 75  0
         if ( exitCode != 0 )
 76  
         {
 77  0
             return new StatusScmResult( cl.toString(), "The cleartool command failed.", stderr.getOutput(), false );
 78  
         }
 79  
 
 80  0
         return new StatusScmResult( cl.toString(), consumer.getUnEditFiles() );
 81  
     }
 82  
 
 83  
     // ----------------------------------------------------------------------
 84  
     //
 85  
     // ----------------------------------------------------------------------
 86  
 
 87  
     public static Commandline createCommandLine( ScmLogger logger, ScmFileSet scmFileSet )
 88  
     {
 89  1
         Commandline command = new Commandline();
 90  
 
 91  1
         File workingDirectory = scmFileSet.getBasedir();
 92  
 
 93  1
         command.setWorkingDirectory( workingDirectory.getAbsolutePath() );
 94  
 
 95  1
         command.setExecutable( "cleartool" );
 96  
 
 97  1
         command.createArg().setValue( "unco" );
 98  1
         command.createArg().setValue( "-keep" );
 99  
 
 100  1
         List<File> files = scmFileSet.getFileList();
 101  1
         for ( File file : files )
 102  
         {
 103  1
             command.createArg().setValue( file.getName() );
 104  
         }
 105  
 
 106  1
         return command;
 107  
     }
 108  
 }