package com.svnutil;
import java.io.File;
import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.tmatesoft.svn.core.SVNDepth;
import org.tmatesoft.svn.core.SVNDirEntry;
import org.tmatesoft.svn.core.SVNURL;
import org.tmatesoft.svn.core.auth.ISVNAuthenticationManager;
import org.tmatesoft.svn.core.internal.io.svn.ISVNConnector;
import org.tmatesoft.svn.core.internal.io.svn.SVNRepositoryFactoryImpl;
import org.tmatesoft.svn.core.internal.wc.DefaultSVNOptions;
import org.tmatesoft.svn.core.io.SVNRepository;
import org.tmatesoft.svn.core.io.SVNRepositoryFactory;
import org.tmatesoft.svn.core.wc.ISVNConflictHandler;
import org.tmatesoft.svn.core.wc.ISVNOptions;
import org.tmatesoft.svn.core.wc.SVNClientManager;
import org.tmatesoft.svn.core.wc.SVNRevision;
import org.tmatesoft.svn.core.wc.SVNUpdateClient;
import org.tmatesoft.svn.core.wc.SVNWCUtil;
@SuppressWarnings("all")
public class ReadDirFromSVN {
//从svn中拿到一个目录的子目录
public static List<String> getFileDir(String username,String password,String SVNRoot){
List<String> lists=new ArrayList<String>();
try{
SVNRepository repository=SVNRepositoryFactory.create(SVNURL.parseURIEncoded(SVNRoot));//找到svn的url
ISVNAuthenticationManager authManager=SVNWCUtil.createDefaultAuthenticationManager(username,password);//用户验证
repository.setAuthenticationManager(authManager);
Collection entries=repository.getDir("", -1, null, (Collection)null);
Iterator iterators=entries.iterator();
while(iterators.hasNext()){
SVNDirEntry entry=(SVNDirEntry)iterators.next();
lists.add(entry.getName());
}
}catch(Exception e){
e.printStackTrace();
}
return lists;
}
//从项目中checkout代码
public static void checkout(String sourceRoot,String targetRoot,String username,String password){
// SVNRepositoryFactoryImpl.setup();
// ISVNOptions options=SVNWCUtil.createDefaultOptions(true);
//SVNClientManager client=SVNClientManager.newInstance((DefaultSVNOptions)options,username,password);//拿到客户端并进行验证
SVNClientManager client=SVNClientManager.newInstance();//拿到客户端
ISVNAuthenticationManager authManager=SVNWCUtil.createDefaultAuthenticationManager(username,password);//用户验证参数
client.setAuthenticationManager(authManager);//进行用户验证
try{
SVNUpdateClient updateClient = client.getUpdateClient();
client.setIgnoreExternals(false);
System.out.println("checkout...");
updateClient.doCheckout(SVNURL.parseURIEncoded(sourceRoot), new File(targetRoot),
SVNRevision.HEAD, SVNRevision.HEAD, true);
System.out.println("checkout complement!");
}catch(Exception e){
e.printStackTrace();
}
}
//测试
public static void main(String[] args) {
// List<String> lists=ReadDirFromSVN.getFileDir("admin", "admin", "https://192.168.1.188/svn/svndemo/javacore/");
// for (String string : lists) {
// System.out.println(string);
// }
ReadDirFromSVN.checkout("https://192.168.1.188/svn/svndemo/javacore/", "E:\\checkout", "admin", "admin");
}
}
还没有评论,来说两句吧...