SVN环境下快速导出增量包(未提交的情况下)

来源:互联网 发布:软件层次结构图 编辑:程序博客网 时间:2024/06/11 18:57

在很多情况下,由于服务器不在开发人员这边,需要开发人员快速将更新的文件打包以增量包的形式发给运维人员或客户那边,但是在更改文件很多的情况下,如何快速将更改的文件打包成增量包?下面我根据自己的解决方法记录一下,希望对大家有所帮助。

1.在SVN未提交代码的情况下,选择项目—>team–>与资源同步(或直接创建补丁)
这里写图片描述

直接点Finish(完成)
点击完成后,根据选择生成的打包文件存放位置查看是否已生成增量包记录(补丁)文件
这里写图片描述
文件生成后,整理代码:

2.根据生产的增量包记录((补丁))文件,读取信息,生成相对应的更新文件,相关代码如下

package com.legendshop.business.controller;import java.io.BufferedInputStream;import java.io.BufferedOutputStream;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.ArrayList;import java.util.HashMap;import java.util.List;import java.util.Map;import java.util.Set;public class FreePatchUtil {     public static String patchFile="F:/patch.txt";//生成的补丁文件,由eclipse svn plugin生成          public static String projectPath="D:/yunjike_workSpace";//项目所在文件夹路径(生成与项目匹配的目录)         public static String webContent="WebContent";//web应用文件夹名          public static String desPath="F:/zengliangbao";//补丁文件包存放路径  (SVN创建补丁的时候选择的位置)        //public static String version="20140711";//补丁版本          /**          * @param args          * @throws Exception           */          public static void main(String[] args) throws Exception {               Map<String,List<String>> map = getPatchFileListMap();             Set<String> keySet = map.keySet();             for (String key : keySet) {                 List<String> fileList = map.get(key);                 copyFiles(fileList,key);              }        }          public static Map<String,List<String>> getPatchFileListMap() throws Exception{              //List<String> fileList=new ArrayList<String>();              FileInputStream f = new FileInputStream(patchFile);               BufferedReader dr=new BufferedReader(new InputStreamReader(f,"utf-8"));              String line;              Map<String,List<String>> map = new HashMap<String,List<String>>();            String webName = "";            while((line=dr.readLine())!=null){                if(line.indexOf("#P")!=-1){                    line=line.replaceAll(" ","");                      line=line.substring(line.indexOf("#P")+2,line.length());                      webName = line;                }                if(line.indexOf("Index:")!=-1){                      line=line.replaceAll(" ","");                      line=line.substring(line.indexOf(":")+1,line.length());                      List<String> fileList = map.get(webName);                    if(fileList==null){                        fileList = new ArrayList<String>();                    }                    fileList.add(line);                      map.put(webName, fileList);                }              }               return map;          }          public static void copyFiles(List<String> list, String webName){              for(String fileName:list){                  String fullFileName=projectPath+"/"+webName+"/"+fileName;//将要复制的文件全路径                  String fullDesFileNameStr=desPath+"/"+webName+"/"+fileName;                String desFilePathStr=fullDesFileNameStr.substring(0,fullDesFileNameStr.lastIndexOf("/"));                  File desFilePath=new File(desFilePathStr);                  if(!desFilePath.exists()){                      desFilePath.mkdirs();                  }                  copyFile(fullFileName, fullDesFileNameStr);                  System.out.println(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();              }          }  }

设置好补丁文件的位置,以及要生成更新文件的位置等配置,运行该类main方法:
这里写图片描述

已跟据补丁文件生成相关已更改的目录和文件,根据输出的目录,去该目录查看
这里写图片描述
直接将该文件压缩发给运维或客户即可

0 0
原创粉丝点击