简体   繁体   中英

SVNKit - Check if Directory exists

So, I've created a project TEST under an SVN repository and I want to know if this project directory exists with SVNKit library. Protocol is http.

I tried for example...

  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);

how can I access repository/project info ?

thanks

Have a look at the example at "Printing Out a Subversion Repository Tree" . It contains the following code:

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 );
}

That checks if your location is ok as a repository root.

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

Iterate over the entries of the current dir.

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

Call it recursively for sub-dirs (if you want to visit). This should give you enough material to do the whole function.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM