Coverage Report - org.apache.maven.scm.provider.clearcase.command.edit.ClearCaseEditCommand
 
Classes in this File Line Coverage Branch Coverage Complexity
ClearCaseEditCommand
27 %
12/43
30 %
3/10
3
 
 1  
 package org.apache.maven.scm.provider.clearcase.command.edit;
 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.edit.AbstractEditCommand;
 29  
 import org.apache.maven.scm.command.edit.EditScmResult;
 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  
  * @version $Id: ClearCaseEditCommand.java 1054772 2011-01-03 21:34:47Z olamy $
 40  
  */
 41  0
 public class ClearCaseEditCommand
 42  
     extends AbstractEditCommand
 43  
     implements ClearCaseCommand
 44  
 {
 45  
     /** {@inheritDoc} */
 46  
     protected ScmResult executeEditCommand( ScmProviderRepository repository, ScmFileSet fileSet )
 47  
         throws ScmException
 48  
     {
 49  0
         if ( getLogger().isDebugEnabled() )
 50  
         {
 51  0
             getLogger().debug( "executing edit command..." );
 52  
         }
 53  0
         Commandline cl = createCommandLine( getLogger(), fileSet );
 54  
 
 55  0
         ClearCaseEditConsumer consumer = new ClearCaseEditConsumer( getLogger() );
 56  
 
 57  0
         CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
 58  
 
 59  
         int exitCode;
 60  
 
 61  
         try
 62  
         {
 63  0
             if ( getLogger().isDebugEnabled() )
 64  
             {
 65  0
                 getLogger().debug(
 66  
                                    "Executing: " + cl.getWorkingDirectory().getAbsolutePath() + ">>"
 67  
                                        + cl.toString() );
 68  
             }
 69  0
             exitCode = CommandLineUtils.executeCommandLine( cl, consumer, stderr );
 70  
         }
 71  0
         catch ( CommandLineException ex )
 72  
         {
 73  0
             throw new ScmException( "Error while executing clearcase command.", ex );
 74  0
         }
 75  
 
 76  0
         if ( exitCode != 0 )
 77  
         {
 78  0
             return new EditScmResult( cl.toString(), "The cleartool command failed.", stderr.getOutput(), false );
 79  
         }
 80  
 
 81  0
         return new EditScmResult( cl.toString(), consumer.getEditFiles() );
 82  
     }
 83  
 
 84  
     // ----------------------------------------------------------------------
 85  
     //
 86  
     // ----------------------------------------------------------------------
 87  
 
 88  
     public static Commandline createCommandLine( ScmLogger logger, ScmFileSet scmFileSet )
 89  
     {
 90  1
         Commandline command = new Commandline();
 91  
 
 92  1
         File workingDirectory = scmFileSet.getBasedir();
 93  
 
 94  1
         command.setWorkingDirectory( workingDirectory.getAbsolutePath() );
 95  
 
 96  1
         command.setExecutable( "cleartool" );
 97  
 
 98  1
         command.createArg().setValue( "co" );
 99  
 
 100  1
         command.createArg().setValue( "-nc" );
 101  
 
 102  1
         List<File> files = scmFileSet.getFileList();
 103  1
         for ( File file : files )
 104  
         {
 105  1
             if ( logger.isInfoEnabled() )
 106  
             {
 107  1
                 logger.info( "edit file: " + file.getAbsolutePath() );
 108  
             }
 109  1
             command.createArg().setValue( file.getAbsolutePath() );
 110  
         }
 111  
 
 112  1
         return command;
 113  
     }
 114  
 
 115  
     public static Commandline createCheckoutCurrentDirCommandLine( ScmFileSet scmFileSet )
 116  
     {
 117  0
         Commandline command = new Commandline();
 118  
 
 119  0
         File workingDirectory = scmFileSet.getBasedir();
 120  
 
 121  0
         command.setWorkingDirectory( workingDirectory.getAbsolutePath() );
 122  
 
 123  0
         command.setExecutable( "cleartool" );
 124  
 
 125  0
         command.createArg().setValue( "co" );
 126  
 
 127  0
         command.createArg().setValue( "-nc" );
 128  
 
 129  0
         command.createArg().setValue( "." );
 130  
 
 131  0
         return command;
 132  
     }
 133  
 
 134  
     public static Commandline createCheckinCurrentDirCommandLine( ScmFileSet scmFileSet )
 135  
     {
 136  0
         Commandline command = new Commandline();
 137  
 
 138  0
         File workingDirectory = scmFileSet.getBasedir();
 139  
 
 140  0
         command.setWorkingDirectory( workingDirectory.getAbsolutePath() );
 141  
 
 142  0
         command.setExecutable( "cleartool" );
 143  
 
 144  0
         command.createArg().setValue( "ci" );
 145  
 
 146  0
         command.createArg().setValue( "-nc" );
 147  
 
 148  0
         command.createArg().setValue( "." );
 149  
 
 150  0
         return command;
 151  
     }
 152  
 
 153  
 }