Example usage for org.eclipse.jgit.api Git cloneRepository

List of usage examples for org.eclipse.jgit.api Git cloneRepository

Introduction

In this page you can find the example usage for org.eclipse.jgit.api Git cloneRepository.

Prototype

public static CloneCommand cloneRepository() 

Source Link

Document

Return a command object to execute a clone command

Usage

From source file:org.jboss.arquillian.ios.impl.WaxSim.java

License:Apache License

private File prepareBinary(String gitRemote, boolean verbose) throws IOException {
    File repository = null;// w w  w  .ja  v a2  s.c o m
    try {
        repository = File.createTempFile("arq-ios", "waxsim");
        repository.delete();
        repository.mkdirs();
        repository.deleteOnExit();
        LOG.log(Level.INFO, "git clone <{0}>.", gitRemote);
        Git.cloneRepository().setDirectory(repository).setURI(gitRemote)
                .setCredentialsProvider(CredentialsProvider.getDefault()).call();

    } catch (Exception e) {
        throw new IOException("Can't clone <" + gitRemote + ">", e);
    }
    LOG.info("building waxsim");
    List<String> output = ProcessExecutor.execute(repository, "xcodebuild", "-project", "WaxSim.xcodeproj");
    if (verbose) {
        for (String line : output) {
            System.out.println(line);
        }
    }
    return new File(repository, "build" + File.separator + "Release" + File.separator + "waxsim");
}

From source file:org.jboss.forge.addon.git.GitUtilsImpl.java

License:Open Source License

@Override
public Git clone(final DirectoryResource dir, final String repoUri) throws GitAPIException {
    CloneCommand clone = Git.cloneRepository().setURI(repoUri).setDirectory(dir.getUnderlyingResourceObject());
    Git git = clone.call();//www  .  j  a  v a  2  s.co  m
    return git;
}

From source file:org.jboss.forge.addon.git.ui.GitCloneCommandImpl.java

License:Open Source License

@Override
public Result execute(UIExecutionContext context) throws Exception {
    DirectoryResource cloneFolder = targetDirectory.getValue();
    if (!cloneFolder.exists()) {
        cloneFolder.mkdirs();//from  ww  w .j  a v a 2 s .c o  m
    }
    Git clone = null;
    try {
        CloneCommand cloneCommand = Git.cloneRepository().setURI(uri.getValue())
                .setDirectory(cloneFolder.getUnderlyingResourceObject());
        cloneCommand.setProgressMonitor(new ProgressMonitorAdapter(context.getProgressMonitor()));
        clone = cloneCommand.call();
    } finally {
        getGitUtils().close(clone);
    }
    context.getUIContext().setSelection(cloneFolder);
    return Results.success();
}

From source file:org.jboss.forge.git.GitUtils.java

License:Open Source License

public static Git clone(final DirectoryResource dir, final String repoUri) throws GitAPIException {
    CloneCommand clone = Git.cloneRepository().setURI(repoUri).setDirectory(dir.getUnderlyingResourceObject());
    Git git = clone.call();//  w w  w  .  java  2s .  c o m
    return git;
}

From source file:org.jboss.maven.plugins.qstools.ArchetypeSyncMojo.java

License:Apache License

/**
 * Clone the informed git repository and checkout the informed branch
 * /*from   w w w  . j a  v a2 s.c o m*/
 * @throws IOException
 * @throws InvalidRemoteException
 * @throws TransportException
 * @throws GitAPIException
 */
private void cloneOriginProject()
        throws IOException, InvalidRemoteException, TransportException, GitAPIException {
    File gitLocalRepo = new File(outputPath + File.separator + "git");
    if (!gitLocalRepo.exists()) {
        getLog().info("Cloning " + projectGitRepo + " to " + gitLocalRepo);
        CloneCommand clone = Git.cloneRepository();
        clone.setBare(false);
        clone.setCloneAllBranches(true);
        clone.setDirectory(gitLocalRepo).setURI(projectGitRepo);
        clone.call();
    }
    getLog().info("Checking out " + branch + " branch");
    Git.open(gitLocalRepo).checkout().setName(branch).call();
}

From source file:org.jboss.tools.aerogear.hybrid.core.plugin.CordovaPluginManager.java

License:Open Source License

