SVNKit (JavaSVN) 是一个纯 Java 的 SVN 客户端库,使用 SVNKit 无需安装任何 SVN 的客户端,支持各种操作系统。
这是一款商业软件,非商业可免费使用。
重要步骤:
1、连接指定的svn库
String url = "http://svn.svnkit.com/repos/svnkit/trunk/doc";
String name = "anonymous";
String password = "anonymous";
SVNRepository repository = null;
try {
repository = SVNRepositoryFactory.create( SVNURL.parseURIDecoded( url ) );
ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager( name , password );
repository.setAuthenticationManager( authManager );
} catch ( SVNException svne ) {
//handle exception
}
2、获取指定路径的目录和文件列表
public static void listEntries( SVNRepository repository, String path ) throws SVNException {
Collection entries = repository.getDir( path, -1 , null , (Collection) null );
Iterator iterator = entries.iterator( );
while ( iterator.hasNext( ) ) {
SVNDirEntry entry = ( SVNDirEntry ) iterator.next( );
System.out.println( "/" + (path.equals( "" ) ? "" : path + "/" ) + entry.getName( ) +
" ( author: '" + entry.getAuthor( ) + "'; revision: " + entry.getRevision( ) +
"; date: " + entry.getDate( ) + ")" );
if ( entry.getKind() == SVNNodeKind.DIR ) {
listEntries( repository, ( path.equals( "" ) ) ? entry.getName( ) : path + "/" + entry.getName( ) );
}
}
}