I’m trying to parse an URL in order to obtain the current branch or trunk.
public SVNConnector(String s_Url, String login, String password, String project) {
try {
url = SVNURL.parseURIEncoded(s_Url);
ISVNAuthenticationManager authManager = new BasicAuthenticationManager(login, password);
DAVRepositoryFactory.setup();
repository = SVNRepositoryFactory.create(url, null);
repository.setAuthenticationManager(authManager);
this.projectName = project;
latestRevision = repository.getLatestRevision();
} catch (SVNException svne) {
logger.error("Impossible to connect to SVN repository. s_Url: "+s_Url+" login:"+login+" password: "+password, svne);
}
}
My URL is something like http://10.61.128.222/svn/i18ntest/trunk or http://10.61.128.222/svn/PFT/branches/protoi18n and I need a method where I could enter this URL and it would return /trunk/ or /branches/protoi18n/, so I could run this:
public List<OutputElement> retrieveI18nFiles() throws SVNException {
List<OutputElement> outs = new ArrayList<OutputElement>();
String path = url.getPath()+"/core/src/main/resources/fr/gefco/"+projectName+"/i18n/"; // this is not working!
latestRevision = repository.getLatestRevision();
// For some reason, type safety is not insured in SVNKit, even if generics are around for some years, now
Collection<SVNDirEntry> entries = repository.getDir(path, latestRevision, (SVNProperties)null, (Collection<SVNDirEntry>)null);
for (SVNDirEntry entry : entries) {
OutputElement out = new OutputElement();
out.setEntry(entry);
out.setOut(retrieveOutputStream(entry,path));
outs.add(out);
}
return outs;
}
url.getPath() is returning /svn/i18ntest/trunk/, which is not what I need. Of course, I could parse it to get the bit I need, but I would like to know first if SVNKit provides any already proven way to do that.
When working with
SVNRepositoryyou need paths relative to the repository root. You may retrieve the repository root URL usingSVNURL root = repository.getRepositoryRoot(true)and then useSVNURLUtil.getRelativeURL(root, url, false)to get the relative path between yoururland the repository root URL.