svn对比结果的补丁打包

因为版本的升级通常都是需要进行war包的补丁文件打包,这是需要去文件对比版本,然后找出修改的文件,然后打成补丁包.文件少的时候,还可以忍受,但是当修改文件多的时候,这兼职

关于,如何打包svn项目的补丁的插件使用常识配置.

1.projectPath

     对于type=1,type=2,type=3:是复制文件来源的路径,另外对于type=2,type=3,还表示要对比的时间的文件夹.

2.diffPath

svn导出的对比文件的路径

3.targetWar

需要打包的文件夹名称

4.outPutPath

输出的war包路径

5.actiontoLower

action文件名称是否转换成小写的.

6.type

类型 ,有三种分别为1,2,3.

type=1 表示的是用svn对比结果的文件,然后将project项目的里面文件进行复制,生成补丁包.

Type=2 ,通常用将war包里面某个时间点(oldDateTime)的之后还有修改的文件,进行复制.生成补丁包.

Type=3,通常用来将项目(project)里面的某个时间点(oldDateTime)的之后还有修改的文件,进行复制.生成补丁包.只会复制src和webRoot下的文件,class文件的复制来源是src下的java文件.

 

7.oldDateTime

对比的时间点.

differPath如何生成svn的对比结果.

通过svn的版本比较

     版本号必须是老版本在前,新版本在后.

  则diffPath=C\:/Users/Administrator/Desktop/\u65B0\u5EFA\u6587\u4EF6\u5939/data.txt

projectPath 配置为项目的地址

targetWar=netinnet_wisdomExam 表示复制到的文件夹名称.

对比的时间点.

differPath路径如何产生.

通过svn的版本比较

 

     版本号必须是老版本在前,新版本在后.

  则diffPath=C\:/Users/Administrator/Desktop/\u65B0\u5EFA\u6587\u4EF6\u5939/data.txt

projectPath 配置为项目的地址

targetWar=netinnet_wisdomExam 表示复制到的文件夹名称.

一个对比结果

Index: WebRoot/webapp2/assets/js/myExam/teacherAction.js
===================================================================
--- WebRoot/webapp2/assets/js/myExam/teacherAction.js	(revision 98051)
+++ WebRoot/webapp2/assets/js/myExam/teacherAction.js	(revision 99084)
@@ -26,6 +26,12 @@
 		//console.info("ResourseTpl:" + tpl);
 		return tpl;
 	};
