zoukankan      html  css  js  c++  java
  • java批量从svn导出多个项目

      近期工作中要对很多项目加相同的依赖,需要将很多项目都从svn导出,感觉一个个导太慢了,由于不会写脚本就从晚上找到svn拉代码的程序,稍作修改很快就拉完了所有代码。直接上必要代码

    必要pom

        <dependency>
          <groupId>org.tmatesoft.svnkit</groupId>
          <artifactId>svnkit</artifactId>
          <version>1.10.1</version>
        </dependency>
    
        <dependency>
          <groupId>org.projectlombok</groupId>
          <artifactId>lombok</artifactId>
          <version>1.18.8</version>
        </dependency>
    

      必要代码

    @Slf4j
    public class SvnService {
        private SVNClientManager clientManager;
    
        public void checkOut(final SvnConfig config) {
            final String user = config.getSourceSvnUser();
            final String password = config.getSourceSvnPassword();
            final String sourceSvn = config.getSourceSvn() + config.getSourceProject();
            try {
                //初始化支持svn://协议的库。 必须先执行此操作。
                SVNRepositoryFactoryImpl.setup();
    
                //相关变量赋值
                SVNURL repositoryURL = SVNURL.parseURIEncoded(sourceSvn);
                ISVNOptions options = SVNWCUtil.createDefaultOptions(true);
                //实例化客户端管理类
                this.clientManager = SVNClientManager.newInstance(
                        (DefaultSVNOptions) options, user, password);
                //要把版本库的内容check out到的目录
                File wcDir = new File(config.getSourceCheckOutDir());
                //通过客户端管理类获得updateClient类的实例。
                SVNUpdateClient updateClient = this.clientManager.getUpdateClient();
                // sets externals not to be ignored during the checkout
                updateClient.setIgnoreExternals(false);
                //执行check out操作,返回工作副本的版本号。
                long workingVersion = updateClient.doCheckout(
                        repositoryURL, wcDir,
                        SVNRevision.HEAD, SVNRevision.HEAD, SVNDepth.INFINITY,
                        false);
    
                log.info("VERSION:{} check out to {}", workingVersion, wcDir);
            } catch (Exception e) {
                log.error("SvnService.doCheckOut error: ", e);
            }
        }
    
        public void update(final SvnConfig config) {
            final String user = config.getSourceSvnUser();
            final String password = config.getSourceSvnPassword();
            final String sourceSvn = config.getSourceSvn() + config.getSourceProject();
            try {
                //初始化支持svn://协议的库。 必须先执行此操作。
                SVNRepositoryFactoryImpl.setup();
                //相关变量赋值
                SVNURL.parseURIEncoded(sourceSvn);
                ISVNOptions options = SVNWCUtil.createDefaultOptions(true);
                //实例化客户端管理类
                this.clientManager = SVNClientManager.newInstance(
                        (DefaultSVNOptions) options, user, password);
    
                //要更新的文件
                File updateFile = new File(config.getSourceCheckOutDir());
                //获得updateClient的实例
                SVNUpdateClient updateClient = this.clientManager.getUpdateClient();
                updateClient.setIgnoreExternals(false);
                //执行更新操作
                long versionNum = updateClient.doUpdate(updateFile, SVNRevision.HEAD, SVNDepth.INFINITY, false, false);
                log.info("updated version is {}", versionNum);
            } catch (Exception e) {
                log.info(e.getMessage() + "{}", e);
            }
        }
    
        public void commit(final SvnConfig config) {
            final String user = config.getSourceSvnUser();
            final String password = config.getSourceSvnPassword();
            final String sourceSvn = config.getSourceSvn() + config.getSourceProject();
            try {
                //初始化支持svn://协议的库。 必须先执行此操作。
                SVNRepositoryFactoryImpl.setup();
                //相关变量赋值
                SVNURL.parseURIEncoded(sourceSvn);
                ISVNOptions options = SVNWCUtil.createDefaultOptions(true);
                //实例化客户端管理类
                this.clientManager = SVNClientManager.newInstance(
                        (DefaultSVNOptions) options, user, password);
                //要提交的文件
                File commitFile = new File(config.getSourceCheckOutDir());
    
                //获取此文件的状态(是文件做了修改还是新添加的文件?)
    
                SVNStatus status = this.clientManager.getStatusClient().doStatus(commitFile, true);
    
                //如果此文件是新增加的则先把此文件添加到版本库,然后提交。
                if (status.getContentsStatus() == SVNStatusType.STATUS_UNVERSIONED) {
    
                    //把此文件增加到版本库中
                    this.clientManager.getWCClient().doAdd(commitFile, false, false, false, SVNDepth.INFINITY, false, false);
                    //提交此文件
                    this.clientManager.getCommitClient().doCommit(
                            new File[]{commitFile}, true, "", null, null, true, false, SVNDepth.INFINITY);
                    System.out.println("add");
                }
    
                //如果此文件不是新增加的,直接提交。
                else {
                    this.clientManager.getCommitClient().doCommit(
                            new File[]{commitFile}, true, "", null, null, true, false, SVNDepth.INFINITY);
                    System.out.println("commit");
    
                }
    
                System.out.println(status.getContentsStatus());
            } catch (Exception e) {
                log.error(e.getMessage() + "{}", e);
            }
        }
    }
    

      其余代码

    参考:https://blog.csdn.net/qq_38292691/article/details/97521810

  • 相关阅读:
    PyQt(Python+Qt)学习随笔:containers容器类部件QStackedWidget重要方法介绍
    什么叫工业4.0,这篇接地气的文章终于讲懂了
    怎样 真正认识一个 人
    华为的绩效管理:减人、增 效、加薪
    羽毛球战术
    魔方教程
    员工培养:事前指导,事后纠正
    一把手瞄准哪里,核心竞争力就在哪里
    海尔的五次战略变革
    如何提高基层员工的执行力
  • 原文地址:https://www.cnblogs.com/javashare/p/12383435.html
Copyright © 2011-2022 走看看