Example usage for org.eclipse.jgit.transport URIish getScheme

List of usage examples for org.eclipse.jgit.transport URIish getScheme

Introduction

In this page you can find the example usage for org.eclipse.jgit.transport URIish getScheme.

Prototype

public String getScheme() 

Source Link

Document

Get protocol name

Usage

From source file:com.docmd.behavior.GitManager.java

public boolean isValidRemoteRepository(URIish repoUri) {
    boolean result;

    if (repoUri.getScheme().toLowerCase().startsWith("http")) {
        String path = repoUri.getPath();
        String newPath = path.endsWith("/") ? path + INFO_REFS_PATH : path + "/" + INFO_REFS_PATH;
        URIish checkUri = repoUri.setPath(newPath);
        InputStream ins = null;/*from   w  w w.j  a  v  a2s .com*/
        try {
            URLConnection conn = new URL(checkUri.toString()).openConnection();
            //conn.setReadTimeout(5000);
            ins = conn.getInputStream();
            result = true;
        } catch (Exception e) {
            if (e.getMessage().contains("403"))
                result = true;
            else
                result = false;
        } finally {
            try {
                ins.close();
            } catch (Exception e) {
                /* ignore */ }
        }
    } else {
        if (repoUri.getScheme().toLowerCase().startsWith("ssh")) {
            RemoteSession ssh = null;
            Process exec = null;
            try {
                ssh = SshSessionFactory.getInstance().getSession(repoUri, null, FS.detect(), 5000);
                exec = ssh.exec("cd " + repoUri.getPath() + "; git rev-parse --git-dir", 5000);
                Integer exitValue = null;
                do {
                    try {
                        exitValue = exec.exitValue();
                    } catch (Exception e) {
                        try {
                            Thread.sleep(1000);
                        } catch (Exception ee) {
                        }
                    }
                } while (exitValue == null);
                result = exitValue == 0;
            } catch (Exception e) {
                result = false;
            } finally {
                try {
                    exec.destroy();
                } catch (Exception e) {
                    /* ignore */ }
                try {
                    ssh.disconnect();
                } catch (Exception e) {
                    /* ignore */ }
            }
        } else {
            result = true;
        }
    }
    return result;
}

From source file:com.google.gerrit.server.git.PushReplication.java

License:Apache License

private boolean usingSSH(final URIish uri) {
    final String scheme = uri.getScheme();
    if (!uri.isRemote())
        return false;
    if (scheme != null && scheme.toLowerCase().contains("ssh"))
        return true;
    if (scheme == null && uri.getHost() != null && uri.getPath() != null)
        return true;
    return false;
}

From source file:com.googlesource.gerrit.plugins.github.replication.Destination.java

License:Apache License

static boolean needsUrlEncoding(URIish uri) {
    return "http".equalsIgnoreCase(uri.getScheme()) || "https".equalsIgnoreCase(uri.getScheme())
            || "amazon-s3".equalsIgnoreCase(uri.getScheme());
}

From source file:com.googlesource.gerrit.plugins.replication.ReplicationQueue.java

License:Apache License

private static boolean isSSH(URIish uri) {
    String scheme = uri.getScheme();
    if (!uri.isRemote()) {
        return false;
    }/*from  w  w w.j a  v  a2s  . c om*/
    if (scheme != null && scheme.toLowerCase().contains("ssh")) {
        return true;
    }
    if (scheme == null && uri.getHost() != null && uri.getPath() != null) {
        return true;
    }
    return false;
}

From source file:com.sap.poc.jgit.storage.jdbc.JdbcDatabaseBuilder.java

License:Eclipse Distribution License