/**
 * Installs a Cordova plugin from a git repository. 
 * This method delegates to {@link #installPlugin(File)} after cloning the
 * repository to a temporary location to complete the installation of the 
 * plugin. //from ww w .ja v a  2  s .  c o m
 * <br/>
 * If commit is not null the cloned repository will be checked out to 
 * commit. 
 * <br/>
 * If subdir is not null it is assumed that the subdir path exists and installation 
 * will be done from that location. 
 * 
 * @param uri
 * @param commit 
 * @param subdir
 * @param overwrite
 * @param monitor 
 * @throws CoreException
 */
public void installPlugin(URI uri, String commit, String subdir, FileOverwriteCallback overwrite,
        IProgressMonitor monitor) throws CoreException {
    File tempRepoDirectory = new File(FileUtils.getTempDirectory(),
            "cordova_plugin_tmp_" + Long.toString(System.currentTimeMillis()));
    tempRepoDirectory.deleteOnExit();
    try {
        if (monitor.isCanceled())
            return;
        monitor.subTask("Clone plugin repository");
        Git git = Git.cloneRepository().setDirectory(tempRepoDirectory).setURI(uri.toString()).call();
        if (commit != null && !monitor.isCanceled()) {
            git.checkout().setName(commit).call();
        }
        monitor.worked(1);
        SubProgressMonitor sm = new SubProgressMonitor(monitor, 1);
        sm.setTaskName("Installing to " + this.project.getProject().getName());
        File pluginDirectory = tempRepoDirectory;
        if (subdir != null) {
            pluginDirectory = new File(tempRepoDirectory, subdir);
            if (!pluginDirectory.isDirectory()) {
                throw new CoreException(new Status(IStatus.ERROR, HybridCore.PLUGIN_ID,
                        subdir + " does not exist in this repo"));
            }
        }
        this.installPlugin(pluginDirectory, overwrite, sm);
    } catch (GitAPIException e) {
        throw new CoreException(
                new Status(IStatus.ERROR, HybridCore.PLUGIN_ID, "Error cloning the plugin repository", e));
    } finally {
        monitor.done();
    }
}

From source file:org.jboss.tools.openshift.ui.bot.test.application.v3.adapter.CreateServerAdapterTest.java

License:Open Source License

private static void cloneGitRepository() {
    try {//from   w  w  w  .j av  a  2  s .  c  o  m
        FileUtils.deleteDirectory(new File(GIT_REPO_DIRECTORY));
        Git.cloneRepository().setURI(GIT_REPO_URL).setDirectory(new File(GIT_REPO_DIRECTORY)).call();
    } catch (GitAPIException | IOException e) {
        throw new RuntimeException("Unable to clone git repository from " + GIT_REPO_URL, e);
    }
}

From source file:org.jboss.tools.openshift.ui.bot.test.application.v3.adapter.DebuggingEAPAppTest.java

License:Open Source License

private static void cloneGitRepository() {
    TestUtils.cleanupGitFolder(new File(GIT_REPO_DIRECTORY));
    try {//  w  w  w . j av a 2  s  . c  o  m
        Git.cloneRepository().setURI(GIT_REPO_URL).setDirectory(new File(GIT_REPO_DIRECTORY)).call();
    } catch (GitAPIException e) {
        throw new RuntimeException("Unable to clone git repository from " + GIT_REPO_URL);
    }
}

From source file:org.jboss.tools.openshift.ui.bot.test.application.v3.adapter.PublishChangesTest.java

License:Open Source License

private static void cloneGitRepository() {
    TestUtils.cleanupGitFolder(new File(GIT_REPO_DIRECTORY), "jboss-eap-quickstarts");
    try {/*  ww w .j  av a 2  s.c om*/
        Git.cloneRepository().setURI(GIT_REPO_URL).setDirectory(new File(GIT_REPO_DIRECTORY)).call();
    } catch (GitAPIException e) {
        throw new RuntimeException("Unable to clone git repository from " + GIT_REPO_URL);
    }
}

From source file:org.jboss.tools.openshift.ui.bot.test.common.OpenShiftUtils.java

License:Open Source License

public static void cloneGitRepository(String gitRepoDirectory, String gitRepoURL, boolean cleanupFolderBefore) {
    if (cleanupFolderBefore) {
        TestUtils.cleanupGitFolder(new File(gitRepoDirectory));
    }//from w  w  w  . jav a 2  s.co m
    try {
        FileUtils.deleteDirectory(new File(gitRepoDirectory));
        Git.cloneRepository().setURI(gitRepoURL).setDirectory(new File(gitRepoDirectory)).call();
    } catch (GitAPIException | IOException e) {
        throw new RuntimeException("Unable to clone git repository from " + gitRepoURL, e);
    }
}