2

我正在尝试解析 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);
        }
    }

我的 URL 类似于http://10.61.128.222/svn/i18ntest/trunkor http://10.61.128.222/svn/PFT/branches/protoi18n,我需要一个可以输入此 URL 的方法,它会返回/trunk/or /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 是否提供任何已经证明的方法来做到这一点。

4

1 回答 1

4

使用时,SVNRepository您需要相对于存储库根目录的路径。您可以使用检索存储库根 URL SVNURL root = repository.getRepositoryRoot(true),然后使用它来获取您和存储库根 URLSVNURLUtil.getRelativeURL(root, url, false)之间的相对路径。url

于 2012-05-31T11:33:38.673 回答