如何使用java获取SVN目录中的文件夹列表

SKR*_*SKR 2 svnkit

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

Viv*_*vek 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;
    }
Run Code Online (Sandbox Code Playgroud)

干杯!!