zoukankan      html  css  js  c++  java
  • 利用SVNKit进行版本库的树的导出

    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, 0, "", 0, 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=3;i<finalPath.length;i++){
                    currentPath+=finalPath[i]+"/";
                }
                System.out.println("****************:     "+currentPath);
                root=repository.getDir(currentPath, -1, 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);
  • 相关阅读:
    ScheduledExecutorService 定时任务运行原理(三)
    ThreadPoolExecutor详解(二)
    Future模式详细讲解及实例分析
    @ApiParam @PathVariable @RequestParam三者区别
    协议及首次使用必读
    关于webmagic的依赖问题:ava.lang.NoClassDefFoundError: org/jsoup/helper/StringUtil
    空指针错误悼念与分析
    原创:idea启动项目的是否报错:java.lang.ClassNotFoundException: javax.servlet.ServletContext
    聚合工程中 context:component-scan 与数据源的思考,的使用说明
    关于component-scan中base-package包含通配符的问题探究
  • 原文地址:https://www.cnblogs.com/wangjiyuan/p/tree2.html
Copyright © 2011-2022 走看看