Example usage for org.eclipse.jgit.transport Transport getTransportProtocols

List of usage examples for org.eclipse.jgit.transport Transport getTransportProtocols

Introduction

In this page you can find the example usage for org.eclipse.jgit.transport Transport getTransportProtocols.

Prototype

public static List<TransportProtocol> getTransportProtocols() 

Source Link

Document

Obtain a copy of the registered protocols.

Usage

From source file:org.z2env.impl.gitcr.GitComponentRepositoryImpl.java

License:Apache License

private static URIish getOrigRepo(String name, Properties props, boolean isOptional) {
    String uri = normalize(props.getProperty(GITCR_URI));
    logger.fine("read GitCR " + name + "::" + GITCR_URI + " = " + uri);

    if (uri == null) {
        throw new IllegalStateException("Missing property " + GITCR_URI + " in " + name);
    }//w ww. j av a  2 s .c  o  m

    URIish uriish;
    try {
        uriish = new URIish(uri);
    } catch (URISyntaxException e1) {
        throw new IllegalStateException("Git-CR '" + name + ": '" + uri + "' is not a valid Git-URI");
    }

    // try normalize to work relative to Z2 home
    if (!uriish.isRemote()) {
        try {
            File f = new File(uri);
            if (!f.isAbsolute()) {
                // relative!
                String zHome = normalize(System.getProperty(Foundation.HOME));
                if (zHome != null) {
                    f = new File(new File(zHome), uri);
                } else {
                    f = new File(uri);
                }

            }
            uri = f.getCanonicalPath();
            uriish = new URIish(uri);
        } catch (Exception e1) {
            throw new IllegalStateException("Git-CR '" + name + ": '" + uri + "' is not a valid Git-URI");
        }
    }

    if (isOptional) {
        // skip all checks for optional repositories
        return uriish;
    }

    boolean canHandle = false;
    for (TransportProtocol transp : Transport.getTransportProtocols()) {
        if (transp.canHandle(uriish)) {

            if (!canHandle && transp.getSchemes().contains("file")) {
                // do some checks in advance
                File gitDir = new File(uri);
                String absPath = null;
                try {
                    absPath = gitDir.getCanonicalPath();
                } catch (IOException e) {
                    throw new IllegalStateException("Git-CR '" + name + ": The path " + gitDir + " defined in "
                            + name + "::" + GITCR_URI + " cannot be canonicalized!", e);
                }

                if (!gitDir.exists()) {
                    throw new IllegalStateException("Git-CR '" + name + ": The path " + gitDir + " (abs-path: "
                            + absPath + ") defined in " + name + "::" + GITCR_URI + " does not exists!");
                }
                if (!gitDir.isDirectory()) {
                    throw new IllegalStateException("Git-CR '" + name + ": The path " + gitDir + " (abs-path: "
                            + absPath + ") defined in " + name + "::" + GITCR_URI + " is not a directory!");
                }
                if (!gitDir.canRead()) {
                    throw new IllegalStateException("Git-CR '" + name + ": The path " + gitDir + " (abs-path: "
                            + absPath + ") defined in " + name + "::" + GITCR_URI
                            + " cannot be accessed! Please check permissions.");
                }
            }

            canHandle = true;
        }
    }

    if (!canHandle) {
        throw new IllegalStateException("Git-CR '" + name + ": The uri " + uri + " defined in " + GITCR_URI
                + " cannot be handled by this git implementation!");
    }

    return uriish;
}