mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-10 07:39:16 +00:00
ICU-5605 various fixes as discussed at the code review
X-SVN-Rev: 21389
This commit is contained in:
parent
f7ee9393c3
commit
41429b049c
10 changed files with 106 additions and 20 deletions
1
.gitattributes
vendored
1
.gitattributes
vendored
|
@ -168,6 +168,7 @@ icu4j/src/com/ibm/icu/dev/tool/docs/icu4j342.api.gz -text
|
|||
icu4j/src/com/ibm/icu/dev/tool/docs/icu4j343.api.gz -text
|
||||
icu4j/src/com/ibm/icu/dev/tool/timezone/ICUZDump.java -text
|
||||
icu4j/src/com/ibm/icu/dev/tool/tzu/CLILoader.java -text
|
||||
icu4j/src/com/ibm/icu/dev/tool/tzu/DirectorySearch.txt -text
|
||||
icu4j/src/com/ibm/icu/dev/tool/tzu/GUILoader.java -text
|
||||
icu4j/src/com/ibm/icu/dev/tool/tzu/ICUFile.java -text
|
||||
icu4j/src/com/ibm/icu/dev/tool/tzu/ICUJarFinder.java -text
|
||||
|
|
|
@ -2100,11 +2100,11 @@
|
|||
<include name="*.bat" />
|
||||
<include name="*.sh" />
|
||||
<include name="*.gif" />
|
||||
<include name="*.txt" />
|
||||
</fileset>
|
||||
<fileset file="${basedir}/${jar.file}" />
|
||||
<fileset file="${build.dir}/${icu4j.data.path}/zoneinfo.res" />
|
||||
</copy>
|
||||
<echo file="${tzu.bin.dir}/DirectorySearch.txt">all</echo>
|
||||
</target>
|
||||
|
||||
<target name="icutzujar" depends="init, icutzu, icutzudata" description="build ICU4J TimeZone Update Utility Classes">
|
||||
|
|
32
icu4j/src/com/ibm/icu/dev/tool/tzu/DirectorySearch.txt
Normal file
32
icu4j/src/com/ibm/icu/dev/tool/tzu/DirectorySearch.txt
Normal file
|
@ -0,0 +1,32 @@
|
|||
# *******************************************************************************
|
||||
# * Copyright (C) 2007, International Business Machines Corporation and *
|
||||
# * others. All Rights Reserved. *
|
||||
# *******************************************************************************
|
||||
#
|
||||
# This file contains the list of directories in the file system that ICUTZU will
|
||||
# use to search for updatable icu4j jar files.
|
||||
#
|
||||
# To include all roots of the file system (ie. 'c:\', 'd:\', 'e:\', etc. in Windows
|
||||
# or '/' in Unix-based systems), insert the following:
|
||||
# all
|
||||
#
|
||||
# To include a directory in the search or to directly include a specific icu4j file,
|
||||
# insert the directory in the native format with a leading '+'. For example in Windows:
|
||||
# +C:\ICU4J
|
||||
# +C:\ICU4J\icu4j.jar
|
||||
# Or in Unix-based systems:
|
||||
# +/usr/icu4j
|
||||
# +/usr/icu4j/icu4j.jar
|
||||
#
|
||||
# To exclude a directory or file from the search, do the same as above but with a
|
||||
# leading '-' instead:
|
||||
# -C:\ICU4J
|
||||
# -/usr/icu4j
|
||||
|
||||
all
|
||||
|
||||
# If you are using a Unix-based platform, it is highly advised add the following
|
||||
# lines:
|
||||
# -/proc
|
||||
# -/dev
|
||||
# -/sys
|
|
@ -19,7 +19,9 @@ import java.net.MalformedURLException;
|
|||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.MissingResourceException;
|
||||
import java.util.jar.Attributes;
|
||||
import java.util.jar.JarEntry;
|
||||
|
@ -81,6 +83,12 @@ public class ICUFile {
|
|||
*/
|
||||
private static final int BUFFER_SIZE = 1024;
|
||||
|
||||
/**
|
||||
* A map that caches links from URLs to time zone data to their downloaded
|
||||
* File counterparts.
|
||||
*/
|
||||
private static final Map cacheMap = new HashMap();
|
||||
|
||||
/**
|
||||
* Determines the version of a timezone resource as a standard file without
|
||||
* locking the file.
|
||||
|
@ -381,6 +389,8 @@ public class ICUFile {
|
|||
|
||||
if (!icuFile.canRead() || !icuFile.canWrite())
|
||||
throw new IOException("Missing permissions for " + icuFile);
|
||||
if ((insertURL = getCachedURL(insertURL)) == null)
|
||||
throw new IOException("Could not download the TZ data.");
|
||||
File backupFile = null;
|
||||
if ((backupFile = createBackupFile(icuFile, backupDir)) == null)
|
||||
throw new IOException("Failed to create a backup file.");
|
||||
|
@ -686,7 +696,6 @@ public class ICUFile {
|
|||
message = "Skipped " + file.getPath()
|
||||
+ " (this tool does not support .ear and .war files).";
|
||||
logger.loglnToBoth(message);
|
||||
logger.showInformationDialog(message);
|
||||
} else if (!file.canRead() || !file.canWrite()) {
|
||||
message = "Skipped " + file.getPath() + " (missing permissions).";
|
||||
} else if (!file.getName().endsWith(".jar")) {
|
||||
|
@ -698,12 +707,10 @@ public class ICUFile {
|
|||
message = "Skipped " + file.getPath()
|
||||
+ " (cannot update signed jars).";
|
||||
logger.loglnToBoth(message);
|
||||
logger.showInformationDialog(message);
|
||||
} else if (isEclipseFragment()) {
|
||||
message = "Skipped " + file.getPath()
|
||||
+ " (eclipse fragments must be updated through ICU).";
|
||||
logger.loglnToBoth(message);
|
||||
logger.showInformationDialog(message);
|
||||
}
|
||||
|
||||
if (message != null)
|
||||
|
@ -804,4 +811,58 @@ public class ICUFile {
|
|||
// return whether the jar is updatable or not
|
||||
return success;
|
||||
}
|
||||
|
||||
private URL getCachedURL(URL url) {
|
||||
File outputFile = (File) cacheMap.get(url);
|
||||
if (outputFile != null) {
|
||||
try {
|
||||
return outputFile.toURL();
|
||||
} catch (MalformedURLException ex) {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
logger.loglnToBoth("Downloading from " + url + " to " + outputFile
|
||||
+ ".");
|
||||
InputStream istream = null;
|
||||
OutputStream ostream = null;
|
||||
byte[] buffer = new byte[BUFFER_SIZE];
|
||||
int bytesRead;
|
||||
boolean success = false;
|
||||
|
||||
try {
|
||||
istream = url.openStream();
|
||||
|
||||
outputFile = File.createTempFile("zoneinfo", "res");
|
||||
outputFile.deleteOnExit();
|
||||
ostream = new FileOutputStream(outputFile);
|
||||
|
||||
while ((bytesRead = istream.read(buffer)) != -1)
|
||||
ostream.write(buffer, 0, bytesRead);
|
||||
|
||||
success = true;
|
||||
logger.loglnToBoth("Download successful.");
|
||||
} catch (IOException ex) {
|
||||
outputFile.delete();
|
||||
logger.loglnToBoth("Download failed.");
|
||||
} finally {
|
||||
// safely close the streams
|
||||
if (istream != null)
|
||||
try {
|
||||
istream.close();
|
||||
} catch (IOException ex) {
|
||||
}
|
||||
if (ostream != null)
|
||||
try {
|
||||
ostream.close();
|
||||
} catch (IOException ex) {
|
||||
}
|
||||
}
|
||||
try {
|
||||
return (success && outputFile != null) ? outputFile.toURL()
|
||||
: null;
|
||||
} catch (MalformedURLException ex) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -63,9 +63,6 @@ public class ICUJarFinder {
|
|||
if (backupDir != null)
|
||||
excluded.add(backupDir);
|
||||
|
||||
// the icutzu_home dir must be specified, don't search it
|
||||
excluded.add(curDir);
|
||||
|
||||
// search each of the included files/directories
|
||||
for (int i = 0; i < included.size(); i++)
|
||||
search(resultModel, logger, (File) included.get(i), excluded,
|
||||
|
|
|
@ -97,6 +97,9 @@ public class ICUTZUMain {
|
|||
File iconFile = new File(args[CUR_DIR] + File.separator
|
||||
+ args[ICON_FILE]);
|
||||
|
||||
// TODO: Remove this once this has been tested!!!
|
||||
System.out.println("Backup directory: " + backupDir.toString());
|
||||
|
||||
if ("true".equalsIgnoreCase(System.getProperty("nogui")))
|
||||
new CLILoader(curDir, backupDir, pathFile, resultFile, tzFile);
|
||||
else
|
||||
|
|
|
@ -284,11 +284,7 @@ public class PathComponent extends JComponent {
|
|||
|
||||
pathSearchButton.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent event) {
|
||||
int[] indices = pathList.getSelectedIndices();
|
||||
if (indices.length > 0)
|
||||
owner.search(indices, pathSubdirOption.isSelected());
|
||||
else
|
||||
owner.searchAll(pathSubdirOption.isSelected());
|
||||
owner.searchAll(pathSubdirOption.isSelected());
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -168,7 +168,7 @@ class PathModel extends AbstractListModel {
|
|||
reader = new BufferedReader(new InputStreamReader(
|
||||
new FileInputStream(pathListFile), "UTF-8"), 4 * 1024);
|
||||
while (reader.ready()) {
|
||||
line = reader.readLine().trim();
|
||||
line = reader.readLine().replace('\ufeff', ' ').trim();
|
||||
|
||||
if (line.length() >= 1) {
|
||||
sign = line.charAt(0);
|
||||
|
|
|
@ -256,11 +256,7 @@ public class ResultComponent extends JComponent {
|
|||
|
||||
resultUpdateButton.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent event) {
|
||||
int[] indices = resultTable.getSelectedRows();
|
||||
if (indices.length > 0)
|
||||
owner.update(indices, getSelectedSource());
|
||||
else
|
||||
owner.updateAll(getSelectedSource());
|
||||
owner.updateAll(getSelectedSource());
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -229,7 +229,7 @@ class ResultModel extends AbstractTableModel {
|
|||
reader = new BufferedReader(new InputStreamReader(
|
||||
new FileInputStream(resultListFile), "UTF-8"), 4 * 1024);
|
||||
while (reader.ready()) {
|
||||
line = reader.readLine().trim();
|
||||
line = reader.readLine().replace('\ufeff', ' ').trim();
|
||||
logger.printlnToScreen(line);
|
||||
|
||||
if (line.length() >= 1 && (tab = line.lastIndexOf('\t')) >= 0) {
|
||||
|
@ -402,7 +402,7 @@ class ResultModel extends AbstractTableModel {
|
|||
fireTableRowsUpdated(i, i);
|
||||
} catch (IOException ex) {
|
||||
// could not update the jar
|
||||
ex.printStackTrace();
|
||||
logger.errorln(ex.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue