package com.nmt.hrp.pms.action.pmsreport;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
public class ChangeCVSRoot {
public static void changeCVSRoot(String path) throws IOException {
File root = new File(path);
long time = System.currentTimeMillis();
if (root.isDirectory()) {
visit(root);
} else {
System.out.println("input path is not a directory : "+path);
}
System.out.println("finish time : "+((System.currentTimeMillis() - time) / 1000)+" second");
}
private static void visit(File parent) throws IOException {
String[] list = parent.list();
String fromRoot = ":pserver:grissom_liu@59.188.107.35:/usr/sourceforge/var/cvsroot";
String toRoot = ":pserver:grissom_liu@192.168.11.105:/usr/sourceforge/var/cvsroot";
for(int i = 0; i < list.length; i++) {
File file = new File(parent, list[i]);
if (file.isDirectory()) {
visit(file);
} else if (file.getName().equals("Root") &&
parent.getName().equals("CVS")) {
FileInputStream fis = new FileInputStream(file);
InputStreamReader isr = new InputStreamReader(fis);
BufferedReader br = new BufferedReader(isr);
String content = br.readLine();
//System.out.println("content : "+content);
if (content.equals(fromRoot)) {
patchFile(file, toRoot);
}
}
}
}
private static void patchFile(File file, String content) throws FileNotFoundException {
System.out.println("patch file :"+file);
FileOutputStream fos = new FileOutputStream(file);
PrintStream ps = new PrintStream(fos);
ps.println(content);
}
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
changeCVSRoot("//192.168.0.111/d/hrp/hrp-pms");
}
}
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/129556/viewspace-530035/,如需转载,请注明出处,否则将追究法律责任。