2

我在我的应用程序中使用 svnkit-1.3.5.jar。在单击按钮的其中一个屏幕上,我需要显示一个 jQuery 对话框,其中包含 SVN 中特定路径中存在的文件夹列表。svnkit 是否提供任何方法来检索存在于特定位置的所有文件夹名称?我如何在java中实现这一点?

4

2 回答 2

6

这是我用于相同目的的代码(使用svnkit 库)。@mstrap 代码的修改版本更清晰。

public static String NAME = "svnusername";
public static String PASSWORD = "svnpass";
public final String TRUNK_VERSION_PATH = "svn://192.168.1.1/path";
public static List<String> apiVersions;

   public List<String> getApiVersion() {
        logger.info("Getting API Version list....");
        apiVersions = new ArrayList<String>();
        SVNURL repositoryURL = null;
        try {
            repositoryURL = SVNURL.parseURIEncoded(TRUNK_VERSION_PATH);
        } catch (SVNException e) {
            logger.error(e);
        }

        SVNRevision revision = SVNRevision.HEAD;
        SvnOperationFactory operationFactory = new SvnOperationFactory();
        operationFactory.setAuthenticationManager(new BasicAuthenticationManager(NAME, PASSWORD));
        SvnList list = operationFactory.createList();
        list.setDepth(SVNDepth.IMMEDIATES);
        list.setRevision(revision);
        list.addTarget(SvnTarget.fromURL(repositoryURL, revision));
        list.setReceiver(new ISvnObjectReceiver<SVNDirEntry>() {
            public void receive(SvnTarget target, SVNDirEntry object) throws SVNException {
                String name = object.getRelativePath();
                if(name!=null && !name.isEmpty()){
                    apiVersions.add(name);
                }
            }
        });
        try {
            list.run();
        } catch (SVNException ex) {
            logger.error(ex);
        }

        return apiVersions;
    }

干杯!!

于 2013-12-18T11:20:56.640 回答
2
final URL url = ...
final SVNRevision revision = ...
final SvnOperationFactory operationFactory = ...

final SvnList list = operationFactory.createList();
list.setDepth(SVNDepth.IMMEDIATES);
list.setRevision(revision);
list.addTarget(SvnTarget.fromURL(url, revision);
list.setReceiver(new ISvnObjectReceiver<SVNDirEntry>() {
    public void receive(SvnTarget target, SVNDirEntry object) throws SVNException {
        final String name = object.getRelativePath();
        System.out.println(name);
    }
});

list.run();
于 2012-11-07T13:31:47.523 回答