Java Code Examples for org.eclipse.jgit.api.CloneCommand#setProgressMonitor()

The following examples show how to use org.eclipse.jgit.api.CloneCommand#setProgressMonitor() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JGitWrapper.java    From mOrgAnd with GNU General Public License v2.0 6 votes vote down vote up
private void createNewRepo(ProgressMonitor monitor) throws GitAPIException, IllegalArgumentException {
    File localRepo = new File(localPath);
    if (localRepo.exists()) // Safety check so we don't accidentally delete directory
        throw new IllegalStateException("Directory already exists");

    try {
        CloneCommand cloneCommand = Git.cloneRepository()
                .setCredentialsProvider(credentialsProvider)
                .setURI(remotePath)
                .setBranch(branch)
                .setDirectory(localRepo)
                .setBare(false);
        if (monitor != null)
            cloneCommand.setProgressMonitor(monitor);
        cloneCommand.call();
    } catch (GitAPIException e) {
        FileUtils.deleteDirectory(localRepo);
        throw e;
    }
}
 
Example 2
Source File: ExtensionPointAction.java    From maestro-java with Apache License 2.0 5 votes vote down vote up
private void doClone() throws GitAPIException, IOException {
    CloneCommand cloneCommand = Git.cloneRepository();

    cloneCommand.setURI(REPOSITORY_URL);

    File repositoryDir = new File(directory, name);
    cloneCommand.setDirectory(repositoryDir);
    cloneCommand.setProgressMonitor(new TextProgressMonitor());

    cloneCommand.call();
    System.out.println("Project directory for project created at " + repositoryDir);

    FileUtils.deleteDirectory(new File(repositoryDir, ".git"));
}
 
Example 3
Source File: CloneTask.java    From ant-git-tasks with Apache License 2.0 5 votes vote down vote up
@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);
        }
}
 
Example 4
Source File: MaestroAgent.java    From maestro-java with Apache License 2.0 4 votes vote down vote up
@Override
public void handle(final AgentSourceRequest note) {
    logger.info("Source request arrived");

    final String sourceUrl = note.getSourceUrl();
    final String branch = note.getBranch();

    if (branch == null) {
        logger.info("Preparing to download code from {}", sourceUrl);
    }
    else {
        logger.info("Preparing to download code from {} from branch {}", sourceUrl, branch);
    }
    final String projectDir = UUID.randomUUID().toString();

    final File repositoryDir = new File(sourceRoot + File.separator + projectDir + File.separator);

    if (!repositoryDir.exists()) {
        if (!repositoryDir.mkdirs()) {
            logger.warn("Unable to create directory: {}", repositoryDir);
        }
    }

    CloneCommand cloneCommand = Git.cloneRepository();

    cloneCommand.setURI(sourceUrl);
    cloneCommand.setDirectory(repositoryDir);
    cloneCommand.setProgressMonitor(NullProgressMonitor.INSTANCE);


    if (branch != null) {
        cloneCommand.setBranch(branch);
    }

    try {
        cloneCommand.call();
        logger.info("Source directory for project created at {}", repositoryDir);
        extensionPoints.add(new ExtensionPoint(new File(repositoryDir, "requests"), true));

        getClient().replyOk(note);
    } catch (GitAPIException e) {
        logger.error("Unable to clone repository: {}", e.getMessage(), e);
        getClient().replyInternalError(note,"Unable to clone repository: %s", e.getMessage());
    }
}