JAVA调用svnkit获取svn树节点

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. }  

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值