+	//缁熻姝g‘鐜?
+	var computGradeRate = function(num,all_num){
+		if(isNaN(num) || isNaN(all_num) || all_num=="0")
+			return 0;
+		return ((num/all_num)*100).toFixed(0);
+	}
 	/*娓叉煋鍒嗘瀽缁撴灉*/
 	var render = function(curPage) {
 		$(curPage).find(".examul").each(function(){
@@ -51,7 +57,8 @@
         		 if(json && json[question_id] && json[question_id][KEY_RIGHT]) {
         			 right = json[question_id][KEY_RIGHT];
         		 }
-            	 var rightHtml ='<li><span class="label-info">姝g‘浜烘暟</span>'+right +"/"+all_num+'</li>';
+            	 var rightHtml ='<li><span class="label-info">姝g‘鐜?/span>'+computGradeRate(right,all_num)+'%</li>\
+            		 <li><span class="label-info">姝g‘浜烘暟</span>'+right +"/"+all_num+'</li>';
             	 var content = $("#tea-"+question_id).html();
             	 ulobj.parent().find("ul[id='tea-"+question_id+"']").html(rightHtml+content);
 
Index: WebRoot/student/st_question_view.jsp
===================================================================
--- WebRoot/student/st_question_view.jsp	(revision 98051)
+++ WebRoot/student/st_question_view.jsp	(revision 99084)
@@ -48,9 +48,9 @@
 	RowSetDTO questionType = RequestUtil.getVar_notNullObj_RowSetDTO(request,"questionType"); 
 	String sys_role = SessionUtil.getVarStringValue(request,"sys_role");
 	boolean isStudent = false;
-	if("student".equals(sys_role)){
-		isStudent = true;
-	}
+	//if("student".equals(sys_role)){
+	//	isStudent = true;
+	//}
 %>
 <body data-spy="scroll" data-target="#indxList">
 <% if(dto.getCachedRowCount()<=0){%>
@@ -66,6 +66,7 @@
     	<%if(isStudent && !"".equals(dto.htmlcol(1,"task_name"))){ %>
     		<button value="缁撴灉鍒嗘瀽" class="button green r"  id="cjAnalysis">鎴愮哗鎶ュ憡 </button>
     	<%}%>
+    	<span value="缁撴灉鍒嗘瀽" class="r" style="color:#FF0000;font-size:14px"><%=dto.col(1,"score")%>鍒?/span>
     </div>
   	
   </div>
Index: WebRoot/WEB-INF/action/student/task.action
===================================================================
--- WebRoot/WEB-INF/action/student/task.action	(revision 98051)
+++ WebRoot/WEB-INF/action/student/task.action	(revision 99084)
@@ -7,6 +7,8 @@
 session.user_code==[:request.user_code]
 session.agency==yx
 request.role==[:role]
+session.sys_role==[:request.role]
+
 request.role=? ==student next=[startTask_student]
 nextAction=[startTask_2]
 
Index: WebRoot/WEB-INF/action/api/course.action
===================================================================
--- WebRoot/WEB-INF/action/api/course.action	(revision 98051)
+++ WebRoot/WEB-INF/action/api/course.action	(revision 99084)
@@ -62,3 +62,9 @@
 request.msg==鑾峰彇鎴愬姛.
 nextAction=common/common[common.pageReturn]
 
+//鑾峰彇棰樼洰 鍙傛暟knowledge_id
+[listTopicsByknowledge]=query
+request.RowCount==[:pageCount]
+request.jsonStr=${[:page],[:request.RowCount]}SELECT topic_id,topic_name FROM e_topic WHERE knowledge_id='[:knowledge_id]'
+request.msg==鑾峰彇鎴愬姛.
+nextAction=common/common[common.pageReturn]
Index: doc/网中网软件_理论题基础服务接口.doc
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Index: src/cn/netinnet/exam/action/taskResultSendAction.java
===================================================================
--- src/cn/netinnet/exam/action/taskResultSendAction.java	(revision 98051)
+++ src/cn/netinnet/exam/action/taskResultSendAction.java	(revision 99084)
@@ -19,6 +19,7 @@
 	Logger log = Logger.getLogger(taskResultSendAction.class);
 	public ActionClassResultDTO execute(HttpServletRequest request) {
 		RowSetDTO dto2json = (RowSetDTO)RequestUtil.getVar(request, "dto2json");
+		String score = RequestUtil.getVarStringValue(request, "score");
 		String json = JsonUtil.dto2JsonString(dto2json);
 		String code = "200";
 		String msg = "推送结果";
@@ -31,8 +32,8 @@
 			 msg = "出错了";
 			 json = "[]";
 		}
-		String jsonStr = "{\"data\":%s,\"code\":\"%s\",\"msg\":\"%s\"}";
-		json = String.format(jsonStr, json,code,msg);
+		String jsonStr = "{\"data\":%s,\"score\" : \"%s\" ,\"code\":\"%s\",\"msg\":\"%s\"}";
+		json = String.format(jsonStr, json,score,code,msg);
 		Map<String,String> map = new HashMap<String,String>();
 		map.put("json",json);
 		try{

 

源代码如下:

package com.zwy.differ;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Properties;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.commons.io.FileUtils;

public class Differ {
	private static String projectPath = "D:/workplace/netinnet_exam_v46";
	private static String diffPath = "C:/Users/Administrator/Desktop/新建文件夹/data.txt";
	private static String targetWar = "netinnet_exam.war";
	private static String outPutPath = "D:/workplace/svnDiff/src/temp";
	private static ArrayList<String> srclist = new ArrayList<String>();
	private static ArrayList<String> webRootlist = new ArrayList<String>();
	private static boolean actiontoLower = true;
	private static String type = "2";
	private static String oldDateTime = "";

	/*载入所需要的属性*/
	private static void loadProperty() {
		InputStream input = Differ.class.getClassLoader().getResourceAsStream("props.properties");
		Properties property = new Properties();
		try {
			property.load(input);
			System.out.println(property.getProperty("projectPath"));
			projectPath = property.getProperty("projectPath");  
			//对于type=1,type=2,type=3:是复制文件来源的路径,另外对于type=2,type=3,还表示要对比的时间的文件夹.
			diffPath = property.getProperty("diffPath");
			//svn导出的对比文件的路径
			targetWar = property.getProperty("targetWar");
			//需要打包的文件夹名称
			outPutPath = property.getProperty("outPutPath");
			//输出的war包路径
			if(!"1".equals(property.getProperty("actiontoLower"))) {
				//是否转换成小写的.
				actiontoLower = false;
			}
			type = property.getProperty("type");
			//类型
			oldDateTime = property.getProperty("oldDateTime");
			//对比的时间
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	//对比整个文件夹下的文件把大于oldDateTime的文件全部复制出来
	private static void copyByLastModify(String path) {
		File rootFile = new File(path);
		File[] files = rootFile.listFiles();
		SimpleDateFormat sdf =  new  SimpleDateFormat("yyyyMMddHHmmss");
		long date = 9999999999999L;
		try {
			Date d = sdf.parse(oldDateTime);
			date = d.getTime();
		} catch (ParseException e) {
			System.out.println("oldDateTime日期不合法,请重新输入");
			e.printStackTrace();
			return;
		}
		String rootPath = new File(projectPath).getAbsolutePath();
		for(File file1 : files) {
			if(file1.isFile()){
				//文件拷贝
				long modify = file1.lastModified();				
				if(date < modify) {
					String filePath = file1.getAbsolutePath();
					String fileName = filePath.substring(rootPath.length());
					System.out.println(fileName);
					fileName = fileName.replace("\\", "/");

					if(fileName.indexOf(".svn") == -1)
						copy(fileName);
				}
			} else {
				//文件夹递归
				copyByLastModify(file1.getAbsolutePath());
			}	
		}
	}
	
	//拷贝java文件,和普通文件.java文件需要转换为对应的.class文件.
	public static void fixedWebRootData() {
		//String basePath = outPutPath + File.separator + targetWar ; 
		for(String fileName : webRootlist) {
			
			copy(fileName);
		}
		for(String fileName : srclist) {
			//int start = fileName.lastIndexOf(".");
			//判断是否是java 如果是的话要改变后缀名
			if(fileName.lastIndexOf(".java") > -1) {
				fileName = fileName.substring(0,fileName.lastIndexOf(".java")) + ".class";
			}
			fileName = "WebRoot/WEB-INF/classes" + fileName.substring(fileName.indexOf("src") + 3 );
			copy(fileName);
		}
	} 
	//复制文件.把项目webRoot下的文件拷贝到war包中
	private static void copy(String srcPath) {
		
		if(srcPath.lastIndexOf(".action") > -1 && actiontoLower) {
			String name = srcPath.substring(srcPath.lastIndexOf("/"));
			srcPath = srcPath.substring(0,srcPath.lastIndexOf("/")) + name.toLowerCase();
		}
		
		String src = projectPath + File.separator + srcPath;
		if( srcPath.indexOf("WebRoot") > -1) {
			srcPath =  srcPath.substring(srcPath.indexOf("WebRoot") + 7 );
		}
		
		String to = outPutPath + File.separator + targetWar + File.separator  + srcPath;
		File toFile = new File(to);
		File srcFile = new File(src);
		//long date = toFile.lastModified();
		//SimpleDateFormat sdf = new  SimpleDateFormat("yyyyMMddHHmmss");
		//System.out.println(sdf.format(date));
		if(!srcFile.isFile()) {
			System.out.println(srcFile + "is not a File");
			return;
		}
		if(!toFile.exists()) {
			toFile.getParentFile().mkdirs();
		}
		try {
			System.out.println(srcFile.getAbsolutePath() +"=======>"+ toFile.getParentFile());
			FileUtils.copyFileToDirectory(srcFile, toFile.getParentFile());
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
/*从日志中正则出所需要的拷贝的文件路径*/
	public static void loadData() {
		
		try {
			String data = FileUtils.readFileToString(new File(diffPath));
//			String[] diffIndex = data.split("===================================================================\r\n");
			Pattern patter = Pattern.compile("Index: [src|WebRoot]\\S*");
			Matcher group = patter.matcher(data);
			while(group.find()) {
				String str = group.group();
				String tag = "Index: "; 
				if(str.indexOf(tag) > -1) {
					str = str.substring(tag.length());
					System.out.println(str);
					if(str.indexOf("src") > -1 ) {
						srclist.add(str);
					} else {
						webRootlist.add(str);
					}
				} else {
					System.out.println("error find " + str);
				}
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	/**/
	public static void main(String[] args) {
		loadProperty();
		if("1".equals(type)){
			loadData();
			fixedWebRootData();
		} else if("2".equals(type)){
			copyByLastModify(projectPath);
		} else if("3".equals(type)){
			javaProjectCopyByLastModify(projectPath);
			fixedWebRootData();

		}
		//zip();
	}

	

	/*主要拷贝的是project下面的src文件和webRoot路径,但是呀忽略class文件,和.svn文件class文件的来源应该是.java文件*/
	private static void javaProjectCopyByLastModify(String path) {
		File rootFile = new File(path);
		File[] files = rootFile.listFiles();
		//long date = toFile.lastModified();
		//SimpleDateFormat sdf = new  SimpleDateFormat("yyyyMMddHHmmss");
		//System.out.println(sdf.format(date));
		SimpleDateFormat sdf =  new  SimpleDateFormat("yyyyMMddHHmmss");
		long date = 9999999999999L;
		try {
			Date d = sdf.parse(oldDateTime);
			date = d.getTime();
		} catch (ParseException e) {
			System.out.println("oldDateTime日期不合法,请重新输入");
			e.printStackTrace();
			return;
		}
		String rootPath = new File(projectPath).getAbsolutePath();
		for(File file1 : files) {
			if(file1.isFile()){
				long modify = file1.lastModified();	
				String filePath = file1.getAbsolutePath();
				String fileName = filePath.substring(rootPath.length() );
				fileName = fileName.replace("\\", "/");
				if(fileName.startsWith("/")) {
					fileName = fileName.substring(1);
				}
				//System.out.println(fileName);

				if(date < modify &&
					(fileName.startsWith("src") || fileName.startsWith("WebRoot")) 
					&& fileName.indexOf( "WebRoot/WEB-INF/classes") == -1 && fileName.indexOf(".svn") == -1) {
					System.out.println(fileName);

					if(fileName.endsWith(".java")) {
						srclist.add(fileName);
					} else {
						webRootlist.add(fileName);
					}
				}
			} else {
				javaProjectCopyByLastModify(file1.getAbsolutePath());
			}	
		}
		
	}
/*zip打包*/
	/*private static void zip() {
		String sourcePath = outPutPath + File.separator + targetWar ;
		Date date = new Date();
		SimpleDateFormat sdf = new  SimpleDateFormat("yyyyMMddHHmmss");
			System.out.println(sdf.format(date));
		
		String zipPath = outPutPath + File.separator + targetWar + sdf.format(date) +".zip";
		ZipUtil.createZip(sourcePath, zipPath);
		
	}*/
}

props.properties 文件夹.

diffPath=C\:/Users/Administrator/Desktop/\u65B0\u5EFA\u6587\u4EF6\u5939/data.txt
#svn对比日志来源,老版本在前新版本在后不然会有问题
#打包的war包名称
outPutPath=D:/workplace/svnDiff/temp
#输出的目标路径
actiontoLower=1

#是否将action的名称转为小写的
#type=2
#oldDateTime=20160714114600
#这个日期之后的修改的文件需要打包
#projectPath=D\:/workplace/netinnet_wisdomExam/WebRoot
#targetWar=netinnet_wisdomExam

#要打包的项目

#type=1
#projectPath=D\:/workplace/netinnet_wisdomExam
#要打包的项目
#diffPath=C\:/Users/Administrator/Desktop/\u65B0\u5EFA\u6587\u4EF6\u5939/revision.diff
#svn对比日志来源,老版本在前新版本在后不然会有问题(90491,98834)
#targetWar=netinnet_wisdomExam
#打包的war包名称

############################################################
#在某个日志的所有文件打包.
type=2
projectPath=E\:/tomcat7055_x86/webapps/account_practice
#要打包的war包
#svn对比日志来源,老版本在前新版本在后不然会有问题(90491,98834)
targetWar=netinnet_wisdomExam
#打包的war包名称
oldDateTime=20160714114600
#时间

#是否将action的名称转为小写的
#type=3
#oldDateTime=20160701114600
#这个日期之后的修改的文件需要打包
#projectPath=D\:/workplace/netinnet_wisdomExam
#targetWar=netinnet_wisdomExam

项目download
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值