Example usage for org.eclipse.jgit.errors TransportException TransportException

List of usage examples for org.eclipse.jgit.errors TransportException TransportException

Introduction

In this page you can find the example usage for org.eclipse.jgit.errors TransportException TransportException.

Prototype

public TransportException(String s) 

Source Link

Document

Constructs an TransportException with the specified detail message.

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;/* www . j ava  2  s. c o m*/

    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 void verifyAndInsertLooseObject(final AnyObjectId id, final byte[] compressed) throws IOException {
    final ObjectLoader uol;
    try {//from  w  ww . j a  v  a  2  s  .co  m
        uol = UnpackedObject.parse(compressed, id);
    } catch (CorruptObjectException parsingError) {
        // Some HTTP servers send back a "200 OK" status with an HTML
        // page that explains the requested file could not be found.
        // These servers are most certainly misconfigured, but many
        // of them exist in the world, and many of those are hosting
        // Git repositories.
        //
        // Since an HTML page is unlikely to hash to one of our loose
        // objects we treat this condition as a FileNotFoundException
        // and attempt to recover by getting the object from another
        // source.
        //
        final FileNotFoundException e;
        e = new FileNotFoundException(id.name());
        e.initCause(parsingError);
        throw e;
    }

    final int type = uol.getType();
    final byte[] raw = uol.getCachedBytes();
    if (objCheck != null) {
        try {
            objCheck.check(type, raw);
        } catch (CorruptObjectException e) {
            throw new TransportException(MessageFormat.format(JGitText.get().transportExceptionInvalid,
                    Constants.typeString(type), id.name(), e.getMessage()));
        }
    }

    ObjectId act = inserter.insert(type, raw);
    if (!AnyObjectId.equals(id, act)) {
        throw new TransportException(MessageFormat.format(JGitText.get().incorrectHashFor, id.name(),
                act.name(), Constants.typeString(type), compressed.length));
    }
    inserter.flush();
}

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

License:Eclipse Distribution License

private void readPackedRefsImpl(final Map<String, Ref> avail, final BufferedReader br) throws IOException {
    Ref last = null;//from w w  w .  jav a2 s.  co  m
    boolean peeled = false;
    for (;;) {
        String line = br.readLine();
        if (line == null)
            break;
        if (line.charAt(0) == '#') {
            if (line.startsWith(RefDirectory.PACKED_REFS_HEADER)) {
                line = line.substring(RefDirectory.PACKED_REFS_HEADER.length());
                peeled = line.contains(RefDirectory.PACKED_REFS_PEELED);
            }
            continue;
        }
        if (line.charAt(0) == '^') {
            if (last == null)
                throw new TransportException(JGitText.get().peeledLineBeforeRef);
            final ObjectId id = ObjectId.fromString(line.substring(1));
            last = new ObjectIdRef.PeeledTag(Ref.Storage.PACKED, last.getName(), last.getObjectId(), id);
            avail.put(last.getName(), last);
            continue;
        }

        final int sp = line.indexOf(' ');
        if (sp < 0)
            throw new TransportException(MessageFormat.format(JGitText.get().unrecognizedRef, line));
        final ObjectId id = ObjectId.fromString(line.substring(0, sp));
        final String name = line.substring(sp + 1);
        if (peeled)
            last = new ObjectIdRef.PeeledNonTag(Ref.Storage.PACKED, name, id);
        else
            last = new ObjectIdRef.Unpeeled(Ref.Storage.PACKED, name, id);
        avail.put(last.getName(), last);
    }
}