Coverage Report - org.apache.maven.scm.provider.jazz.command.update.JazzUpdateCommand
 
Classes in this File Line Coverage Branch Coverage Complexity
JazzUpdateCommand
16 %
4/25
0 %
0/12
3,333
 
 1  
 package org.apache.maven.scm.provider.jazz.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.ScmFile;
 24  
 import org.apache.maven.scm.ScmFileSet;
 25  
 import org.apache.maven.scm.ScmVersion;
 26  
 import org.apache.maven.scm.command.changelog.ChangeLogCommand;
 27  
 import org.apache.maven.scm.command.update.AbstractUpdateCommand;
 28  
 import org.apache.maven.scm.command.update.UpdateScmResult;
 29  
 import org.apache.maven.scm.provider.ScmProviderRepository;
 30  
 import org.apache.maven.scm.provider.jazz.command.JazzConstants;
 31  
 import org.apache.maven.scm.provider.jazz.command.JazzScmCommand;
 32  
 import org.apache.maven.scm.provider.jazz.command.changelog.JazzChangeLogCommand;
 33  
 import org.apache.maven.scm.provider.jazz.command.consumer.ErrorConsumer;
 34  
 
 35  
 import java.util.Iterator;
 36  
 
 37  
 //
 38  
 // The Maven SCM Plugin "update" goal is equivalent to the RTC "accept" command.
 39  
 //
 40  
 // NOTE: What is not clear from the docs, is that the accept command will also
 41  
 // update the sandbox with the changes that have been accepted into the repository.
 42  
 // However, I have checked with Rational Support, and this is indeed the expected
 43  
 // behaviour. This may come from the fact that you can accept changes into a
 44  
 // repository workspace, without having a sandbox loaded; though this makes no
 45  
 // sense to us from a maven usage context (as we only work in a sandbox).
 46  
 //
 47  
 // See the following links for additional information on the RTC "create snapshot" command:
 48  
 // RTC 2.0.0.2:
 49  
 // http://publib.boulder.ibm.com/infocenter/rtc/v2r0m0/topic/com.ibm.team.scm.doc/topics/r_scm_cli_accept.html
 50  
 // RTC 3.0:
 51  
 // http://publib.boulder.ibm.com/infocenter/clmhelp/v3r0/topic/com.ibm.team.scm.doc/topics/r_scm_cli_accept.html
 52  
 // RTC 3.0.1:
 53  
 // http://publib.boulder.ibm.com/infocenter/clmhelp/v3r0m1/topic/com.ibm.team.scm.doc/topics/r_scm_cli_accept.html
 54  
 //
 55  
 
 56  
 /**
 57  
  * @author <a href="mailto:ChrisGWarp@gmail.com">Chris Graham</a>
 58  
  */
 59  1
 public class JazzUpdateCommand
 60  
     extends AbstractUpdateCommand
 61  
 {
 62  
     /**
 63  
      * {@inheritDoc}
 64  
      */
 65  
     protected UpdateScmResult executeUpdateCommand( ScmProviderRepository repo, ScmFileSet fileSet, ScmVersion version )
 66  
         throws ScmException
 67  
     {
 68  0
         if ( getLogger().isDebugEnabled() )
 69  
         {
 70  0
             getLogger().debug( "Executing update command..." );
 71  
         }
 72  
 
 73  0
         JazzUpdateConsumer updateConsumer = new JazzUpdateConsumer( repo, getLogger() );
 74  0
         ErrorConsumer err = new ErrorConsumer( getLogger() );
 75  
 
 76  0
         JazzScmCommand updateCmd = createAcceptCommand( repo, fileSet );
 77  0
         int status = updateCmd.execute( updateConsumer, err );
 78  
 
 79  0
         if ( status != 0 || err.hasBeenFed() )
 80  
         {
 81  0
             return new UpdateScmResult( updateCmd.getCommandString(),
 82  
                                         "Error code for Jazz SCM update command - " + status, err.getOutput(), false );
 83  
         }
 84  
 
 85  0
         if ( getLogger().isDebugEnabled() )
 86  
         {
 87  0
             Iterator<ScmFile> iter = updateConsumer.getUpdatedFiles().iterator();
 88  0
             if ( iter.hasNext() )
 89  
             {
 90  0
                 getLogger().debug( "Iterating over \"Update\" results" );
 91  0
                 while ( iter.hasNext() )
 92  
                 {
 93  0
                     ScmFile file = (ScmFile) iter.next();
 94  0
                     getLogger().debug( file.getPath() + " : " + file.getStatus() );
 95  0
                 }
 96  
             }
 97  
             else
 98  
             {
 99  0
                 getLogger().debug( "There are no updated files" );
 100  
             }
 101  
         }
 102  
 
 103  
         // Now, just (re)load the workspace into the sand box.
 104  
         // We can use the checkout directory for this.
 105  0
         return new UpdateScmResult( updateCmd.getCommandString(), updateConsumer.getUpdatedFiles() );
 106  
     }
 107  
 
 108  
     public JazzScmCommand createAcceptCommand( ScmProviderRepository repo, ScmFileSet fileSet )
 109  
     {
 110  1
         JazzScmCommand command = new JazzScmCommand( JazzConstants.CMD_ACCEPT, repo, fileSet, getLogger() );
 111  
 
 112  1
         command.addArgument( JazzConstants.ARG_FLOW_COMPONENTS );
 113  
 
 114  1
         return command;
 115  
     }
 116  
 
 117  
     /**
 118  
      * {@inheritDoc}
 119  
      */
 120  
     protected ChangeLogCommand getChangeLogCommand()
 121  
     {
 122  0
         JazzChangeLogCommand command = new JazzChangeLogCommand();
 123  
 
 124  0
         command.setLogger( getLogger() );
 125  
 
 126  0
         return command;
 127  
     }
 128  
 
 129  
 }