List of usage examples for org.eclipse.jgit.transport URIish getPort
public int getPort()
From source file:com.genuitec.eclipse.gerrit.tools.utils.GerritUtils.java
License:Open Source License
public static String getGerritProjectName(Repository repository) { try {/* w ww . j ava 2 s . c o m*/ RemoteConfig config = new RemoteConfig(repository.getConfig(), "origin"); //$NON-NLS-1$ List<URIish> urls = new ArrayList<URIish>(config.getPushURIs()); urls.addAll(config.getURIs()); for (URIish uri : urls) { if (uri.getPort() == 29418) { //Gerrit refspec String path = uri.getPath(); while (path.startsWith("/")) { //$NON-NLS-1$ path = path.substring(1); } return path; } break; } } catch (Exception e) { GerritToolsPlugin.getDefault().log(e); } return null; }
From source file:com.genuitec.eclipse.gerrit.tools.utils.GerritUtils.java
License:Open Source License
public static String getGerritURL(Repository repository) { String best = null;//w ww . j a va2s . c o m try { RemoteConfig config = new RemoteConfig(repository.getConfig(), "origin"); //$NON-NLS-1$ List<URIish> urls = new ArrayList<URIish>(config.getPushURIs()); urls.addAll(config.getURIs()); for (URIish uri : urls) { best = "https://" + uri.getHost(); //$NON-NLS-1$ if (uri.getPort() == 29418) { //Gerrit refspec return best; } break; } } catch (Exception e) { GerritToolsPlugin.getDefault().log(e); } return best; }
From source file:com.googlesource.gerrit.plugins.replication.PushResultProcessing.java
License:Apache License
private static String resolveNodeName(URIish uri) { StringBuilder sb = new StringBuilder(); if (uri.isRemote()) { sb.append(uri.getHost());/* www.ja v a 2s. c o m*/ if (uri.getPort() != -1) { sb.append(":"); sb.append(uri.getPort()); } } else { sb.append(uri.getPath()); } return sb.toString(); }
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 ww . j av a2 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)); 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);//from ww w .ja v a 2 s . com 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:jetbrains.buildServer.buildTriggers.vcs.git.GitMapFullPath.java
License:Apache License
private boolean urlsMatch(@NotNull GitVcsRoot root, @NotNull FullPath fullPath) { String url = removeBranch(fullPath.getRepositoryUrl()); final URIish uri; try {//from w w w . j a v a2 s . c o m uri = new URIish(url); } catch (final URISyntaxException e) { if (ReferencesResolverUtil.containsReference(url)) { LOG.warn("Unresolved parameter in url " + url + ", root " + LogUtil.describe(root)); } else { LOG.warnAndDebugDetails( "Error while parsing VCS root url " + url + ", root " + LogUtil.describe(root), e); } return false; } final URIish settingsUrl = root.getRepositoryFetchURL(); if (settingsUrl == null) { return false; } if (uri.getHost() == null && settingsUrl.getHost() != null || uri.getHost() != null && !uri.getHost().equals(settingsUrl.getHost())) { return false; } if (uri.getPort() != settingsUrl.getPort()) { return false; } if (uri.getPath() == null && settingsUrl.getPath() != null || uri.getPath() != null && !uri.getPath().equals(settingsUrl.getPath())) { return false; } return true; }
From source file:org.apache.sshd.git.transport.GitSshdSession.java
License:Apache License
public GitSshdSession(URIish uri, CredentialsProvider credentialsProvider, FS fs, int tms) throws IOException, InterruptedException { String user = uri.getUser();//from www . j a v a 2s. c o m final String pass = uri.getPass(); String host = uri.getHost(); int port = uri.getPort(); char[] pass2 = null; if (!credentialsProvider.isInteractive()) { CredentialItem.Username usrItem = new CredentialItem.Username(); CredentialItem.Password pwdItem = new CredentialItem.Password(); if (credentialsProvider.get(uri, usrItem, pwdItem)) { if (user == null) { user = usrItem.getValue(); } else if (user.equals(usrItem.getValue())) { pass2 = pwdItem.getValue(); } } } client = createClient(); client.start(); session = client.connect(user, host, port).verify( PropertyResolverUtils.getLongProperty(client, CONNECT_TIMEOUT_PROP, DEFAULT_CONNECT_TIMEOUT)) .getSession(); if (log.isDebugEnabled()) { log.debug("Connected to {}:{}", host, port); } if (pass != null) { session.addPasswordIdentity(pass); } if (pass2 != null) { session.addPasswordIdentity(new String(pass2)); } session.auth() .verify(PropertyResolverUtils.getLongProperty(session, AUTH_TIMEOUT_PROP, DEFAULT_AUTH_TIMEOUT)); if (log.isDebugEnabled()) { log.debug("Authenticated: {}", session); } }
From source file:org.eclipse.egit.core.op.ConfigureGerritAfterCloneTask.java
License:Open Source License
/** * Try to use Gerrit's "Get Version" REST API endpoint [1] to detect if the * repository is hosted on a Gerrit server. * <p/>// www . ja va 2s. co m * [1] <a href= * "https://gerrit-documentation.storage.googleapis.com/Documentation/2.11 * /rest-api-config.html#get-version">Gerrit 2.11 Get Version REST * endpoint</a> * * @param repo * the repository to be configured * * @return {@code true} if the repository is hosted on a Gerrit server * @throws IOException * @throws MalformedURLException * @throws URISyntaxException */ private boolean isGerrit(Repository repo) throws MalformedURLException, IOException, URISyntaxException { URIish u = new URIish(uri); final String s = u.getScheme(); final String host = u.getHost(); final String path = u.getPath(); // shortcut for Eclipse Gerrit server if (host != null && host.equals(GIT_ECLIPSE_ORG)) { if (HTTPS.equals(s) && (u.getPort() == 443 || u.getPort() == -1) && path != null && path.startsWith(GERRIT_CONTEXT_ROOT)) { return true; } else if (SSH.equals(s) && u.getPort() == GERRIT_SSHD_DEFAULT_PORT) { return true; } } if (path != null && (HTTP.equals(s) || HTTPS.equals(s))) { String baseURL = u.setPath("/").toString(); //$NON-NLS-1$ baseURL = baseURL.substring(0, baseURL.length() - 1); String tmpPath = ""; //$NON-NLS-1$ int slash = 1; while (true) { HttpURLConnection httpConnection = null; try { httpConnection = (HttpURLConnection) new URL( baseURL + tmpPath + GERRIT_CONFIG_SERVER_VERSION_API).openConnection(); NetUtil.setSslVerification(repo, httpConnection); httpConnection.setRequestMethod("GET"); //$NON-NLS-1$ httpConnection.setReadTimeout(1000 * timeout); int responseCode = httpConnection.getResponseCode(); switch (responseCode) { case HttpURLConnection.HTTP_OK: try (InputStream in = httpConnection.getInputStream()) { String response = readFully(in, "UTF-8"); //$NON-NLS-1$ return response.startsWith(GERRIT_XSSI_MAGIC_STRING); } case HttpURLConnection.HTTP_NOT_FOUND: if (slash > path.length()) { return false; } slash = path.indexOf('/', slash); if (slash == -1) { // try the entire path slash = path.length(); } tmpPath = path.substring(0, slash); slash++; break; default: return false; } } catch (IOException e) { return false; } finally { if (httpConnection != null) { httpConnection.disconnect(); } } } } else if (SSH.equals(s)) { if (u.getPort() < 0 || u.getUser() == null || credentialsProvider == null) { return false; } URIish sshUri = u.setPath(""); //$NON-NLS-1$ try { String result = runSshCommand(sshUri, credentialsProvider, repo.getFS(), GERRIT_SSHD_VERSION_API); return result != null && GERRIT_SSHD_REPLY.matcher(result).matches(); } catch (IOException e) { // Something went wrong with the connection or with the command // execution. Maybe the server didn't recognize the command. Do // the safe thing and claim it wasn't a Gerrit. In the worst // case, the user may have to do the Gerrit config setup via // the ConfigureGerritWizard. return false; } } return false; }
From source file:org.eclipse.egit.ui.internal.components.RepositorySelectionPage.java
License:Open Source License
private void updateFields(final String text) { try {/*from w w w . j a v a 2 s . co m*/ eventDepth++; if (eventDepth != 1) return; final URIish u = new URIish(text); safeSet(hostText, u.getHost()); safeSet(pathText, u.getPath()); safeSet(userText, u.getUser()); safeSet(passText, u.getPass()); if (u.getPort() > 0) portText.setText(Integer.toString(u.getPort())); else portText.setText(""); //$NON-NLS-1$ if (u.getScheme() != null) { scheme.select(scheme.indexOf(u.getScheme())); scheme.notifyListeners(SWT.Selection, new Event()); } updateAuthGroup(); uri = u; } catch (URISyntaxException err) { // leave uriText as it is, but clean up underlying uri and // decomposed fields uri = new URIish(); hostText.setText(""); //$NON-NLS-1$ pathText.setText(""); //$NON-NLS-1$ userText.setText(""); //$NON-NLS-1$ passText.setText(""); //$NON-NLS-1$ portText.setText(""); //$NON-NLS-1$ scheme.select(-1); } finally { eventDepth--; } checkPage(); }
From source file:org.eclipse.n4js.utils.git.GitUtils.java
License:Open Source License
/** * Compare the two given git remote URIs. This method is a reimplementation of {@link URIish#equals(Object)} with * one difference. The scheme of the URIs is only considered if both URIs have a non-null and non-empty scheme part. * * @param lhs/*from w ww.ja v a 2s .c o m*/ * the left hand side * @param rhs * the right hand side * @return <code>true</code> if the two URIs are to be considered equal and <code>false</code> otherwise */ private static boolean equals(URIish lhs, URIish rhs) { // We only consider the scheme if both URIs have one if (!StringUtils.isEmptyOrNull(lhs.getScheme()) && !StringUtils.isEmptyOrNull(rhs.getScheme())) { if (!Objects.equals(lhs.getScheme(), rhs.getScheme())) return false; } if (!equals(lhs.getUser(), rhs.getUser())) return false; if (!equals(lhs.getPass(), rhs.getPass())) return false; if (!equals(lhs.getHost(), rhs.getHost())) return false; if (lhs.getPort() != rhs.getPort()) return false; if (!pathEquals(lhs.getPath(), rhs.getPath())) return false; return true; }