SVNKit - 检查目录是否存在

时间:2011-11-25 15:45:22

标签: java svn repository versioning svnkit

所以,我在SVN存储库下创建了一个项目TEST,我想知道这个项目目录是否与SVNKit库一起存在。协议是http。

我试过例如......

  private String urlSviluppo = "http://myrepo/SVILUPPO";


  DAVRepositoryFactory.setup();
  SVNURL url = SVNURL.parseURIDecoded(urlSviluppo);

  ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager("user", "pwd");      

  DAVRepository repositorySviluppo = (DAVRepository)DAVRepositoryFactory.create(url, null);
  repositorySviluppo.setAuthenticationManager(authManager);

  DefaultSVNOptions options = SVNWCUtil.createDefaultOptions(true);
  SVNClientManager clientManager = SVNClientManager.newInstance(options, "user", "pwd");

  clientManager.createRepository(url, true);

如何访问存储库/项目信息?

谢谢

1 个答案:

答案 0 :(得分:1)

查看"Printing Out a Subversion Repository Tree"处的示例。它包含以下代码:

SVNNodeKind nodeKind = repository.checkPath( "" ,  -1 );
if ( nodeKind == SVNNodeKind.NONE ) {
      System.err.println( "There is no entry at '" + url + "'." );
      System.exit( 1 );
} else if ( nodeKind == SVNNodeKind.FILE ) {
      System.err.println( "The entry at '" + url + "' is a file while a directory was expected." );
      System.exit( 1 );
}

检查您的位置是否可以作为存储库根目录。

Collection entries = repository.getDir( path, -1 , null , (Collection) null );
Iterator iterator = entries.iterator( );
while ( iterator.hasNext( ) ) {
     SVNDirEntry entry = ( SVNDirEntry ) iterator.next( );
     ...

迭代当前目录的条目。

if ( entry.getKind() == SVNNodeKind.DIR ) {
    listEntries( repository, ( path.equals( "" ) ) ? entry.getName( ) : path + "/" + entry.getName( ) );
....

递归调用sub-dirs(如果你想访问)。这应该给你足够的材料来完成整个功能。