我正在尝试解析URL以获取当前分支或主干。
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);
}
}
我的网址类似于http://10.61.128.222/svn/i18ntest/trunk
或http://10.61.128.222/svn/PFT/branches/protoi18n
,我需要一种可以输入此网址的方法,它会返回/trunk/
或/branches/protoi18n/
,因此我可以运行这样:
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()
正在返回/svn/i18ntest/trunk/
,这不是我需要的。当然,我可以解析它以获得我需要的位,但我想首先知道SVNKit是否提供了任何已经证明的方法来做到这一点。
答案 0 :(得分:4)
使用SVNRepository
时,您需要相对于存储库根目录的路径。您可以使用SVNURL root = repository.getRepositoryRoot(true)
检索存储库根URL,然后使用SVNURLUtil.getRelativeURL(root, url, false)
获取url
与存储库根URL之间的相对路径。