All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.maven.scm.plugin.CheckoutMojo Maven / Gradle / Ivy

Go to download

Kuali version of the maven-scm-plugin that supports removing files from SCM. The 1.6-SNAPSHOT version of the maven-scm-plugin at Apache has this ability but their 1.6-SNAPSHOT version hasn't been released yet. As soon as they do, the Kuali version of this plugin can be abandoned in favor of the one from Apache

The newest version!
package org.apache.maven.scm.plugin;

/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

import java.io.File;
import java.io.IOException;

import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.scm.ScmException;
import org.apache.maven.scm.ScmFileSet;
import org.apache.maven.scm.ScmResult;
import org.apache.maven.scm.repository.ScmRepository;
import org.codehaus.plexus.util.FileUtils;

/**
 * Get a fresh copy of the latest source from the configured scm url.
 *
 * @author Emmanuel Venisse
 * @version $Id: CheckoutMojo.java 928132 2010-03-27 03:39:51Z dantran $
 * @goal checkout
 * @requiresProject false
 */
public class CheckoutMojo
    extends AbstractScmMojo
{
    /**
     * Use Export instead of checkout
     *
     * @parameter expression="${useExport}" defaultValue="false";
     */
    private boolean useExport;
    
    /**
     * The directory to checkout the sources to for the bootstrap and checkout goals.
     *
     * @parameter expression="${checkoutDirectory}" default-value="${project.build.directory}/checkout"
     */
    private File checkoutDirectory;

    /**
     * Skip checkout if checkoutDirectory exists.
     *
     * @parameter expression="${skipCheckoutIfExists}" default-value="false"
     */
    private boolean skipCheckoutIfExists = false;

    /**
     * The version type (branch/tag/revision) of scmVersion.
     *
     * @parameter expression="${scmVersionType}"
     */
    private String scmVersionType;

    /**
     * The version (revision number/branch name/tag name).
     *
     * @parameter expression="${scmVersion}"
     */
    private String scmVersion;

    /**
     * allow extended mojo (ie BootStrap ) to see checkout result
     */
    private ScmResult checkoutResult;

    /** {@inheritDoc} */
    public void execute()
        throws MojoExecutionException
    {
        super.execute();

        //skip checkout if checkout directory is already created. See SCM-201
        checkoutResult = null;
        if ( !getCheckoutDirectory().isDirectory() || !this.skipCheckoutIfExists )
        {
            checkoutResult = checkout();
        }
    }

    protected File getCheckoutDirectory()
    {
        return this.checkoutDirectory;
    }

    public void setCheckoutDirectory( File checkoutDirectory )
    {
        this.checkoutDirectory = checkoutDirectory;
    }

    protected ScmResult checkout()
        throws MojoExecutionException
    {
        try
        {
            ScmRepository repository = getScmRepository();

            this.prepareOutputDirectory( getCheckoutDirectory() );
            
            ScmResult result = null;
            
            ScmFileSet fileSet = new ScmFileSet( getCheckoutDirectory().getAbsoluteFile() );
            if ( useExport )
            {
                result = getScmManager().export( repository,fileSet, getScmVersion( scmVersionType, scmVersion ) );
            }
            else
            {
                result = getScmManager().checkOut( repository,fileSet , getScmVersion( scmVersionType, scmVersion ) );
            }

            checkResult( result );
            
           
            handleExcludesIncludesAfterCheckoutAndExport( this.checkoutDirectory );

            return result;
        }
        catch ( ScmException e )
        {
            throw new MojoExecutionException( "Cannot run checkout command : ", e );
        }
    }

    private void prepareOutputDirectory( File ouputDirectory )
        throws MojoExecutionException
    {
        try
        {
            this.getLog().info( "Removing " + ouputDirectory );

            FileUtils.deleteDirectory( getCheckoutDirectory() );
        }
        catch ( IOException e )
        {
            throw new MojoExecutionException( "Cannot remove " + ouputDirectory );
        }
        
        if ( !getCheckoutDirectory().mkdirs() )
        {
            throw new MojoExecutionException( "Cannot create " + ouputDirectory );
        }
    }
    
    protected ScmResult getCheckoutResult()
    {
        return checkoutResult;
    }
    

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy