summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew John Hughes <gnu_andrew@member.fsf.org>2008-06-06 00:27:01 +0000
committerAndrew John Hughes <gnu_andrew@member.fsf.org>2008-06-06 00:27:01 +0000
commitf09c91c3291f102ba52727a82031771d08603c2b (patch)
tree6db6fd29c5dc7f46ebe7db6d0af3b173b8371976
parent7cf521a28ef044f5bfb9c4a75b46085db6d420d2 (diff)
downloadclasspath-f09c91c3291f102ba52727a82031771d08603c2b.tar.gz
Backport gjar fix to 0.97.2
2008-06-06 Andrew John Hughes <gnu_andrew@member.fsf.org> * tools/gnu/classpath/tools/common/ClasspathToolParser.java: Fixed indentation and changed to use OptionException. * tools/gnu/classpath/tools/getopt/OptionException.java: (OptionException(String,Throwable)): Added. 2008-06-03 Robert Schuster <robertschuster@fsfe.org> * tools/gnu/classpath/tools/jar/Main.java: (run): Call different ClasspathToolParser.parse() variant. (getParser): Changed return type to ClasspathToolParser. * tools/gnu/classpath/tools/javah/GcjhMain.java: (getParser): Changed return type to ClasspathToolParser. * tools/gnu/classpath/tools/javah/Main.java: (getParser): Changed return type to ClasspathToolParser. * tools/gnu/classpath/tools/getopt/Parser.java: Make 'programName' protected. * tools/gnu/classpath/tools/common/ClasspathToolParser.java: (parse(String[], FileArgumentCallback,boolean): New method. (parse(String[], boolean): New method. (parseFileList): New method. (parseLine): New method. (AtFileArgumentCallback): New inner class. 2008-06-03 Andrew John Hughes <gnu_andrew@member.fsf.org> * tools/gnu/classpath/tools/getopt/OptionException.java, * tools/gnu/classpath/tools/jar/Main.java: Revert previous changes to allow Schuster's patch to do the same.
-rw-r--r--ChangeLog32
-rw-r--r--tools/gnu/classpath/tools/common/ClasspathToolParser.java152
-rw-r--r--tools/gnu/classpath/tools/jar/Main.java86
-rw-r--r--tools/gnu/classpath/tools/javah/GcjhMain.java7
-rw-r--r--tools/gnu/classpath/tools/javah/Main.java6
5 files changed, 221 insertions, 62 deletions
diff --git a/ChangeLog b/ChangeLog
index 27e8ae16c..6e259d07a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,37 @@
2008-06-06 Andrew John Hughes <gnu_andrew@member.fsf.org>
+ * tools/gnu/classpath/tools/common/ClasspathToolParser.java:
+ Fixed indentation and changed to use OptionException.
+ * tools/gnu/classpath/tools/getopt/OptionException.java:
+ (OptionException(String,Throwable)): Added.
+
+2008-06-03 Robert Schuster <robertschuster@fsfe.org>
+
+ * tools/gnu/classpath/tools/jar/Main.java:
+ (run): Call different ClasspathToolParser.parse() variant.
+ (getParser): Changed return type to ClasspathToolParser.
+ * tools/gnu/classpath/tools/javah/GcjhMain.java:
+ (getParser): Changed return type to ClasspathToolParser.
+ * tools/gnu/classpath/tools/javah/Main.java:
+ (getParser): Changed return type to ClasspathToolParser.
+ * tools/gnu/classpath/tools/getopt/Parser.java: Make 'programName'
+ protected.
+ * tools/gnu/classpath/tools/common/ClasspathToolParser.java:
+ (parse(String[], FileArgumentCallback,boolean): New method.
+ (parse(String[], boolean): New method.
+ (parseFileList): New method.
+ (parseLine): New method.
+ (AtFileArgumentCallback): New inner class.
+
+2008-06-03 Andrew John Hughes <gnu_andrew@member.fsf.org>
+
+ * tools/gnu/classpath/tools/getopt/OptionException.java,
+ * tools/gnu/classpath/tools/jar/Main.java:
+ Revert previous changes to allow Schuster's patch to
+ do the same.
+
+2008-06-06 Andrew John Hughes <gnu_andrew@member.fsf.org>
+
* java/lang/Integer.java:
(parseInt(String, int, boolean)): Disallow "-+".
diff --git a/tools/gnu/classpath/tools/common/ClasspathToolParser.java b/tools/gnu/classpath/tools/common/ClasspathToolParser.java
index e44b9011c..b2e508729 100644
--- a/tools/gnu/classpath/tools/common/ClasspathToolParser.java
+++ b/tools/gnu/classpath/tools/common/ClasspathToolParser.java
@@ -38,9 +38,16 @@ exception statement from your version. */
package gnu.classpath.tools.common;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.Reader;
import java.text.MessageFormat;
+import java.util.ArrayList;
import gnu.classpath.Configuration;
+import gnu.classpath.tools.getopt.FileArgumentCallback;
import gnu.classpath.tools.getopt.Option;
import gnu.classpath.tools.getopt.OptionException;
import gnu.classpath.tools.getopt.Parser;
@@ -84,4 +91,149 @@ public class ClasspathToolParser
}
});
}
+
+ public void parse(String[] inArgs, FileArgumentCallback files,
+ boolean handleFileLists)
+ {
+ FileArgumentCallback cb;
+
+ if (handleFileLists)
+ cb = new AtFileArgumentCallback(files);
+ else
+ cb = files;
+
+ parse(inArgs, cb);
+ }
+
+ public String[] parse(String[] inArgs, boolean handleFileLists)
+ {
+ final ArrayList<String> fileResult = new ArrayList<String>();
+
+ final FileArgumentCallback cb = new FileArgumentCallback()
+ {
+ public void notifyFile(String fileArgument)
+ {
+ fileResult.add(fileArgument);
+ }
+ };
+
+ if (handleFileLists)
+ parse(inArgs, new AtFileArgumentCallback(cb));
+ else
+ parse(inArgs, cb);
+
+ return fileResult.toArray(new String[fileResult.size()]);
+ }
+
+
+ /**
+ * Simple function that takes the given {@link Reader}, treats it like
+ * a textfile and reads all the whitespace separated entries from it
+ * and adds them to the @{link FileArgumentCallback} instance.
+ *
+ * @param reader the reader to read from.
+ * @param cb the callback to post the filenames to.
+ * @throws OptionException if an error occurs reading the list.
+ */
+ public void parseFileList(Reader reader, FileArgumentCallback cb)
+ throws OptionException
+ {
+ BufferedReader breader = new BufferedReader(reader);
+ String line = null;
+
+ try
+ {
+ while ((line = breader.readLine()) != null)
+ parseLine(line, cb);
+
+ reader.close();
+ }
+ catch (IOException ioe)
+ {
+ throw new OptionException("I/O error while reading a file list", ioe);
+ }
+
+ }
+
+ /**
+ * Parses whitespace separated file entries.
+ *
+ * Note: This is not coping with whitespace in files or quoting.
+ *
+ * @param line the line of the file to parse.
+ * @param cb the callback to pass the parsed file to.
+ * @throws IOException if an I/O error occurs.
+ * @throws OptionException if an error occurs in the callback.
+ */
+ private void parseLine(String line, FileArgumentCallback cb)
+ throws IOException, OptionException
+ {
+ final int length = line.length();
+ int start = 0;
+ int end = 0;
+
+ // While not reached end of line ...
+ while (start < length)
+ {
+ // Search for first non-whitespace character for the start of a word.
+ while (Character.isWhitespace(line.codePointAt(start)))
+ {
+ start++;
+
+ if (start == length)
+ return;
+ }
+
+ end = start + 1;
+
+ // Search for first whitespace character for the end of a word.
+ while (end < length && !Character.isWhitespace(line.codePointAt(end)))
+ end++;
+
+ cb.notifyFile(line.substring(start, end));
+
+ start = end + 1;
+ }
+ }
+
+ /**
+ * Implementation of {@link FileArgumentCallback} that handles
+ * file arguments in {@link #notifyFile} starting with a <code>@</code>
+ * through {@link ClasspathToolParser#parseFileList}.
+ */
+ class AtFileArgumentCallback extends FileArgumentCallback
+ {
+ FileArgumentCallback cb;
+
+ AtFileArgumentCallback(FileArgumentCallback cb)
+ {
+ this.cb = cb;
+ }
+
+ @Override
+ public void notifyFile(String fileArgument)
+ throws OptionException
+ {
+ if (fileArgument.codePointAt(0) == '@')
+ {
+ FileReader fr = null;
+
+ try
+ {
+ fr = new FileReader(fileArgument.substring(1));
+ }
+ catch (FileNotFoundException fnfe)
+ {
+ throw new OptionException("File not found: " + fileArgument.substring(1),
+ fnfe);
+ }
+
+ ClasspathToolParser.this.parseFileList(fr, cb);
+ }
+ else
+ cb.notifyFile(fileArgument);
+ }
+
+ }
+
}
diff --git a/tools/gnu/classpath/tools/jar/Main.java b/tools/gnu/classpath/tools/jar/Main.java
index 073f231c3..e5f1a3fb1 100644
--- a/tools/gnu/classpath/tools/jar/Main.java
+++ b/tools/gnu/classpath/tools/jar/Main.java
@@ -47,16 +47,10 @@ 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
@@ -73,6 +67,9 @@ 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;
@@ -88,9 +85,6 @@ 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)
@@ -105,32 +99,18 @@ public class Main
class HandleFile
extends FileArgumentCallback
{
- @Override
public void notifyFile(String fileArgument)
- throws OptionException
{
- if (fileArgument.charAt(0) == '@')
- try
- {
- fileLists.offer(new FileInputStream(fileArgument.substring(1)));
- }
- catch (FileNotFoundException e)
- {
- throw new OptionException("File " + fileArgument + " not found.", e);
- }
+ Entry entry;
+ if (changedDirectory != null)
+ {
+ entry = new Entry(new File(changedDirectory, fileArgument),
+ fileArgument);
+ changedDirectory = null;
+ }
else
- {
- 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);
- }
+ entry = new Entry(new File(fileArgument));
+ entries.add(entry);
}
}
@@ -192,11 +172,11 @@ public class Main
}
}
- private Parser initializeParser()
+ private ClasspathToolParser initializeParser()
{
- Parser p = new JarParser("jar"); //$NON-NLS-1$
+ ClasspathToolParser 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$
@@ -258,7 +238,7 @@ public class Main
{
public void parsed(String argument) throws OptionException
{
- fileLists.offer(System.in);
+ readNamesFromStdin = true;
}
});
p.add(grp);
@@ -266,38 +246,32 @@ public class Main
return p;
}
- /**
- * Read the names of additional class files from
- * {@code stdin} and/or files prefixed with {@code '@'}.
- */
private void readNames()
{
- for (InputStream is : fileLists)
+ 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 _)
{
- 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.
- }
+ // Ignore.
}
}
private void run(String[] args)
throws InstantiationException, IllegalAccessException, IOException
{
- Parser p = initializeParser();
+ ClasspathToolParser p = initializeParser();
// Special hack to emulate old tar-style commands.
if (args.length > 0 && args[0].charAt(0) != '-')
args[0] = '-' + args[0];
- p.parse(args, new HandleFile());
- readNames();
+ p.parse(args, new HandleFile(), true);
+ if (readNamesFromStdin)
+ readNames();
Action t = (Action) operationMode.newInstance();
t.run(this);
}
diff --git a/tools/gnu/classpath/tools/javah/GcjhMain.java b/tools/gnu/classpath/tools/javah/GcjhMain.java
index 7faed1691..15bcec263 100644
--- a/tools/gnu/classpath/tools/javah/GcjhMain.java
+++ b/tools/gnu/classpath/tools/javah/GcjhMain.java
@@ -38,10 +38,11 @@
package gnu.classpath.tools.javah;
+import gnu.classpath.tools.common.ClasspathToolParser;
+
import gnu.classpath.tools.getopt.Option;
import gnu.classpath.tools.getopt.OptionException;
import gnu.classpath.tools.getopt.OptionGroup;
-import gnu.classpath.tools.getopt.Parser;
import java.io.IOException;
import java.util.ArrayList;
@@ -60,9 +61,9 @@ public class GcjhMain extends Main
return "gcjh";
}
- protected Parser getParser()
+ protected ClasspathToolParser getParser()
{
- Parser result = super.getParser();
+ ClasspathToolParser result = super.getParser();
result.setHeader("usage: gcjh [OPTION]... CLASS...");
diff --git a/tools/gnu/classpath/tools/javah/Main.java b/tools/gnu/classpath/tools/javah/Main.java
index 66453b3bc..bfca44446 100644
--- a/tools/gnu/classpath/tools/javah/Main.java
+++ b/tools/gnu/classpath/tools/javah/Main.java
@@ -188,7 +188,7 @@ public class Main
return "javah";
}
- protected Parser getParser()
+ protected ClasspathToolParser getParser()
{
ClasspathToolParser result = new ClasspathToolParser(getName(), true);
result.setHeader("usage: javah [OPTIONS] CLASS...");
@@ -339,8 +339,8 @@ public class Main
protected void run(String[] args) throws IOException
{
- Parser p = getParser();
- String[] classNames = p.parse(args);
+ ClasspathToolParser p = getParser();
+ String[] classNames = p.parse(args, true);
postParse(classNames);
loader = classpath.getLoader();