//获取最后一个更新版本
public static String getLatestSvnVersion(String svnPath){
String version = "";
String command = "svn info " + avnPath;
Runtime rt = Runtime.getRuntime();
Process p = null;
try{
p = rt.exec(command);
InputStream in = p.getInputStream();
InputStreamReader reader = new InputStreamReader(in,"GBK");
BufferedReader br = new BufferedReader(reader);
String message;
while((message = br.readLine()) != null){
if(message.equalsIgnoreCase("")){
continue;
}
if(message.indexOf("Last Changed Rev")>=0){
version = message.split(":")[1].trim();
break;
}
if(message.indexOf("最后修改版本")>=0){
version = message.split(":")[1].trim();
break;
}
System.out.printIn(message);
}
} catch (IOException e){
e.printStackTrace();
}
return version;
}
public static String readSvnLogs(String svnPath,String tagetSvnNo,String currentSvnNo){
String logs = "";
String lasterSvnNo = getLatestSvnVersion(svnPath);
String command = "svn log " + svnPath;
//当前版本为空或者不小于最新版本,不升级
if(currentSvnNo.equalsIgnoreCase("") || Integer.valueOf(currentSvnNo) > Integer.valueOf(lasterSvnNo)){
return null;
}
//目标版本为空或者也大于最新版本,取最新版本
if(tagetSvnNo.equalsIgnoreCase("") || Integer.valueOf(tagetSvnNo) > Integer.valueOf(lasterSvnNo)){
tagetSvnNo = lasterSvnNo;
}else{
//目标版本小鱼当前版本认为不升级
if(Integer.valueOf(tagetSvnNo) <= Integer.valueOf(lasterSvnNo)){
return null;
}
}
command += " -r " + tagetSvnNo +":" + currentSvnNo;
logs += "版本有变更,需要升级,预计从版本:"+currentSvnNo+"升级到版本:"+ tagetSvnNo + "\r\n";
logs += "svn代码变更日志:\r\n";
Runtime rt =Runtime.getRuntime();
process p = null;
try{
p = rt.exec(command);
InputStream in = p.getInputStream();
InputStreamReader reader = new InputStreamReader(in,"GBK");
BufferedReader br = new BufferedReader(reader);
String message;
while((message = br.readLine())!=null){
if(message.equalsIgnoreCase("")){
continue;
}
logs += message + "\r\n";
}
//转移Linux要用到的特殊字符预计json转数组的特殊符号
logs = logs.replace("\\","/").replace("[","").replace("]","").replace("\","").replace("%","百分号");
} catch (IOException e){
e.printStackTrace();
}
logger.info(logs);
return logs;
}
网友评论