public void testConnection() throws SVNException { String encodedUrl = SVNEncodingUtil.autoURIEncode(addressSvn); SVNRepository repository = SVNRepositoryFactory.create(SVNURL.parseURIEncoded(encodedUrl)); repository.setAuthenticationManager(authManager); repository.testConnection(); }
public SVNNodeKind checkRepositoryPath(AbstractProject context, SVNURL repoURL) throws SVNException { SVNRepository repository = null; try { repository = getRepository(context, repoURL); repository.testConnection(); long rev = repository.getLatestRevision(); String repoPath = getRelativePath(repoURL, repository); return repository.checkPath(repoPath, rev); } finally { if (repository != null) { repository.closeSession(); } } }
public static void listEntries(SVNRepository repository, String path) throws SVNException { Collection<?> entries = repository.getDir(path, -1, null, (Collection<?>) null); Iterator<?> iterator = entries.iterator(); while (iterator.hasNext()) { SVNDirEntry entry = (SVNDirEntry) iterator.next(); System.out.println("/" + (path.equals("") ? "" : path + "/") + entry.getName()); if (entry.getKind() == SVNNodeKind.DIR) { listEntries(repository, (path.equals("")) ? entry.getName() : path + "/" + entry.getName()); } } }
private SVNRepository getSourceRepository() throws SVNException { if (mySourceRepository == null) { mySourceRepository = SVNRepositoryFactory.create(myRepos.getLocation()); mySourceRepository.setAuthenticationManager(myRepos.getAuthenticationManager()); mySourceRepository.setDebugLog(myRepos.getDebugLog()); mySourceRepository.setTunnelProvider(myRepos.getTunnelProvider()); mySourceRepository.setCanceller(myRepos.getCanceller()); } return mySourceRepository; }
protected SVNURL ensureSessionURL(SVNRepository repository, SVNURL url) throws SVNException { SVNURL oldURL = repository.getLocation(); if (url == null) { url = repository.getRepositoryRoot(true); } if (!url.equals(oldURL)) { repository.setLocation(url, false); return oldURL; } return null; }
DAVRepositoryFactory.setup(); String url = "(directory in svn url)"; String name = "(login name)"; String password = "(login password)"; SVNRepository repository = null; repository = SVNRepositoryFactory.create(SVNURL.parseURIDecoded(url)); ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager(name, password); repository.setAuthenticationManager(authManager); SVNDirEntry entry = repository.info(".", -1); System.out.println("Latest Rev: " + entry.getRevision());
private void doList(SVNRepository repos, long rev, final ISVNDirEntryHandler handler, boolean fetchLocks, SVNDepth depth, int entryFields) throws SVNException { SVNURL url = repos.getLocation(); SVNURL reposRoot = repos.getRepositoryRoot(false); SVNDirEntry entry = null; SVNException error = null; try { entry = repos.info("", rev); } catch (SVNException svne) { if (svne.getErrorMessage().getErrorCode() == SVNErrorCode.RA_NOT_IMPLEMENTED) { error = svne; } else { SVNNodeKind kind = repos.checkPath("", rev); if (kind != SVNNodeKind.NONE) { if (!url.equals(reposRoot)) { String name = SVNPathUtil.tail(repos.getLocation().getPath()); repos.setLocation(repos.getLocation().removePathTail(), false); Collection dirEntries = repos.getDir("", rev, null, entryFields, (Collection) null); repos.setLocation(url, false); for (Iterator ents = dirEntries.iterator(); ents.hasNext();) { SVNDirEntry dirEntry = (SVNDirEntry) ents.next(); if (name.equals(dirEntry.getName())) { entry = dirEntry; break; SVNProperties props = new SVNProperties(); repos.getDir("", rev, props, entryFields, (Collection) null); SVNProperties revProps = repos.getRevisionProperties(rev, null); String author = revProps.getStringValue(SVNRevisionProperty.AUTHOR); String dateStr = revProps.getStringValue(SVNRevisionProperty.DATE);
String urlWithoutRevision = getUrlWithoutRevision(url); SVNURL repoURL = SVNURL.parseURIDecoded(urlWithoutRevision); if (checkRepositoryPath(context, repoURL) != SVNNodeKind.NONE) { if (isRevisionPresent(revision) && !revision.isValid()) { return FormValidation.errorWithMarkup(Messages.SubversionSCM_doCheckRemote_invalidRevision()); try { repository = getRepository(context, repoURL); long rev = repository.getLatestRevision(); while (p.length() > 0) { p = SVNPathUtil.removeTail(p); if (repository.checkPath(p, rev) == SVNNodeKind.DIR) { repository.getDir(p, rev, false, entries); if (e.getKind() == SVNNodeKind.DIR) { paths.add(e.getName()); } finally { if (repository != null) { repository.closeSession();
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(); } }
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 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())); try { translatingStream.flush();
public void getInheritedProperties(String path, long revision, String propertyName, ISVNInheritedPropertiesHandler handler) throws SVNException { if (isInvalidRevision(revision)) { revision = getLatestRevision(); if (hasCapability(SVNCapability.INHERITED_PROPS)) { getInheritedPropertiesImpl(path, revision, propertyName, handler); return; final SVNURL originalLocation = getLocation(); String rootRelativePath = getRepositoryPath(""); try { while(!"/".equals(rootRelativePath)) { rootRelativePath = "/"; setLocation(getLocation().removePathTail(), false); final SVNProperties properties = new SVNProperties(); try { getDir("", revision, properties, 0, (ISVNDirEntryHandler) null); } catch (SVNAuthenticationException ae) { continue; final SVNProperties filtered = new SVNProperties(); if (propertyName != null && properties.containsName(propertyName)) { filtered.put(propertyName, properties.getSVNPropertyValue(propertyName)); } else if (propertyName == null) { setLocation(originalLocation, false);
@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(); } }
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()); } } }
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");
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; SVNProperties adjustedProperties = new SVNProperties(); for (Iterator propNamesIter = props.nameSet().iterator(); propNamesIter.hasNext();) { String propName = (String) propNamesIter.next(); SVNPropertyValue propValue = props.getSVNPropertyValue(propName); if (SVNProperty.MERGE_INFO.equals(propName) && !myIsSameRepository) { adjustedProperties.put(propName, propValue); } else { SVNURL mergeSourceRootURL = myRepository2.getRepositoryRoot(true); SVNURL targetURL = getURL(path); SVNURL oldURL = ensureSessionURL(myRepository2, targetURL); 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]; 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);
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); } } }