Coverage Report - org.apache.maven.scm.plugin.CheckoutMojo
 
Classes in this File Line Coverage Branch Coverage Complexity
CheckoutMojo
0%
0/31
0%
0/8
2.667
 
 1  
 package org.apache.maven.scm.plugin;
 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  
 
 25  
 import org.apache.maven.plugin.MojoExecutionException;
 26  
 import org.apache.maven.scm.ScmException;
 27  
 import org.apache.maven.scm.ScmFileSet;
 28  
 import org.apache.maven.scm.ScmResult;
 29  
 import org.apache.maven.scm.repository.ScmRepository;
 30  
 import org.codehaus.plexus.util.FileUtils;
 31  
 
 32  
 /**
 33  
  * Get a fresh copy of the latest source from the configured scm url.
 34  
  *
 35  
  * @author <a href="evenisse@apache.org">Emmanuel Venisse</a>
 36  
  * @version $Id: CheckoutMojo.java 928132 2010-03-27 03:39:51Z dantran $
 37  
  * @goal checkout
 38  
  * @requiresProject false
 39  
  */
 40  0
 public class CheckoutMojo
 41  
     extends AbstractScmMojo
 42  
 {
 43  
     /**
 44  
      * Use Export instead of checkout
 45  
      *
 46  
      * @parameter expression="${useExport}" defaultValue="false";
 47  
      */
 48  
     private boolean useExport;
 49  
     
 50  
     /**
 51  
      * The directory to checkout the sources to for the bootstrap and checkout goals.
 52  
      *
 53  
      * @parameter expression="${checkoutDirectory}" default-value="${project.build.directory}/checkout"
 54  
      */
 55  
     private File checkoutDirectory;
 56  
 
 57  
     /**
 58  
      * Skip checkout if checkoutDirectory exists.
 59  
      *
 60  
      * @parameter expression="${skipCheckoutIfExists}" default-value="false"
 61  
      */
 62  0
     private boolean skipCheckoutIfExists = false;
 63  
 
 64  
     /**
 65  
      * The version type (branch/tag/revision) of scmVersion.
 66  
      *
 67  
      * @parameter expression="${scmVersionType}"
 68  
      */
 69  
     private String scmVersionType;
 70  
 
 71  
     /**
 72  
      * The version (revision number/branch name/tag name).
 73  
      *
 74  
      * @parameter expression="${scmVersion}"
 75  
      */
 76  
     private String scmVersion;
 77  
 
 78  
     /**
 79  
      * allow extended mojo (ie BootStrap ) to see checkout result
 80  
      */
 81  
     private ScmResult checkoutResult;
 82  
 
 83  
     /** {@inheritDoc} */
 84  
     public void execute()
 85  
         throws MojoExecutionException
 86  
     {
 87  0
         super.execute();
 88  
 
 89  
         //skip checkout if checkout directory is already created. See SCM-201
 90  0
         checkoutResult = null;
 91  0
         if ( !getCheckoutDirectory().isDirectory() || !this.skipCheckoutIfExists )
 92  
         {
 93  0
             checkoutResult = checkout();
 94  
         }
 95  0
     }
 96  
 
 97  
     protected File getCheckoutDirectory()
 98  
     {
 99  0
         return this.checkoutDirectory;
 100  
     }
 101  
 
 102  
     public void setCheckoutDirectory( File checkoutDirectory )
 103  
     {
 104  0
         this.checkoutDirectory = checkoutDirectory;
 105  0
     }
 106  
 
 107  
     protected ScmResult checkout()
 108  
         throws MojoExecutionException
 109  
     {
 110  
         try
 111  
         {
 112  0
             ScmRepository repository = getScmRepository();
 113  
 
 114  0
             this.prepareOutputDirectory( getCheckoutDirectory() );
 115  
             
 116  0
             ScmResult result = null;
 117  
             
 118  0
             ScmFileSet fileSet = new ScmFileSet( getCheckoutDirectory().getAbsoluteFile() );
 119  0
             if ( useExport )
 120  
             {
 121  0
                 result = getScmManager().export( repository,fileSet, getScmVersion( scmVersionType, scmVersion ) );
 122  
             }
 123  
             else
 124  
             {
 125  0
                 result = getScmManager().checkOut( repository,fileSet , getScmVersion( scmVersionType, scmVersion ) );
 126  
             }
 127  
 
 128  0
             checkResult( result );
 129  
             
 130  
            
 131  0
             handleExcludesIncludesAfterCheckoutAndExport( this.checkoutDirectory );
 132  
 
 133  0
             return result;
 134  
         }
 135  0
         catch ( ScmException e )
 136  
         {
 137  0
             throw new MojoExecutionException( "Cannot run checkout command : ", e );
 138  
         }
 139  
     }
 140  
 
 141  
     private void prepareOutputDirectory( File ouputDirectory )
 142  
         throws MojoExecutionException
 143  
     {
 144  
         try
 145  
         {
 146  0
             this.getLog().info( "Removing " + ouputDirectory );
 147  
 
 148  0
             FileUtils.deleteDirectory( getCheckoutDirectory() );
 149  
         }
 150  0
         catch ( IOException e )
 151  
         {
 152  0
             throw new MojoExecutionException( "Cannot remove " + ouputDirectory );
 153  0
         }
 154  
         
 155  0
         if ( !getCheckoutDirectory().mkdirs() )
 156  
         {
 157  0
             throw new MojoExecutionException( "Cannot create " + ouputDirectory );
 158  
         }
 159  0
     }
 160  
     
 161  
     protected ScmResult getCheckoutResult()
 162  
     {
 163  0
         return checkoutResult;
 164  
     }
 165  
     
 166  
 
 167  
 }