Coverage Report - org.apache.maven.scm.provider.hg.command.checkout.HgCheckOutCommand
 
Classes in this File Line Coverage Branch Coverage Complexity
HgCheckOutCommand
0 %
0/28
0 %
0/10
8
 
 1  
 package org.apache.maven.scm.provider.hg.command.checkout;
 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.ScmVersion;
 26  
 import org.apache.maven.scm.command.Command;
 27  
 import org.apache.maven.scm.command.checkout.AbstractCheckOutCommand;
 28  
 import org.apache.maven.scm.command.checkout.CheckOutScmResult;
 29  
 import org.apache.maven.scm.provider.ScmProviderRepository;
 30  
 import org.apache.maven.scm.provider.hg.HgUtils;
 31  
 import org.apache.maven.scm.provider.hg.command.HgCommandConstants;
 32  
 import org.apache.maven.scm.provider.hg.command.HgConsumer;
 33  
 import org.apache.maven.scm.provider.hg.repository.HgScmProviderRepository;
 34  
 import org.codehaus.plexus.util.FileUtils;
 35  
 import org.codehaus.plexus.util.StringUtils;
 36  
 
 37  
 import java.io.File;
 38  
 import java.io.IOException;
 39  
 import java.util.ArrayList;
 40  
 import java.util.List;
 41  
 
 42  
 /**
 43  
  * @author <a href="mailto:thurner.rupert@ymono.net">thurner rupert</a>
 44  
  * @author Olivier Lamy
 45  
  * @version $Id: HgCheckOutCommand.java 1207290 2011-11-28 15:20:44Z olamy $
 46  
  */
 47  0
 public class HgCheckOutCommand
 48  
     extends AbstractCheckOutCommand
 49  
     implements Command
 50  
 {
 51  
     /**
 52  
      * {@inheritDoc}
 53  
      */
 54  
     protected CheckOutScmResult executeCheckOutCommand( ScmProviderRepository repo, ScmFileSet fileSet,
 55  
                                                         ScmVersion scmVersion, boolean recursive )
 56  
         throws ScmException
 57  
     {
 58  0
         HgScmProviderRepository repository = (HgScmProviderRepository) repo;
 59  0
         String url = repository.getURI();
 60  
 
 61  0
         File checkoutDir = fileSet.getBasedir();
 62  
         try
 63  
         {
 64  0
             if ( getLogger().isInfoEnabled() )
 65  
             {
 66  0
                 getLogger().info( "Removing " + checkoutDir );
 67  
             }
 68  0
             FileUtils.deleteDirectory( checkoutDir );
 69  
         }
 70  0
         catch ( IOException e )
 71  
         {
 72  0
             throw new ScmException( "Cannot remove " + checkoutDir );
 73  0
         }
 74  
 
 75  
         // Do the actual checkout
 76  0
         List<String> cmdList = new ArrayList<String>();
 77  0
         if ( repo.isPushChanges() )
 78  
         {
 79  0
             cmdList.add( HgCommandConstants.CLONE_CMD );
 80  
         }
 81  
         else
 82  
         {
 83  0
             cmdList.add( HgCommandConstants.UPDATE_CMD );
 84  
         }
 85  0
         if ( scmVersion != null && !StringUtils.isEmpty( scmVersion.getName() ) )
 86  
         {
 87  0
             cmdList.add( HgCommandConstants.REVISION_OPTION );
 88  0
             cmdList.add( scmVersion.getName() );
 89  
         }
 90  0
         if ( !repo.isPushChanges() )
 91  
         {
 92  0
             cmdList.add( HgCommandConstants.CLEAN_OPTION );
 93  
         }
 94  0
         cmdList.add( url );
 95  0
         cmdList.add( checkoutDir.getAbsolutePath() );
 96  0
         String[] checkoutCmd = cmdList.toArray( new String[0] );
 97  0
         HgConsumer checkoutConsumer = new HgConsumer( getLogger() );
 98  0
         HgUtils.execute( checkoutConsumer, getLogger(), checkoutDir.getParentFile(), checkoutCmd );
 99  
 
 100  
         // Do inventory to find list of checkedout files
 101  0
         String[] inventoryCmd = new String[]{ HgCommandConstants.INVENTORY_CMD };
 102  0
         HgCheckOutConsumer consumer = new HgCheckOutConsumer( getLogger(), checkoutDir );
 103  0
         ScmResult result = HgUtils.execute( consumer, getLogger(), checkoutDir, inventoryCmd );
 104  
 
 105  0
         return new CheckOutScmResult( consumer.getCheckedOutFiles(), result );
 106  
     }
 107  
 }