Coverage Report - org.apache.maven.scm.provider.jazz.command.unedit.JazzUnEditCommand
 
Classes in this File Line Coverage Branch Coverage Complexity
JazzUnEditCommand
57 %
12/21
41 %
5/12
4,5
 
 1  
 package org.apache.maven.scm.provider.jazz.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 org.apache.maven.scm.ScmException;
 23  
 import org.apache.maven.scm.ScmFileSet;
 24  
 import org.apache.maven.scm.ScmResult;
 25  
 import org.apache.maven.scm.command.unedit.AbstractUnEditCommand;
 26  
 import org.apache.maven.scm.command.unedit.UnEditScmResult;
 27  
 import org.apache.maven.scm.provider.ScmProviderRepository;
 28  
 import org.apache.maven.scm.provider.jazz.command.JazzConstants;
 29  
 import org.apache.maven.scm.provider.jazz.command.JazzScmCommand;
 30  
 import org.apache.maven.scm.provider.jazz.command.consumer.DebugLoggerConsumer;
 31  
 import org.apache.maven.scm.provider.jazz.command.consumer.ErrorConsumer;
 32  
 
 33  
 import java.io.File;
 34  
 import java.util.Iterator;
 35  
 import java.util.List;
 36  
 
 37  
 // In RTC the need to 'edit' or 'lock' a file is not required. It is actually encouraged to not 
 38  
 // lock 'text' based files and to only lock binary file types.
 39  
 //
 40  
 // The Maven SCM plugin "edit" goal has been implemented by using the RTC "lock acquire/release" commands. 
 41  
 //
 42  
 // See the following links for additional information on the RTC "lock acquire" command:
 43  
 // RTC 2.0.0.2:
 44  
 // http://publib.boulder.ibm.com/infocenter/rtc/v2r0m0/topic/com.ibm.team.scm.doc/topics/r_scm_cli_lock_acquire.html
 45  
 // RTC 3.0:
 46  
 // http://publib.boulder.ibm.com/infocenter/clmhelp/v3r0/topic/com.ibm.team.scm.doc/topics/r_scm_cli_lock_acquire.html
 47  
 // RTC 3.0.1:
 48  
 // http://publib.boulder.ibm.com/infocenter/clmhelp/v3r0m1/topic/com.ibm.team.scm.doc/topics/r_scm_cli_lock_acquire.html
 49  
 //
 50  
 // See the following links for additional information on the RTC "lock release" command:
 51  
 // RTC 2.0.0.2:
 52  
 // http://publib.boulder.ibm.com/infocenter/rtc/v2r0m0/topic/com.ibm.team.scm.doc/topics/r_scm_cli_lock_release.html
 53  
 // RTC 3.0:
 54  
 // http://publib.boulder.ibm.com/infocenter/clmhelp/v3r0/topic/com.ibm.team.scm.doc/topics/r_scm_cli_lock_release.html
 55  
 // RTC 3.0.1:
 56  
 // http://publib.boulder.ibm.com/infocenter/clmhelp/v3r0m1/topic/com.ibm.team.scm.doc/topics/r_scm_cli_lock_release.html
 57  
 //
 58  
 
 59  
 /**
 60  
  * @author <a href="mailto:ChrisGWarp@gmail.com">Chris Graham</a>
 61  
  */
 62  2
 public class JazzUnEditCommand
 63  
     extends AbstractUnEditCommand
 64  
 {
 65  
     /**
 66  
      * {@inheritDoc}
 67  
      */
 68  
     protected ScmResult executeUnEditCommand( ScmProviderRepository repo, ScmFileSet fileSet )
 69  
         throws ScmException
 70  
     {
 71  0
         if ( getLogger().isDebugEnabled() )
 72  
         {
 73  0
             getLogger().debug( "Executing unedit command..." );
 74  
         }
 75  
 
 76  0
         DebugLoggerConsumer uneditConsumer = new DebugLoggerConsumer( getLogger() );
 77  0
         ErrorConsumer errConsumer = new ErrorConsumer( getLogger() );
 78  
 
 79  0
         JazzScmCommand uneditCmd = createUneditCommand( repo, fileSet );
 80  0
         int status = uneditCmd.execute( uneditConsumer, errConsumer );
 81  
 
 82  0
         if ( status != 0 || errConsumer.hasBeenFed() )
 83  
         {
 84  0
             return new UnEditScmResult( uneditCmd.getCommandString(),
 85  
                                         "Error code for Jazz SCM unedit command - " + status, errConsumer.getOutput(),
 86  
                                         false );
 87  
         }
 88  
 
 89  0
         return new UnEditScmResult( uneditCmd.getCommandString(), "Successfully Completed.", uneditConsumer.getOutput(),
 90  
                                     true );
 91  
     }
 92  
 
 93  
     public JazzScmCommand createUneditCommand( ScmProviderRepository repo, ScmFileSet fileSet )
 94  
     {
 95  2
         JazzScmCommand command =
 96  
             new JazzScmCommand( JazzConstants.CMD_LOCK, JazzConstants.CMD_SUB_RELEASE, repo, fileSet, getLogger() );
 97  
 
 98  2
         List<File> files = fileSet.getFileList();
 99  2
         if ( files != null && !files.isEmpty() )
 100  
         {
 101  1
             Iterator<File> it = files.iterator();
 102  3
             while ( it.hasNext() )
 103  
             {
 104  2
                 File file = (File) it.next();
 105  2
                 command.addArgument( file.getPath() ); // Un-Lock only the files specified
 106  2
             }
 107  1
         }
 108  
         else
 109  
         {
 110  1
             command.addArgument( "." ); // Un-Lock all files
 111  
         }
 112  
 
 113  2
         return command;
 114  
     }
 115  
 }