eclipse svn插件site-1.10.1
Slik-Subversion-1.8.0-x64.msi ---可以使用svn命令,如svn status 显示修改过的本地文件,如下示例:
I:\workspace70\ahdx_lcbmi70_chaxun>svn status
? .settings
? classes\SocketClient.class
? classes\SocketClientShortlink.class
? classes\com
M config\businessconfig.xml
M readme.txt
M src\com\xxx\lcbmi\sockets\SocketMultiServer.java
M src\com\xxx\lcbmi\sockets\SocketServer.java
M src\com\xxx\lcbmk\business\Customer.java
? src\com\xxx\lcbmk\business\Peap.java
M src\com\xxx\lcbmk\business\Rule.java
M src\com\xxx\lcbmk\common\ServiceList.java
M src\com\xxx\lcbmk\core\SpecialValueProc.java
? upline
可以使用java代码获取此列表,制作成shell脚本,用来进行代码的批量更新。
package svnkitDemo;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.lang.StringUtils;
public class SvnExportModfileList {
public static void main(String[] args) {
callShell();
}
/**
*
* 执行命令行命令,返回该命令的返回值
*
* @author zhaigx
*/
private static void callShell() {
String workDir = "i:/workspace70/gzdx_wslcims80/";
boolean isWebProject = true;
// web应用: 去除workDir的class目录
String classPathRmWorkDir = "WebRoot/lcbms/WEB-INF/classes";
System.out.println("workDir: " + workDir);
ProcessBuilder pb = null;
InputStream is = null;
InputStreamReader isr = null;
BufferedReader br = null;
String line = "";
try {
// 创建一个进程示例
List<String> list = new ArrayList<String>();
list.add("cmd.exe");
list.add("/C");
list.add("svn status");
pb = new ProcessBuilder(list);
// 设置工作目录
pb.directory(new File(workDir));
pb.redirectErrorStream(true);
Process p = pb.start();
// // 将执行结果打印显示
is = p.getInputStream();
isr = new InputStreamReader(is, "GBK");
br = new BufferedReader(isr);
File file = null;
List<String> listFile = new ArrayList<String>(3);
while ((line = br.readLine()) != null) {
System.out.println(line);
String[] str = line.split("\\s+");// STAUTS PATH
file = new File(workDir + str[1]);
// 过滤不需要的文件
if ((str[0].equals("?") && file.isFile())
|| file.getName().endsWith(".class")
|| file.getName().startsWith(".")
|| str[1].startsWith("classes")) {
if (file.getName().endsWith(".class")
&& file.getName().indexOf("$") >= 0) {
// 内部类
} else {
continue;
}
}
listFile.add(strReplace(line, isWebProject, classPathRmWorkDir));
}
int size = listFile.size();
// for (int i = 0; i < size; i++) {
// System.out.println("++" + listFile.get(i));
// }
System.out.println("=========符合条件的文件数:" + size);
createBackupShell(listFile, workDir);
System.out.println("\n\n");
createUpdateShell(listFile, workDir);
} catch (Exception e) {
e.printStackTrace();
System.out.println("ERROR LINE: " + line);
} finally {
try {
if (br != null) {
br.close();
}
} catch (IOException e) {
e.printStackTrace();
}
try {
if (isr != null) {
isr.close();
}
} catch (IOException e) {
e.printStackTrace();
}
try {
if (is != null) {
is.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
private static String strReplace(String line, boolean isWebProject,
String classPath) {
line = line.replace("\\", "/");
if (!isWebProject) {
line = line.replace("src/", "classes/");
} else {
line = line.replace("src/", classPath + "/");
}
line = line.replace(".java", ".class");
return line;
}
public static void createBackupShell(List<String> list, String workDir) {
int size = list.size();
String line = "";
String print = "";
String data = "";
int num = 0;
for (int i = 0; i < size; i++) {
line = list.get(i);
if (StringUtils.isEmpty(line)) {
continue;
}
String[] str = line.split("\\s+");// STAUTS PATH
if (str.length < 2) {
data = str[0];
} else {
data = str[1];
}
print = "cp $workDir/" + data + "\t $workDir/" + data + "$time";
System.out.println(print);
num++;
}
System.out.println("-------" + num);
}
public static void createUpdateShell(List<String> list, String workDir) {
int size = list.size();
String line = "";
String print = "";
String data = "";
int num = 0;
for (int i = 0; i < size; i++) {
line = list.get(i);
String[] str = line.split("\\s+");// STAUTS PATH
if (str.length < 2) {
data = str[0];
} else {
data = str[1];
}
int index = data.lastIndexOf("/");
if (index >= 0) {
print = "cp $sourceFileDir" + data.substring(index)
+ "\t $workDir/" + data;
} else {
continue;
}
System.out.println(print);
num++;
}
System.out.println("-------" + num);
}
}
shell脚本:
backupFile.sh
sourceFileDir=/codedir
workDir=/gzdx_lcbmi80
time=20130717
cp $workDir/RUN/start.sh $workDir/RUN/start.sh$time
cp $workDir/config/businessobject.xml $workDir/config/businessobject.xml$time
cp $workDir/config/datacheck.xsd $workDir/config/datacheck.xsd$time
。。。。。。
updateFile.sh
sourceFileDir=/codedir
workDir=/gzdx_lcbmi80
time=20130717
cp $sourceFileDir/start.sh $workDir/RUN/start.sh
cp $sourceFileDir/businessobject.xml $workDir/config/businessobject.xml
cp $sourceFileDir/datacheck.xsd $workDir/config/datacheck.xsd
。。。。。。
ftp脚本 ftpFile.sh:
#在目标主机反ftp到中转机取代码
LOCAL_DIR=/data/lcb0/codedir
REM_DIR=/lcims/zhax
if [ ! -d "$LOCAL_DIR" ];then
mkdir $LOCAL_DIR
fi
HOST_IP='10.1.1.24'
USRNM='lci0'
PWD='&s'
sftp $HOST_IP >> ${LOCAL_DIR}/ftp.log <<!
lcd $LOCAL_DIR
cd $REM_DIR
get *
bye
!
sftp脚本:
#在目标主机反ftp到中转机取代码
LOCAL_DIR=/data/lcb0/codedir
REM_DIR=/lcims/zigx
if [ ! -d "$LOCAL_DIR" ];then
mkdir $LOCAL_DIR
fi
HOST_IP='10.1.1.24'
USRNM='lci0'
PWD='ms'
sftp $HOST_IP >> ${LOCAL_DIR}/ftp.log <<!
lcd $LOCAL_DIR
cd $REM_DIR
get *
bye
!