Coverage Report - org.apache.maven.scm.provider.clearcase.command.checkin.ClearCaseCheckInCommand
 
Classes in this File Line Coverage Branch Coverage Complexity
ClearCaseCheckInCommand
43 %
13/30
33 %
4/12
6
 
 1  
 package org.apache.maven.scm.provider.clearcase.command.checkin;
 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.ScmVersion;
 28  
 import org.apache.maven.scm.command.checkin.AbstractCheckInCommand;
 29  
 import org.apache.maven.scm.command.checkin.CheckInScmResult;
 30  
 import org.apache.maven.scm.provider.ScmProviderRepository;
 31  
 import org.apache.maven.scm.provider.clearcase.command.ClearCaseCommand;
 32  
 import org.codehaus.plexus.util.cli.CommandLineException;
 33  
 import org.codehaus.plexus.util.cli.CommandLineUtils;
 34  
 import org.codehaus.plexus.util.cli.Commandline;
 35  
 
 36  
 /**
 37  
  * @author <a href="mailto:wim.deblauwe@gmail.com">Wim Deblauwe</a>
 38  
  * @author Olivier Lamy
 39  
  * @version $Id: ClearCaseCheckInCommand.java 1054455 2011-01-02 18:40:29Z olamy $
 40  
  */
 41  0
 public class ClearCaseCheckInCommand
 42  
     extends AbstractCheckInCommand
 43  
     implements ClearCaseCommand
 44  
 {
 45  
     // ----------------------------------------------------------------------
 46  
     // AbstractCheckOutCommand Implementation
 47  
     // ----------------------------------------------------------------------
 48  
 
 49  
     /** {@inheritDoc} */
 50  
     protected CheckInScmResult executeCheckInCommand( ScmProviderRepository scmProviderRepository, ScmFileSet fileSet,
 51  
                                                       String message, ScmVersion version )
 52  
         throws ScmException
 53  
     {
 54  0
         if ( getLogger().isDebugEnabled() )
 55  
         {
 56  0
             getLogger().debug( "executing checkin command..." );
 57  
         }
 58  0
         Commandline cl = createCommandLine( fileSet, message );
 59  
 
 60  0
         ClearCaseCheckInConsumer consumer = new ClearCaseCheckInConsumer( getLogger() );
 61  
 
 62  0
         CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
 63  
 
 64  
         int exitCode;
 65  
 
 66  
         try
 67  
         {
 68  0
             if ( getLogger().isDebugEnabled() )
 69  
             {
 70  0
                 getLogger().debug(
 71  
                                    "Executing: " + cl.getWorkingDirectory().getAbsolutePath() + ">>"
 72  
                                        + cl.toString() );
 73  
             }
 74  0
             exitCode = CommandLineUtils.executeCommandLine( cl, consumer, stderr );
 75  
         }
 76  0
         catch ( CommandLineException ex )
 77  
         {
 78  0
             throw new ScmException( "Error while executing clearcase command.", ex );
 79  0
         }
 80  
 
 81  0
         if ( exitCode != 0 )
 82  
         {
 83  0
             return new CheckInScmResult( cl.toString(), "The cleartool command failed.", stderr.getOutput(), false );
 84  
         }
 85  
 
 86  0
         return new CheckInScmResult( cl.toString(), consumer.getCheckedInFiles() );
 87  
     }
 88  
 
 89  
     // ----------------------------------------------------------------------
 90  
     //
 91  
     // ----------------------------------------------------------------------
 92  
 
 93  
     public static Commandline createCommandLine( ScmFileSet scmFileSet, String message )
 94  
         throws ScmException
 95  
     {
 96  1
         Commandline command = new Commandline();
 97  
 
 98  1
         File workingDirectory = scmFileSet.getBasedir();
 99  
 
 100  1
         command.setWorkingDirectory( workingDirectory.getAbsolutePath() );
 101  
 
 102  1
         command.setExecutable( "cleartool" );
 103  
 
 104  1
         command.createArg().setValue( "ci" );
 105  
 
 106  1
         if ( message != null )
 107  
         {
 108  1
             command.createArg().setValue( "-c" );
 109  1
             command.createArg().setLine( "\"" + message + "\"" );
 110  
         }
 111  
         else
 112  
         {
 113  0
             command.createArg().setValue( "-nc" );
 114  
         }
 115  
 
 116  1
         List<File> files = scmFileSet.getFileList();
 117  1
         if ( files.isEmpty() )
 118  
         {
 119  0
             throw new ScmException( "There are no files in the fileset to check in!" );
 120  
         }
 121  1
         for ( File file : files )
 122  
         {
 123  1
             command.createArg().setValue( file.getAbsolutePath() );
 124  
         }
 125  
 
 126  1
         return command;
 127  
     }
 128  
 }