1.使用svn 生成 补丁包文件
选择要生成补丁包的项目,右键-》 选择term -> 创建补丁包,
补丁包文件名为:2015-04-18-safe-patch.txt
2.解析补丁包文件,生成更新文件。
public class FreePatchUtil {
// 2015-02-26patch.txt
public static String patchFile = "E:/tjisoftstone/beijing_update/cbe_merchant_api/2015-04-18-safe-patch.txt";// 补丁文件,由eclipse
// svn
// plugin生成
public static String projectPath = "E:/tjisoftstone/tianjin_pay_new/cbe_merchant_api";// 项目文件夹路径
public static String webContent = "WebContent";// web应用文件夹名
public static String classPath = projectPath
+ "/WebContent/WEB-INF/classes";// class存放路径
public static String desPath = "E:/tjisoftstone/beijing_update/cbe_merchant_api";// 补丁文件包存放路径
public static String version = "2015-04-18-safe-patch";// 2015-04-1-chinapay-patch
// "2015-03-27-chinapay";//补丁版本
/**
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
copyFiles(getPatchFileList());
// getPatchFileList();
}
public static List<String> getPatchFileList() throws Exception {
List<String> fileList = new ArrayList<String>();
FileInputStream f = new FileInputStream(patchFile);
BufferedReader dr = new BufferedReader(new InputStreamReader(f));
String line;
while ((line = dr.readLine()) != null) {
if (line.indexOf("Index:") != -1) {
line = line.replaceAll(" ", "");
line = line.substring(line.indexOf(":") + 1, line.length());
fileList.add(line);
}
}
return fileList;
}
public static void copyFiles(List<String> list) {
for (String fullFileName : list) {
if (fullFileName.indexOf("src/") != -1) {// 对源文件目录下的文件处理
// E:/tjisoftstone/dianpiao/dp_3_0/DraftManage-ebank/src/test/patch/FreePatchUtil.java
// String fileName=fullFileName.replace("src","");
int classStart = fullFileName.lastIndexOf("src");
String fileName = fullFileName.substring(classStart,
fullFileName.length()).replace("src", "");
fullFileName = classPath + fileName;
if (fileName.endsWith(".java")) {
fileName = fileName.replace(".java", ".class");
fullFileName = fullFileName.replace(".java", ".class");
}
String tempDesPath = fileName.substring(0, fileName
.lastIndexOf("/"));
String desFilePathStr = desPath + "/" + version
+ "/WebContent/WEB-INF/classes" + tempDesPath;
String desFileNameStr = desPath + "/" + version
+ "/WebContent/WEB-INF/classes" + fileName;
File desFilePath = new File(desFilePathStr);
if (!desFilePath.exists()) {
desFilePath.mkdirs();
}
System.out.print("fullFileName:" + fullFileName);
System.out.println("desFileNameStr:" + desFileNameStr);
copyFile(fullFileName, desFileNameStr);
System.out.println(fullFileName + "复制完成");
} else if (fullFileName.indexOf(".jsp") != -1) {// 对普通目录的处理
// jsp 页面复制
fullFileName = projectPath + "/" + fullFileName;
int start = fullFileName.lastIndexOf("WebContent");
String desFileName = fullFileName.substring(start, fullFileName
.length());
// String desFileName=fullFileName.replaceAll(webContent,"");
// fullFileName=projectPath+"/"+fullFileName;//将要复制的文件全路径
String fullDesFileNameStr = desPath + "/" + version + "/"
+ desFileName;
String desFilePathStr = fullDesFileNameStr.substring(0,
fullDesFileNameStr.lastIndexOf("/"));
File desFilePath = new File(desFilePathStr);
if (!desFilePath.exists()) {
desFilePath.mkdirs();
}
copyFile(fullFileName, fullDesFileNameStr);
System.out.println(fullDesFileNameStr + "复制完成");
} else {
System.out.println("无法解析:" + fullFileName);
int start = fullFileName.lastIndexOf("WebContent");
String desFileName = fullFileName.substring(start, fullFileName
.length());
fullFileName = projectPath + "/" + fullFileName;
System.out.println("无法解析:" + fullFileName);
String fullDesFileNameStr = desPath + "/" + version + "/"
+ desFileName;
String desFilePathStr = fullDesFileNameStr.substring(0,
fullDesFileNameStr.lastIndexOf("/"));
File desFilePath = new File(desFilePathStr);
if (!desFilePath.exists()) {
desFilePath.mkdirs();
}
copyFile(fullFileName, fullDesFileNameStr);
System.out.println("源地址:" + fullFileName + "----"
+ fullDesFileNameStr + "复制完成");
}
}
}
private static void copyFile(String sourceFileNameStr, String desFileNameStr) {
File srcFile = new File(sourceFileNameStr);
File desFile = new File(desFileNameStr);
try {
copyFile(srcFile, desFile);
} catch (IOException e) {
e.printStackTrace();
}
}
public static void copyFile(File sourceFile, File targetFile)
throws IOException {
BufferedInputStream inBuff = null;
BufferedOutputStream outBuff = null;
try {
// 新建文件输入流并对它进行缓冲
inBuff = new BufferedInputStream(new FileInputStream(sourceFile));
// 新建文件输出流并对它进行缓冲
outBuff = new BufferedOutputStream(new FileOutputStream(targetFile));
// 缓冲数组
byte[] b = new byte[1024 * 5];
int len;
while ((len = inBuff.read(b)) != -1) {
outBuff.write(b, 0, len);
}
// 刷新此缓冲的输出流
outBuff.flush();
} finally {
// 关闭流
if (inBuff != null)
inBuff.close();
if (outBuff != null)
outBuff.close();
}
}
}