利用SVNKit进行版本库的树的导出

时间:2022-04-24 22:22:25
public List searchByTree(String userName,String passwd,String SVNServerUrl,String dirUrl){
//这里有点像 storeManager的查看功能,但是是从 应用模型的目录开始查看的。
SVNURL repositoryUrl=null;
SVNRepository repository=null;
SVNRepositoryFactoryImpl.setup();
try {
repositoryUrl=SVNURL.parseURIEncoded(SVNServerUrl);
repository=SVNRepositoryFactory.create(repositoryUrl); ISVNAuthenticationManager authenticationManager=SVNWCUtil.createDefaultAuthenticationManager(userName, passwd);
repository.setAuthenticationManager(authenticationManager);
result.clear();
FileNode rootNode=new FileNode("root", SVNServerUrl, , "", , null, null);
listTree(repository, dirUrl,rootNode);
result.add(rootNode);
} catch (Exception e) {
// TODO: handle exception
}
return result;
}
public void listTree(SVNRepository repository,String dirUrl,FileNode node){
String currentPath="";
List list=new ArrayList();
Collection root;
try {
String finalPath[]=dirUrl.split("/");
for(int i=;i<finalPath.length;i++){
currentPath+=finalPath[i]+"/";
}
System.out.println("****************: "+currentPath);
root=repository.getDir(currentPath, -, null, (Collection)null);
Iterator iterator=root.iterator();
while (iterator.hasNext()) {
SVNDirEntry entry=(SVNDirEntry)iterator.next();
if (entry.getKind()==SVNNodeKind.DIR) {
FileNode subDirNode=new FileNode(entry.getName(), entry.getURL().toString(),entry.getRevision(),entry.getAuthor(),entry.getSize(), entry.getDate(), null);
System.out.println("********"+entry.getURL());
listTree(repository, entry.getURL().toString(), subDirNode);
list.add(subDirNode);
} else {
FileNode subnode=new FileNode(entry.getName(), entry.getURL().toString(),entry.getRevision(),entry.getAuthor(),entry.getSize(), entry.getDate(), null);
list.add(subnode);
} }
} catch (SVNException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
node.setChildren(list);
}

以上这段代码,实现了将版本库中的东西组织成List的操作。最后返回的result就是要的list。

调用的时候这样子:

ModelDeveloper developer=new ModelDeveloper();
List ddList=developer.searchByTree("test", "test", "svn://localhost/", ""); //当最后一个参数为“‘时,就是从根目录检索,导出整个结构树。当最后一个参数为"svn://localhost/aa/b"时,就是从版本库的aa/b下的东西导出。
treeViewer.setInput(ddList);