diff --git a/icu4j/src/com/ibm/icu/dev/tool/tzu/CLILoader.java b/icu4j/src/com/ibm/icu/dev/tool/tzu/CLILoader.java index 17a875b6b5..f999daabf5 100644 --- a/icu4j/src/com/ibm/icu/dev/tool/tzu/CLILoader.java +++ b/icu4j/src/com/ibm/icu/dev/tool/tzu/CLILoader.java @@ -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 { diff --git a/icu4j/src/com/ibm/icu/dev/tool/tzu/DirectorySearch.txt b/icu4j/src/com/ibm/icu/dev/tool/tzu/DirectorySearch.txt index 012edee7d5..6fe6344d04 100644 --- a/icu4j/src/com/ibm/icu/dev/tool/tzu/DirectorySearch.txt +++ b/icu4j/src/com/ibm/icu/dev/tool/tzu/DirectorySearch.txt @@ -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 diff --git a/icu4j/src/com/ibm/icu/dev/tool/tzu/GUILoader.java b/icu4j/src/com/ibm/icu/dev/tool/tzu/GUILoader.java index a286ff61e3..e211491528 100644 --- a/icu4j/src/com/ibm/icu/dev/tool/tzu/GUILoader.java +++ b/icu4j/src/com/ibm/icu/dev/tool/tzu/GUILoader.java @@ -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) { diff --git a/icu4j/src/com/ibm/icu/dev/tool/tzu/ICUFile.java b/icu4j/src/com/ibm/icu/dev/tool/tzu/ICUFile.java index aa46cbf0af..cc180427ea 100644 --- a/icu4j/src/com/ibm/icu/dev/tool/tzu/ICUFile.java +++ b/icu4j/src/com/ibm/icu/dev/tool/tzu/ICUFile.java @@ -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(); diff --git a/icu4j/src/com/ibm/icu/dev/tool/tzu/ICUJarFinder.java b/icu4j/src/com/ibm/icu/dev/tool/tzu/ICUJarFinder.java index 978787d3e7..3c25e748bd 100644 --- a/icu4j/src/com/ibm/icu/dev/tool/tzu/ICUJarFinder.java +++ b/icu4j/src/com/ibm/icu/dev/tool/tzu/ICUJarFinder.java @@ -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. */ diff --git a/icu4j/src/com/ibm/icu/dev/tool/tzu/ICUTZUMain.java b/icu4j/src/com/ibm/icu/dev/tool/tzu/ICUTZUMain.java index 00a38c604f..d1be4ac96f 100644 --- a/icu4j/src/com/ibm/icu/dev/tool/tzu/ICUTZUMain.java +++ b/icu4j/src/com/ibm/icu/dev/tool/tzu/ICUTZUMain.java @@ -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); diff --git a/icu4j/src/com/ibm/icu/dev/tool/tzu/PathModel.java b/icu4j/src/com/ibm/icu/dev/tool/tzu/PathModel.java index 467d616a1a..cccc756b51 100644 --- a/icu4j/src/com/ibm/icu/dev/tool/tzu/PathModel.java +++ b/icu4j/src/com/ibm/icu/dev/tool/tzu/PathModel.java @@ -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?)"); } } diff --git a/icu4j/src/com/ibm/icu/dev/tool/tzu/ResultComponent.java b/icu4j/src/com/ibm/icu/dev/tool/tzu/ResultComponent.java index 7feaae0b4a..bc5f1b105b 100644 --- a/icu4j/src/com/ibm/icu/dev/tool/tzu/ResultComponent.java +++ b/icu4j/src/com/ibm/icu/dev/tool/tzu/ResultComponent.java @@ -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); }