This adds support in gjar for the @file argument as used by the OpenJDK build.
ChangeLog: 2008-06-02 Andrew John Hughes <[EMAIL PROTECTED]> * tools/gnu/classpath/tools/getopt/OptionException.java: (OptionException(String,Throwable)): New constructor. * tools/gnu/classpath/tools/jar/Main.java: (fileLists): New queue for streams containing lists of files. (HandleFile.NotifyFile(String)): Check for '@' arguments and add to stream queue. (parsed(String)): Add stdin to queue instead of setting flag. (readNames()): Work with the queue rather than just stdin. (run(String[])): Always execute readNames(). -- Andrew :) Support Free Java! Contribute to GNU Classpath and the OpenJDK http://www.gnu.org/software/classpath http://openjdk.java.net PGP Key: 94EFD9D8 (http://subkeys.pgp.net) Fingerprint = F8EF F1EA 401E 2E60 15FA 7927 142C 2591 94EF D9D8
Index: tools/gnu/classpath/tools/getopt/OptionException.java =================================================================== RCS file: /sources/classpath/classpath/tools/gnu/classpath/tools/getopt/OptionException.java,v retrieving revision 1.1 diff -u -u -r1.1 OptionException.java --- tools/gnu/classpath/tools/getopt/OptionException.java 8 May 2006 18:38:21 -0000 1.1 +++ tools/gnu/classpath/tools/getopt/OptionException.java 2 Jun 2008 22:22:04 -0000 @@ -49,4 +49,10 @@ { super(message); } + + public OptionException(String message, Throwable cause) + { + super(message, cause); + } + } Index: tools/gnu/classpath/tools/jar/Main.java =================================================================== RCS file: /sources/classpath/classpath/tools/gnu/classpath/tools/jar/Main.java,v retrieving revision 1.9 diff -u -u -r1.9 Main.java --- tools/gnu/classpath/tools/jar/Main.java 31 Jan 2007 17:05:34 -0000 1.9 +++ tools/gnu/classpath/tools/jar/Main.java 2 Jun 2008 22:22:04 -0000 @@ -47,10 +47,16 @@ import java.io.BufferedReader; import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.InputStream; import java.io.InputStreamReader; import java.io.IOException; + import java.text.MessageFormat; import java.util.ArrayList; +import java.util.LinkedList; +import java.util.Queue; import java.util.zip.ZipOutputStream; public class Main @@ -67,9 +73,6 @@ /** The zip storage mode. */ int storageMode = ZipOutputStream.DEFLATED; - /** True if we should read file names from stdin. */ - boolean readNamesFromStdin = false; - /** True for verbose mode. */ boolean verbose = false; @@ -85,6 +88,9 @@ /** Used only while parsing, holds the first argument for -C. */ String changedDirectory; + /** A queue of input streams from which to read lists of files. */ + private final Queue<InputStream> fileLists = new LinkedList<InputStream>(); + void setArchiveFile(String filename) throws OptionException { if (archiveFile != null) @@ -99,18 +105,32 @@ class HandleFile extends FileArgumentCallback { + @Override public void notifyFile(String fileArgument) + throws OptionException { - Entry entry; - if (changedDirectory != null) - { - entry = new Entry(new File(changedDirectory, fileArgument), - fileArgument); - changedDirectory = null; - } + if (fileArgument.charAt(0) == '@') + try + { + fileLists.offer(new FileInputStream(fileArgument.substring(1))); + } + catch (FileNotFoundException e) + { + throw new OptionException("File " + fileArgument + " not found.", e); + } else - entry = new Entry(new File(fileArgument)); - entries.add(entry); + { + Entry entry; + if (changedDirectory != null) + { + entry = new Entry(new File(changedDirectory, fileArgument), + fileArgument); + changedDirectory = null; + } + else + entry = new Entry(new File(fileArgument)); + entries.add(entry); + } } } @@ -176,7 +196,7 @@ { 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$ @@ -238,7 +258,7 @@ { public void parsed(String argument) throws OptionException { - readNamesFromStdin = true; + fileLists.offer(System.in); } }); p.add(grp); @@ -246,19 +266,26 @@ return p; } + /** + * Read the names of additional class files from + * [EMAIL PROTECTED] stdin} and/or files prefixed with [EMAIL PROTECTED] '@'}. + */ private void readNames() { - String line; - try - { - BufferedReader br - = new BufferedReader(new InputStreamReader(System.in)); - while ((line = br.readLine()) != null) - entries.add(new Entry(new File(line))); - } - catch (IOException _) + for (InputStream is : fileLists) { - // Ignore. + String line; + try + { + BufferedReader br + = new BufferedReader(new InputStreamReader(is)); + while ((line = br.readLine()) != null) + entries.add(new Entry(new File(line))); + } + catch (IOException _) + { + // Ignore. + } } } @@ -270,8 +297,7 @@ if (args.length > 0 && args[0].charAt(0) != '-') args[0] = '-' + args[0]; p.parse(args, new HandleFile()); - if (readNamesFromStdin) - readNames(); + readNames(); Action t = (Action) operationMode.newInstance(); t.run(this); }