Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/387.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何使用SVNkit识别SVN路径是目录还是文件?_Java_Svn_Svnkit - Fatal编程技术网

Java 如何使用SVNkit识别SVN路径是目录还是文件?

Java 如何使用SVNkit识别SVN路径是目录还是文件?,java,svn,svnkit,Java,Svn,Svnkit,假设您有如下指定的SVN路径,我如何知道该项是SVN目录或SVN文件。谢谢 http://cvs-server.test.com:8001/svn/test 已更新 SVNURL svnUrl = SVNURL.parseURIEncoded(url); SVNRepository repos = SVNRepositoryFactory.create(svnUrl); ISVNAuthenticationManager

假设您有如下指定的SVN路径,我如何知道该项是SVN目录或SVN文件。谢谢

http://cvs-server.test.com:8001/svn/test
已更新

            SVNURL svnUrl = SVNURL.parseURIEncoded(url);
            SVNRepository repos = SVNRepositoryFactory.create(svnUrl);
            ISVNAuthenticationManager authManager = 
            SVNWCUtil.createDefaultAuthenticationManager("user1","123");

            repos.setAuthenticationManager(authManager);

            SVNNodeKind nodeKind = repos.checkPath(url, repos.getLatestRevision());

为什么即使url是一个文件,我也得到了
none
?我确信这个url存在于SVN中。下跪。。。SVNkit有很多bug

试试这样的方法:

String url = "http://cvs-server.test.com:8001/svn/test";
SVNURL svnUrl = SVNURL.parseURIEncoded(url);
SVNRepository repos = SVNRepositoryFactory.create(svnUrl);
ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager(DEFAULT_USER, DEFAULT_PASS);
repos.setAuthenticationManager(authManager); 
SVNNodeKind nodeKind = repos.checkPath("", repos.getLatestRevision());

nodeKind
将是
文件
目录

中的一个。如果您遇到错误,请报告给

checkPath
不适用于URL,它适用于绝对路径(即相对于存储库根目录)或相对路径(相对于为其构建
SVNRepository
实例的URL)——有关详细信息,请参阅其javadoc

所以你可以用这个代码

SVNNodeKind nodeKind = repos.checkPath("", repos.getLatestRevision());
甚至

SVNNodeKind nodeKind = repos.checkPath("", -1);
第二种变体速度更快,因为它不执行
getLatestRevision
请求,而且它是一种相当流行的检查URL是否存在的方法,这在SVNKit本身中经常使用

或者,您可以使用绝对路径(以“/”开头),但要指定的路径取决于您的存储库根。您可以通过运行

$ svn info "http://cvs-server.test.com:8001/svn/test"
repos.getRepositoryRoot(true);
或者通过跑步

$ svn info "http://cvs-server.test.com:8001/svn/test"
repos.getRepositoryRoot(true);

来自SVNKit代码。绝对路径应以“/”开头,并与获得的存储库根相对。

这是正确的方法:

public static boolean isFolder(String url) throws SVNException {
    SVNURL svnURL = SVNURL.parseURIEncoded(url);
    SVNRepository repos = SVNRepositoryFactory.create(svnURL);
    ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager(DEFAULT_USER, DEFAULT_PASS);
    repos.setAuthenticationManager(authManager);
    SVNNodeKind nodeKind = repos.checkPath("", repos.getLatestRevision());
    System.out.println(nodeKind);
    return nodeKind != null && nodeKind == SVNNodeKind.DIR;
}

您的意思是:如何确定文件系统上的特定文件夹处于版本控制之下?您在受版本控制的文件夹中隐藏了名为
.svn
的文件夹。这就是你的意思吗?请看我的帖子。我刚刚更新了。谢谢你为什么不需要指定用户名和密码?你必须。。。但那不是你的问题。我假设你到目前为止知道SVNKIT。为什么我得到
none
甚至url是svn文件?这是一个bug吗?请用
/test
而不是
http://cvs-server.test.com:8001/svn/test
就像我在回答中提到的那样。