ICU-5605 various fixes as discussed at the code review
X-SVN-Rev: 21395
This commit is contained in:
parent
072dcd0d3f
commit
a2b9088df9
@ -94,8 +94,8 @@ public class CLILoader {
|
||||
.getProperty("discoveronly"));
|
||||
boolean silentPatch = "true".equalsIgnoreCase(System
|
||||
.getProperty("silentpatch"));
|
||||
File logFile = new File(curDir.getPath() + File.separator
|
||||
+ (discoverOnly ? "icutzu_discover.log" : "icutzu_patch.log"));
|
||||
File logFile = new File(curDir.getPath(),
|
||||
(discoverOnly ? "icutzu_discover.log" : "icutzu_patch.log"));
|
||||
|
||||
// create the logger based on the silentpatch option
|
||||
try {
|
||||
|
@ -25,8 +25,8 @@
|
||||
|
||||
all
|
||||
|
||||
# If you are using a Unix-based platform, it is highly advised add the following
|
||||
# lines:
|
||||
# -/proc
|
||||
# -/dev
|
||||
# -/sys
|
||||
# If you are not using a Unix-based platform, the following lines should be removed:
|
||||
|
||||
-/proc
|
||||
-/dev
|
||||
-/sys
|
||||
|
@ -152,8 +152,7 @@ public class GUILoader {
|
||||
|
||||
// get the logger instance
|
||||
try {
|
||||
File logFile = new File(curDir.getPath() + File.separator
|
||||
+ "icutzugui.log");
|
||||
File logFile = new File(curDir.getPath(), "icutzugui.log");
|
||||
logger = Logger.getInstance(logFile, Logger.NORMAL, resultGUI
|
||||
.getStatusBar(), pathFrame);
|
||||
} catch (FileNotFoundException ex) {
|
||||
|
@ -543,17 +543,15 @@ public class ICUFile {
|
||||
|
||||
File backupFile = null;
|
||||
File backupDesc = null;
|
||||
File backupDir = new File(backupBase.getPath() + File.separator
|
||||
+ prefix);
|
||||
File backupDir = new File(backupBase.getPath(), prefix);
|
||||
PrintStream ostream = null;
|
||||
|
||||
try {
|
||||
backupBase.mkdir();
|
||||
backupDir.mkdir();
|
||||
backupFile = File.createTempFile(prefix, suffix, backupDir);
|
||||
backupDesc = new File(backupDir.getPath()
|
||||
+ File.separator
|
||||
+ backupFile.getName().substring(0,
|
||||
backupDesc = new File(backupDir.getPath(), backupFile.getName()
|
||||
.substring(0,
|
||||
backupFile.getName().length() - suffix.length())
|
||||
+ ".txt");
|
||||
backupDesc.createNewFile();
|
||||
|
@ -53,15 +53,43 @@ public class ICUJarFinder {
|
||||
List excluded = new ArrayList();
|
||||
for (int i = 0; i < paths.length; i++) {
|
||||
IncludePath path = paths[i];
|
||||
File file = path.getPath();
|
||||
try {
|
||||
file = file.getCanonicalFile();
|
||||
} catch (IOException ex) {
|
||||
// recover in the simplest way, but report the error
|
||||
file = file.getAbsoluteFile();
|
||||
logger.errorln(ex.getMessage());
|
||||
}
|
||||
if (path.isIncluded())
|
||||
included.add(path.getPath());
|
||||
included.add(file);
|
||||
else
|
||||
excluded.add(path.getPath());
|
||||
excluded.add(file);
|
||||
}
|
||||
|
||||
// if the backup dir is specified, don't search it
|
||||
if (backupDir != null)
|
||||
excluded.add(backupDir);
|
||||
if (backupDir != null) {
|
||||
File file = backupDir;
|
||||
try {
|
||||
file = file.getCanonicalFile();
|
||||
} catch (IOException ex) {
|
||||
// recover in the simplest way, but report the error
|
||||
file = file.getAbsoluteFile();
|
||||
logger.errorln(ex.getMessage());
|
||||
}
|
||||
excluded.add(file);
|
||||
}
|
||||
|
||||
// exclude the icu4j.jar that comes with this tool
|
||||
File file = new File(curDir.getPath(), "icu4j.jar");
|
||||
try {
|
||||
file = file.getCanonicalFile();
|
||||
} catch (IOException ex) {
|
||||
// recover in the simplest way, but report the error
|
||||
file = file.getAbsoluteFile();
|
||||
logger.errorln(ex.getMessage());
|
||||
}
|
||||
excluded.add(file);
|
||||
|
||||
// search each of the included files/directories
|
||||
for (int i = 0; i < included.size(); i++)
|
||||
@ -98,6 +126,14 @@ public class ICUJarFinder {
|
||||
private static ResultModel search(ResultModel resultModel, Logger logger,
|
||||
File file, List excluded, boolean subdirs, int depth,
|
||||
long lastShowtime) throws InterruptedException {
|
||||
// ensure that the file is in canonical form
|
||||
try {
|
||||
file = file.getCanonicalFile();
|
||||
} catch (IOException ex) {
|
||||
logger.errorln(ex.getMessage());
|
||||
return resultModel;
|
||||
}
|
||||
|
||||
// check for interruptions
|
||||
if (Thread.currentThread().isInterrupted())
|
||||
throw new InterruptedException();
|
||||
@ -105,11 +141,10 @@ public class ICUJarFinder {
|
||||
// make sure the current file/directory isn't excluded
|
||||
Iterator iter = excluded.iterator();
|
||||
while (iter.hasNext())
|
||||
if (file.getAbsoluteFile().equals(
|
||||
((File) iter.next()).getAbsoluteFile()))
|
||||
if (file.equals(((File) iter.next())))
|
||||
return resultModel;
|
||||
|
||||
if (file.isDirectory() && (subdirs || depth == 0)) {
|
||||
if ((subdirs || depth == 0) && file.isDirectory() && !isSymbolic(file)) {
|
||||
// recurse through each file/directory inside this directory
|
||||
File[] dirlist = file.listFiles();
|
||||
if (dirlist != null && dirlist.length > 0) {
|
||||
@ -143,6 +178,30 @@ public class ICUJarFinder {
|
||||
return resultModel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests whether a file is a symbolic link by comparing the absolute path
|
||||
* with the canonical path.
|
||||
*
|
||||
* @param file
|
||||
* The file to check.
|
||||
* @return Whether the file is a symbolic link.
|
||||
*/
|
||||
private static boolean isSymbolic(File file) {
|
||||
try {
|
||||
File parent = file.getParentFile();
|
||||
if (parent == null)
|
||||
parent = new File(".");
|
||||
File betterFile = new File(parent.getCanonicalPath(), file
|
||||
.getName());
|
||||
return !betterFile.getAbsoluteFile().equals(
|
||||
betterFile.getCanonicalFile());
|
||||
} catch (IOException ex) {
|
||||
// if getCanonicalFile throws an IOException for this file, we won't
|
||||
// want to dig into this path
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* An empty constructor that restricts construction.
|
||||
*/
|
||||
|
@ -89,16 +89,16 @@ public class ICUTZUMain {
|
||||
}
|
||||
|
||||
File curDir = new File(args[CUR_DIR]).getAbsoluteFile();
|
||||
File backupDir = new File(args[CUR_DIR] + File.separator
|
||||
+ args[BACKUP_DIR]).getAbsoluteFile();
|
||||
File pathFile = new File(args[CUR_DIR] + File.separator
|
||||
+ args[PATH_FILE]).getAbsoluteFile();
|
||||
File resultFile = new File(args[CUR_DIR] + File.separator
|
||||
+ args[RESULT_FILE]).getAbsoluteFile();
|
||||
File tzFile = new File(args[CUR_DIR] + File.separator
|
||||
+ args[TZ_FILE]).getAbsoluteFile();
|
||||
File iconFile = new File(args[CUR_DIR] + File.separator
|
||||
+ args[ICON_FILE]).getAbsoluteFile();
|
||||
File backupDir = new File(args[CUR_DIR], args[BACKUP_DIR])
|
||||
.getAbsoluteFile();
|
||||
File pathFile = new File(args[CUR_DIR], args[PATH_FILE])
|
||||
.getAbsoluteFile();
|
||||
File resultFile = new File(args[CUR_DIR], args[RESULT_FILE])
|
||||
.getAbsoluteFile();
|
||||
File tzFile = new File(args[CUR_DIR], args[TZ_FILE])
|
||||
.getAbsoluteFile();
|
||||
File iconFile = new File(args[CUR_DIR], args[ICON_FILE])
|
||||
.getAbsoluteFile();
|
||||
|
||||
if ("true".equalsIgnoreCase(System.getProperty("nogui")))
|
||||
new CLILoader(curDir, backupDir, pathFile, resultFile, tzFile);
|
||||
|
@ -180,11 +180,9 @@ class PathModel extends AbstractListModel {
|
||||
"Each path entry must start with a + or - to denote inclusion/exclusion",
|
||||
lineNumber);
|
||||
if (!add(line))
|
||||
pathListError(
|
||||
"\""
|
||||
+ line.substring(1).trim()
|
||||
+ "\" is not a valid file or directory (perhaps it does not exist?)",
|
||||
lineNumber);
|
||||
logger
|
||||
.errorln(line.substring(1).trim()
|
||||
+ " is not a valid file or directory (perhaps it does not exist?)");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -218,11 +218,12 @@ public class ResultComponent extends JComponent {
|
||||
String selection = "";
|
||||
int[] rows = resultTable.getSelectedRows();
|
||||
for (int i = 0; i < rows.length; i++)
|
||||
selection += resultModel.getValueAt(rows[i],
|
||||
ResultModel.COLUMN_FILE_PATH)
|
||||
+ File.separator
|
||||
+ resultModel.getValueAt(rows[i],
|
||||
ResultModel.COLUMN_FILE_NAME) + "\n";
|
||||
selection += new File(resultModel.getValueAt(rows[i],
|
||||
ResultModel.COLUMN_FILE_PATH).toString(),
|
||||
resultModel.getValueAt(rows[i],
|
||||
ResultModel.COLUMN_FILE_NAME).toString())
|
||||
.toString()
|
||||
+ "\n";
|
||||
getToolkit().getSystemClipboard().setContents(
|
||||
new StringSelection(selection), null);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user