I'm checking this in. This localizes the messages in jar.
Tom 2006-05-15 Tom Tromey <[EMAIL PROTECTED]> * 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. Index: tools/gnu/classpath/tools/jar/Creator.java =================================================================== RCS file: /cvsroot/classpath/classpath/tools/gnu/classpath/tools/jar/Creator.java,v retrieving revision 1.4 diff -u -r1.4 Creator.java --- tools/gnu/classpath/tools/jar/Creator.java 15 May 2006 01:57:29 -0000 1.4 +++ tools/gnu/classpath/tools/jar/Creator.java 15 May 2006 16:19:23 -0000 @@ -46,6 +46,7 @@ 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 @@ 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 @@ 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 @@ 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 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 { Index: tools/gnu/classpath/tools/jar/Extractor.java =================================================================== RCS file: /cvsroot/classpath/classpath/tools/gnu/classpath/tools/jar/Extractor.java,v retrieving revision 1.2 diff -u -r1.2 Extractor.java --- tools/gnu/classpath/tools/jar/Extractor.java 8 May 2006 23:51:49 -0000 1.2 +++ tools/gnu/classpath/tools/jar/Extractor.java 15 May 2006 16:19:23 -0000 @@ -44,6 +44,7 @@ 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 @@ // 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 @@ 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 @@ 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); } } } Index: tools/gnu/classpath/tools/jar/Indexer.java =================================================================== RCS file: /cvsroot/classpath/classpath/tools/gnu/classpath/tools/jar/Indexer.java,v retrieving revision 1.3 diff -u -r1.3 Indexer.java --- tools/gnu/classpath/tools/jar/Indexer.java 15 May 2006 01:57:29 -0000 1.3 +++ tools/gnu/classpath/tools/jar/Indexer.java 15 May 2006 16:19:23 -0000 @@ -44,6 +44,7 @@ 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 @@ 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 @@ { 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 @@ 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 @@ 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()); Index: tools/gnu/classpath/tools/jar/Main.java =================================================================== RCS file: /cvsroot/classpath/classpath/tools/gnu/classpath/tools/jar/Main.java,v retrieving revision 1.5 diff -u -r1.5 Main.java --- tools/gnu/classpath/tools/jar/Main.java 15 May 2006 01:57:29 -0000 1.5 +++ tools/gnu/classpath/tools/jar/Main.java 15 May 2006 16:19:23 -0000 @@ -47,6 +47,7 @@ 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 @@ 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 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 @@ 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..."); + Parser p = new JarParser("jar"); //$NON-NLS-1$ + p.setHeader(Messages.getString("Main.Usage")); //$NON-NLS-1$ - 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)); + 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 @@ // -@ 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 @@ } 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); } Index: resource/gnu/classpath/tools/jar/messages.properties =================================================================== RCS file: resource/gnu/classpath/tools/jar/messages.properties diff -N resource/gnu/classpath/tools/jar/messages.properties --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ resource/gnu/classpath/tools/jar/messages.properties 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,71 @@ +# messages.properties -- English language messages +# 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. + +Creator.Ignoring=ignoring entry {1} +Creator.Adding=adding: {1} (in={2,number,integer}) (out={3,number,integer}) (stored {4,number,integer}%) +Extractor.Created=\ \ created: {1} +Extractor.Extracted=\ extracted: {1} +Extractor.Inflated=\ \ inflated: {1} +Indexer.Indexing=indexing: {1} +Main.ArchiveAlreadySet=archive file name already set to {1} +Main.ModeAlreaySet=operation mode already specified +Main.MustSpecify=must specify one of -t, -c, -u, -x, or -i +Main.TwoArgsReqd=-C argument requires both directory and filename +Main.CantHaveBoth=can't specify both -m and -M +Main.NoFilesWithi=can't specify file arguments when using -i +Main.NoMAndi=can't specify -M with -i +Main.AnotherNomAndi=can't specify -m with -i +Main.Usage=Usage: jar -ctxui [OPTIONS] jar-file [-C DIR FILE] FILE... +Main.OpMode=Operation mode +Main.Create=create a new archive +Main.Extract=extract from archive +Main.List=list archive contents +Main.Update=update archive +Main.Index=compute archive index +Main.FileArg=FILE +Main.OpMods=Operation modifiers +Main.ArchiveName=specify archive file name +Main.FileArg2=FILE +Main.NoZip=store only; no ZIP compression +Main.Verbose=verbose operation +Main.NoManifest=do not create a manifest file +Main.ManifestName=specify manifest file +Main.ManifestArgName=FILE +Main.FileNameGroup=File name selection +Main.ChangeDir=change to directory before the next file +Main.ChangeDirArg=DIR FILE +Main.InternalError=jar: internal error: Index: tools/gnu/classpath/tools/jar/Messages.java =================================================================== RCS file: tools/gnu/classpath/tools/jar/Messages.java diff -N tools/gnu/classpath/tools/jar/Messages.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ tools/gnu/classpath/tools/jar/Messages.java 1 Jan 1970 00:00:00 -0000 @@ -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 + '!'; + } + } +}