public String getSessionRelativePath(String urlString) throws ClientException { try { final SVNURL url = SVNURL.parseURIEncoded(urlString); return SVNPathUtil.getPathAsChild(svnRepository.getLocation().getPath(), url.getPath()); } catch (SVNException e) { throw ClientException.fromException(e); } }
@Override public URI getUri() { SVNURL svnurl; svnurl = getSvnurl(); try { svnurl = SVNURL.create(svnurl.getProtocol(), null, svnurl.getHost(), svnurl.hasPort() ? svnurl.getPort() : -1, svnurl.getPath(), false); } catch (SVNException e) { throw new IllegalStateException(e.getMessage(), e); } return URI.create(root.getFilesystem().getScheme() + ":" + svnurl.toString()); }
/** * Constructs a new <b>SVNURL</b> representation removing a tail path * segment from the path component of this representation. * * @return a new <b>SVNURL</b> representation */ public SVNURL removePathTail() throws SVNException { String newPath = SVNPathUtil.removeTail(myPath); String url = composeURL(getProtocol(), getUserInfo(), getHost(), myIsDefaultPort ? -1 : getPort(), newPath); return parseURIDecoded(url); } /**
/** * Returns a string representing a decoded url. * * @return a decoded url string */ public String toDecodedString() { return composeURL(getProtocol(), getUserInfo(), getHost(), myIsDefaultPort ? -1 : getPort(), getPath()); }
/** * Returns a string representing a UTF-8 encoded url. * * @return an encoded url string */ public String toString() { if (myURL == null) { myURL = composeURL(getProtocol(), getUserInfo(), getHost(), myIsDefaultPort ? -1 : getPort(), getURIEncodedPath()); } return myURL; }
public void handleDirEntry(SVNDirEntry dirEntry) throws SVNException { if (entries != null) { dirEntry = new SVNDirEntry(url.appendPath(dirEntry.getName(), false), repositoryRoot, dirEntry.getName(), dirEntry.getKind(), dirEntry.getSize(), dirEntry.hasProperties(), dirEntry.getRevision(), dirEntry.getDate(), dirEntry.getAuthor()); entries.add(dirEntry); } } };
private void collectInfo(SVNRepository repos, SVNDirEntry entry, SVNRevision rev, String path, SVNURL root, String uuid, SVNURL url, Map locks, boolean recursive, ISVNInfoHandler handler) throws SVNException { checkCancelled(); String displayPath = repos.getFullPath(path); displayPath = displayPath.substring(repos.getLocation().getPath().length()); if ("".equals(displayPath) || "/".equals(displayPath)) { displayPath = path; } handler.handleInfo(SVNInfo.createInfo(displayPath, root, uuid, url, rev, entry, (SVNLock) locks.get(path))); if (entry.getKind() == SVNNodeKind.DIR && recursive) { Collection children = repos.getDir(path, rev.getNumber(), null, new ArrayList()); for (Iterator ents = children.iterator(); ents.hasNext();) { SVNDirEntry child = (SVNDirEntry) ents.next(); SVNURL childURL = url.appendPath(child.getName(), false); collectInfo(repos, child, rev, SVNPathUtil.append(path, child.getName()), root, uuid, childURL, locks, recursive, handler); } } }
SVNProperties properties; try { properties = externals == null ? null : new SVNProperties(); entries = repository.getDir(path, rev, properties, entryFields, entries); } catch (SVNAuthenticationException e) { return; } catch (SVNException e) { if (e.getErrorMessage().getErrorCode() == SVNErrorCode.RA_NOT_AUTHORIZED) { return; SVNPropertyValue svnExternalsVaule = properties == null ? null : properties.getSVNPropertyValue(SVNProperty.EXTERNALS); if (svnExternalsVaule != null) { SVNURL location = repository.getLocation(); externals.put(location.appendPath(path, false), svnExternalsVaule); String childPath = SVNPathUtil.append(path, entry.getName()); entry.setRelativePath(childPath); if (entry.getKind() == SVNNodeKind.FILE || depth == SVNDepth.IMMEDIATES || depth == SVNDepth.INFINITY) { entry.setExternalParentUrl(externalParentUrl); entry.setExternalTarget(externalTarget);
public SCMRepository info() { SVNRepository repository = null; try { SVNURL url = SVNURL.parseURIEncoded(path); repository = SVNRepositoryFactory.create(url); authenticateIfNecessary(repository); SVNDirEntry firstRevision = repository.info("/", 0); SVNDirEntry lastRevision = repository.info("/", SVNRevision.HEAD.getNumber()); return new SCMRepository(this, lastRevision.getURL().getPath(), path, String.valueOf(lastRevision.getRevision()), String.valueOf(firstRevision .getRevision())); } catch (SVNException e) { throw new RuntimeException("error in getHead() for " + path, e); } finally { if (repository != null) repository.closeSession(); } }
SVNURL repoURL = SVNURL.parseURIEncoded(remote); StandardCredentials credentials = lookupCredentials(context, value, repoURL); SVNRepository repo = descriptor().getRepository(context, repoURL, credentials, Collections .<String, Credentials>emptyMap(), null); String repoRoot = repo.getRepositoryRoot(true).toDecodedString(); String repoPath = repo.getLocation().toDecodedString().substring(repoRoot.length()); SVNPath path = new SVNPath(repoPath, true, true); SVNNodeKind svnNodeKind = repo.checkPath(path.getTarget(), path.getPegRevision().getNumber()); if (svnNodeKind != SVNNodeKind.DIR) { return FormValidation.error("Credentials looks fine but the repository URL is invalid"); LOGGER.log(Level.SEVERE, e.getErrorMessage().getMessage()); return FormValidation.error("Unable to access the repository");
@Nullable @Override public RepositoryInfo getRepository(@NotNull SVNURL url) throws SVNException { final Map.Entry<String, VcsRepository> entry = getMapped(mapping, url.getPath()); if (entry != null) { return new RepositoryInfo( SVNURL.create(url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort() == SVNURL.getDefaultPortNumber(url.getProtocol()) ? -1 : url.getPort(), entry.getKey(), true), entry.getValue() ); } return null; }
public static void remotePropertyGet(SVNURL url, SVNNodeKind kind, String path, SVNRepository repos, long revNumber, SVNDepth depth, ISvnObjectReceiver<SVNProperties> receiver) throws SVNException { SVNURL fullURL = url.appendPath(path, false); SVNProperties props = new SVNProperties(); final Collection<SVNDirEntry> dirEntries = new LinkedList<SVNDirEntry>(); if (kind == SVNNodeKind.DIR) { repos.getDir(path, revNumber, props, SVNDirEntry.DIRENT_KIND, handler); } else if (kind == SVNNodeKind.FILE) { repos.getFile(path, revNumber, props, null); } else { SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.NODE_UNKNOWN_KIND, "Unknown node kind for ''{0}''", fullURL); for (String name : new HashSet<String>(props.nameSet())) { if (!SVNProperty.isRegularProperty(name)) { props.remove(name); if (entry.getKind() == SVNNodeKind.FILE || depth.compareTo(SVNDepth.FILES) > 0) { String entryPath = SVNPathUtil.append(path, entry.getName()); SVNDepth depthBelow = depth; if (depth == SVNDepth.IMMEDIATES) { depthBelow = SVNDepth.EMPTY; remotePropertyGet(url, entry.getKind(), entryPath, repos, revNumber, depthBelow, receiver);
return null; SVNMergeRange ranges[] = rangeList.getRanges(); LinkedList adjustedRanges = new LinkedList(); SVNURL mergeSourceURL = mergeSourceRootURL.appendPath(sourcePath, false); for (int i = 0; i < ranges.length; i++) { SVNMergeRange range = ranges[i]; try { locations = getLocations(targetURL, null, myRepository2, SVNRevision.create(targetEntry.getRevision()), SVNRevision.create(range.getStartRevision() + 1), SVNRevision.UNDEFINED); SVNURL startURL = locations[0].getURL(); if (!mergeSourceURL.equals(startURL)) { adjustedRanges.add(range); SVNErrorCode code = svne.getErrorMessage().getErrorCode(); if (code == SVNErrorCode.CLIENT_UNRELATED_RESOURCES || code == SVNErrorCode.RA_DAV_PATH_NOT_FOUND || Map implicitMergeInfo = getHistoryAsMergeInfo(null, path, SVNRevision.create(targetEntry.getRevision()), targetEntry.getRevision(), SVNRepository.INVALID_REVISION, myRepository2, myWCAccess); myRepository2.setLocation(oldURL, false);
public void process( @NotNull CmdLine cmdLine ) throws IOException, SVNException { cmdLine.out( SubversionMessageHandler.get( "module.list.repository.entries" ) ); String repositoryUrl = cmdLine.read( SubversionMessageHandler.get( "wich.repository.shall.be.used" ), subversionSupport.getRepositoryUrls(), null ); subversionSupport.addRepositoryUrl( repositoryUrl ); cmdLine.warning( SubversionMessageHandler.get( "listing.repository.entries" ) ); cmdLine.out( SubversionMessageHandler.get( "repository" ) ); cmdLine.success( '\t' + repositoryUrl ); SVNURL svnurl = SVNURL.parseURIDecoded( repositoryUrl ); SVNRepository repository = SVNRepositoryFactory.create( svnurl ); repository.setAuthenticationManager( subversionSupport.getAuthenticationManager() ); Collection<SVNDirEntry> dirEntry = repository.getDir( ".", repository.getLatestRevision(), null, ( Collection<?> ) null ); for ( SVNDirEntry entry : dirEntry ) { cmdLine.out( entry.getRelativePath() + "\t\t(" + entry.getKind() + ")" ); } } }
public void doGetFileContents(SVNURL url, SVNRevision pegRevision, SVNRevision revision, boolean expandKeywords, SVNProperties properties, OutputStream dst) throws SVNException { revision = revision == null || !revision.isValid() ? SVNRevision.HEAD : revision; SVNRepository repos = createRepository(url, null, null, pegRevision, revision, null); checkCancelled(); long revNumber = getRevisionNumber(revision, repos, null); checkCancelled(); SVNNodeKind nodeKind = repos.checkPath("", revNumber); checkCancelled(); if (nodeKind == SVNNodeKind.DIR) { repos.getFile("", revNumber, properties, new SVNCancellableOutputStream(dst, this)); } else { if (properties == null) { properties = new SVNProperties(); repos.getFile("", revNumber, properties, null); checkCancelled(); String mimeType = properties.getStringValue(SVNProperty.MIME_TYPE); String charset = SVNTranslator.getCharset(properties.getStringValue(SVNProperty.CHARSET), mimeType, repos.getLocation().toString(), getOptions()); String keywords = properties.getStringValue(SVNProperty.KEYWORDS); String eol = properties.getStringValue(SVNProperty.EOL_STYLE); String cmtDate = properties.getStringValue(SVNProperty.COMMITTED_DATE); String author = properties.getStringValue(SVNProperty.LAST_AUTHOR); Map keywordsMap = SVNTranslator.computeKeywords(keywords, expandKeywords ? repos.getLocation().toString() : null, repos.getRepositoryRoot(true).toString(), author, cmtDate, cmtRev, getOptions()); OutputStream translatingStream = SVNTranslator.getTranslatingOutputStream(dst, charset, SVNTranslator.getEOL(eol, getOptions()), false, keywordsMap, expandKeywords); repos.getFile("", revNumber, null, new SVNCancellableOutputStream(translatingStream, getEventDispatcher()));
private void pushDirInfo(SVNRepository repos, SVNRevision rev, String dir, SVNURL root, String uuid, SVNURL url, Map<String, SVNLock> locks, SVNDepth depth) throws SVNException { Collection<SVNDirEntry> children = repos.getDir(dir, rev.getNumber(), null, SVNDirEntry.DIRENT_SIZE | SVNDirEntry.DIRENT_KIND | SVNDirEntry.DIRENT_CREATED_REVISION | SVNDirEntry.DIRENT_TIME | SVNDirEntry.DIRENT_LAST_AUTHOR, new ArrayList<SVNDirEntry>()); for (SVNDirEntry child : children) { SVNURL childURL = url.appendPath(child.getName(), false); String path = SVNPathUtil.append(dir, child.getName()); String fsPath = "/" + SVNPathUtil.getRelativePath(root.toDecodedString(), childURL.toDecodedString()); SVNLock lock = locks.get(fsPath); if (depth.compareTo(SVNDepth.IMMEDIATES) >= 0 || (depth == SVNDepth.FILES && child.getKind() == SVNNodeKind.FILE)) { SvnInfo info = creatSvnInfoForEntry(root, uuid, child, childURL, rev.getNumber(), lock); getOperation().receive(SvnTarget.fromURL(childURL), info); } if (depth == SVNDepth.INFINITY && child.getKind() == SVNNodeKind.DIR) { pushDirInfo(repos, rev, path, root, uuid, childURL, locks, depth); } } }
public void run() throws SVNException { List targets = getEnvironment().combineTargets(null, false); if (!targets.isEmpty()) { targets.remove(0); } String[] locks = (String[]) targets.toArray(new String[targets.size()]); SVNRepository repository = SVNRepositoryFactory.create(SVNURL.fromFile(getLocalRepository())); String userName = System.getProperty("user.name", "administrator"); repository.setAuthenticationManager(new BasicAuthenticationManager(userName, "")); repository.setCanceller(getEnvironment()); for (int i = 0; i < locks.length; i++) { String lockPath = locks[i]; try { SVNLock lock = repository.getLock(lockPath); if (lock == null) { getEnvironment().getOut().println("Path '" + lockPath + "' isn't locked."); continue; } Map pathToToken = new SVNHashMap(); pathToToken.put(lockPath, lock.getID()); repository.unlock(pathToToken, true, this); } catch (SVNException e) { getEnvironment().handleError(e.getErrorMessage()); } } }
@Override public ChangeSet getHead() { SVNRepository repository = null; try { SVNURL url = SVNURL.parseURIEncoded(path); repository = SVNRepositoryFactory.create(url); authenticateIfNecessary(repository); SVNDirEntry entry = repository.info("/", -1); return new ChangeSet(String.valueOf(entry.getRevision()), convertToCalendar(entry.getDate())); } catch (SVNException e) { throw new RuntimeException("error in getHead() for " + path, e); } finally { if (repository != null) repository.closeSession(); } }
SVNProperties baseMap = oldBaseProps.asMap(); if (modifiedProps == null) { modifiedProps = new SVNProperties(); for(Iterator names = baseMap.nameSet().iterator(); names.hasNext();) { String name = (String) names.next(); if (!modifiedProps.containsName(name)) { modifiedProps.put(name, SVNPropertyValue.create(null)); modifiedProps, null, null, true, false, log); } catch (SVNException svne) { SVNErrorMessage err = svne.getErrorMessage().wrap("Couldn't do property merge"); SVNErrorManager.error(err, svne, SVNLogType.WC); event.setURL(myCurrentDirectory.URL != null ? SVNURL.parseURIEncoded(myCurrentDirectory.URL) : null); myWCAccess.handleEvent(event);
@Override public C execute(final SVNRepository repo, final SVNClientManager clientManager) throws Exception { final Long revision = parseRevisionOrDie(version); // use raw repo to check if the path exists final SVNNodeKind nodeType = repo.checkPath(path, revision); if (SVNNodeKind.NONE.equals(nodeType)) { LOGGER.warn(repo.getLocation() + "/" + path + " @r" + revision + " is SVNNodeKind.NONE returning " + defaultValue); return defaultValue; } final SVNWCClient client = clientManager.getWCClient(); final SVNURL url = svnUrl.appendPath(path, true); final SVNRevision svnRevision = SVNRevision.create(revision); final ByteArrayOutputStream baos = new ByteArrayOutputStream(); client.doGetFileContents(url, svnRevision, svnRevision, /* expandKeywords */ false, baos); final C testDefinition = objectMapper.readValue(baos.toByteArray(), c); try { baos.close(); } catch (IOException e) { /* ignore */ } return testDefinition; }