public JdbcDatabaseBuilder setURI(final String uri) throws URISyntaxException {
    final URIish u = new URIish(uri);

    final String scheme = u.getScheme();
    if (!scheme.startsWith(Main.GIT_JDBC_PREFIX))
        throw new IllegalArgumentException();
    final int beginVendor = scheme.lastIndexOf("+") + 1;
    final String vendor = scheme.substring(beginVendor);
    if (vendor.length() < 1)
        throw new IllegalArgumentException();
    setVendor(vendor);/*from w  w w  . j  a v  a  2s  . c o m*/

    final String host = u.getHost();
    if (host == null || host.length() < 1)
        throw new IllegalArgumentException();
    final int port = u.getPort();
    if (port == -1)
        throw new IllegalArgumentException();
    setHost(host + ":" + port);

    String path = u.getPath();
    if (path.startsWith("/"))
        path = path.substring(1);

    int endDbName = path.indexOf("/");
    if (endDbName < 0)
        endDbName = path.length();
    setDatabaseName(path.substring(0, endDbName));
    return this;
}

From source file:com.sap.poc.jgit.storage.jdbc.JdbcRepositoryBuilder.java

License:Eclipse Distribution License

public JdbcRepositoryBuilder setURI(final String uri) throws URISyntaxException {
    final URIish u = new URIish(uri);

    final String scheme = u.getScheme();
    if (!scheme.startsWith(Main.GIT_JDBC_PREFIX))
        throw new IllegalArgumentException();
    final int beginVendor = scheme.lastIndexOf("+") + 1;
    final String vendor = scheme.substring(beginVendor);
    if (vendor.length() < 1)
        throw new IllegalArgumentException();
    setVendor(vendor);/*w w  w .  j a v  a 2  s .c  o m*/

    final String host = u.getHost();
    if (host == null || host.length() < 1)
        throw new IllegalArgumentException();
    final int port = u.getPort();
    if (port == -1)
        throw new IllegalArgumentException();
    setHost(host + ":" + port);

    String path = u.getPath();
    if (path.startsWith("/"))
        path = path.substring(1);

    int endDbName = path.indexOf("/");
    if (endDbName < 0)
        endDbName = path.length();
    setDatabaseName(path.substring(0, endDbName));

    final int beginRepoName = endDbName + 1;
    setRepositoryName(path.substring(beginRepoName));
    return self();
}

From source file:edu.tum.cs.mylyn.provisioning.git.GitProvisioningUtil.java

License:Open Source License

public static boolean mightUseKeyAuth(URIish uri) {
    return SCHEME_SSH.equals(uri.getScheme());
}

From source file:jetbrains.buildServer.buildTriggers.vcs.git.agent.UpdaterImpl.java

License:Apache License

private boolean isRequireAuth(@NotNull String url) {
    try {// www. jav a 2s  . c o m
        URIish uri = new URIish(url);
        String scheme = uri.getScheme();
        if (scheme == null || "git".equals(scheme)) //no auth for anonymous protocol and for local repositories
            return false;
        String user = uri.getUser();
        if (user != null) //respect a user specified in config
            return false;
        return true;
    } catch (URISyntaxException e) {
        return false;
    }
}

From source file:jetbrains.buildServer.buildTriggers.vcs.git.agent.UpdaterImpl.java

License:Apache License

@Nullable
private Trinity<String, String, String> getLfsAuth() {
    try {/*w w  w.  j  ava 2  s.c  o  m*/
        URIish uri = new URIish(myRoot.getRepositoryFetchURL().toString());
        String scheme = uri.getScheme();
        if (myRoot.getAuthSettings().getAuthMethod() == AuthenticationMethod.PASSWORD
                && ("http".equals(scheme) || "https".equals(scheme))) {
            String lfsUrl = uri.setPass("").setUser("").setPath("").toASCIIString();
            if (lfsUrl.endsWith(".git")) {
                lfsUrl += "/info/lfs";
            } else {
                lfsUrl += lfsUrl.endsWith("/") ? ".git/info/lfs" : "/.git/info/lfs";
            }
            return Trinity.create(lfsUrl, myRoot.getAuthSettings().getUserName(),
                    myRoot.getAuthSettings().getPassword());
        }
    } catch (Exception e) {
        LOG.debug("Cannot get lfs auth config", e);
    }
    return null;
}

From source file:jetbrains.buildServer.buildTriggers.vcs.git.AuthSettings.java

License:Apache License

private boolean isAnonymousProtocol(@NotNull URIish uriish) {
    return "git".equals(uriish.getScheme());
}