mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-10 07:39:16 +00:00
ICU-5606 updated icutzu further, fixing logger issues, jar finding logic, and gui issues
X-SVN-Rev: 21140
This commit is contained in:
parent
c90741d9fc
commit
302edb731f
8 changed files with 232 additions and 159 deletions
|
@ -30,20 +30,23 @@ public class CLILoader {
|
|||
// parse the arguments using UOption.parseArgs
|
||||
int argsleft = UOption.parseArgs(args, options);
|
||||
|
||||
// set the logging options
|
||||
if (options[QUIET].doesOccur)
|
||||
Logger.setVerbosity(Logger.QUIET);
|
||||
else if (options[VERBOSE].doesOccur)
|
||||
Logger.setVerbosity(Logger.VERBOSE);
|
||||
else
|
||||
Logger.setVerbosity(Logger.NORMAL);
|
||||
|
||||
// if help is specified, show the help specs and do nothing else
|
||||
if (options[HELP].doesOccur) {
|
||||
showHelp();
|
||||
return;
|
||||
}
|
||||
|
||||
// init the logger
|
||||
logger = Logger.initLogger(Logger.DEFAULT_FILENAME,
|
||||
options[QUIET].doesOccur ? Logger.QUIET
|
||||
: options[VERBOSE].doesOccur ? Logger.VERBOSE
|
||||
: Logger.NORMAL);
|
||||
|
||||
// create the resultModel, the pathModel, and the sourceModel
|
||||
resultModel = new ResultModel(logger);
|
||||
pathModel = new PathModel(resultModel, logger);
|
||||
sourceModel = new SourceModel(logger);
|
||||
|
||||
// make sure only there is only one update mode in the options
|
||||
int choiceType = (options[OFFLINE].doesOccur ? 1 : 0)
|
||||
+ (options[TZVERSION].doesOccur ? 1 : 0)
|
||||
|
@ -100,11 +103,11 @@ public class CLILoader {
|
|||
|
||||
// search the paths for updatable icu4j files
|
||||
try {
|
||||
Logger.println("Search started.", Logger.NORMAL);
|
||||
logger.println("Search started.", Logger.NORMAL);
|
||||
pathModel.searchAll(options[RECURSE].doesOccur, backupDir);
|
||||
Logger.println("Search done.", Logger.NORMAL);
|
||||
logger.println("Search done.", Logger.NORMAL);
|
||||
} catch (InterruptedException ex) {
|
||||
Logger.println("Search interrupted.", Logger.NORMAL);
|
||||
logger.println("Search interrupted.", Logger.NORMAL);
|
||||
}
|
||||
|
||||
// get the name and url associated with the update mode (or null if
|
||||
|
@ -136,17 +139,17 @@ public class CLILoader {
|
|||
while (resultIter.hasNext()) {
|
||||
try {
|
||||
ICUFile entry = (ICUFile) resultIter.next();
|
||||
Logger.println("", Logger.NORMAL);
|
||||
Logger.println("Filename: " + entry.getFile().getName(),
|
||||
logger.println("", Logger.NORMAL);
|
||||
logger.println("Filename: " + entry.getFile().getName(),
|
||||
Logger.NORMAL);
|
||||
Logger.println("Location: " + entry.getFile().getParent(),
|
||||
logger.println("Location: " + entry.getFile().getParent(),
|
||||
Logger.NORMAL);
|
||||
Logger.println("Current Version: " + entry.getTZVersion(),
|
||||
logger.println("Current Version: " + entry.getTZVersion(),
|
||||
Logger.NORMAL);
|
||||
|
||||
if (!entry.getFile().canRead()
|
||||
|| !entry.getFile().canWrite()) {
|
||||
Logger.println("Missing permissions for "
|
||||
logger.println("Missing permissions for "
|
||||
+ entry.getFile().getName() + ".",
|
||||
Logger.NORMAL);
|
||||
continue;
|
||||
|
@ -181,14 +184,14 @@ public class CLILoader {
|
|||
}
|
||||
} catch (IOException ex) {
|
||||
// error in command-line input ???
|
||||
Logger.errorln("Error in command-line input.");
|
||||
logger.errorln("Error in command-line input.");
|
||||
}
|
||||
}
|
||||
|
||||
Logger.println("", Logger.NORMAL);
|
||||
Logger.println("ICUTZU finished successfully.", Logger.NORMAL);
|
||||
logger.println("", Logger.NORMAL);
|
||||
logger.println("ICUTZU finished successfully.", Logger.NORMAL);
|
||||
} catch (IllegalArgumentException ex) {
|
||||
Logger.errorln(ex.getMessage());
|
||||
logger.errorln(ex.getMessage());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -197,53 +200,53 @@ public class CLILoader {
|
|||
String currentVersion, BufferedReader reader) throws IOException {
|
||||
int betterness = chosenVersion.compareToIgnoreCase(currentVersion);
|
||||
if (betterness == 0) {
|
||||
Logger.println("Updating should have no effect on this file.",
|
||||
logger.println("Updating should have no effect on this file.",
|
||||
Logger.NORMAL);
|
||||
Logger.println("Update anyway?", Logger.NORMAL);
|
||||
logger.println("Update anyway?", Logger.NORMAL);
|
||||
} else if (betterness < 0) {
|
||||
Logger
|
||||
logger
|
||||
.println(
|
||||
"Warning: The version specified is older than the one present in the file.",
|
||||
Logger.NORMAL);
|
||||
Logger.println("Update anyway?", Logger.NORMAL);
|
||||
logger.println("Update anyway?", Logger.NORMAL);
|
||||
} else {
|
||||
Logger.println("Update to " + chosenVersion + "?", Logger.NORMAL);
|
||||
logger.println("Update to " + chosenVersion + "?", Logger.NORMAL);
|
||||
}
|
||||
|
||||
Logger.println(" [yes (default), no]\n: ", Logger.NORMAL);
|
||||
logger.println(" [yes (default), no]\n: ", Logger.NORMAL);
|
||||
return reader.readLine().trim().toLowerCase();
|
||||
}
|
||||
|
||||
private String askChoice(BufferedReader reader) throws IOException {
|
||||
Logger.println("Available Versions: ", Logger.NORMAL);
|
||||
logger.println("Available Versions: ", Logger.NORMAL);
|
||||
Iterator sourceIter = sourceModel.iterator();
|
||||
|
||||
Logger.println(getLocalName(), Logger.NORMAL);
|
||||
logger.println(getLocalName(), Logger.NORMAL);
|
||||
while (sourceIter.hasNext())
|
||||
Logger.println(", " + ((Map.Entry) sourceIter.next()).getKey(),
|
||||
logger.println(", " + ((Map.Entry) sourceIter.next()).getKey(),
|
||||
Logger.NORMAL);
|
||||
Logger.println("", Logger.NORMAL);
|
||||
logger.println("", Logger.NORMAL);
|
||||
|
||||
Logger
|
||||
logger
|
||||
.println(
|
||||
"Update to which version? [best (default), none, local copy, <specific version above>]",
|
||||
Logger.NORMAL);
|
||||
Logger.println(": ", Logger.NORMAL);
|
||||
logger.println(": ", Logger.NORMAL);
|
||||
return reader.readLine().trim().toLowerCase();
|
||||
}
|
||||
|
||||
private void update(ICUFile entry, String chosenString, URL url) {
|
||||
Logger.println("Updating to " + chosenString + "...", Logger.NORMAL);
|
||||
logger.println("Updating to " + chosenString + "...", Logger.NORMAL);
|
||||
try {
|
||||
entry.updateJar(url, backupDir);
|
||||
Logger.println("Update done.", Logger.NORMAL);
|
||||
logger.println("Update done.", Logger.NORMAL);
|
||||
} catch (IOException ex) {
|
||||
Logger.error("Could not update " + entry.getFile().getName());
|
||||
logger.error("Could not update " + entry.getFile().getName());
|
||||
}
|
||||
}
|
||||
|
||||
private void skipUpdate() {
|
||||
Logger.println("Update skipped.", Logger.NORMAL);
|
||||
logger.println("Update skipped.", Logger.NORMAL);
|
||||
}
|
||||
|
||||
private String getBestName() {
|
||||
|
@ -288,19 +291,19 @@ public class CLILoader {
|
|||
}
|
||||
}
|
||||
|
||||
private static void showHelp() {
|
||||
Logger.println("Help!", Logger.NORMAL);
|
||||
private void showHelp() {
|
||||
logger.println("Help!", Logger.NORMAL);
|
||||
}
|
||||
|
||||
private static void syntaxError(String message) {
|
||||
private void syntaxError(String message) {
|
||||
throw new IllegalArgumentException("Error in argument list: " + message);
|
||||
}
|
||||
|
||||
private ResultModel resultModel = new ResultModel();
|
||||
private ResultModel resultModel;
|
||||
|
||||
private PathModel pathModel = new PathModel(resultModel);
|
||||
private PathModel pathModel;
|
||||
|
||||
private SourceModel sourceModel = new SourceModel();
|
||||
private SourceModel sourceModel;
|
||||
|
||||
private File backupDir = null;
|
||||
|
||||
|
@ -338,4 +341,6 @@ public class CLILoader {
|
|||
private static final int NOBACKUP = 9;
|
||||
|
||||
private static final int DISCOVERONLY = 10;
|
||||
|
||||
private Logger logger;
|
||||
}
|
|
@ -19,9 +19,10 @@ public class GUILoader {
|
|||
public GUILoader() {
|
||||
String title = "ICU Time Zone Updater";
|
||||
|
||||
resultModel = new ResultModel();
|
||||
pathModel = new PathModel(resultModel);
|
||||
sourceModel = new SourceModel();
|
||||
logger = Logger.initLogger(Logger.DEFAULT_FILENAME, Logger.NORMAL);
|
||||
resultModel = new ResultModel(logger);
|
||||
pathModel = new PathModel(resultModel, logger);
|
||||
sourceModel = new SourceModel(logger);
|
||||
|
||||
pathGUI = new PathComponent(this, pathModel);
|
||||
pathFrame = new JFrame(title + " - Search Paths");
|
||||
|
@ -78,7 +79,7 @@ public class GUILoader {
|
|||
|
||||
workerThread = new Thread(new Runnable() {
|
||||
public void run() {
|
||||
Logger.println("Search started.", Logger.NORMAL);
|
||||
logger.println("Search started.", Logger.NORMAL);
|
||||
setCancelSearchEnabled(true);
|
||||
setUpdateEnabled(false);
|
||||
setSearchEnabled(false);
|
||||
|
@ -91,7 +92,7 @@ public class GUILoader {
|
|||
setSearchEnabled(true);
|
||||
setUpdateEnabled(true);
|
||||
setCancelSearchEnabled(false);
|
||||
Logger.println("Search ended.", Logger.NORMAL);
|
||||
logger.println("Search ended.", Logger.NORMAL);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -103,7 +104,7 @@ public class GUILoader {
|
|||
|
||||
workerThread = new Thread(new Runnable() {
|
||||
public void run() {
|
||||
Logger.println("Search started.", Logger.NORMAL);
|
||||
logger.println("Search started.", Logger.NORMAL);
|
||||
setCancelSearchEnabled(true);
|
||||
setUpdateEnabled(false);
|
||||
setSearchEnabled(false);
|
||||
|
@ -116,7 +117,7 @@ public class GUILoader {
|
|||
setSearchEnabled(true);
|
||||
setUpdateEnabled(true);
|
||||
setCancelSearchEnabled(false);
|
||||
Logger.println("Search ended.", Logger.NORMAL);
|
||||
logger.println("Search ended.", Logger.NORMAL);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -128,7 +129,7 @@ public class GUILoader {
|
|||
|
||||
workerThread = new Thread(new Runnable() {
|
||||
public void run() {
|
||||
Logger.println("Update started.", Logger.NORMAL);
|
||||
logger.println("Update started.", Logger.NORMAL);
|
||||
setCancelUpdateEnabled(true);
|
||||
setUpdateEnabled(false);
|
||||
setSearchEnabled(false);
|
||||
|
@ -139,7 +140,7 @@ public class GUILoader {
|
|||
setUpdateEnabled(true);
|
||||
setSearchEnabled(true);
|
||||
setCancelUpdateEnabled(false);
|
||||
Logger.println("Update ended.", Logger.NORMAL);
|
||||
logger.println("Update ended.", Logger.NORMAL);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -151,7 +152,7 @@ public class GUILoader {
|
|||
|
||||
workerThread = new Thread(new Runnable() {
|
||||
public void run() {
|
||||
Logger.println("Update started.", Logger.NORMAL);
|
||||
logger.println("Update started.", Logger.NORMAL);
|
||||
setCancelUpdateEnabled(true);
|
||||
setUpdateEnabled(false);
|
||||
setSearchEnabled(false);
|
||||
|
@ -162,7 +163,7 @@ public class GUILoader {
|
|||
setUpdateEnabled(true);
|
||||
setSearchEnabled(true);
|
||||
setCancelUpdateEnabled(false);
|
||||
Logger.println("Update ended.", Logger.NORMAL);
|
||||
logger.println("Update ended.", Logger.NORMAL);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -224,4 +225,6 @@ public class GUILoader {
|
|||
private JFrame resultFrame;
|
||||
|
||||
private File backupDir;
|
||||
|
||||
private Logger logger;
|
||||
}
|
|
@ -13,18 +13,18 @@ import java.net.*;
|
|||
import com.ibm.icu.util.*;
|
||||
|
||||
public class ICUFile {
|
||||
public ICUFile(File file) throws IOException {
|
||||
public ICUFile(File file, Logger logger) throws IOException {
|
||||
this.file = file;
|
||||
ICUFile.logger = logger;
|
||||
|
||||
if (!file.isFile())
|
||||
throw new IOException(file + " is not a file.");
|
||||
|
||||
throw new IOException("not a file");
|
||||
if (!isUpdatable())
|
||||
throw new IOException(file + " is not an updatable ICU4J jar file.");
|
||||
throw new IOException("not an updatable ICU4J jar");
|
||||
if (isSigned())
|
||||
throw new IOException("not a signed jar");
|
||||
|
||||
tzVersion = findEntryTZVersion(file, insertEntry);
|
||||
|
||||
Logger.println("Added: " + file, Logger.NORMAL);
|
||||
}
|
||||
|
||||
public File getFile() {
|
||||
|
@ -117,8 +117,9 @@ public class ICUFile {
|
|||
}
|
||||
|
||||
private static boolean copyFile(File inputFile, File outputFile) {
|
||||
Logger.println("Coping from \"" + inputFile + "\" to \"" + outputFile
|
||||
+ "\"", Logger.VERBOSE);
|
||||
logger.println("Coping from " + inputFile + " to " + outputFile + ".",
|
||||
Logger.VERBOSE);
|
||||
logger.logln("Coping from " + inputFile + " to " + outputFile + ".");
|
||||
InputStream istream = null;
|
||||
OutputStream ostream = null;
|
||||
byte[] buffer = new byte[BUFFER_SIZE];
|
||||
|
@ -133,9 +134,12 @@ public class ICUFile {
|
|||
ostream.write(buffer, 0, bytesRead);
|
||||
|
||||
success = true;
|
||||
logger.println("Copy successful.", Logger.VERBOSE);
|
||||
logger.logln("Copy successful.");
|
||||
} catch (IOException ex) {
|
||||
// ex.printStackTrace();
|
||||
outputFile.delete();
|
||||
logger.println("Copy failed.", Logger.VERBOSE);
|
||||
logger.logln("Copy failed.");
|
||||
} finally {
|
||||
// safely close the streams
|
||||
if (istream != null)
|
||||
|
@ -156,8 +160,10 @@ public class ICUFile {
|
|||
|
||||
private static boolean copyEntry(File inputFile, JarEntry inputEntry,
|
||||
File outputFile) {
|
||||
Logger.println("Coping from \"" + inputFile + "!/" + inputEntry
|
||||
+ "\" to \"" + outputFile + "\"", Logger.VERBOSE);
|
||||
logger.println("Coping from " + inputFile + "!/" + inputEntry + " to "
|
||||
+ outputFile + ".", Logger.VERBOSE);
|
||||
logger.logln("Coping from " + inputFile + "!/" + inputEntry + " to "
|
||||
+ outputFile + ".");
|
||||
JarFile jar = null;
|
||||
InputStream istream = null;
|
||||
OutputStream ostream = null;
|
||||
|
@ -174,9 +180,13 @@ public class ICUFile {
|
|||
ostream.write(buffer, 0, bytesRead);
|
||||
|
||||
success = true;
|
||||
logger.println("Copy successful.", Logger.VERBOSE);
|
||||
logger.logln("Copy successful.");
|
||||
} catch (IOException ex) {
|
||||
// ex.printStackTrace();
|
||||
outputFile.delete();
|
||||
logger.println("Copy failed.", Logger.VERBOSE);
|
||||
logger.logln("Copy failed.");
|
||||
} finally {
|
||||
// safely close the streams
|
||||
if (jar != null)
|
||||
|
@ -203,8 +213,10 @@ public class ICUFile {
|
|||
|
||||
private static boolean createUpdatedJar(File inputFile, File outputFile,
|
||||
JarEntry insertEntry, URL inputURL) {
|
||||
Logger.println("Inserting \"" + inputURL + "\" into \"" + inputFile
|
||||
+ "/" + insertEntry + "\"", Logger.VERBOSE);
|
||||
logger.println("Inserting " + inputURL + " into " + inputFile + "/"
|
||||
+ insertEntry + ".", Logger.VERBOSE);
|
||||
logger.logln("Inserting " + inputURL + " into " + inputFile + "/"
|
||||
+ insertEntry + ".");
|
||||
JarFile jar = null;
|
||||
JarOutputStream ostream = null;
|
||||
InputStream istream = null;
|
||||
|
@ -244,9 +256,13 @@ public class ICUFile {
|
|||
}
|
||||
|
||||
success = true;
|
||||
logger.println("Insert successful.", Logger.VERBOSE);
|
||||
logger.logln("Insert successful.");
|
||||
} catch (IOException ex) {
|
||||
// ex.printStackTrace();
|
||||
outputFile.delete();
|
||||
logger.println("Insert failed.", Logger.VERBOSE);
|
||||
logger.logln("Insert failed.");
|
||||
} finally {
|
||||
// safely close the streams
|
||||
if (istream != null)
|
||||
|
@ -284,32 +300,32 @@ public class ICUFile {
|
|||
try {
|
||||
jar = new JarFile(file);
|
||||
Manifest manifest = jar.getManifest();
|
||||
if (manifest != null) {
|
||||
Iterator iter = manifest.getEntries().values().iterator();
|
||||
while (iter.hasNext()) {
|
||||
Attributes attr = (Attributes) iter.next();
|
||||
icuTitle = attr
|
||||
.getValue(Attributes.Name.IMPLEMENTATION_TITLE);
|
||||
icuVersion = attr
|
||||
.getValue(Attributes.Name.IMPLEMENTATION_VERSION);
|
||||
if (!("ICU for Java".equals(icuTitle) || "Modularized ICU for Java"
|
||||
.equals(icuTitle)))
|
||||
continue;
|
||||
if (manifest == null)
|
||||
return hasFile(jar);
|
||||
Iterator iter = manifest.getEntries().values().iterator();
|
||||
while (iter.hasNext()) {
|
||||
Attributes attr = (Attributes) iter.next();
|
||||
icuTitle = attr.getValue(Attributes.Name.IMPLEMENTATION_TITLE);
|
||||
icuVersion = attr
|
||||
.getValue(Attributes.Name.IMPLEMENTATION_VERSION);
|
||||
if (!("ICU for Java".equals(icuTitle) || "Modularized ICU for Java"
|
||||
.equals(icuTitle)))
|
||||
continue;
|
||||
|
||||
// since it's an ICU file, we will search inside for the
|
||||
// intended file
|
||||
success = hasFile(jar);
|
||||
break;
|
||||
}
|
||||
// since it's an ICU file, we will search inside for the
|
||||
// intended file
|
||||
success = hasFile(jar);
|
||||
break;
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
// unable to create the JarFile,
|
||||
// unable to get the Manifest
|
||||
// log the unexplained i/o error, but we must drudge on
|
||||
Logger.println("Error with " + file, Logger.NORMAL);
|
||||
// ex.printStackTrace();
|
||||
logger.println("I/O Error with " + file.getPath(), Logger.VERBOSE);
|
||||
logger.logln("I/O Error with " + file.getPath());
|
||||
} catch (Exception ex) {
|
||||
// ex.printStackTrace();
|
||||
} finally {
|
||||
// new Throwable().printStackTrace();
|
||||
if (jar != null)
|
||||
try {
|
||||
jar.close();
|
||||
|
@ -318,7 +334,6 @@ public class ICUFile {
|
|||
}
|
||||
}
|
||||
return success;
|
||||
|
||||
}
|
||||
|
||||
private boolean hasFile(JarFile jar) {
|
||||
|
@ -331,6 +346,10 @@ public class ICUFile {
|
|||
return false;
|
||||
}
|
||||
|
||||
private boolean isSigned() {
|
||||
return insertEntry.getCertificates() != null;
|
||||
}
|
||||
|
||||
public static String findEntryTZVersion(File icuFile, JarEntry tzEntry) {
|
||||
try {
|
||||
File temp = File.createTempFile("zoneinfo", ".res");
|
||||
|
@ -338,7 +357,7 @@ public class ICUFile {
|
|||
copyEntry(icuFile, tzEntry, temp);
|
||||
return findTZVersion(temp);
|
||||
} catch (IOException ex) {
|
||||
// ex.printStackTrace();
|
||||
logger.logln(ex.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -350,7 +369,7 @@ public class ICUFile {
|
|||
copyFile(tzFile, temp);
|
||||
return findTZVersion(temp);
|
||||
} catch (IOException ex) {
|
||||
// ex.printStackTrace();
|
||||
logger.logln(ex.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -380,7 +399,6 @@ public class ICUFile {
|
|||
return tzVersion;
|
||||
} catch (MissingResourceException ex) {
|
||||
// not an error -- some zoneinfo files do not have a version number
|
||||
// included
|
||||
} catch (MalformedURLException ex) {
|
||||
// this should never happen
|
||||
ex.printStackTrace();
|
||||
|
@ -406,4 +424,6 @@ public class ICUFile {
|
|||
private String icuVersion;
|
||||
|
||||
private String tzVersion;
|
||||
|
||||
private static Logger logger;
|
||||
}
|
||||
|
|
|
@ -13,8 +13,9 @@ public class ICUJarFinder {
|
|||
private ICUJarFinder() {
|
||||
}
|
||||
|
||||
public static void search(ResultModel resultModel, IncludePath[] paths,
|
||||
boolean subdirs, File backupDir) throws InterruptedException {
|
||||
public static ResultModel search(ResultModel resultModel, Logger logger,
|
||||
IncludePath[] paths, boolean subdirs, File backupDir)
|
||||
throws InterruptedException {
|
||||
List included = new ArrayList();
|
||||
List excluded = new ArrayList();
|
||||
|
||||
|
@ -29,46 +30,63 @@ public class ICUJarFinder {
|
|||
if (backupDir != null)
|
||||
excluded.add(backupDir);
|
||||
|
||||
Logger.println("*************", Logger.NORMAL);
|
||||
Logger.println("Included:", Logger.NORMAL);
|
||||
logger.println("*************", Logger.VERBOSE);
|
||||
logger.println("Included:", Logger.VERBOSE);
|
||||
for (int i = 0; i < included.size(); i++)
|
||||
Logger.println(included.get(i), Logger.NORMAL);
|
||||
Logger.println("Excluded:", Logger.NORMAL);
|
||||
logger.println(included.get(i).toString(), Logger.VERBOSE);
|
||||
logger.println("Excluded:", Logger.VERBOSE);
|
||||
for (int i = 0; i < excluded.size(); i++)
|
||||
Logger.println(excluded.get(i), Logger.NORMAL);
|
||||
Logger.println("*************", Logger.NORMAL);
|
||||
logger.println(excluded.get(i).toString(), Logger.VERBOSE);
|
||||
logger.println("*************", Logger.VERBOSE);
|
||||
|
||||
for (int i = 0; i < included.size(); i++)
|
||||
search(resultModel, (File) included.get(i), excluded, subdirs, true);
|
||||
search(resultModel, logger, (File) included.get(i), excluded,
|
||||
subdirs, 0);
|
||||
|
||||
return resultModel;
|
||||
}
|
||||
|
||||
private static void search(ResultModel resultModel, File file,
|
||||
List excluded, boolean subdirs, boolean firstdip)
|
||||
private static ResultModel search(ResultModel resultModel, Logger logger,
|
||||
File file, List excluded, boolean subdirs, int depth)
|
||||
throws InterruptedException {
|
||||
Iterator iter = excluded.iterator();
|
||||
while (iter.hasNext())
|
||||
if (file.getAbsolutePath().equalsIgnoreCase(
|
||||
((File) iter.next()).getAbsolutePath()))
|
||||
return;
|
||||
return resultModel;
|
||||
|
||||
if (file.exists()) {
|
||||
if (file.isFile() && file.getName().endsWith(".jar")) {
|
||||
try {
|
||||
resultModel.add(new ICUFile(file));
|
||||
resultModel.add(new ICUFile(file, logger));
|
||||
logger.println("Added " + file.getPath() + ".",
|
||||
Logger.NORMAL);
|
||||
logger.logln("Added " + file.getPath() + ".");
|
||||
} catch (IOException ex) {
|
||||
// if it's not an ICU file we care about, ignore it
|
||||
logger.println("Skipped " + file.getPath() + " ("
|
||||
+ ex.getMessage() + ").", Logger.VERBOSE);
|
||||
logger.logln("Skipped " + file.getPath() + " ("
|
||||
+ ex.getMessage() + ").");
|
||||
}
|
||||
} else if (file.isDirectory() && (subdirs || firstdip)) {
|
||||
Logger.println(file, Logger.NORMAL);
|
||||
} else if (file.isDirectory() && (subdirs || depth == 0)) {
|
||||
logger.println(file.getPath(), Logger.VERBOSE);
|
||||
File[] dirlist = file.listFiles();
|
||||
if (dirlist != null)
|
||||
for (int i = 0; i < dirlist.length; i++)
|
||||
search(resultModel, dirlist[i], excluded, subdirs,
|
||||
false);
|
||||
Thread.sleep(0);
|
||||
search(resultModel, logger, dirlist[i], excluded,
|
||||
subdirs, depth + 1);
|
||||
if (Thread.interrupted())
|
||||
throw new InterruptedException();
|
||||
} else if (file.isFile()
|
||||
&& (file.getName().endsWith(".ear") || file.getName()
|
||||
.endsWith(".war"))) {
|
||||
logger.logln("Skipped " + file.getPath()
|
||||
+ " (ear/war files not supported).");
|
||||
logger.println("Skipped " + file.getPath()
|
||||
+ " (ear/war files not supported).", Logger.NORMAL);
|
||||
}
|
||||
}
|
||||
return resultModel;
|
||||
}
|
||||
|
||||
}
|
|
@ -13,49 +13,60 @@ import java.io.FileNotFoundException;
|
|||
|
||||
public class Logger {
|
||||
|
||||
static {
|
||||
try {
|
||||
log = new PrintStream(new FileOutputStream("icutzu.log"));
|
||||
} catch (FileNotFoundException ex) {
|
||||
System.err.println("Could not create a log file.");
|
||||
}
|
||||
}
|
||||
|
||||
private Logger() {
|
||||
}
|
||||
|
||||
public static void setVerbosity(int verbosity) {
|
||||
Logger.verbosity = verbosity;
|
||||
public static Logger initLogger(String filename, int verbosity) {
|
||||
try {
|
||||
System.out.println("Log file: " + filename);
|
||||
if (logger.log != null)
|
||||
logger.log.close();
|
||||
logger.log = new PrintStream(new FileOutputStream(filename));
|
||||
logger.verbosity = verbosity;
|
||||
} catch (FileNotFoundException ex) {
|
||||
System.err.println("Could not create " + filename + ".");
|
||||
}
|
||||
return logger;
|
||||
}
|
||||
|
||||
public static int getVerbosity() {
|
||||
public static Logger getInstance() {
|
||||
return logger;
|
||||
}
|
||||
|
||||
public void setVerbosity(int verbosity) {
|
||||
this.verbosity = verbosity;
|
||||
}
|
||||
|
||||
public int getVerbosity() {
|
||||
return verbosity;
|
||||
}
|
||||
|
||||
public static void print(Object output, int verbosity) {
|
||||
if (verbosity >= Logger.verbosity)
|
||||
public void print(String output, int verbosity) {
|
||||
if (verbosity >= this.verbosity)
|
||||
System.out.print(output);
|
||||
}
|
||||
|
||||
public static void println(Object output, int verbosity) {
|
||||
if (verbosity >= Logger.verbosity)
|
||||
public void println(String output, int verbosity) {
|
||||
if (verbosity >= this.verbosity)
|
||||
System.out.println(output);
|
||||
}
|
||||
|
||||
public static void error(Object output) {
|
||||
public void error(String output) {
|
||||
System.err.print(output);
|
||||
}
|
||||
|
||||
public static void errorln(Object output) {
|
||||
public void errorln(String output) {
|
||||
System.err.println(output);
|
||||
}
|
||||
|
||||
public static void log(Object output) {
|
||||
log.print(output);
|
||||
public void log(String output) {
|
||||
if (log != null)
|
||||
log.print(output);
|
||||
}
|
||||
|
||||
public static void logln(Object output) {
|
||||
log.println(output);
|
||||
public void logln(String output) {
|
||||
if (log != null)
|
||||
log.println(output);
|
||||
}
|
||||
|
||||
public static final int QUIET = -1;
|
||||
|
@ -64,7 +75,11 @@ public class Logger {
|
|||
|
||||
public static final int VERBOSE = 1;
|
||||
|
||||
private static int verbosity = NORMAL;
|
||||
private int verbosity = NORMAL;
|
||||
|
||||
private static PrintStream log;
|
||||
private PrintStream log;
|
||||
|
||||
private static Logger logger = new Logger();
|
||||
|
||||
public static final String DEFAULT_FILENAME = "icutzu.log";
|
||||
}
|
||||
|
|
|
@ -11,8 +11,9 @@ import javax.swing.*;
|
|||
import java.io.*;
|
||||
|
||||
class PathModel extends AbstractListModel {
|
||||
public PathModel(ResultModel resultModel) {
|
||||
public PathModel(ResultModel resultModel, Logger logger) {
|
||||
this.resultModel = resultModel;
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
public Iterator iterator() {
|
||||
|
@ -141,7 +142,7 @@ class PathModel extends AbstractListModel {
|
|||
else
|
||||
iter.next();
|
||||
|
||||
ICUJarFinder.search(resultModel, paths, subdirs, backupDir);
|
||||
ICUJarFinder.search(resultModel, logger, paths, subdirs, backupDir);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -153,7 +154,7 @@ class PathModel extends AbstractListModel {
|
|||
Iterator iter = list.iterator();
|
||||
for (int i = 0; i < n; i++)
|
||||
paths[i] = (IncludePath) iter.next();
|
||||
ICUJarFinder.search(resultModel, paths, subdirs, backupDir);
|
||||
ICUJarFinder.search(resultModel, logger, paths, subdirs, backupDir);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -169,4 +170,6 @@ class PathModel extends AbstractListModel {
|
|||
public static final String PATHLIST_FILENAME = "DirectorySearch.txt";
|
||||
|
||||
public static final long serialVersionUID = 1337;
|
||||
|
||||
private Logger logger;
|
||||
}
|
|
@ -12,7 +12,8 @@ import java.io.*;
|
|||
import java.net.*;
|
||||
|
||||
class ResultModel extends AbstractTableModel {
|
||||
public ResultModel() {
|
||||
public ResultModel(Logger logger) {
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
public int getColumnCount() {
|
||||
|
@ -61,7 +62,7 @@ class ResultModel extends AbstractTableModel {
|
|||
|
||||
public boolean add(File file) {
|
||||
try {
|
||||
ICUFile entry = new ICUFile(file);
|
||||
ICUFile entry = new ICUFile(file, logger);
|
||||
if (file.canRead() && file.canWrite())
|
||||
add(permissibleList, hidden, entry);
|
||||
add(completeList, !hidden, entry);
|
||||
|
@ -219,4 +220,6 @@ class ResultModel extends AbstractTableModel {
|
|||
private boolean hidden = true;
|
||||
|
||||
public static final long serialVersionUID = 1338;
|
||||
|
||||
private Logger logger;
|
||||
}
|
||||
|
|
|
@ -15,6 +15,33 @@ import javax.swing.text.html.*;
|
|||
import javax.swing.text.html.parser.*;
|
||||
|
||||
class SourceModel extends AbstractListModel implements ComboBoxModel {
|
||||
public SourceModel(Logger logger) {
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
public static void initialize(Logger logger) {
|
||||
// cannot make TZ_BASE_URL and TZ_LOCAL_URL final since url creations
|
||||
// need to be try-catched
|
||||
try {
|
||||
TZ_BASE_URL = new URL(TZ_BASE_URLSTRING_START);
|
||||
|
||||
if (!TZ_LOCAL_FILE.exists()) {
|
||||
logger.errorln("Local copy (zoneinfo.res) does not exist.");
|
||||
} else {
|
||||
TZ_LOCAL_URL = TZ_LOCAL_FILE.toURL();
|
||||
TZ_LOCAL_VERSION = ICUFile.findFileTZVersion(TZ_LOCAL_FILE);
|
||||
if (TZ_LOCAL_VERSION == null) {
|
||||
logger.errorln("Failed to determine version of local copy");
|
||||
} else {
|
||||
TZ_LOCAL_CHOICE = "Local Copy (" + TZ_LOCAL_VERSION + ")";
|
||||
}
|
||||
}
|
||||
} catch (MalformedURLException ex) {
|
||||
// this shouldn't happen
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void findSources() {
|
||||
BufferedReader reader = null;
|
||||
try {
|
||||
|
@ -143,28 +170,7 @@ class SourceModel extends AbstractListModel implements ComboBoxModel {
|
|||
|
||||
public static URL TZ_LOCAL_URL = null;
|
||||
|
||||
static {
|
||||
// cannot make TZ_BASE_URL and TZ_LOCAL_URL final since url creations
|
||||
// need to be try-catched
|
||||
try {
|
||||
TZ_BASE_URL = new URL(TZ_BASE_URLSTRING_START);
|
||||
|
||||
if (!TZ_LOCAL_FILE.exists()) {
|
||||
Logger.errorln("Local copy (zoneinfo.res) does not exist.");
|
||||
} else {
|
||||
TZ_LOCAL_URL = TZ_LOCAL_FILE.toURL();
|
||||
TZ_LOCAL_VERSION = ICUFile.findFileTZVersion(TZ_LOCAL_FILE);
|
||||
if (TZ_LOCAL_VERSION == null) {
|
||||
Logger.errorln("Failed to determine version of local copy");
|
||||
} else {
|
||||
TZ_LOCAL_CHOICE = "Local Copy (" + TZ_LOCAL_VERSION + ")";
|
||||
}
|
||||
}
|
||||
} catch (MalformedURLException ex) {
|
||||
// this shouldn't happen
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static final long serialVersionUID = 1339;
|
||||
|
||||
private Logger logger;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue