diff options
author | Andrew John Hughes <gnu_andrew@member.fsf.org> | 2008-06-02 22:59:05 +0000 |
---|---|---|
committer | Andrew John Hughes <gnu_andrew@member.fsf.org> | 2008-06-02 22:59:05 +0000 |
commit | 8f24da8bef52a21f8b18d0883fb9514ff5f8b138 (patch) | |
tree | 65ed6c0cd75d6bdf20e052858d466bb49a77bb36 | |
parent | f96acb3407597642d4ce0ca828c8e39db128e10f (diff) | |
download | classpath-8f24da8bef52a21f8b18d0883fb9514ff5f8b138.tar.gz |
Backport gjar fix to 0.97 branch.
2008-06-02 Andrew John Hughes <gnu_andrew@member.fsf.org>
* 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().
-rw-r--r-- | ChangeLog | 12 | ||||
-rw-r--r-- | tools/gnu/classpath/tools/getopt/OptionException.java | 6 | ||||
-rw-r--r-- | tools/gnu/classpath/tools/jar/Main.java | 78 |
3 files changed, 70 insertions, 26 deletions
@@ -1,3 +1,15 @@ +2008-06-02 Andrew John Hughes <gnu_andrew@member.fsf.org> + + * 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(). + 2008-05-06 Andrew John Hughes <gnu_andrew@member.fsf.org> PR classpath/35482 diff --git a/tools/gnu/classpath/tools/getopt/OptionException.java b/tools/gnu/classpath/tools/getopt/OptionException.java index a09d716f4..2d7f77a55 100644 --- a/tools/gnu/classpath/tools/getopt/OptionException.java +++ b/tools/gnu/classpath/tools/getopt/OptionException.java @@ -49,4 +49,10 @@ public class OptionException { super(message); } + + public OptionException(String message, Throwable cause) + { + super(message, cause); + } + } diff --git a/tools/gnu/classpath/tools/jar/Main.java b/tools/gnu/classpath/tools/jar/Main.java index d52028fef..073f231c3 100644 --- a/tools/gnu/classpath/tools/jar/Main.java +++ b/tools/gnu/classpath/tools/jar/Main.java @@ -47,10 +47,16 @@ import gnu.classpath.tools.getopt.Parser; 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 @@ public class Main /** 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 @@ public class Main /** 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 @@ public class Main 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 @@ public class Main { 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 class Main { public void parsed(String argument) throws OptionException { - readNamesFromStdin = true; + fileLists.offer(System.in); } }); p.add(grp); @@ -246,19 +266,26 @@ public class Main return p; } + /** + * Read the names of additional class files from + * {@code stdin} and/or files prefixed with {@code '@'}. + */ 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 @@ public class Main 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); } |