自动生成项目更新补丁

package com.matt.utils.patch;

import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * 根据SVN日志提交记录自动生成增量补丁文件
 * @author matt0614@qq.com
 * 根据idea gitLab 生成的.path文件生成补丁
 *
 */
public class CreatePatchFileFromPatchFile {

	private static final String patchFile ="D:\\workspace\\newpath.patch"; //补丁位置

    private static final String projectPath="D:\\workspace\\idea\\ztsc\\zzxt\\";//项目文件 开发路径

    private static final String classPath="D:\\workspace\\idea\\ztsc\\zzxt\\out\\artifacts\\zzxt_Web_exploded\\WEB-INF\\classes\\";//class文件路径

    private static final String savePath="F:\\工作目录\\09.种子管理系统\\patchs\\zzxt20170417\\";//补丁文件包存放文件夹

	private static final String WebContent = "WebContent";//WebRoot 名称

	
	/**
	 * 得到文件列表新方法
	 * @return
	 * @throws IOException 
	 */
	public static List<String> getFileList() throws IOException{
		File file = new File(patchFile);
		List<String> lines = FileUtils.readLines(file, "GBK"); 
		List<String> fileList = new ArrayList<String>();
		for(String filePath:lines){
			if(filePath.startsWith("Index:")){
				int s = filePath.indexOf(":");
				String fileSrc = filePath.substring(s+1).trim();
				if(!fileList.contains(fileSrc)){
					fileSrc = fileSrc.replace("/", "\\");
					if (fileSrc.lastIndexOf(".java") != -1) {
						String classFile = fileSrc.replace(".java", ".class");
						classFile = classFile.replace("src\\", "");
						classFile = classPath + classFile;
						fileList.add(classFile);
						System.out.println("更新列表:" + classFile);
					} else {
						fileSrc = projectPath + fileSrc;
						fileList.add(fileSrc);
						System.out.println("更新列表:" + fileSrc);
					}
				}
			}
		}
		return fileList;
	}

	private static void copyFilesList(List<String> list) {
		String toFilePath = "";
		for (String sourFile:list) {
			if (sourFile.lastIndexOf(".java") != -1) {
				//todo 如果需要复制java源文件,在这写相应代码
			} else if (sourFile.lastIndexOf(".class") != -1) {
				toFilePath = savePath + WebContent + sourFile.replace(classPath, "\\WEB-INF\\classe\\");
			} else {
				toFilePath = sourFile.replace(projectPath, "");
				toFilePath  = savePath + toFilePath;
			}
			File file = new File(toFilePath);
			String fileName = file.getName();
			toFilePath = toFilePath.replace(fileName, "");
			copy(sourFile, toFilePath);
		}
	}

	private static void copy(String sourFile, String toDir) {
		try {
			File file = new File(sourFile);
			FileUtils.copyFileToDirectory(file, new File(toDir));
			System.out.println("复制文件:" + file.getName()+" 到 "+toDir);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	public static void main(String[] args) throws IOException {
		List<String> list = getFileList();
		copyFilesList(list);
	}
}

 

转载于:https://my.oschina.net/matt0614/blog/880913

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值