Example usage for org.eclipse.jgit.api SubmoduleUpdateCommand setProgressMonitor

List of usage examples for org.eclipse.jgit.api SubmoduleUpdateCommand setProgressMonitor

Introduction

In this page you can find the example usage for org.eclipse.jgit.api SubmoduleUpdateCommand setProgressMonitor.

Prototype

public SubmoduleUpdateCommand setProgressMonitor(final ProgressMonitor monitor) 

Source Link

Document

The progress monitor associated with the clone operation.

Usage

From source file:org.eclipse.egit.core.op.SubmoduleUpdateOperation.java

License:Open Source License

public void execute(final IProgressMonitor monitor) throws CoreException {
    IWorkspaceRunnable action = new IWorkspaceRunnable() {

        public void run(IProgressMonitor pm) throws CoreException {
            pm.beginTask("", 3); //$NON-NLS-1$
            Git git = Git.wrap(repository);

            Collection<String> updated = null;
            try {
                SubmoduleInitCommand init = git.submoduleInit();
                for (String path : paths)
                    init.addPath(path);//from  w  w w.  ja  v  a 2s .  c  o m
                init.call();
                pm.worked(1);

                SubmoduleUpdateCommand update = git.submoduleUpdate();
                for (String path : paths)
                    update.addPath(path);
                update.setProgressMonitor(new EclipseGitProgressTransformer(new SubProgressMonitor(pm, 2)));
                updated = update.call();
                pm.worked(1);
                SubProgressMonitor refreshMonitor = new SubProgressMonitor(pm, 1);
                refreshMonitor.beginTask("", updated.size()); //$NON-NLS-1$
                for (String path : updated) {
                    Repository subRepo = SubmoduleWalk.getSubmoduleRepository(repository, path);
                    if (subRepo != null)
                        ProjectUtil.refreshValidProjects(ProjectUtil.getValidOpenProjects(subRepo),
                                new SubProgressMonitor(refreshMonitor, 1));
                    else
                        refreshMonitor.worked(1);
                }
                refreshMonitor.done();
            } catch (GitAPIException e) {
                throw new TeamException(e.getLocalizedMessage(), e.getCause());
            } catch (IOException e) {
                throw new TeamException(e.getLocalizedMessage(), e.getCause());
            } finally {
                if (updated != null && !updated.isEmpty())
                    repository.notifyIndexChanged();
                pm.done();
            }
        }
    };
    ResourcesPlugin.getWorkspace().run(action, monitor != null ? monitor : new NullProgressMonitor());
}

From source file:org.eclipse.n4js.utils.git.GitUtils.java

License:Open Source License

/**
 * Update the submodules with the given repository-relative <code>submodulePaths</code> inside the Git repository at
 * the given clone path. Throws exceptions in case of error.
 *
 * @param submodulePaths//from  w  ww  .  java  2 s  .com
 *            repository-relative paths of the submodules to update; if empty, all submodules will be updated.
 */
public static void updateSubmodules(final Path localClonePath, final Iterable<String> submodulePaths,
        final IProgressMonitor monitor) {

    if (!isValidLocalClonePath(localClonePath)) {
        throw new IllegalArgumentException("invalid localClonePath: " + localClonePath);
    }

    @SuppressWarnings("restriction")
    final ProgressMonitor gitMonitor = null == monitor ? createMonitor()
            : new org.eclipse.egit.core.EclipseGitProgressTransformer(monitor);

    try (final Git git = open(localClonePath.toFile())) {
        final SubmoduleUpdateCommand cmd = git.submoduleUpdate();
        for (String submodulePath : submodulePaths) {
            cmd.addPath(submodulePath);
        }
        cmd.setProgressMonitor(gitMonitor);
        cmd.setTransportConfigCallback(TRANSPORT_CALLBACK);
        cmd.call();
    } catch (Exception e) {
        LOGGER.error(e.getClass().getSimpleName() + " while trying to update submodules "
                + Iterables.toString(submodulePaths) + " of repository '" + localClonePath + "':"
                + e.getLocalizedMessage());
        Throwables.throwIfUnchecked(e);
        throw new RuntimeException(e);
    }
}

From source file:org.eclipse.oomph.setup.git.impl.GitCloneTaskImpl.java

License:Open Source License

private static void addSubmodules(SetupTaskContext context, Git git, SubProgressMonitor monitor)
        throws Exception {
    context.log("Adding submodules");

    git.submoduleInit().call();//w  w  w. j av a2 s  .  c  o  m

    SubmoduleUpdateCommand updateCommand = git.submoduleUpdate();
    updateCommand.setProgressMonitor(new EclipseGitProgressTransformer(monitor));
    updateCommand.call();
}