summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorTom Tromey <tromey@redhat.com>2006-05-15 16:23:47 +0000
committerTom Tromey <tromey@redhat.com>2006-05-15 16:23:47 +0000
commitd1001cf3dfdbbbf0f7c8f2e44fdfc3ba6d72336a (patch)
tree2a9c4c22bb06c45426fd7452da0b48479371c837 /tools
parentc2803e2a5fe10d871fd35e77e1f60bc99224ecd0 (diff)
downloadclasspath-d1001cf3dfdbbbf0f7c8f2e44fdfc3ba6d72336a.tar.gz
* tools/gnu/classpath/tools/jar/Main.java (setArchiveFile): Use
MessageFormat. * tools/gnu/classpath/tools/jar/Indexer.java (indexJarFile): Use MessageFormat. * tools/gnu/classpath/tools/jar/Extractor.java: Externalized strings. (run): Use MessageFormat. * resource/gnu/classpath/tools/jar/messages.properties: New file. * tools/gnu/classpath/tools/jar/Creator.java: Externalized strings. (writeFile): Use MessageFormat.
Diffstat (limited to 'tools')
-rw-r--r--tools/gnu/classpath/tools/jar/Creator.java22
-rw-r--r--tools/gnu/classpath/tools/jar/Extractor.java20
-rw-r--r--tools/gnu/classpath/tools/jar/Indexer.java13
-rw-r--r--tools/gnu/classpath/tools/jar/Main.java60
-rw-r--r--tools/gnu/classpath/tools/jar/Messages.java67
5 files changed, 140 insertions, 42 deletions
diff --git a/tools/gnu/classpath/tools/jar/Creator.java b/tools/gnu/classpath/tools/jar/Creator.java
index e10addd5b..55159660d 100644
--- a/tools/gnu/classpath/tools/jar/Creator.java
+++ b/tools/gnu/classpath/tools/jar/Creator.java
@@ -46,6 +46,7 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
@@ -88,7 +89,11 @@ public class Creator
if (writtenItems.contains(filename))
{
if (verbose)
- System.err.println("ignoring entry " + filename);
+ {
+ String msg = MessageFormat.format(Messages.getString("Creator.Ignoring"), //$NON-NLS-1$
+ new Object[] { filename });
+ System.err.println(msg);
+ }
return;
}
@@ -121,8 +126,15 @@ public class Creator
perc = 0;
else
perc = 100 - (100 * csize) / size;
- System.err.println("adding: " + filename + " (in=" + size + ") (out="
- + entry.getSize() + ") (stored " + perc + "%)");
+ String msg = MessageFormat.format(Messages.getString("Creator.Adding"), //$NON-NLS-1$
+ new Object[]
+ {
+ filename,
+ Long.valueOf(size),
+ Long.valueOf(entry.getSize()),
+ Long.valueOf(perc)
+ });
+ System.err.println(msg);
}
}
@@ -177,7 +189,7 @@ public class Creator
throws IOException
{
// We've already written the manifest, make sure to mark it.
- writtenItems.add("META-INF/");
+ writtenItems.add("META-INF/"); //$NON-NLS-1$
writtenItems.add(JarFile.MANIFEST_NAME);
ArrayList allEntries = getAllEntries(parameters);
@@ -222,7 +234,7 @@ public class Creator
public void run(Main parameters) throws IOException
{
- if (parameters.archiveFile == null || parameters.archiveFile.equals("-"))
+ if (parameters.archiveFile == null || parameters.archiveFile.equals("-")) //$NON-NLS-1$
writeCommandLineEntries(parameters, System.out);
else
{
diff --git a/tools/gnu/classpath/tools/jar/Extractor.java b/tools/gnu/classpath/tools/jar/Extractor.java
index 942fc667b..ed647cbfe 100644
--- a/tools/gnu/classpath/tools/jar/Extractor.java
+++ b/tools/gnu/classpath/tools/jar/Extractor.java
@@ -44,6 +44,7 @@ import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
@@ -111,7 +112,7 @@ public class Extractor
// Open the input file.
ZipInputStream zis;
File zfile = parameters.archiveFile;
- if (zfile == null || "-".equals(zfile.getName()))
+ if (zfile == null || "-".equals(zfile.getName())) //$NON-NLS-1$
zis = new ZipInputStream(System.in);
else
{
@@ -132,7 +133,12 @@ public class Extractor
if (file.mkdirs())
{
if (parameters.verbose)
- System.err.println(" created: " + file);
+ {
+ String msg
+ = MessageFormat.format(Messages.getString("Extractor.Created"), //$NON-NLS-1$
+ new Object[] { file });
+ System.err.println(msg);
+ }
}
continue;
}
@@ -145,9 +151,13 @@ public class Extractor
if (parameters.verbose)
{
- String leader = (entry.getMethod() == ZipEntry.STORED
- ? " extracted" : " inflated");
- System.err.println(leader + ": " + file);
+ String fmt;
+ if (entry.getMethod() == ZipEntry.STORED)
+ fmt = Messages.getString("Extractor.Extracted"); //$NON-NLS-1$
+ else
+ fmt = Messages.getString("Extractor.Inflated"); //$NON-NLS-1$
+ String msg = MessageFormat.format(fmt, new Object[] { file });
+ System.err.println(msg);
}
}
}
diff --git a/tools/gnu/classpath/tools/jar/Indexer.java b/tools/gnu/classpath/tools/jar/Indexer.java
index 3fff8e1af..86fe4ee36 100644
--- a/tools/gnu/classpath/tools/jar/Indexer.java
+++ b/tools/gnu/classpath/tools/jar/Indexer.java
@@ -44,6 +44,7 @@ import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
+import java.text.MessageFormat;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.Iterator;
@@ -61,7 +62,11 @@ public class Indexer
throws IOException
{
if (verbose)
- System.err.println("indexing: " + fileName);
+ {
+ String msg = MessageFormat.format(Messages.getString("Indexer.Indexing"), //$NON-NLS-1$
+ new Object[] { fileName });
+ System.err.println(msg);
+ }
JarFile jf = new JarFile(fileName);
// Index the files in this jar.
@@ -71,7 +76,7 @@ public class Indexer
{
JarEntry entry = (JarEntry) e.nextElement();
String name = entry.getName();
- if (name.startsWith("META-INF/"))
+ if (name.startsWith("META-INF/")) //$NON-NLS-1$
continue;
int index = name.lastIndexOf('/');
if (index != -1)
@@ -102,7 +107,7 @@ public class Indexer
String jars = attrs.getValue(Attributes.Name.CLASS_PATH);
if (jars != null)
{
- StringTokenizer st = new StringTokenizer(jars, " ");
+ StringTokenizer st = new StringTokenizer(jars, " "); //$NON-NLS-1$
while (st.hasMoreTokens())
{
String name = st.nextToken();
@@ -127,7 +132,7 @@ public class Indexer
if (contents.length() != 0)
{
// Insert in reverse order to avoid computing anything.
- contents.insert(0, "1.0\n\n");
+ contents.insert(0, "1.0\n\n"); //$NON-NLS-1$
contents.insert(0, IndexListParser.JAR_INDEX_VERSION_KEY);
ByteArrayInputStream in
= new ByteArrayInputStream(contents.toString().getBytes());
diff --git a/tools/gnu/classpath/tools/jar/Main.java b/tools/gnu/classpath/tools/jar/Main.java
index ae802d0c7..8ea770bb6 100644
--- a/tools/gnu/classpath/tools/jar/Main.java
+++ b/tools/gnu/classpath/tools/jar/Main.java
@@ -47,6 +47,7 @@ import gnu.classpath.tools.getopt.Parser;
import java.io.File;
import java.io.IOException;
+import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.zip.ZipOutputStream;
@@ -85,8 +86,11 @@ public class Main
void setArchiveFile(String filename) throws OptionException
{
if (archiveFile != null)
- throw new OptionException("archive file name already set to "
- + archiveFile);
+ {
+ String fmt = MessageFormat.format(Messages.getString("Main.ArchiveAlreadySet"), //$NON-NLS-1$
+ new Object[] { archiveFile });
+ throw new OptionException(fmt);
+ }
archiveFile = new File(filename);
}
@@ -130,7 +134,7 @@ public class Main
public void parsed(String argument) throws OptionException
{
if (operationMode != null)
- throw new OptionException("operation mode already specified");
+ throw new OptionException(Messages.getString("Main.ModeAlreaySet")); //$NON-NLS-1$
operationMode = mode;
// We know this is only the case for -i.
if (argument != null)
@@ -148,68 +152,68 @@ public class Main
protected void validate() throws OptionException
{
if (operationMode == null)
- throw new OptionException("must specify one of -t, -c, -u, -x, or -i");
+ throw new OptionException(Messages.getString("Main.MustSpecify")); //$NON-NLS-1$
if (changedDirectory != null)
- throw new OptionException("-C argument requires both directory and filename");
+ throw new OptionException(Messages.getString("Main.TwoArgsReqd")); //$NON-NLS-1$
if (! wantManifest && manifestFile != null)
- throw new OptionException("can't specify both -m and -M");
+ throw new OptionException(Messages.getString("Main.CantHaveBoth")); //$NON-NLS-1$
if (operationMode == Indexer.class)
{
// Some extra validation for -i.
if (! entries.isEmpty())
- throw new OptionException("can't specify file arguments when using -i");
+ throw new OptionException(Messages.getString("Main.NoFilesWithi")); //$NON-NLS-1$
if (! wantManifest)
- throw new OptionException("can't specify -M with -i");
+ throw new OptionException(Messages.getString("Main.NoMAndi")); //$NON-NLS-1$
if (manifestFile != null)
- throw new OptionException("can't specify -m with -i");
+ throw new OptionException(Messages.getString("Main.AnotherNomAndi")); //$NON-NLS-1$
}
}
}
private Parser initializeParser()
{
- Parser p = new JarParser("jar");
- p.setHeader("Usage: jar -ctxui [OPTIONS] jar-file [-C DIR FILE] FILE...");
-
- OptionGroup grp = new OptionGroup("Operation mode");
- grp.add(new ModeOption('c', "create a new archive", Creator.class));
- grp.add(new ModeOption('x', "extract from archive", Extractor.class));
- grp.add(new ModeOption('t', "list archive contents", Lister.class));
- grp.add(new ModeOption('u', "update archive", Updater.class));
+ Parser p = new JarParser("jar"); //$NON-NLS-1$
+ p.setHeader(Messages.getString("Main.Usage")); //$NON-NLS-1$
+
+ OptionGroup grp = new OptionGroup(Messages.getString("Main.OpMode")); //$NON-NLS-1$
+ grp.add(new ModeOption('c', Messages.getString("Main.Create"), Creator.class)); //$NON-NLS-1$
+ grp.add(new ModeOption('x', Messages.getString("Main.Extract"), Extractor.class)); //$NON-NLS-1$
+ grp.add(new ModeOption('t', Messages.getString("Main.List"), Lister.class)); //$NON-NLS-1$
+ grp.add(new ModeOption('u', Messages.getString("Main.Update"), Updater.class)); //$NON-NLS-1$
// Note that -i works in-place and explicitly requires a file name.
- grp.add(new ModeOption('i', "compute archive index", "FILE", Indexer.class));
+ grp.add(new ModeOption('i', Messages.getString("Main.Index"), Messages.getString("Main.FileArg"), Indexer.class)); //$NON-NLS-1$ //$NON-NLS-2$
p.add(grp);
- grp = new OptionGroup("Operation modifiers");
- grp.add(new Option('f', "specify archive file name", "FILE")
+ grp = new OptionGroup(Messages.getString("Main.OpMods")); //$NON-NLS-1$
+ grp.add(new Option('f', Messages.getString("Main.ArchiveName"), Messages.getString("Main.FileArg2")) //$NON-NLS-1$ //$NON-NLS-2$
{
public void parsed(String argument) throws OptionException
{
setArchiveFile(argument);
}
});
- grp.add(new Option('0', "store only; no ZIP compression")
+ grp.add(new Option('0', Messages.getString("Main.NoZip")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
storageMode = ZipOutputStream.STORED;
}
});
- grp.add(new Option('v', "verbose operation")
+ grp.add(new Option('v', Messages.getString("Main.Verbose")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
verbose = true;
}
});
- grp.add(new Option('M', "do not create a manifest file")
+ grp.add(new Option('M', Messages.getString("Main.NoManifest")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
wantManifest = false;
}
});
- grp.add(new Option('m', "specify manifest file", "FILE")
+ grp.add(new Option('m', Messages.getString("Main.ManifestName"), Messages.getString("Main.ManifestArgName")) //$NON-NLS-1$ //$NON-NLS-2$
{
public void parsed(String argument) throws OptionException
{
@@ -219,9 +223,9 @@ public class Main
// -@
p.add(grp);
- grp = new OptionGroup("File name selection");
- grp.add(new Option('C', "change to directory before the next file",
- "DIR FILE")
+ grp = new OptionGroup(Messages.getString("Main.FileNameGroup")); //$NON-NLS-1$
+ grp.add(new Option('C', Messages.getString("Main.ChangeDir"), //$NON-NLS-1$
+ Messages.getString("Main.ChangeDirArg")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
@@ -254,7 +258,7 @@ public class Main
}
catch (Exception e)
{
- System.err.println("jar: internal error:");
+ System.err.println(Messages.getString("Main.InternalError")); //$NON-NLS-1$
e.printStackTrace(System.err);
System.exit(1);
}
diff --git a/tools/gnu/classpath/tools/jar/Messages.java b/tools/gnu/classpath/tools/jar/Messages.java
new file mode 100644
index 000000000..ea54bd08f
--- /dev/null
+++ b/tools/gnu/classpath/tools/jar/Messages.java
@@ -0,0 +1,67 @@
+/* Messages.java -- localization support for jar
+ Copyright (C) 2006 Free Software Foundation, Inc.
+
+ This file is part of GNU Classpath.
+
+ GNU Classpath is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ GNU Classpath is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with GNU Classpath; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301 USA.
+
+ Linking this library statically or dynamically with other modules is
+ making a combined work based on this library. Thus, the terms and
+ conditions of the GNU General Public License cover the whole
+ combination.
+
+ As a special exception, the copyright holders of this library give you
+ permission to link this library with independent modules to produce an
+ executable, regardless of the license terms of these independent
+ modules, and to copy and distribute the resulting executable under
+ terms of your choice, provided that you also meet, for each linked
+ independent module, the terms and conditions of the license of that
+ module. An independent module is a module which is not derived from
+ or based on this library. If you modify this library, you may extend
+ this exception to your version of the library, but you are not
+ obligated to do so. If you do not wish to do so, delete this
+ exception statement from your version. */
+
+
+package gnu.classpath.tools.jar;
+
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
+public class Messages
+{
+ private static final String BUNDLE_NAME
+ = "gnu.classpath.tools.jar.messages"; //$NON-NLS-1$
+
+ private static final ResourceBundle RESOURCE_BUNDLE
+ = ResourceBundle.getBundle(BUNDLE_NAME);
+
+ private Messages()
+ {
+ }
+
+ public static String getString(String key)
+ {
+ try
+ {
+ return RESOURCE_BUNDLE.getString(key);
+ }
+ catch (MissingResourceException e)
+ {
+ return '!' + key + '!';
+ }
+ }
+}