protected static String getHostname(String uri) { try { URIish urIish = new URIish(uri); return urIish.getHost(); } catch (URISyntaxException e) { return null; } } }
protected static boolean isSshUri(Object uri) { if(uri != null) { try { URIish urIish = new URIish(uri.toString()); String scheme = urIish.getScheme(); if(scheme == null && hasText(urIish.getHost()) && hasText(urIish.getUser())) { //JGit returns null if using SCP URI but user and host will be populated return true; } return scheme != null && !scheme.matches("^(http|https)$"); } catch (URISyntaxException e) { return false; } } return false; }
public static String retrieveProjectId(GitLabClient client, String remoteUrl) throws ProjectIdResolutionException { try { String baseUri = client.getHostUrl(); String projectId; if (baseUri != null && remoteUrl.startsWith(baseUri)) { projectId = new URIish(remoteUrl.substring(baseUri.length())).getPath(); if (projectId.contains(":")) { projectId = projectId.substring(projectId.indexOf(":")); } else if (projectId.startsWith(".")) { projectId = projectId.substring(projectId.indexOf("/")); } } else { projectId = new URIish(remoteUrl).getPath(); } if (projectId.startsWith(":")) { projectId = projectId.substring(1); } Matcher matcher = PROJECT_ID_PATTERN.matcher(projectId); if (matcher.matches()) { return matcher.group("projectId"); } else { throw new ProjectIdResolutionException(String.format("Failed to retrieve GitLab projectId for %s", remoteUrl)); } } catch (URISyntaxException e) { throw new ProjectIdResolutionException(String.format("Failed to retrieve GitLab projectId for %s", remoteUrl), e); } }
private URIish retrieveUrIish(PushHook hook) { try { if (hook.getRepository() != null) { return new URIish(hook.getRepository().getUrl()); } } catch (URISyntaxException e) { LOGGER.log(Level.WARNING, "could not parse URL"); } return null; } }
protected URIish retrieveUrIish(WebHook hook) { try { if (hook.getRepository() != null) { return new URIish(hook.getRepository().getUrl()); } } catch (URISyntaxException e) { LOGGER.log(Level.WARNING, "could not parse URL"); } return null; }
public void run() { for (SCMSource scmSource : ((SCMSourceOwner) project).getSCMSources()) { if (scmSource instanceof GitSCMSource) { GitSCMSource gitSCMSource = (GitSCMSource) scmSource; try { if (new URIish(gitSCMSource.getRemote()).equals(new URIish(gitSCMSource.getRemote()))) { if (!gitSCMSource.isIgnoreOnPushNotifications()) { LOGGER.log(Level.FINE, "Notify scmSourceOwner {0} about changes for {1}", toArray(project.getName(), gitSCMSource.getRemote())); ((SCMSourceOwner) project).onSCMSourceUpdated(scmSource); } else { LOGGER.log(Level.FINE, "Ignore on push notification for scmSourceOwner {0} about changes for {1}", toArray(project.getName(), gitSCMSource.getRemote())); } } } catch (URISyntaxException e) { // nothing to do } } } } }
@Signature public Memory remoteAdd(String name, String uri) throws URISyntaxException, GitAPIException { RemoteAddCommand command = getWrappedObject().remoteAdd(); command.setName(name); command.setUri(new URIish(uri)); return GitUtils.valueOf(command.call()); }
@Signature public Memory remoteSetUrl(String name, String uri, boolean push) throws URISyntaxException, GitAPIException { RemoteSetUrlCommand command = getWrappedObject().remoteSetUrl(); command.setName(name); command.setUri(new URIish(uri)); command.setPush(push); return GitUtils.valueOf(command.call()); }
/** * Return a new URI matching this one, but with a different scheme. * * @param n * the new value for scheme. * @return a new URI with the updated value. */ public URIish setScheme(String n) { final URIish r = new URIish(this); r.scheme = n; return r; }
/** * Return a new URI matching this one, but with a different user. * * @param n * the new value for user. * @return a new URI with the updated value. */ public URIish setUser(String n) { final URIish r = new URIish(this); r.user = n; return r; }
/** * Return a new URI matching this one, but with a different port. * * @param n * the new value for port. * @return a new URI with the updated value. */ public URIish setPort(int n) { final URIish r = new URIish(this); r.port = n > 0 ? n : -1; return r; }
/** * Return a new URI matching this one, but with a different host. * * @param n * the new value for host. * @return a new URI with the updated value. */ public URIish setHost(String n) { final URIish r = new URIish(this); r.host = n; return r; }
/** * Return a new URI matching this one, but with a different password. * * @param n * the new value for password. * @return a new URI with the updated value. */ public URIish setPass(String n) { final URIish r = new URIish(this); r.pass = n; return r; }
@Override URIish getURI() { return new URIish(httpObjectsUrl); }
/** * Return a new URI matching this one, but with a different path. * * @param n * the new value for path. * @return a new URI with the updated value. */ public URIish setPath(String n) { final URIish r = new URIish(this); r.path = n; r.rawPath = n; return r; }
/** * Return a new URI matching this one, but with a different (raw) path. * * @param n * the new value for path. * @return a new URI with the updated value. * @throws java.net.URISyntaxException */ public URIish setRawPath(String n) throws URISyntaxException { final URIish r = new URIish(this); r.path = unescape(n); r.rawPath = n; return r; }
/** * Register a repository connection over the internal test protocol. * * @param req * connection context. This instance is reused for all connections * made using this protocol; if it is stateful and usable only for * one connection, the same repository should be registered * multiple times. * @param remote * remote repository to connect to. * @return a URI that can be used to connect to this repository for both fetch * and push. */ public synchronized URIish register(C req, Repository remote) { URIish uri; try { int n = handles.size(); uri = new URIish(SCHEME + "://test/conn" + n); //$NON-NLS-1$ } catch (URISyntaxException e) { throw new IllegalStateException(); } handles.put(uri, new Handle(req, remote)); return uri; }
@Override URIish getURI() { URIish u = new URIish(); u = u.setScheme(S3_SCHEME); u = u.setHost(bucketName); u = u.setPath("/" + objectsKey); //$NON-NLS-1$ return u; }
private static URIish createURI(Session session) { URIish uri = new URIish(); uri = uri.setScheme("ssh"); //$NON-NLS-1$ uri = uri.setUser(session.getUserName()); uri = uri.setHost(session.getHost()); uri = uri.setPort(session.getPort()); return uri; }