获取SVN版本区间内所有修改过的文件并COPY到指定的目录 import java.io.BufferedReader;import java.io.File;import java.io.FileReader;import java.io.IOException;import java.util.ArrayList;import java.util.List;import org.apa
import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; import java.util.ArrayList; import java.util.List; import org.apache.commons.io.FileUtils; /** * 找出时间段内修改的文件并保存到指定的目录。 * @author 连山 * */ public class SVNUtils { public static void main(String[] args) throws IOException, InterruptedException { String svnurl = "https://192.168.0.207:8443/svn/farben/trunk/farben-scm"; String startDate = "4598";//"{2017-09-08}"; String endDate = "4604";//"{2017-09-08}"; String sourcePath = "E:\\svnobject\\farben\\trunk\\farben-scm"; String savePath = "E:\\svnobject\\versions\\scm\\2017-09-18"; Runtime runtime=Runtime.getRuntime(); String fileSeparator = System.getProperty("file.separator"); String filePath = "J:\\changedfiles" + System.currentTimeMillis() + ".txt"; //从svn找出时间段内修改过的文件,并保存到filePath中。 System.out.println("获取svn修改记录"); Process process = runtime.exec("cmd /c svn diff -r " + startDate + ":" + endDate + " --summarize " + svnurl + " > " + filePath); process.waitFor();//等待命令执行完毕 boolean con = process.exitValue() >= 0; process.destroy(); process = null; ListfileList = new ArrayList (); //如果命令执行成功 if(con){ //按行读取生成的文件 BufferedReader bf = null; try { bf = new BufferedReader(new FileReader(filePath)); String str = null; while ((str = bf.readLine()) != null) { fileList.add(str.substring(str.indexOf(svnurl) + svnurl.length(), str.length())); } } catch (Exception e) { e.printStackTrace(); } finally { if (bf != null) bf.close(); } } System.out.println("开始COPY文件"); //把文件COPY到指定的目录。 for(int i = 0; i < fileList.size(); i++ ){ if(!fileList.get(i).endsWith(".java")){ //前端文件 File srcFile = new File(sourcePath + fileList.get(i)); File destFile = new File(savePath + fileSeparator + fileList.get(i).replace("/src/main/", fileSeparator)); //过滤掉目录 if(!srcFile.isDirectory()){ FileUtils.copyFile(srcFile, destFile); } System.out.println(fileList.get(i) + " >>> " + destFile.getAbsolutePath()); }else{ //java文件 //注意匿名类以及内部类不会处理,需要自己手动COPY //找到对应的class,或者自己编译为class文件 String path = fileList.get(i).replace(".java", ".class"); String javapath = sourcePath + path; javapath = javapath.replace("/src/main/java/", fileSeparator + "target" + fileSeparator + "classes" + fileSeparator); File srcFile = new File(javapath); File destFile = new File(savePath + path.replace("/src/main/", fileSeparator)); if(!srcFile.isDirectory()){ FileUtils.copyFile(srcFile, destFile); } System.out.println(fileList.get(i) + " >>> " + destFile.getAbsolutePath()); } } System.out.println("执行结束"); } }