现在的位置: 首页 > 综合 > 正文

JAVA调用svnkit获取svn树节点

2013年08月20日 ⁄ 综合 ⁄ 共 1397字 ⁄ 字号 评论关闭

SVNKit (JavaSVN) 是一个纯 Java 的 SVN 客户端库,使用 SVNKit 无需安装任何 SVN 的客户端,支持各种操作系统。

这是一款商业软件,非商业可免费使用。

下载svnkit.

 

重要步骤:

1、连接指定的svn库

Java代码  收藏代码
  1. String url = "http://svn.svnkit.com/repos/svnkit/trunk/doc";  
  2. String name = "anonymous";  
  3. String password = "anonymous";  
  4.   
  5. SVNRepository repository = null;  
  6. try {  
  7.     repository = SVNRepositoryFactory.create( SVNURL.parseURIDecoded( url ) );  
  8.     ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager( name , password );  
  9.     repository.setAuthenticationManager( authManager );  
  10. catch ( SVNException svne ) {  
  11.     //handle exception  
  12. }  

 

 

2、获取指定路径的目录和文件列表

Java代码  收藏代码
  1. public static void listEntries( SVNRepository repository, String path ) throws SVNException {  
  2.     Collection entries = repository.getDir( path, -1 , null , (Collection) null );  
  3.     Iterator iterator = entries.iterator( );  
  4.     while ( iterator.hasNext( ) ) {  
  5.         SVNDirEntry entry = ( SVNDirEntry ) iterator.next( );  
  6.         System.out.println( "/" + (path.equals( "" ) ? "" : path + "/" ) + entry.getName( ) +   
  7.                            " ( author: '" + entry.getAuthor( ) + "'; revision: " + entry.getRevision( ) +   
  8.                            "; date: " + entry.getDate( ) + ")" );  
  9.         if ( entry.getKind() == SVNNodeKind.DIR ) {  
  10.             listEntries( repository, ( path.equals( "" ) ) ? entry.getName( ) : path + "/" + entry.getName( ) );  
  11.         }  
  12.     }  
  13. }  

抱歉!评论已关闭.