svn如何提取文件更新列表
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; public class SvnExportModfileList { public static void main(String[] args) { callShell(); } /** * * 执行命令行命令,返回该命令的返回值 * * @param command * 命令行命令 * * */ private static void callShell() { String workDir = "i:/workspace70/gzdx_lcbmi80/"; System.out.println("workDir: " + workDir); ProcessBuilder pb = null; InputStream is = null; InputStreamReader isr = null; BufferedReader br = null; 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); String line; File file = null; List<String> listFile = new ArrayList<String>(3); while ((line = br.readLine()) != null) { String[] str = line.split("\\s+");// STAUTS PATH file = new File(workDir + str[1]); // 过滤目录和不需要的文件 if (file.isDirectory() || file.getName().endsWith(".class") || file.getName().startsWith(".") || str[1].startsWith("classes")) { continue; } System.out.println(line); listFile.add(line.replace("\\", "/") .replace("src/", "classes/") .replace(".java", ".class")); } System.out.println("=========符合条件的文件数:" + listFile.size()); createBackupShell(listFile, workDir); System.out.println("\n\n"); createUpdateShell(listFile, workDir); } catch (Exception e) { e.printStackTrace(); } 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(); } } } public static void createBackupShell(List<String> list, String workDir) { int size = list.size(); String line = ""; int num = 0; for (int i = 0; i < size; i++) { line = list.get(i); String[] str = line.split("\\s+");// STAUTS PATH String print = "cp $workDir/" + str[1] + "\t $workDir/" + str[1] + "$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 = ""; int num = 0; for (int i = 0; i < size; i++) { line = list.get(i); String[] str = line.split("\\s+");// STAUTS PATH int index = str[1].lastIndexOf("/"); String print = ""; if (index >= 0) { print = "cp $sourceFileDir" + str[1].substring(index) + "\t $workDir/" + str[1]; } 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
。。。。。。