SVN代码增量打包工具

获取SVN提交版本记录

打开SVN历史提交记录,选择需要增量的修订,右键点击“Generate ChangeLog”,粘贴处其中的全部内容
在这里插入图片描述

修改打包方法中的路径

修改工具方法中modelFile的txt文件路径及名称,内容为粘贴的修订记录;woekPath为项目编译后的代码位置;packPath为生成增量包位置;rep数组为替换的SVN修订记录标签(有需要可以增加)在这里插入图片描述`package com.casic.core.util;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashSet;

/**

  • 增量补丁打包工具

  • @author liudongyu
    */
    public class IncrementalPackingUtil {

    public static void main(String[] args) throws IOException, InterruptedException {
    //补丁日志
    String modelFile = “E:/packModel.txt”;
    //本地编译项目路径
    String workPath = “G:/develop/szyd_workspace_new/apache-tomcat-7.0.81/webapps/szyd”;
    //生成增量补丁包路径
    String packPath = “E:/20190925_SZYD_01_UPDATE”;

     //补丁日志路径替换内容
     String[] rep = {"M /szyd/","A /szyd/"}; 
     
     Thread.sleep(500);
     System.err.println("-------------------------------------开始打包------------------------------------------");
    
     InputStreamReader isr = new InputStreamReader(new FileInputStream(modelFile), "GBK");
     @SuppressWarnings("resource")
     BufferedReader bufferedInputStream = new BufferedReader(isr);
     
     HashSet<String> errorLine = new HashSet<>();
     String line=null;
     int num = 0;
     int successnum = 0;
     
     while( (line=bufferedInputStream.readLine())!=null){
    
     	line = line.trim();
     	for(int i=0;i<rep.length;i++){
         	if(line.indexOf(rep[i])!=-1){
         		line = line.replace(rep[i], "");
         	}
     	}
     	
        if(line.endsWith(".java")||line.indexOf("resources/")==0){
     	   try{
     	   String substring = line.substring(line.indexOf("/"));
     	   substring = substring.replace(".java",".class");
     	   
     	   if(new File(workPath+"/WEB-INF/classes"+substring).exists()){
         	   boolean createFile = createFile(workPath+"/WEB-INF/classes"+substring,packPath);
         	   if(createFile){
         	       ++successnum; 
         	       System.out.println(++num+"、(成功)"+line);
         	   }
     	   }else{
     	       System.out.println(++num+"、(失败)"+line);
     	       errorLine.add(line);
     		   continue;
     	   }
     	   
         	   int i = 1;
         	   while(true){
         		   String substring_NB = substring.replace(".class", "$"+i+".class");
         		   if(substring_NB!=null&&substring_NB.indexOf("$"+i+".class")==-1){
         			   break;
         		   }
             	   //判断是否存在内部类
             	   File file = new File(workPath+"/WEB-INF/classes"+substring_NB);
             	   boolean exists = file.exists();
             	   if(exists){
             		   //如果存在
             		   try{
     	            	   if(createFile(workPath+"/WEB-INF/classes"+substring_NB,packPath)){
     	            	       ++successnum; 
     	            	       System.out.println(++num+"、(成功)"+line+"--内部类("+i+")");
     	            	   }
             		   }catch(Exception e){
             			   System.err.println(++num+"、(失败)"+line+"--内部类("+i+")");
                  		   errorLine.add(line+"--内部类("+i+")");
             		   }finally{
             			   i+=1;
             		   }
             	   }else{
             		   break;
             	   }
         	   }
    
     	   }catch(Exception e){
     		  System.err.println(++num+"、(失败)"+line);
     		  errorLine.add(line);
     	   }
        }else if(!"".equals(line)){
     	       try{
         	   String substring = line.indexOf("/")!=-1?line.substring(line.indexOf("/")):line;
         	   
         	   File file = new File(workPath+substring);
         	   
         	   if(file.exists()&&file.isFile()){
             	   boolean createFile = createFile(workPath+substring,packPath);
             	   if(createFile){
             	       ++successnum;
             	       System.out.println(++num+"、(成功)"+line);
             	    }
         	    }else{
         	    	errorLine.add(line);
         	    }
         	   
     	       }catch(Exception e){
     	    	   System.err.println(++num+"、(失败)"+line);
     	    	   errorLine.add(line);
     	       }
        }
     }
     if(num!=successnum){
         System.err.println("-------------------------------------打包完成[共"+num+"个文件,成功转换"+successnum+"个文件]-------------------------------------");
     }else{
     	System.err.println("-------------------------------------打包完成[共"+num+"个文件,成功转换"+successnum+"个文件]-------------------------------------");
     }
     
     if(errorLine.size()>0){
     	System.err.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>输出未成功打包的日志行");
     	int i = 1;
     	for (String s:errorLine) {
     		System.out.println(i+++"."+s);
     	}
     }
    

    }

    public static boolean createFile(String filePath,String packPath){
    //读取源文件
    String substring = filePath.substring(filePath.indexOf(“webapps”));
    packPath+=substring;
    File file = new File(packPath.substring(0,packPath.lastIndexOf("/")));
    if(!file.exists()){
    file.mkdirs();
    }
    FileInputStream fileInputStream = null;
    FileOutputStream fileOutputStream = null;
    try {
    fileInputStream = new FileInputStream(filePath);
    fileOutputStream = new FileOutputStream(packPath);
    byte[] buf = new byte[1024];
    int bytesRead=0;
    while((bytesRead=fileInputStream.read(buf))!=-1){
    fileOutputStream.write(buf, 0, bytesRead);
    }
    }catch (Exception e) {
    e.printStackTrace();
    return false;
    }finally{
    try {
    fileInputStream.close();
    fileOutputStream.close();
    } catch (IOException e) {
    e.printStackTrace();
    return false;
    }
    }
    return true;
    }

}
`

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值