Coverage Report - org.apache.maven.scm.provider.clearcase.command.tag.ClearCaseTagCommand
 
Classes in this File Line Coverage Branch Coverage Complexity
ClearCaseTagCommand
27 %
12/44
25 %
4/16
3,75
 
 1  
 package org.apache.maven.scm.provider.clearcase.command.tag;
 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.ScmTagParameters;
 29  
 import org.apache.maven.scm.command.tag.AbstractTagCommand;
 30  
 import org.apache.maven.scm.command.tag.TagScmResult;
 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.checkin.ClearCaseCheckInConsumer;
 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: ClearCaseTagCommand.java 1056959 2011-01-09 15:02:55Z olamy $
 42  
  */
 43  0
 public class ClearCaseTagCommand
 44  
     extends AbstractTagCommand
 45  
     implements ClearCaseCommand
 46  
 {
 47  
     
 48  
     protected ScmResult executeTagCommand( ScmProviderRepository scmProviderRepository, ScmFileSet fileSet, String tag,
 49  
                                            String message )
 50  
         throws ScmException
 51  
     {
 52  0
         return executeTagCommand( scmProviderRepository, fileSet, tag, new ScmTagParameters( message ) );
 53  
     }
 54  
     
 55  
     /** {@inheritDoc} */
 56  
     protected ScmResult executeTagCommand( ScmProviderRepository scmProviderRepository, ScmFileSet fileSet, String tag,
 57  
                                            ScmTagParameters scmTagParameters )
 58  
         throws ScmException
 59  
     {
 60  0
         if ( getLogger().isDebugEnabled() )
 61  
         {
 62  0
             getLogger().debug( "executing tag command..." );
 63  
         }
 64  0
         Commandline cl = createCommandLine( fileSet, tag );
 65  
 
 66  0
         ClearCaseCheckInConsumer consumer = new ClearCaseCheckInConsumer( getLogger() );
 67  
 
 68  0
         CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
 69  
 
 70  
         int exitCode;
 71  
 
 72  
         try
 73  
         {
 74  0
             if ( getLogger().isDebugEnabled() )
 75  
             {
 76  0
                 getLogger().debug( "Creating label: " + tag );
 77  
             }
 78  0
             Commandline newLabelCommandLine = createNewLabelCommandLine( fileSet, tag );
 79  0
             if ( getLogger().isDebugEnabled() )
 80  
             {
 81  0
                 getLogger().debug(
 82  
                                    "Executing: " + newLabelCommandLine.getWorkingDirectory().getAbsolutePath()
 83  
                                        + ">>" + newLabelCommandLine.toString() );
 84  
             }
 85  0
             exitCode = CommandLineUtils.executeCommandLine( newLabelCommandLine,
 86  
                                                             new CommandLineUtils.StringStreamConsumer(), stderr );
 87  
 
 88  0
             if ( exitCode == 0 )
 89  
             {
 90  0
                 getLogger().debug( "Executing: " + cl.getWorkingDirectory().getAbsolutePath() + ">>" + cl.toString() );
 91  0
                 exitCode = CommandLineUtils.executeCommandLine( cl, consumer, stderr );
 92  
             }
 93  
         }
 94  0
         catch ( CommandLineException ex )
 95  
         {
 96  0
             throw new ScmException( "Error while executing clearcase command.", ex );
 97  0
         }
 98  
 
 99  0
         if ( exitCode != 0 )
 100  
         {
 101  0
             return new TagScmResult( cl.toString(), "The cleartool command failed.", stderr.getOutput(), false );
 102  
         }
 103  
 
 104  0
         return new TagScmResult( cl.toString(), consumer.getCheckedInFiles() );
 105  
     }
 106  
 
 107  
     // ----------------------------------------------------------------------
 108  
     //
 109  
     // ----------------------------------------------------------------------
 110  
 
 111  
     public static Commandline createCommandLine( ScmFileSet scmFileSet, String tag )
 112  
     {
 113  1
         Commandline command = new Commandline();
 114  
 
 115  1
         File workingDirectory = scmFileSet.getBasedir();
 116  
 
 117  1
         command.setWorkingDirectory( workingDirectory.getAbsolutePath() );
 118  
 
 119  1
         command.setExecutable( "cleartool" );
 120  
 
 121  1
         command.createArg().setValue( "mklabel" );
 122  1
         List<File> files = scmFileSet.getFileList();
 123  1
         if ( files.isEmpty() )
 124  
         {
 125  0
             command.createArg().setValue( "-recurse" );
 126  
         }
 127  1
         command.createArg().setValue( tag );
 128  
 
 129  1
         if ( files.size() > 0 )
 130  
         {
 131  1
             for ( File file : files )
 132  
             {
 133  1
                 command.createArg().setValue( file.getName() );
 134  
             }
 135  
         }
 136  
         else
 137  
         {
 138  0
             command.createArg().setValue( "." );
 139  
         }
 140  
 
 141  1
         return command;
 142  
     }
 143  
 
 144  
     private static Commandline createNewLabelCommandLine( ScmFileSet scmFileSet, String tag )
 145  
     {
 146  0
         Commandline command = new Commandline();
 147  
 
 148  0
         File workingDirectory = scmFileSet.getBasedir();
 149  
 
 150  0
         command.setWorkingDirectory( workingDirectory.getAbsolutePath() );
 151  
 
 152  0
         command.setExecutable( "cleartool" );
 153  
 
 154  0
         command.createArg().setValue( "mklbtype" );
 155  0
         command.createArg().setValue( "-nc" );
 156  0
         command.createArg().setValue( tag );
 157  
 
 158  0
         return command;
 159  
     }
 160  
 }