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

com.rimerosolutions.ant.git.tasks.CloneTask Maven / Gradle / Ivy

There is a newer version: 1.3.2
Show newest version
/*
 * Copyright 2013 Rimero Solutions
 *
 * Licensed 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.
 */
package com.rimerosolutions.ant.git.tasks;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.eclipse.jgit.api.CloneCommand;

import com.rimerosolutions.ant.git.AbstractGitTask;
import com.rimerosolutions.ant.git.GitBuildException;

/**
 * Clone a repository.
 *
 * 
{@code
 *  
 *    
 *  }
* *

Git documentation about clone

*

JGit CloneCommand

* * @author Yves Zoundi */ public class CloneTask extends AbstractGitTask { private String branchToTrack; private boolean bare = false; private boolean cloneSubModules = true; private boolean cloneAllBranches = false; private boolean noCheckout = false; private List branchNames = new ArrayList(); private static final String TASK_NAME = "git-clone"; private static final String MESSAGE_CLONE_FAILED = "Could not clone URL '%s'."; @Override public String getName() { return TASK_NAME; } /** * Sets the branch names to clone * * @antdoc.notrequired * @param branchNames Comma separated list of branches to clone */ public void setBranchNames(String branchNames) { this.branchNames.addAll(Arrays.asList(branchNames.split(","))); } /** * Sets the branch to track * * @antdoc.notrequired * @param branchToTrack The branch to track */ public void setBranchToTrack(String branchToTrack) { this.branchToTrack = branchToTrack; } /** * Sets whether or not the repository is bare * * @antdoc.notrequired * @param bare Whether or not the repository is bare (Default false) */ public void setBare(boolean bare) { this.bare = bare; } /** * Sets whether or not sub-modules should be cloned * * @antdoc.notrequired * @param cloneSubModules Whether or not to clone sub-modules (Default true) */ public void setCloneSubModules(boolean cloneSubModules) { this.cloneSubModules = cloneSubModules; } /** * Whether or not to clone all branches * * @antdoc.notrequired * @param cloneAllBranches Default is true */ public void setCloneAllBranches(boolean cloneAllBranches) { this.cloneAllBranches = cloneAllBranches; } /** * Sets whether or not to checkout any branches * * @antdoc.notrequired * @param noCheckout Whether or not to checkout any branch (Default false) */ public void setNoCheckout(boolean noCheckout) { this.noCheckout = noCheckout; } @Override public void execute() { try { CloneCommand cloneCommand = new CloneCommand(); if (branchToTrack != null) { cloneCommand.setBranch(branchToTrack); } if (!branchNames.isEmpty()) { cloneCommand.setBranchesToClone(branchNames); } cloneCommand.setURI(getUri()). setBare(bare). setCloneAllBranches(cloneAllBranches). setCloneSubmodules(cloneSubModules). setNoCheckout(noCheckout). setDirectory(getDirectory()); setupCredentials(cloneCommand); if (getProgressMonitor() != null) { cloneCommand.setProgressMonitor(getProgressMonitor()); } cloneCommand.call(); } catch (Exception e) { throw new GitBuildException(String.format(MESSAGE_CLONE_FAILED, getUri()), e); } } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy