Coverage Report - org.apache.maven.scm.provider.clearcase.command.update.ClearCaseUpdateCommand
 
Classes in this File Line Coverage Branch Coverage Complexity
ClearCaseUpdateCommand
28 %
7/25
0 %
0/6
3
 
 1  
 package org.apache.maven.scm.provider.clearcase.command.update;
 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.ScmVersion;
 25  
 import org.apache.maven.scm.command.changelog.ChangeLogCommand;
 26  
 import org.apache.maven.scm.command.update.AbstractUpdateCommand;
 27  
 import org.apache.maven.scm.command.update.UpdateScmResult;
 28  
 import org.apache.maven.scm.provider.ScmProviderRepository;
 29  
 import org.apache.maven.scm.provider.clearcase.command.ClearCaseCommand;
 30  
 import org.apache.maven.scm.provider.clearcase.command.changelog.ClearCaseChangeLogCommand;
 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  
 
 37  
 /**
 38  
  * @author <a href="mailto:wim.deblauwe@gmail.com">Wim Deblauwe</a>
 39  
  * @author Olivier Lamy
 40  
  * @version $Id: ClearCaseUpdateCommand.java 1056980 2011-01-09 17:23:55Z olamy $
 41  
  */
 42  0
 public class ClearCaseUpdateCommand
 43  
     extends AbstractUpdateCommand
 44  
     implements ClearCaseCommand
 45  
 {
 46  
     /** {@inheritDoc} */
 47  
     protected UpdateScmResult executeUpdateCommand( ScmProviderRepository repository, ScmFileSet fileSet,
 48  
                                                     ScmVersion version )
 49  
         throws ScmException
 50  
     {
 51  0
         if ( getLogger().isDebugEnabled() )
 52  
         {
 53  0
             getLogger().debug( "executing update command..." );
 54  
         }
 55  0
         Commandline cl = createCommandLine( fileSet );
 56  
 
 57  0
         ClearCaseUpdateConsumer consumer = new ClearCaseUpdateConsumer( getLogger() );
 58  
 
 59  0
         CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
 60  
 
 61  
         int exitCode;
 62  
 
 63  
         try
 64  
         {
 65  0
             if ( getLogger().isDebugEnabled() )
 66  
             {
 67  0
                 getLogger().debug(
 68  
                                    "Executing: " + cl.getWorkingDirectory().getAbsolutePath() + ">>"
 69  
                                        + cl.toString() );
 70  
             }
 71  0
             exitCode = CommandLineUtils.executeCommandLine( cl, consumer, stderr );
 72  
         }
 73  0
         catch ( CommandLineException ex )
 74  
         {
 75  0
             throw new ScmException( "Error while executing clearcase command.", ex );
 76  0
         }
 77  
 
 78  0
         if ( exitCode != 0 )
 79  
         {
 80  0
             return new UpdateScmResult( cl.toString(), "The cleartool command failed.", stderr.getOutput(), false );
 81  
         }
 82  
 
 83  0
         return new UpdateScmResult( cl.toString(), consumer.getUpdatedFiles() );
 84  
     }
 85  
 
 86  
     /** {@inheritDoc} */
 87  
     protected ChangeLogCommand getChangeLogCommand()
 88  
     {
 89  0
         ClearCaseChangeLogCommand changeLogCmd = new ClearCaseChangeLogCommand();
 90  
 
 91  0
         changeLogCmd.setLogger( getLogger() );
 92  
 
 93  0
         return changeLogCmd;
 94  
     }
 95  
 
 96  
     // ----------------------------------------------------------------------
 97  
     //
 98  
     // ----------------------------------------------------------------------
 99  
 
 100  
     public static Commandline createCommandLine( ScmFileSet scmFileSet )
 101  
     {
 102  1
         Commandline command = new Commandline();
 103  
 
 104  1
         File workingDirectory = scmFileSet.getBasedir();
 105  
 
 106  1
         command.setWorkingDirectory( workingDirectory.getAbsolutePath() );
 107  
 
 108  1
         command.setExecutable( "cleartool" );
 109  
 
 110  1
         command.createArg().setValue( "update" );
 111  
 
 112  1
         command.createArg().setValue( "-f" );
 113  
 
 114  1
         return command;
 115  
     }
 116  
 }