ファイル比較インクリメンタル更新システム発行インクリメンタル更新
オンラインシステムとパブリッシュの準備が必要なシステム間のファイルの違いを探し、差異ファイルのリストを生成します.変更されたファイル、新しいファイル、削除するファイルを探します.
手順を使用して、
1 eclipseはmaven工場にインポートします.
2 IncrementalUpdatetoolsを開きます.java
3クラス内の定数を変更するFILE_PATHは、自分の指定したインクリメンタルファイルに格納されているディレクトリに変更し、そのディレクトリが空であることを保証する必要があります.
4右クリックrun as javaアプリケーション
5コンソールに比較する必要がある2つのプロジェクトのプロジェクトパスを入力します.1つ目はオンラインで実行されているプロジェクトディレクトリ、2つ目はパブリッシュの準備ができているプロジェクトディレクトリを入力します.
既知の問題
1インクリメンタルファイルとフォルダの変更時間と作成時間が変更されます.(fixed)
コメント、
詳細なテストは行われていません(windowsファイルシステムで簡単なテストが行われ、linuxはテストされていません)
問題があったら、フィードバックしてください.ありがとう
ダウンロードアドレス
http://down.51cto.com/data/1096372
本文は“Chase”のブログから出て、転載して作者と連絡してください!
手順を使用して、
1 eclipseはmaven工場にインポートします.
2 IncrementalUpdatetoolsを開きます.java
3クラス内の定数を変更するFILE_PATHは、自分の指定したインクリメンタルファイルに格納されているディレクトリに変更し、そのディレクトリが空であることを保証する必要があります.
4右クリックrun as javaアプリケーション
5コンソールに比較する必要がある2つのプロジェクトのプロジェクトパスを入力します.1つ目はオンラインで実行されているプロジェクトディレクトリ、2つ目はパブリッシュの準備ができているプロジェクトディレクトリを入力します.
既知の問題
1インクリメンタルファイルとフォルダの変更時間と作成時間が変更されます.(fixed)
コメント、
詳細なテストは行われていません(windowsファイルシステムで簡単なテストが行われ、linuxはテストされていません)
問題があったら、フィードバックしてください.ありがとう
ダウンロードアドレス
http://down.51cto.com/data/1096372
package com.chase;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.regex.Pattern;
import org.apache.commons.io.FileUtils;
/**
*
* @author [email protected]
* @Version : V<1.0> <Mar 01, 2014>
*/
public class IncrementalUpdateTools {
// , ,
public static final String LASTEST_FILE_PATH = "/difference";
public static String originalPath;
public static String destinationPath;
public final static String WAR_FILE_NAME = "web";
//
public final static String[] skippedFiles = { "([.]svn)","([.]bak)","([.]svn-base)", "(Thumbs[.]db)" };
/**
*
*
* @author [email protected]
* @param name
*
* @return
*/
public static File path2File(String name) {
System.out.println(" " + name + " :");
byte[] b = new byte[1024];
int n;
File f = null;
String pathStr;
try {
while (null == f || !f.exists()) {
n = System.in.read(b);
pathStr = new String(b, 0, n - 2);
f = new File(pathStr);
if (f.exists()) {
break;
} else {
System.out.println(name + " ! :");
}
}
} catch (IOException e) {
e.printStackTrace();
}
return f;
}
public static boolean regexMatch(String regex, String name) {
Pattern p;
p = Pattern.compile(regex);
return p.matcher(name).find();
}
/**
* MD5
*
* @author [email protected]
* @param ff
*
* @param pathStr
*
* @return
*/
public static Map<String, String> allFiles(File ff, String pathStr) {
Map<String, String> map = new HashMap<String, String>();
File[] files = ff.listFiles();
String filePath, fileMD5;
StringBuffer sb = new StringBuffer();
boolean flag = false;;
FileInputStream fis;
try {
for (File f : files) {
for (String s : skippedFiles) {
if (regexMatch(s, f.getName())) {
sb.append(s + " match ----> "
+ f.getName() + "
");
flag = true;
break;
}
}
if (flag){
flag = false;
continue;
}
if (f.isFile()) {
filePath = f.getAbsolutePath();
fis = new FileInputStream(f);
fileMD5 = org.apache.commons.codec.digest.DigestUtils
.md5Hex(fis);
System.out.println(filePath);
map.put(filePath.replace(pathStr, ""), fileMD5);
} else {
map.putAll(allFiles(f, pathStr));
}
}
if(null != sb && !"".equals(sb.toString())){
System.out.println(" ,");
System.out.println(sb.toString());
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return map;
}
/**
* map, ,
*
* @author [email protected]
* @param oMap
*
* @param dMap
*
* @return
*/
public static List<List<String>> mapComparison(Map<String, String> oMap,
Map<String, String> dMap) {
Entry<String, String> dEntry;
List<String> amendedList = new ArrayList<String>(), diffList = new ArrayList<String>();
List<List<String>> list = new ArrayList<List<String>>();
int counter = 0;
Iterator<Entry<String, String>> it = dMap.entrySet().iterator();
while (it.hasNext()) {
dEntry = it.next();
if (oMap.containsKey(dEntry.getKey())) {//
if (oMap.get(dEntry.getKey()).equals(dEntry.getValue())) {//
} else {
amendedList.add(dEntry.getKey());
}
} else {//
diffList.add(dEntry.getKey());
}
counter++;
}
list.add(amendedList);
list.add(diffList);
return list;
}
/**
*
*
* @author [email protected]
* @param srcFile
*
* @param destFile
*
*/
public static boolean copyFile(File srcFile, File destFile) {
boolean f = false;
try {
// System.out.println(" " + srcFile.getAbsolutePath() + " "
// + destFile.getAbsolutePath() + " ");
if (destFile.exists()) {
throw new Exception(" ! !");
}
if (!destFile.getParentFile().exists()) {
// System.out.println(" :" + destFile.getParent());
if (!destFile.getParentFile().mkdirs()) {
throw new Exception(" !");
} else {
// System.out.println(" !");
}
}
destFile.setLastModified(srcFile.lastModified());
// FileInputStream fis = new FileInputStream(srcFile);
// FileOutputStream fos = new FileOutputStream(distFile);
// FileChannel fic = fis.getChannel();
// FileChannel foc = fos.getChannel();
// foc.transferFrom(fic, 0, fic.size());
// fic.close();
// foc.close();
// fis.close();
// fos.close();
FileUtils.copyFile(srcFile, destFile, true);
f = true;
// System.out.println(" " + srcFile.getAbsolutePath() + " "
// + destFile.getAbsolutePath() + " ");
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return f;
}
public static void main(String[] args) {
String originalPathStr, destPathStr;
Map<String, String> oMap, dMap;
List<List<String>> list;
List<String> amendList, diffList;
File ff = path2File(" ");
originalPathStr = ff.getAbsolutePath();
oMap = allFiles(ff, originalPathStr);
ff = path2File(" ");
destPathStr = ff.getAbsolutePath();
dMap = allFiles(ff, destPathStr);
System.out.println(" !");
list = mapComparison(oMap, dMap);
System.out.println(" !");
amendList = list.get(0);//
diffList = list.get(1);//
System.out.println(" !");
for (String amendFile : amendList) {
copyFile(new File(destPathStr + File.separator + amendFile),
new File(LASTEST_FILE_PATH + File.separator + amendFile));
}
for (String diffFile : diffList) {
copyFile(new File(destPathStr + File.separator + diffFile),
new File(LASTEST_FILE_PATH + File.separator + diffFile));
}
System.out.println(" !");
System.out.println(" !");
list = mapComparison(dMap, oMap);
System.out.println(" !");
amendList = list.get(0);//
System.out.println(" " + amendList.size() + " :");
for (String diffFile : amendList) {
System.out.println(originalPathStr + File.separator + diffFile);
}
diffList = list.get(1);//
System.out.println(" " + diffList.size() + " :");
for (String diffFile : diffList) {
System.out.println(originalPathStr + File.separator + diffFile);
}
System.out.println(" !");
}
}
本文は“Chase”のブログから出て、転載して作者と連絡してください!