Refine search
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; } }
private List<String> getProjectBranches(Job<?, ?> project) { final URIish sourceRepository = getSourceRepoURLDefault(project); GitLabConnectionProperty connectionProperty = project.getProperty(GitLabConnectionProperty.class); if (connectionProperty != null && connectionProperty.getClient() != null) { return GitLabProjectBranchesService.instance().getBranches(connectionProperty.getClient(), sourceRepository.toString()); } else { LOGGER.log(Level.WARNING, "getProjectBranches: gitlabHostUrl hasn't been configured globally. Job {0}.", project.getFullName()); return Collections.emptyList(); } }
@Override public boolean canHandle(URIish uri, Repository local, String remoteName) { if (uri.getPath() == null || uri.getPort() > 0 || uri.getUser() != null || uri.getPass() != null || uri.getHost() != null || (uri.getScheme() != null && !getSchemes().contains(uri.getScheme()))) return false; return true; }
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; }
/** * Creates a message digest * @param uri * @return * @throws NoSuchAlgorithmException */ private static byte[] canonicalRequestDigest(URIish uri) throws NoSuchAlgorithmException { StringBuilder canonicalRequest = new StringBuilder(); canonicalRequest.append("GIT\n") // codecommit uses GIT as the request method .append(uri.getPath()).append("\n") // URI request path .append("\n") // Query string, always empty for codecommit // Next is canonical headers, codecommit only requires the host header .append("host:").append(uri.getHost()).append("\n") .append("\n") // canonical headers are always terminated by newline .append("host\n"); // The list of canonical headers, only one for codecommit MessageDigest digest = MessageDigest.getInstance(SHA_256); return digest.digest(canonicalRequest.toString().getBytes()); }
/** * Update this remote's definition within the configuration. * * @param rc * the configuration file to store ourselves into. */ public void update(Config rc) { final List<String> vlst = new ArrayList<>(); vlst.clear(); for (URIish u : getURIs()) vlst.add(u.toPrivateString()); rc.setStringList(SECTION, getName(), KEY_URL, vlst); vlst.clear(); for (URIish u : getPushURIs()) vlst.add(u.toPrivateString()); rc.setStringList(SECTION, getName(), KEY_PUSHURL, vlst); vlst.clear(); for (RefSpec u : getFetchRefSpecs()) vlst.add(u.toString()); rc.setStringList(SECTION, getName(), KEY_FETCH, vlst); vlst.clear(); for (RefSpec u : getPushRefSpecs()) vlst.add(u.toString()); rc.setStringList(SECTION, getName(), KEY_PUSH, vlst); set(rc, KEY_UPLOADPACK, getUploadPack(), DEFAULT_UPLOAD_PACK); set(rc, KEY_RECEIVEPACK, getReceivePack(), DEFAULT_RECEIVE_PACK); set(rc, KEY_TAGOPT, getTagOpt().option(), TagOpt.AUTO_FOLLOW.option()); set(rc, KEY_MIRROR, mirror, DEFAULT_MIRROR); set(rc, KEY_TIMEOUT, timeout, 0); }
int bestMatchLength = -1; boolean withUser = false; String uPath = uri.getPath(); boolean hasPath = !StringUtils.isEmptyOrNull(uPath); if (hasPath) { URIish candidate = new URIish(s); if (!compare(uri.getScheme(), candidate.getScheme()) || !compare(uri.getHost(), candidate.getHost())) { continue; if (defaultedPort(uri.getPort(), uri.getScheme()) != defaultedPort(candidate.getPort(), candidate.getScheme())) { continue; if (candidate.getUser() != null) { if (!candidate.getUser().equals(uri.getUser())) { continue; String cPath = candidate.getPath(); int matchLength = -1; if (StringUtils.isEmptyOrNull(cPath)) {
private void addOrigin() throws URISyntaxException, GitAPIException { RemoteAddCommand add = git.remoteAdd(); add.setName("origin"); String uri = "https://example.org/repo"; add.setUri(new URIish(uri)); add.call(); assertEquals("origin", git.remoteList().call().iterator().next().getName()); assertEquals(uri, git.remoteList().call().iterator().next().getURIs().iterator().next().toString()); } }
/** {@inheritDoc} */ @Deprecated public void clone(RemoteConfig rc, boolean useShallowClone) throws GitException, InterruptedException { // Assume only 1 URL for this repository final String source = rc.getURIs().get(0).toPrivateString(); clone(source, rc.getName(), useShallowClone, null); }
URISyntaxException, TransportException { if (local != null) { final RemoteConfig cfg = new RemoteConfig(local.getConfig(), remote); if (doesNotExist(cfg)) return open(local, new URIish(remote), null); return open(local, cfg, op); } else return open(new URIish(remote));
@Override public boolean canHandle(URIish uri, Repository local, String remoteName) { if (uri.getScheme() == null) { // scp-style URI "host:path" does not have scheme. return uri.getHost() != null && uri.getPath() != null && uri.getHost().length() != 0 && uri.getPath().length() != 0; } return super.canHandle(uri, local, remoteName); }
private String format(boolean includePassword, boolean escapeNonAscii) { final StringBuilder r = new StringBuilder(); if (getScheme() != null) { r.append(getScheme()); r.append("://"); //$NON-NLS-1$ if (getUser() != null) { r.append(escape(getUser(), true, escapeNonAscii)); if (includePassword && getPass() != null) { r.append(':'); r.append(escape(getPass(), true, escapeNonAscii)); if (getHost() != null) { if (getUser() != null && getUser().length() > 0) r.append('@'); r.append(escape(getHost(), false, escapeNonAscii)); if (getScheme() != null && getPort() > 0) { r.append(':'); r.append(getPort()); if (getPath() != null) { if (getScheme() != null) { if (!getPath().startsWith("/") && !getPath().isEmpty()) //$NON-NLS-1$ r.append('/'); } else if (getHost() != null) r.append(':'); if (getScheme() != null) if (escapeNonAscii) r.append(escape(getPath(), false, escapeNonAscii)); else
public static ArrayMemory valueOf(RemoteConfig value) { ArrayMemory memory = new ArrayMemory(); memory.refOfIndex("name").assign(value.getName()); memory.refOfIndex("receivePack").assign(value.getReceivePack()); memory.refOfIndex("uploadPack").assign(value.getUploadPack()); memory.refOfIndex("mirror").assign(value.isMirror()); memory.refOfIndex("timeout").assign(value.getTimeout()); memory.refOfIndex("tagOpt").assign(value.getTagOpt().name()); ArrayMemory uris = ArrayMemory.createListed(value.getURIs().size()); for (URIish urIish : value.getURIs()) { uris.add(urIish.toPrivateString()); } memory.refOfIndex("uris").assign(uris); return memory; }
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); } }
public String getRemoteUrl(String defaultRemoteUrl) { if (StringUtils.isBlank(defaultRemoteUrl)) { RemoteConfig remoteConfig = getJenkinsScm().getRepositories().get(0); URIish uri = remoteConfig.getURIs().get(0); return uri.toPrivateString(); } return defaultRemoteUrl; }
String commandFor(String exe) { String path = uri.getPath(); if (uri.getScheme() != null && uri.getPath().startsWith("/~")) //$NON-NLS-1$ path = (uri.getPath().substring(1)); final StringBuilder cmd = new StringBuilder(); cmd.append(exe); cmd.append(' '); cmd.append(QuotedString.BOURNE.quote(path)); return cmd.toString(); }