Example usage for org.eclipse.jgit.lib ProgressMonitor endTask

List of usage examples for org.eclipse.jgit.lib ProgressMonitor endTask

Introduction

In this page you can find the example usage for org.eclipse.jgit.lib ProgressMonitor endTask.

Prototype

void endTask();

Source Link

Document

Finish the current task, so the next can begin.

Usage

From source file:it.com.atlassian.labs.speakeasy.util.jgit.WalkFetchConnection.java

License:Eclipse Distribution License

private void downloadObject(final ProgressMonitor pm, final AnyObjectId id) throws TransportException {
    if (alreadyHave(id))
        return;//from   w ww.j  a v  a 2  s .c om

    for (;;) {
        // Try a pack file we know about, but don't have yet. Odds are
        // that if it has this object, it has others related to it so
        // getting the pack is a good bet.
        //
        if (downloadPackedObject(pm, id))
            return;

        // Search for a loose object over all alternates, starting
        // from the one we last successfully located an object through.
        //
        final String idStr = id.name();
        final String subdir = idStr.substring(0, 2);
        final String file = idStr.substring(2);
        final String looseName = subdir + "/" + file;

        for (int i = lastRemoteIdx; i < remotes.size(); i++) {
            if (downloadLooseObject(id, looseName, remotes.get(i))) {
                lastRemoteIdx = i;
                return;
            }
        }
        for (int i = 0; i < lastRemoteIdx; i++) {
            if (downloadLooseObject(id, looseName, remotes.get(i))) {
                lastRemoteIdx = i;
                return;
            }
        }

        // Try to obtain more pack information and search those.
        //
        while (!noPacksYet.isEmpty()) {
            final WalkRemoteObjectDatabase wrr = noPacksYet.removeFirst();
            final Collection<String> packNameList;
            try {
                pm.beginTask("Listing packs", ProgressMonitor.UNKNOWN);
                packNameList = wrr.getPackNames();
            } catch (IOException e) {
                // Try another repository.
                //
                recordError(id, e);
                continue;
            } finally {
                pm.endTask();
            }

            if (packNameList == null || packNameList.isEmpty())
                continue;
            for (final String packName : packNameList) {
                if (packsConsidered.add(packName))
                    unfetchedPacks.add(new RemotePack(wrr, packName));
            }
            if (downloadPackedObject(pm, id))
                return;
        }

        // Try to expand the first alternate we haven't expanded yet.
        //
        Collection<WalkRemoteObjectDatabase> al = expandOneAlternate(id, pm);
        if (al != null && !al.isEmpty()) {
            for (final WalkRemoteObjectDatabase alt : al) {
                remotes.add(alt);
                noPacksYet.add(alt);
                noAlternatesYet.add(alt);
            }
            continue;
        }

        // We could not obtain the object. There may be reasons why.
        //
        List<Throwable> failures = fetchErrors.get(id);
        final TransportException te;

        te = new TransportException(MessageFormat.format(JGitText.get().cannotGet, id.name()));
        if (failures != null && !failures.isEmpty()) {
            if (failures.size() == 1)
                te.initCause(failures.get(0));
            else
                te.initCause(new CompoundException(failures));
        }
        throw te;
    }
}

From source file:it.com.atlassian.labs.speakeasy.util.jgit.WalkFetchConnection.java

License:Eclipse Distribution License

private Collection<WalkRemoteObjectDatabase> expandOneAlternate(final AnyObjectId id,
        final ProgressMonitor pm) {
    while (!noAlternatesYet.isEmpty()) {
        final WalkRemoteObjectDatabase wrr = noAlternatesYet.removeFirst();
        try {/*  ww w.  ja  v  a  2s  . c  om*/
            pm.beginTask(JGitText.get().listingAlternates, ProgressMonitor.UNKNOWN);
            Collection<WalkRemoteObjectDatabase> altList = wrr.getAlternates();
            if (altList != null && !altList.isEmpty())
                return altList;
        } catch (IOException e) {
            // Try another repository.
            //
            recordError(id, e);
        } finally {
            pm.endTask();
        }
    }
    return null;
}