Coverage Report - org.apache.maven.scm.provider.bazaar.command.checkout.BazaarCheckOutCommand
 
Classes in this File Line Coverage Branch Coverage Complexity
BazaarCheckOutCommand
0 %
0/25
0 %
0/8
8
 
 1  
 package org.apache.maven.scm.provider.bazaar.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 java.io.File;
 23  
 import java.io.IOException;
 24  
 import java.util.ArrayList;
 25  
 import java.util.List;
 26  
 
 27  
 import org.apache.maven.scm.ScmException;
 28  
 import org.apache.maven.scm.ScmFileSet;
 29  
 import org.apache.maven.scm.ScmResult;
 30  
 import org.apache.maven.scm.ScmVersion;
 31  
 import org.apache.maven.scm.command.checkout.AbstractCheckOutCommand;
 32  
 import org.apache.maven.scm.command.checkout.CheckOutScmResult;
 33  
 import org.apache.maven.scm.provider.ScmProviderRepository;
 34  
 import org.apache.maven.scm.provider.bazaar.BazaarUtils;
 35  
 import org.apache.maven.scm.provider.bazaar.command.BazaarConstants;
 36  
 import org.apache.maven.scm.provider.bazaar.command.BazaarConsumer;
 37  
 import org.apache.maven.scm.provider.bazaar.repository.BazaarScmProviderRepository;
 38  
 import org.codehaus.plexus.util.FileUtils;
 39  
 import org.codehaus.plexus.util.StringUtils;
 40  
 
 41  
 /**
 42  
  * @author <a href="mailto:torbjorn@smorgrav.org">Torbjorn Eikli Smorgrav</a>
 43  
  * @author Olivier Lamy
 44  
  * @version $Id: BazaarCheckOutCommand.java 1054738 2011-01-03 20:40:39Z olamy $
 45  
  */
 46  0
 public class BazaarCheckOutCommand
 47  
     extends AbstractCheckOutCommand
 48  
 {
 49  
     /** {@inheritDoc} */
 50  
     protected CheckOutScmResult executeCheckOutCommand( ScmProviderRepository repo, ScmFileSet fileSet,
 51  
                                                         ScmVersion version, boolean recursive )
 52  
         throws ScmException
 53  
     {
 54  0
         BazaarScmProviderRepository repository = (BazaarScmProviderRepository) repo;
 55  0
         String url = repository.getURI();
 56  
 
 57  0
         File checkoutDir = fileSet.getBasedir();
 58  
         try
 59  
         {
 60  0
             if ( getLogger().isInfoEnabled() )
 61  
             {
 62  0
                 getLogger().info( "Removing " + checkoutDir );
 63  
             }
 64  0
             FileUtils.deleteDirectory( checkoutDir );
 65  
         }
 66  0
         catch ( IOException e )
 67  
         {
 68  0
             throw new ScmException( "Cannot remove " + checkoutDir );
 69  0
         }
 70  
 
 71  
         // Do the actual checkout
 72  0
         List<String> checkoutCmd = new ArrayList<String>();
 73  0
         checkoutCmd.add( BazaarConstants.BRANCH_CMD );
 74  0
         checkoutCmd.add( url );
 75  0
         checkoutCmd.add( checkoutDir.getAbsolutePath() );
 76  0
         if ( version != null && StringUtils.isNotEmpty( version.getName() ) ) {
 77  0
              checkoutCmd.add( BazaarConstants.REVISION_OPTION );
 78  0
              checkoutCmd.add( "tag:" + version.getName() );
 79  
         }
 80  0
         BazaarConsumer checkoutConsumer = new BazaarConsumer( getLogger() );
 81  0
         BazaarUtils.execute( checkoutConsumer, getLogger(), checkoutDir.getParentFile(),
 82  
                              (String[]) checkoutCmd.toArray( new String[0] ) );
 83  
 
 84  
         // Do inventory to find list of checkedout files
 85  0
         String[] inventoryCmd = new String[]{BazaarConstants.INVENTORY_CMD};
 86  0
         BazaarCheckOutConsumer consumer = new BazaarCheckOutConsumer( getLogger(), checkoutDir );
 87  0
         ScmResult result = BazaarUtils.execute( consumer, getLogger(), checkoutDir, inventoryCmd );
 88  0
         if ( !result.isSuccess() )
 89  
         {
 90  0
             throw new ScmException( result.getProviderMessage() );
 91  
         }
 92  0
         return new CheckOutScmResult( consumer.getCheckedOutFiles(), result );
 93  
     }
 94  
 }