blob: 6a62a12a20d5cd0ad7356addca176400a571b80f [file] [log] [blame]
package org.eclipse.epf.toolbox.utils;
import java.io.File;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.eclipse.epf.common.utils.FileUtil;
public class CopyPIIFiles {
private static CopyPIIFiles instance = new CopyPIIFiles();
private static boolean localDebug = true;
private static final String[] startWithFiles = {
"splash.",
};
private static final String[] types = {
".properties",
".htm",
".html",
".js",
};
private static final String[] pathNames = {
"com.ibm.rmc",
"org.eclipse.epf",
};
private static final String[] excludeFolders = {
"bin",
"CVS",
"nl",
};
private static Set<String> typeSet;
private static Set<String> excludeFolderSet;
static {
typeSet = new HashSet<String>();
for (String type : types) {
typeSet.add(type);
}
excludeFolderSet = new HashSet<String>();
for (String folder : excludeFolders) {
excludeFolderSet.add(folder);
}
}
//Hard coded parameters
private String sourceRootFolderStr = "C:\\Documents and Settings\\wlu\\Desktop\\Dev\\aa_devTemp\\Rmc75SnapshortOn_04022009\\Rmc75SnapshortOn_04022009";
private String targetRootFolderStr = "C:\\Documents and Settings\\wlu\\Desktop\\Dev\\aa_devTemp\\Rmc75SnapshortOn_04022009\\RmcPIIFiles";
private File sourceRootFolder;
private File targetRootFolder;
public CopyPIIFiles() {
sourceRootFolder = new File(sourceRootFolderStr);
targetRootFolder = new File(targetRootFolderStr);
}
public static void main(String[] args) {
instance.execute();
}
public void execute() {
if (targetRootFolder.exists()) {
FileUtil.deleteAllFiles(targetRootFolder.getAbsolutePath());
} else {
targetRootFolder.mkdir();
}
copy(sourceRootFolder, targetRootFolder);
}
private boolean copy(File srcFolder, File tgtFolder) {
File[] files = srcFolder.listFiles();
List<File> subDirs = new ArrayList<File>();
int ccCount = 0;
for (File file : files) {
if (file.isDirectory()) {
if (toProcessFolder(file)) {
subDirs.add(file);
}
} else {
if (toCopyFile(file)) {
ccCount++;
File tgtFile = new File(tgtFolder, file.getName());
FileUtil.copyFile(file, tgtFile);
}
}
}
if (localDebug && ccCount > 0) {
System.out.println("LD> # of file copied: " + ccCount + ", " + srcFolder.getAbsolutePath().substring(
sourceRootFolderStr.length()));
}
for (File subDir : subDirs) {
File tgtSubDir = new File(tgtFolder, subDir.getName());
tgtSubDir.mkdir();
if (! copy(subDir, tgtSubDir)) {
tgtSubDir.delete();
}
}
return ccCount > 0;
}
private boolean toCopyFile(File file) {
String fileName = file.getName();
for (String str : startWithFiles) {
if (fileName.startsWith(str)) {
return true;
}
}
int ix = fileName.lastIndexOf(".");
if (ix < 0) {
return false;
}
String ext = fileName.substring(ix);
return typeSet.contains(ext);
}
private boolean toProcessFolder(File folder) {
if (excludeFolderSet.contains(folder.getName())) {
return false;
}
String filePath = folder.getAbsolutePath();
boolean containingName = false;
for (String str : pathNames) {
if (filePath.indexOf(str) >= 0) {
containingName = true;
break;
}
}
return containingName;
}
}