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

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

Introduction

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

Prototype

@Override
public String toString() 

Source Link

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;//  w ww  .  j  a v  a 2s.  c  o  m
        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.gdt.eclipse.gph.egit.wizard.CloneRepositoryWizardPage.java

License:Open Source License

private File getLocalDirForRepo(String repoURL) {
    RepositoryUtil repoUtil = Activator.getDefault().getRepositoryUtil();

    for (String configuredRepo : repoUtil.getConfiguredRepositories()) {
        try {//from www .ja va 2s . co  m
            File repoFile = new File(configuredRepo);

            Repository repository = Activator.getDefault().getRepositoryCache().lookupRepository(repoFile);

            try {
                RemoteConfig originConfig = new RemoteConfig(repository.getConfig(), "origin");

                for (URIish uri : originConfig.getURIs()) {
                    String uriStr = uri.toString();

                    if (repoURL.equals(uriStr)) {
                        return repoFile.getParentFile();
                    }
                }
            } catch (URISyntaxException exception) {

            }
        } catch (IOException ioe) {
            ioe.printStackTrace();
        }
    }

    return null;
}

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

License:Apache License

private void replicateProject(final URIish replicateURI, final String head) {
    SshSessionFactory sshFactory = SshSessionFactory.getInstance();
    RemoteSession sshSession;/*from   w  w w.  j a va  2 s  .  c  o  m*/
    String projectPath = QuotedString.BOURNE.quote(replicateURI.getPath());

    if (!usingSSH(replicateURI)) {
        log.warn("Cannot create new project on remote site since the connection " + "method is not SSH: "
                + replicateURI.toString());
        return;
    }

    OutputStream errStream = createErrStream();
    String cmd = "mkdir -p " + projectPath + "&& cd " + projectPath + "&& git init --bare"
            + "&& git symbolic-ref HEAD " + QuotedString.BOURNE.quote(head);

    try {
        sshSession = sshFactory.getSession(replicateURI, null, FS.DETECTED, 0);
        Process proc = sshSession.exec(cmd, 0);
        proc.getOutputStream().close();
        StreamCopyThread out = new StreamCopyThread(proc.getInputStream(), errStream);
        StreamCopyThread err = new StreamCopyThread(proc.getErrorStream(), errStream);
        out.start();
        err.start();
        try {
            proc.waitFor();
            out.halt();
            err.halt();
        } catch (InterruptedException interrupted) {
            // Don't wait, drop out immediately.
        }
        sshSession.disconnect();
    } catch (IOException e) {
        log.error("Communication error when trying to replicate to: " + replicateURI.toString() + "\n"
                + "Error reported: " + e.getMessage() + "\n" + "Error in communication: "
                + errStream.toString());
    }
}

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

License:Apache License

private static boolean matches(URIish uri, String urlMatch) {
    if (urlMatch == null || urlMatch.equals("") || urlMatch.equals("*")) {
        return true;
    }//w w  w  . ja  va  2 s  .com
    return uri.toString().contains(urlMatch);
}

From source file:com.photon.phresco.framework.impl.SCMManagerImpl.java

License:Apache License

void additionalAuthentication(String passPhrase) {
    final String passwordPhrase = passPhrase;
    JschConfigSessionFactory sessionFactory = new JschConfigSessionFactory() {
        @Override/*from www.j a  va2s  .  c o m*/
        protected void configure(OpenSshConfig.Host hc, Session session) {
            CredentialsProvider provider = new CredentialsProvider() {
                @Override
                public boolean isInteractive() {
                    return false;
                }

                @Override
                public boolean supports(CredentialItem... items) {
                    return true;
                }

                @Override
                public boolean get(URIish uri, CredentialItem... items) throws UnsupportedCredentialItem {
                    for (CredentialItem item : items) {
                        if (item instanceof CredentialItem.StringType) {
                            ((CredentialItem.StringType) item).setValue(passwordPhrase);
                        }
                    }
                    return true;
                }
            };
            UserInfo userInfo = new CredentialsProviderUserInfo(session, provider);
            // Unknown host key for ssh
            java.util.Properties config = new java.util.Properties();
            config.put(STRICT_HOST_KEY_CHECKING, NO);
            session.setConfig(config);

            session.setUserInfo(userInfo);
        }
    };

    SshSessionFactory.setInstance(sessionFactory);

    /*
     * Enable clone of https url by trusting those urls
     */
    // Create a trust manager that does not validate certificate chains
    TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
        public java.security.cert.X509Certificate[] getAcceptedIssuers() {
            return null;
        }

        public void checkClientTrusted(java.security.cert.X509Certificate[] certs, String authType) {
        }

        public void checkServerTrusted(java.security.cert.X509Certificate[] certs, String authType) {
        }
    } };

    final String https_proxy = System.getenv(HTTPS_PROXY);
    final String http_proxy = System.getenv(HTTP_PROXY);

    ProxySelector.setDefault(new ProxySelector() {
        final ProxySelector delegate = ProxySelector.getDefault();

        @Override
        public List<Proxy> select(URI uri) {
            // Filter the URIs to be proxied

            if (uri.toString().contains(HTTPS) && StringUtils.isNotEmpty(http_proxy) && http_proxy != null) {
                try {
                    URI httpsUri = new URI(https_proxy);
                    String host = httpsUri.getHost();
                    int port = httpsUri.getPort();
                    return Arrays.asList(new Proxy(Type.HTTP, InetSocketAddress.createUnresolved(host, port)));
                } catch (URISyntaxException e) {
                    if (debugEnabled) {
                        S_LOGGER.debug("Url exception caught in https block of additionalAuthentication()");
                    }
                }
            }

            if (uri.toString().contains(HTTP) && StringUtils.isNotEmpty(http_proxy) && http_proxy != null) {
                try {
                    URI httpUri = new URI(http_proxy);
                    String host = httpUri.getHost();
                    int port = httpUri.getPort();
                    return Arrays.asList(new Proxy(Type.HTTP, InetSocketAddress.createUnresolved(host, port)));
                } catch (URISyntaxException e) {
                    if (debugEnabled) {
                        S_LOGGER.debug("Url exception caught in http block of additionalAuthentication()");
                    }
                }
            }

            // revert to the default behaviour
            return delegate == null ? Arrays.asList(Proxy.NO_PROXY) : delegate.select(uri);
        }

        @Override
        public void connectFailed(URI uri, SocketAddress sa, IOException ioe) {
            if (uri == null || sa == null || ioe == null) {
                throw new IllegalArgumentException("Arguments can't be null.");
            }
        }
    });

    // Install the all-trusting trust manager
    try {
        SSLContext sc = SSLContext.getInstance(SSL);
        sc.init(null, trustAllCerts, new java.security.SecureRandom());
        HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
    } catch (GeneralSecurityException e) {
        e.getLocalizedMessage();
    }
}

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

License:Open Source License

private RepositoryWrapper getRepositoryFromEgit(IInteractionContext context, ProvisioningElement handle) {
    RepositoryCache repositoryCache = org.eclipse.egit.core.Activator.getDefault().getRepositoryCache();
    for (Repository repository : repositoryCache.getAllRepositories()) {
        URIish cloneUri = GitProvisioningUtil.getCloneUri(repository);
        if (handle.getIdentifier().equals(cloneUri.toString())) {
            return new RepositoryWrapper(repository);
        }/*from w w  w.  j a va 2  s .  co m*/
    }
    return null;
}

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

License:Open Source License

@Override
public ProvisioningElement createProvisioningElement(Object object) {
    if (object instanceof Repository) {
        Repository repository = (Repository) object;
        URIish cloneUri = GitProvisioningUtil.getCloneUri(repository);
        if (cloneUri != null) {
            return new ProvisioningElement(GitContributor.CONTENT_TYPE, cloneUri.toString(), true);
        }/*  w w w . j  a v a 2s . com*/
    }
    return null;
}

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

License:Open Source License

public static String getProjectName(URIish cloneUri) {
    if (cloneUri != null) {
        try {/*from w  w w  .j  av  a2 s . co m*/
            URI uri = new URI(cloneUri.toString());
            String path = uri.getPath();
            String projectName = path.substring(path.lastIndexOf('/') + 1);
            if (projectName.length() == 0) {
                path = path.substring(0, path.length() - 1);
                projectName = path.substring(path.lastIndexOf('/') + 1);
            }

            if (projectName.length() < 4) {
                return GitProvisioningUtil.getProjectNameFallback(cloneUri);
            }
            return projectName;
        } catch (URISyntaxException e) {
            return GitProvisioningUtil.getProjectNameFallback(cloneUri);
        }
    }

    return GitProvisioningUtil.getProjectNameFallback(cloneUri);
}

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

License:Open Source License

private static String getProjectNameFallback(URIish project) {
    return project.toString();
}

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

License:Open Source License

@Override
public String toString() {
    URIish cloneUri = getCloneURI();
    if (cloneUri != null) {
        return cloneUri.toString();
    }/*w  w  w  .  j a  va2s  .co  m*/

    return "";
}