summaryrefslogtreecommitdiff
path: root/tools/gnu/classpath/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools/gnu/classpath/tools')
-rw-r--r--tools/gnu/classpath/tools/appletviewer/AppletClassLoader.java81
-rw-r--r--tools/gnu/classpath/tools/appletviewer/AppletSecurityManager.java95
-rw-r--r--tools/gnu/classpath/tools/appletviewer/AppletTag.java485
-rw-r--r--tools/gnu/classpath/tools/appletviewer/AppletWarning.java66
-rw-r--r--tools/gnu/classpath/tools/appletviewer/CommonAppletContext.java133
-rw-r--r--tools/gnu/classpath/tools/appletviewer/CommonAppletStub.java138
-rw-r--r--tools/gnu/classpath/tools/appletviewer/ConsoleDialog.java175
-rw-r--r--tools/gnu/classpath/tools/appletviewer/ErrorApplet.java53
-rw-r--r--tools/gnu/classpath/tools/appletviewer/Main.java293
-rw-r--r--tools/gnu/classpath/tools/appletviewer/PluginAppletContext.java72
-rw-r--r--tools/gnu/classpath/tools/appletviewer/PluginAppletViewer.java172
-rw-r--r--tools/gnu/classpath/tools/appletviewer/PluginAppletWindow.java454
-rw-r--r--tools/gnu/classpath/tools/appletviewer/StandaloneAppletContext.java75
-rw-r--r--tools/gnu/classpath/tools/appletviewer/StandaloneAppletViewer.java144
-rw-r--r--tools/gnu/classpath/tools/appletviewer/StandaloneAppletWindow.java559
-rw-r--r--tools/gnu/classpath/tools/appletviewer/TagParser.java302
-rw-r--r--tools/gnu/classpath/tools/getopt/ClasspathToolParser.java73
-rw-r--r--tools/gnu/classpath/tools/getopt/FileArgumentCallback.java61
-rw-r--r--tools/gnu/classpath/tools/getopt/Messages.java67
-rw-r--r--tools/gnu/classpath/tools/getopt/Option.java200
-rw-r--r--tools/gnu/classpath/tools/getopt/OptionException.java52
-rw-r--r--tools/gnu/classpath/tools/getopt/OptionGroup.java271
-rw-r--r--tools/gnu/classpath/tools/getopt/Parser.java454
-rw-r--r--tools/gnu/classpath/tools/giop/GRMIC.java23
-rw-r--r--tools/gnu/classpath/tools/giop/GRMIC.txt24
-rw-r--r--tools/gnu/classpath/tools/giop/grmic/GiopRmicCompiler.java94
-rw-r--r--tools/gnu/classpath/tools/jar/Action.java51
-rw-r--r--tools/gnu/classpath/tools/jar/Creator.java247
-rw-r--r--tools/gnu/classpath/tools/jar/Entry.java60
-rw-r--r--tools/gnu/classpath/tools/jar/Extractor.java164
-rw-r--r--tools/gnu/classpath/tools/jar/Indexer.java144
-rw-r--r--tools/gnu/classpath/tools/jar/Lister.java90
-rw-r--r--tools/gnu/classpath/tools/jar/Main.java266
-rw-r--r--tools/gnu/classpath/tools/jar/Messages.java67
-rw-r--r--tools/gnu/classpath/tools/jar/Updater.java91
-rw-r--r--tools/gnu/classpath/tools/jarsigner/JarSigner.java2
-rw-r--r--tools/gnu/classpath/tools/jarsigner/Main.java269
-rw-r--r--tools/gnu/classpath/tools/jarsigner/jarsigner.txt116
-rw-r--r--tools/gnu/classpath/tools/keytool/CertReqCmd.java167
-rw-r--r--tools/gnu/classpath/tools/keytool/Command.java41
-rw-r--r--tools/gnu/classpath/tools/keytool/DeleteCmd.java114
-rw-r--r--tools/gnu/classpath/tools/keytool/ExportCmd.java168
-rw-r--r--tools/gnu/classpath/tools/keytool/GenKeyCmd.java197
-rw-r--r--tools/gnu/classpath/tools/keytool/IdentityDBCmd.java126
-rw-r--r--tools/gnu/classpath/tools/keytool/ImportCmd.java168
-rw-r--r--tools/gnu/classpath/tools/keytool/KeyCloneCmd.java160
-rw-r--r--tools/gnu/classpath/tools/keytool/KeyPasswdCmd.java141
-rw-r--r--tools/gnu/classpath/tools/keytool/ListCmd.java130
-rw-r--r--tools/gnu/classpath/tools/keytool/Main.java231
-rw-r--r--tools/gnu/classpath/tools/keytool/PrintCertCmd.java73
-rw-r--r--tools/gnu/classpath/tools/keytool/SelfCertCmd.java194
-rw-r--r--tools/gnu/classpath/tools/keytool/StorePasswdCmd.java114
-rw-r--r--tools/gnu/classpath/tools/keytool/keytool.txt616
-rw-r--r--tools/gnu/classpath/tools/rmi/RMIC.java25
-rw-r--r--tools/gnu/classpath/tools/rmi/RMIC.txt36
55 files changed, 7375 insertions, 1509 deletions
diff --git a/tools/gnu/classpath/tools/appletviewer/AppletClassLoader.java b/tools/gnu/classpath/tools/appletviewer/AppletClassLoader.java
new file mode 100644
index 000000000..dfbedfe36
--- /dev/null
+++ b/tools/gnu/classpath/tools/appletviewer/AppletClassLoader.java
@@ -0,0 +1,81 @@
+/* AppletClassLoader -- a loader for applet classes
+ Copyright (C) 2004, 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.appletviewer;
+
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.ArrayList;
+
+public class AppletClassLoader extends URLClassLoader
+{
+ /**
+ * Constructs a new <code>AppletLoader</code> object.
+ *
+ * @param codebase the codebase of the applet
+ * @param archives the urls to add to the search path
+ */
+ public AppletClassLoader(URL codebase, ArrayList archives)
+ {
+ super(new URL[0]);
+
+ for (int count = 0; count < archives.size(); count++)
+ addURL((URL) archives.get(count));
+
+ addURL(codebase);
+ }
+
+ /**
+ * Finds the specified class. This method should be overridden by
+ * class loader implementations that follow the delegation model for
+ * loading classes, and will be invoked by the loadClass method after
+ * checking the parent class loader for the requested class. The default
+ * implementation throws a ClassNotFoundException.
+ *
+ * (description copied from java.lang.ClassLoader.findClass(String))
+ *
+ * @param name The name of the class.
+ *
+ * @return the resulting <code>Class</code> object.
+ *
+ * @exception ClassNotFoundException if the class is not found.
+ */
+ protected Class findClass(String name) throws ClassNotFoundException
+ {
+ return super.findClass(name);
+ }
+}
diff --git a/tools/gnu/classpath/tools/appletviewer/AppletSecurityManager.java b/tools/gnu/classpath/tools/appletviewer/AppletSecurityManager.java
new file mode 100644
index 000000000..32ab31639
--- /dev/null
+++ b/tools/gnu/classpath/tools/appletviewer/AppletSecurityManager.java
@@ -0,0 +1,95 @@
+/* AppletSecurityManager.java -- an applet security manager
+ Copyright (C) 2004, 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.appletviewer;
+
+import java.io.FilePermission;
+import java.net.SocketPermission;
+import java.security.Permission;
+import java.security.SecurityPermission;
+import java.util.PropertyPermission;
+
+class AppletSecurityManager extends SecurityManager
+{
+ private boolean plugin;
+
+ AppletSecurityManager(boolean plugin)
+ {
+ this.plugin = plugin;
+ }
+
+ public void checkPermission(Permission permission)
+ {
+ if (permission == null)
+ throw new NullPointerException();
+
+ // FIXME: we need to restrict this.
+ //
+ // libgcj asks for "java.io.FilePermission <<ALL FILES>> execute"
+ // to be able to execute "addr2line" to get proper stack traces.
+ if (permission instanceof FilePermission)
+ return;
+
+ // FIXME: we need to restrict this.
+ if (permission instanceof SecurityPermission)
+ return;
+
+ // FIXME: is this really needed ?
+ if (permission instanceof PropertyPermission)
+ return;
+
+ // Needed to allow to access AWT event queue.
+ if (permission.getName().equals("accessEventQueue"))
+ return;
+
+ // Needed to create a class loader for each codebase.
+ if (permission.getName().equals("createClassLoader"))
+ return;
+
+ // FIXME: we need to allow access to codebase here.
+
+ if (permission instanceof SocketPermission // for net access
+ || permission instanceof RuntimePermission) // for checkWrite(FileDescriptor)
+ return;
+
+ if (! plugin && permission.getName().equals("exitVM"))
+ return;
+
+ // Reject all other permissions.
+ throw new SecurityException();
+ }
+}
diff --git a/tools/gnu/classpath/tools/appletviewer/AppletTag.java b/tools/gnu/classpath/tools/appletviewer/AppletTag.java
new file mode 100644
index 000000000..b2d7ccb2b
--- /dev/null
+++ b/tools/gnu/classpath/tools/appletviewer/AppletTag.java
@@ -0,0 +1,485 @@
+/* AppletTag.java -- a representation of an HTML APPLET tag
+ Copyright (C) 2003, 2004, 2005, 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.appletviewer;
+
+import gnu.xml.dom.html2.DomHTMLAppletElement;
+import gnu.xml.dom.html2.DomHTMLEmbedElement;
+import gnu.xml.dom.html2.DomHTMLObjectElement;
+
+import java.awt.Dimension;
+import java.awt.Toolkit;
+
+import java.io.File;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import java.text.NumberFormat;
+import java.text.ParseException;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Locale;
+
+/**
+ * @author Lillian Angel (langel@redhat.com)
+ * @author Thomas Fitzsimmons (fitzsim@redhat.com)
+ */
+class AppletTag
+{
+
+ /**
+ * The document base of this applet.
+ */
+ URL documentbase;
+
+ /**
+ * name of applet tag.
+ */
+ String name = "";
+
+ /**
+ * code of applet tag.
+ */
+ String code = "";
+
+ /**
+ * codebase of applet tag.
+ */
+ String codebase = "";
+
+ /**
+ * The archives.
+ */
+ ArrayList archives = new ArrayList();
+
+ /**
+ * The parameters.
+ */
+ HashMap parameters = new HashMap();
+
+ /**
+ * The screen size.
+ */
+ Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
+
+ /**
+ * Default constructor.
+ */
+ AppletTag()
+ {
+ // Do nothing.
+ }
+
+ /**
+ * Constructs an AppletTag and parses the given applet element.
+ *
+ * @param appElement - the Applet element to parse.
+ */
+ AppletTag(DomHTMLAppletElement appElement)
+ {
+ name = appElement.getName();
+ parameters.put("name", name);
+
+ parameters.put("object", appElement.getObject());
+ parameters.put("align", appElement.getAlign());
+ parameters.put("alt", appElement.getAlt());
+ parameters.put("height", appElement.getHeight());
+ parameters.put("hspace", Integer.toString(appElement.getHspace()));
+ parameters.put("vspace", Integer.toString(appElement.getVspace()));
+ parameters.put("width", appElement.getWidth());
+
+ TagParser.parseParams(appElement, this);
+
+ if (code.equals(""))
+ {
+ code = appElement.getCode();
+ if (code.equals(""))
+ code = appElement.getCls();
+ }
+
+ // Must initialize codebase before archives
+ if (codebase.equals(""))
+ {
+ codebase = appElement.getCodeBase();
+ if (codebase.equals(""))
+ codebase = appElement.getSrc();
+ }
+
+ if (archives.size() == 0)
+ {
+ String arcs = "";
+ String arch = appElement.getArchive();
+
+ if (code.indexOf(".") < 0)
+ arcs = code + ".jar";
+
+ if (!arch.equals(""))
+ arcs += "," + arch;
+
+ if (!arcs.equals(""))
+ archives = TagParser.parseArchives(arcs, this);
+ }
+ }
+
+ /**
+ * Constructs an AppletTag and parses the given embed element.
+ *
+ * @param embElement - the Embed element to parse.
+ */
+ AppletTag(DomHTMLEmbedElement embElement)
+ {
+ // In an EMBED tag, a parameter is any non-standard attribute. This
+ // is a problem for applets that take parameters named "code",
+ // "codebase", "archive", "object", or "type". The solution is to
+ // allow the same attributes, prefixed by "java_". The presence of
+ // a "java_" attribute indicates that the non-prefixed attribute
+ // should be interpreted as a parameter. For example if "java_code"
+ // and "code" attributes are present in the EMBED tag then the
+ // "code" attribute is interpreted as a parameter.
+
+ name = embElement.getName();
+ parameters.put("name", name);
+
+ String jobj = embElement.getJavaObject();
+ if (!jobj.equals(""))
+ parameters.put("java_object", jobj);
+ else
+ parameters.put("object", embElement.getObject());
+
+ parameters.put("width", embElement.getWidth());
+ parameters.put("height", embElement.getHeight());
+ parameters.put("align", embElement.getAlign());
+ parameters.put("alt", embElement.getAlt());
+ parameters.put("hspace", Integer.toString(embElement.getHspace()));
+ parameters.put("mayscript", embElement.getMayscript());
+ parameters.put("pluginspage", embElement.getPluginsPage());
+ parameters.put("title", embElement.getTitle());
+ parameters.put("type", embElement.getType());
+ parameters.put("java_type", embElement.getJavaType());
+ parameters.put("vspace", Integer.toString(embElement.getVspace()));
+
+ TagParser.parseParams(embElement, this);
+
+ // Must initialize codebase before archives
+ if (codebase.equals(""))
+ {
+ String javacb = embElement.getJavaCodeBase();
+ if (!javacb.equals(""))
+ codebase = javacb;
+ else
+ codebase = embElement.getCodeBase();
+ }
+
+ if (code.equals(""))
+ {
+ String jcode = embElement.getJavaCode();
+ if (!jcode.equals(""))
+ code = jcode;
+ else
+ code = embElement.getCode();
+ }
+
+ if (archives.size() == 0)
+ {
+ String arcs = "";
+ String jarch = embElement.getJavaArchive();
+ String arch = embElement.getArchive();
+
+ if (code.indexOf(".") < 0)
+ arcs = code + ".jar";
+
+ if (!jarch.equals(""))
+ arcs += "," + jarch;
+ else if (!arch.equals(""))
+ arcs += "," + arch;
+
+ if (!arcs.equals(""))
+ archives = TagParser.parseArchives(arcs, this);
+ }
+ }
+
+ /**
+ * Constructs an AppletTag and parses the given object element.
+ *
+ * @param objElement - the Object element to parse.
+ */
+ AppletTag(DomHTMLObjectElement objElement)
+ {
+ // In an OBJECT tag, a parameter is any non-standard attribute. This
+ // is a problem for applets that take parameters named "code",
+ // "codebase", "archive", "object", or "type". The solution is to
+ // allow the same attributes, prefixed by "java_". The presence of
+ // a "java_" attribute indicates that the non-prefixed attribute
+ // should be interpreted as a parameter. For example if "java_code"
+ // and "code" attributes are present in the OBJECT tag then the
+ // "code" attribute is interpreted as a parameter.
+
+ name = objElement.getName();
+ parameters.put("name", name);
+
+ String jobj = objElement.getJavaObject();
+ if (!jobj.equals(""))
+ parameters.put("java_object", jobj);
+ else
+ parameters.put("object", objElement.getObject());
+
+ parameters.put("type", objElement.getType());
+ parameters.put("java_type", objElement.getJavaType());
+ parameters.put("align", objElement.getAlign());
+ parameters.put("codetype", objElement.getCodeType());
+ parameters.put("data", objElement.getData());
+ parameters.put("declare", Boolean.toString(objElement.getDeclare()));
+ parameters.put("height", objElement.getHeight());
+ parameters.put("hspace", Integer.toString(objElement.getHspace()));
+ parameters.put("border", objElement.getBorder());
+ parameters.put("standby", objElement.getStandby());
+ parameters.put("tabindex", Integer.toString(objElement.getTabIndex()));
+ parameters.put("usemap", objElement.getUseMap());
+ parameters.put("vspace", Integer.toString(objElement.getVspace()));
+ parameters.put("width", objElement.getWidth());
+ parameters.put("mayscript", objElement.getMayscript());
+ parameters.put("scriptable", objElement.getScriptable());
+
+ TagParser.parseParams(objElement, this);
+
+ // Must initialize codebase before archives
+ if (codebase.equals(""))
+ {
+ String javacb = objElement.getJavaCodeBase();
+ if (! javacb.equals(""))
+ codebase = javacb;
+ else
+ codebase = objElement.getCodeBase();
+ }
+
+ if (code.equals(""))
+ {
+ String jcode = objElement.getJavaCode();
+ if (!jcode.equals(""))
+ code = jcode;
+ else
+ code = objElement.getCode();
+ }
+
+ if (archives.size() == 0)
+ {
+ String arcs = "";
+ String jarch = objElement.getJavaArchive();
+ String arch = objElement.getArchive();
+
+ if (code.indexOf(".") < 0)
+ arcs = code + ".jar";
+
+ if (!jarch.equals(""))
+ arcs += "," + jarch;
+ else if (!arch.equals(""))
+ arcs += "," + arch;
+
+ if (!arcs.equals(""))
+ archives = TagParser.parseArchives(arcs, this);
+ }
+ }
+
+ /**
+ * String representation of the tag.
+ *
+ * @return the string representation.
+ */
+ public String toString()
+ {
+ return (" name=" + name + "\n" + " code=" + code + "\n" + " codebase="
+ + codebase + "\n" + " archive=" + archives + "\n" + " parameters="
+ + parameters + "\n" + " documentbase=" + documentbase + "\n");
+ }
+
+ /**
+ * Returns the size of the applet.
+ *
+ * @return the size.
+ */
+ Dimension getSize()
+ {
+ Dimension size = new Dimension(320, 200);
+
+ try
+ {
+ String widthStr = (String) parameters.get("width");
+
+ if (widthStr != null && ! widthStr.equals(""))
+ {
+ if (widthStr.charAt(widthStr.length() - 1) == '%')
+ {
+ double p = NumberFormat.getPercentInstance(Locale.US).parse(widthStr).intValue() / 100.0;
+ size.width = (int)(p * screenSize.width);
+ }
+ else
+ size.width = NumberFormat.getInstance(Locale.US).parse(widthStr).intValue();
+ }
+ }
+ catch (ParseException e)
+ {
+ // Use default.
+ }
+
+ try
+ {
+ String heightStr = (String) parameters.get("height");
+
+ if (heightStr != null && !heightStr.equals(""))
+ {
+ if (heightStr.charAt(heightStr.length() - 1) == '%')
+ {
+ double p = NumberFormat.getPercentInstance(Locale.US).parse(heightStr).intValue() / 100.0;
+ size.height = (int) (p * screenSize.height);
+ }
+ else
+ size.height = NumberFormat.getInstance(Locale.US).parse(heightStr).intValue();
+ }
+ }
+ catch (ParseException e)
+ {
+ // Use default.
+ }
+
+ return size;
+ }
+
+ /**
+ * Gets the code base.
+ *
+ * @return the codebase.
+ */
+ String getCodeBase()
+ {
+ return codebase;
+ }
+
+ /**
+ * Gets the archive list.
+ *
+ * @return the archive list.
+ */
+ ArrayList getArchives()
+ {
+ return archives;
+ }
+
+ /**
+ * Gets the code.
+ *
+ * @return the code.
+ */
+ String getCode()
+ {
+ return code;
+ }
+
+ /**
+ * Gets the document base.
+ *
+ * @return the document base.
+ */
+ URL getDocumentBase()
+ {
+ return documentbase;
+ }
+
+ /**
+ * Gets the specified parameter.
+ *
+ * @param name - the specified parameter.
+ * @return the parameter.
+ */
+ String getParameter(String name)
+ {
+ return (String) parameters.get(name.toLowerCase());
+ }
+
+ /**
+ * Prepends the base to the codebase.
+ *
+ * @return the new URL.
+ */
+ URL prependCodeBase(String base) throws MalformedURLException
+ {
+ if (documentbase == null)
+ documentbase = TagParser.db;
+
+ URL fullcodebase;
+
+ //If no codebase was specified, default to documentbase.
+ if (codebase.equals(""))
+ {
+ if (documentbase.getFile().endsWith(File.separator))
+ fullcodebase = documentbase;
+ else
+ {
+ String dirname = documentbase.getFile();
+
+ // Determine dirname for file by stripping everything
+ // past the last file separator.
+ dirname = dirname.substring(0,
+ dirname.lastIndexOf(File.separatorChar) + 1);
+
+ fullcodebase = new URL(documentbase.getProtocol(),
+ documentbase.getHost(),
+ documentbase.getPort(), dirname);
+ }
+ }
+ else
+ {
+ // codebase was specified.
+ URL codebaseURL = new URL(documentbase, codebase);
+
+ if ("file".equals(codebaseURL.getProtocol()))
+ {
+ if (new File(codebaseURL.getFile()).isDirectory() && !codebase.endsWith(File.separator))
+ fullcodebase = new URL(documentbase, codebase + File.separator);
+ else
+ fullcodebase = new URL(documentbase, codebase);
+ }
+ else if (codebase.endsWith(File.separator))
+ fullcodebase = new URL(documentbase, codebase);
+ else
+ fullcodebase = new URL(documentbase, codebase + File.separator);
+ }
+
+ return new URL(fullcodebase, base);
+ }
+}
diff --git a/tools/gnu/classpath/tools/appletviewer/AppletWarning.java b/tools/gnu/classpath/tools/appletviewer/AppletWarning.java
new file mode 100644
index 000000000..b2376a4cb
--- /dev/null
+++ b/tools/gnu/classpath/tools/appletviewer/AppletWarning.java
@@ -0,0 +1,66 @@
+/* AppletWarning -- a security warning message display dialog
+ Copyright (C) 2003, 2004, 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.appletviewer;
+
+import javax.swing.JOptionPane;
+
+/**
+ * @author Michael Koch (konqueror@gmx.de)
+ */
+public class AppletWarning
+{
+ private static String TITLE = "WARNING";
+ private static boolean showWarning = false;
+
+ private static String MESSAGE =
+ "The current version of this applet plugin does not provide\n" +
+ "a security manager capable of handling Java (tm) applets. Applets\n" +
+ "have UNRESTRICTED access to your computer. This means they can do\n" +
+ "anything you can do, like deleting all your important data.\n\n" +
+ "Continue ?";
+
+ public static int show()
+ {
+ if (showWarning)
+ return JOptionPane.showConfirmDialog(null, MESSAGE, TITLE,
+ JOptionPane.YES_NO_OPTION,
+ JOptionPane.WARNING_MESSAGE);
+ else
+ return JOptionPane.YES_OPTION;
+ }
+}
diff --git a/tools/gnu/classpath/tools/appletviewer/CommonAppletContext.java b/tools/gnu/classpath/tools/appletviewer/CommonAppletContext.java
new file mode 100644
index 000000000..7e118e931
--- /dev/null
+++ b/tools/gnu/classpath/tools/appletviewer/CommonAppletContext.java
@@ -0,0 +1,133 @@
+/* CommonAppletContext.java -- a common applet's context
+ Copyright (C) 2004, 2005, 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.appletviewer;
+
+import java.applet.Applet;
+import java.applet.AppletContext;
+import java.applet.AudioClip;
+import java.awt.Image;
+import java.awt.Toolkit;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+
+
+/*
+ * CommonAppletContext represents the common context stuff for both
+ * types, plugins and standalone.
+ */
+abstract class CommonAppletContext
+ implements AppletContext
+{
+ // FIXME: this needs to be static, and we need one AppletContext per
+ // Applet.
+ List applets = new ArrayList();
+ HashMap streams = new HashMap();
+
+ void addApplet(Applet applet)
+ {
+ applets.add(applet);
+ }
+
+ ///////////////////////////////
+ //// AppletContext methods ////
+ ///////////////////////////////
+ public AudioClip getAudioClip(URL url)
+ {
+ return Applet.newAudioClip(url);
+ }
+
+ public Image getImage(URL url)
+ {
+ return Toolkit.getDefaultToolkit().getImage(url);
+ }
+
+ public Applet getApplet(String name)
+ {
+ Applet a;
+ String appletName;
+ Iterator i = applets.iterator();
+
+ while (i.hasNext())
+ {
+ a = (Applet) i.next();
+
+ appletName = a.getParameter("name");
+ if (a != null && appletName != null && appletName.equals(name))
+ return a;
+ }
+ return null;
+ }
+
+ public Enumeration getApplets()
+ {
+ return Collections.enumeration(applets);
+ }
+
+ public void showDocument(URL url)
+ {
+ showDocument(url, "_self");
+ }
+
+ /*
+ // FIXME: implement.
+ public abstract void showDocument (URL url, String target);
+
+ // FIXME: implement.
+ public abstract void showStatus (String status);
+ */
+ public void setStream(String key, InputStream stream)
+ {
+ streams.put(key, stream);
+ }
+
+ public InputStream getStream(String key)
+ {
+ return (InputStream) streams.get(key);
+ }
+
+ public Iterator getStreamKeys()
+ {
+ return streams.keySet().iterator();
+ }
+}
diff --git a/tools/gnu/classpath/tools/appletviewer/CommonAppletStub.java b/tools/gnu/classpath/tools/appletviewer/CommonAppletStub.java
new file mode 100644
index 000000000..bc0cc45e1
--- /dev/null
+++ b/tools/gnu/classpath/tools/appletviewer/CommonAppletStub.java
@@ -0,0 +1,138 @@
+/* CommonAppletStub.java -- an applet-browser interface class
+ Copyright (C) 2003, 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.appletviewer;
+
+import java.applet.AppletContext;
+import java.applet.AppletStub;
+import java.applet.Applet;
+import java.net.MalformedURLException;
+import java.net.URL;
+
+
+class CommonAppletStub
+ implements AppletStub
+{
+ private AppletTag tag;
+ private AppletContext context;
+ private Applet applet;
+
+ CommonAppletStub(AppletTag tag, AppletContext context, Applet applet)
+ {
+ this.tag = tag;
+ this.context = context;
+ this.applet = applet;
+ }
+
+ ////////////////////////////////
+ ////// AppletStub Methods //////
+ ////////////////////////////////
+
+ /**
+ * Tests whether or not this applet is currently active. An applet
+ * becomes active just before the browser invokes start (), and
+ * becomes inactive just before the browser invokes stop ().
+ *
+ * @return true if applet is active, false otherwise
+ */
+ public boolean isActive()
+ {
+ return true;
+ }
+
+ /**
+ * Returns the basename URL of the document in which this applet is
+ * embedded.
+ *
+ * @return the document base url.
+ */
+ public URL getDocumentBase()
+ {
+ return tag.getDocumentBase();
+ }
+
+ /**
+ * Returns the URL of the code base for this applet.
+ *
+ * @return the codebase url
+ */
+ public URL getCodeBase()
+ {
+ try
+ {
+ return tag.prependCodeBase("");
+ }
+ catch (MalformedURLException e)
+ {
+ throw new RuntimeException("unknown codebase");
+ }
+ }
+
+ /**
+ * Returns the value of the specified parameter that was specified
+ * in the <code>APPLET</code> tag for this applet.
+ *
+ * @param name the key name
+ *
+ * @return the key value
+ */
+ public String getParameter(String name)
+ {
+ return (String) tag.getParameter(name.toLowerCase());
+ }
+
+ /**
+ * Returns the applet context for this applet.
+ *
+ * @return the context
+ */
+ public AppletContext getAppletContext()
+ {
+ return context;
+ }
+
+ /**
+ * Requests that the applet window for this applet be resized.
+ *
+ * @param width the new witdh
+ * @param height the new height
+ */
+ public void appletResize(int width, int height)
+ {
+ applet.setBounds (0, 0, width, height);
+ }
+}
diff --git a/tools/gnu/classpath/tools/appletviewer/ConsoleDialog.java b/tools/gnu/classpath/tools/appletviewer/ConsoleDialog.java
new file mode 100644
index 000000000..9c937cc77
--- /dev/null
+++ b/tools/gnu/classpath/tools/appletviewer/ConsoleDialog.java
@@ -0,0 +1,175 @@
+/* ConsoleDialog -- a console dialog for applets
+ Copyright (C) 2003, 2004, 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.appletviewer;
+
+import java.awt.BorderLayout;
+import java.awt.Button;
+import java.awt.FlowLayout;
+import java.awt.Frame;
+import java.awt.Panel;
+import java.awt.TextArea;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.PrintStream;
+
+
+/**
+ * This class is a little dialog showing standard output and standard error output.
+ *
+ * @author Michael Koch (konqueror@gmx.de)
+ */
+public class ConsoleDialog extends Frame
+ implements ActionListener
+{
+ static class InternalOutputStream extends OutputStream
+ {
+ private ConsoleDialog console;
+
+ public InternalOutputStream(ConsoleDialog console)
+ {
+ super();
+ this.console = console;
+ }
+
+ public void write(int data) throws IOException
+ {
+ console.print(String.valueOf((char) data));
+ }
+ }
+
+ private TextArea textArea;
+ private Button buttonClear;
+ private Button buttonHide;
+ private PrintStream printStream;
+
+ /**
+ * Creates a console dialog object.
+ */
+ public ConsoleDialog()
+ {
+ super(Main.messages.getString("gcjwebplugin.console_title"));
+
+ setSize(400, 200);
+ setLayout(new BorderLayout());
+ addWindowListener(new WindowAdapter()
+ {
+ public void windowClosing(WindowEvent event)
+ {
+ hide();
+ }
+ });
+
+ textArea = new TextArea();
+ textArea.setEditable(false);
+ add(textArea);
+
+ Panel panel = new Panel();
+ panel.setLayout(new FlowLayout());
+ add(panel, BorderLayout.SOUTH);
+
+ buttonClear = new Button(Main.messages.getString("gcjwebplugin.console_clear"));
+ buttonClear.addActionListener(this);
+ panel.add(buttonClear);
+
+ buttonHide = new Button(Main.messages.getString("gcjwebplugin.console_hide"));
+ buttonHide.addActionListener(this);
+ panel.add(buttonHide);
+
+ printStream = new PrintStream(new InternalOutputStream(this));
+ clearTextArea();
+ }
+
+ /**
+ * Clears the content of the textarea and inserts the initial text.
+ */
+ public void clearTextArea()
+ {
+ textArea.setText("");
+
+ println("java.vm.version: " + System.getProperty("java.vm.version"));
+ println("java.vm.vendor: " + System.getProperty("java.vm.vendor"));
+ }
+
+ /**
+ * Print a message into the console dialog.
+ *
+ * @param message the message to print.
+ */
+ public void print(String message)
+ {
+ textArea.append(message);
+ }
+
+ /**
+ * Print a line into the console dialog.
+ *
+ * @param message the line to print.
+ */
+ public void println(String message)
+ {
+ print(message + "\n");
+ }
+
+ /**
+ * Perform actions on button clicks inside the console dialog.
+ *
+ * @param event the event.
+ */
+ public void actionPerformed(ActionEvent event)
+ {
+ if (event.getSource() == buttonHide)
+ hide(); // Hide console window.
+ else if (event.getSource() == buttonClear)
+ clearTextArea(); // Clear text area and insert standard messages.
+ }
+
+ /**
+ * Returns a <code>PrintStream</code> object that prints into the
+ * console dialog.
+ *
+ * @return the <code>PrintStream</code> object.
+ */
+ public PrintStream getPrintStream()
+ {
+ return printStream;
+ }
+}
diff --git a/tools/gnu/classpath/tools/appletviewer/ErrorApplet.java b/tools/gnu/classpath/tools/appletviewer/ErrorApplet.java
new file mode 100644
index 000000000..059dbee40
--- /dev/null
+++ b/tools/gnu/classpath/tools/appletviewer/ErrorApplet.java
@@ -0,0 +1,53 @@
+/* ErrorApplet.java -- an applet to load in case of an error
+ Copyright (C) 2004, 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.appletviewer;
+
+import java.applet.Applet;
+import java.awt.BorderLayout;
+import java.awt.Button;
+
+public class ErrorApplet extends Applet
+{
+ public ErrorApplet(String message)
+ {
+ setLayout(new BorderLayout());
+
+ Button button = new Button(message);
+ add(button);
+ }
+}
diff --git a/tools/gnu/classpath/tools/appletviewer/Main.java b/tools/gnu/classpath/tools/appletviewer/Main.java
new file mode 100644
index 000000000..1d9fed2b0
--- /dev/null
+++ b/tools/gnu/classpath/tools/appletviewer/Main.java
@@ -0,0 +1,293 @@
+/* Main.java -- a standalone viewer for Java applets
+ Copyright (C) 2003, 2004, 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.appletviewer;
+
+import gnu.classpath.tools.getopt.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.applet.Applet;
+import java.awt.Dimension;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.ResourceBundle;
+
+
+class Main
+{
+ /**
+ * The localized strings are kept in a separate file.
+ */
+ public static final ResourceBundle messages = ResourceBundle.getBundle
+ ("gnu.classpath.tools.appletviewer.MessagesBundle");
+
+ private static HashMap classLoaderCache = new HashMap();
+
+ private static ClassLoader getClassLoader(URL codebase, ArrayList archives)
+ {
+ // Should load class loader each time. It is possible that there
+ // are more than one applet to be loaded with different archives.
+ AppletClassLoader loader = new AppletClassLoader(codebase, archives);
+ classLoaderCache.put(codebase, loader);
+
+ return loader;
+ }
+
+ private static String code = null;
+ private static String codebase = null;
+ private static String archive = null;
+ private static List parameters = new ArrayList();
+ private static Dimension dimensions = new Dimension(-1, -1);
+ private static String pipeInName = null;
+ private static String pipeOutName = null;
+ private static boolean pluginMode = false;
+ private static Parser parser = null;
+
+ static Applet createApplet(AppletTag tag)
+ {
+ Applet applet = null;
+
+ try
+ {
+ ClassLoader loader = getClassLoader(tag.prependCodeBase(""),
+ tag.getArchives());
+ String code = tag.getCode();
+
+ if (code.endsWith(".class"))
+ code = code.substring(0, code.length() - 6).replace('/', '.');
+
+ Class c = loader.loadClass(code);
+ applet = (Applet) c.newInstance();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+
+ if (applet == null)
+ applet = new ErrorApplet("Error loading applet");
+
+ return applet;
+ }
+
+ protected static boolean verbose;
+
+ /**
+ * The main method starting the applet viewer.
+ *
+ * @param args the arguments given on the command line.
+ *
+ * @exception IOException if an error occurs.
+ */
+ public static void main(String[] args) throws IOException
+ {
+ parser = new ClasspathToolParser("appletviewer", true);
+ parser.setHeader("usage: appletviewer [OPTION] -code CODE | URL...");
+
+ OptionGroup attributeGroup = new OptionGroup("Applet tag options");
+
+ attributeGroup.add(new Option("code", Main.messages.getString
+ ("gcjwebplugin.code_description"),
+ "CODE")
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ code = argument;
+ }
+ });
+ attributeGroup.add(new Option("codebase", Main.messages.getString
+ ("gcjwebplugin.codebase_description"),
+ "CODEBASE")
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ codebase = argument;
+ }
+ });
+ attributeGroup.add(new Option("archive", Main.messages.getString
+ ("gcjwebplugin.archive_description"),
+ "ARCHIVE")
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ archive = argument;
+ }
+ });
+ attributeGroup.add(new Option("width", Main.messages.getString
+ ("gcjwebplugin.width_description"),
+ "WIDTH")
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ dimensions.width = Integer.parseInt(argument);
+ }
+ });
+ attributeGroup.add(new Option("height", Main.messages.getString
+ ("gcjwebplugin.height_description"),
+ "HEIGHT")
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ dimensions.height = Integer.parseInt(argument);
+ }
+ });
+ attributeGroup.add(new Option("param", Main.messages.getString
+ ("gcjwebplugin.param_description"),
+ "NAME,VALUE")
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ parameters.add(argument);
+ }
+ });
+ OptionGroup pluginGroup = new OptionGroup("Plugin option");
+ pluginGroup.add(new Option("plugin", Main.messages.getString
+ ("gcjwebplugin.plugin_description"),
+ "INPUT,OUTPUT")
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ pluginMode = true;
+ int comma = argument.indexOf(',');
+ pipeInName = argument.substring(0, comma);
+ pipeOutName = argument.substring(comma + 1);
+ }
+ });
+ OptionGroup debuggingGroup = new OptionGroup("Debugging option");
+ debuggingGroup.add(new Option("verbose", Main.messages.getString
+ ("gcjwebplugin.verbose_description"),
+ (String) null)
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ verbose = true;
+ }
+ });
+ OptionGroup compatibilityGroup = new OptionGroup("Compatibility options");
+ compatibilityGroup.add(new Option("debug", Main.messages.getString
+ ("gcjwebplugin.debug_description"),
+ (String) null)
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ // Currently ignored.
+ }
+ });
+ compatibilityGroup.add(new Option("encoding", Main.messages.getString
+ ("gcjwebplugin.encoding_description"),
+ "CHARSET")
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ // FIXME: We should probably be using
+ // java.nio.charset.CharsetDecoder to handle the encoding. What
+ // is the status of Classpath's implementation?
+ }
+ });
+ parser.add(attributeGroup);
+ parser.add(pluginGroup);
+ parser.add(debuggingGroup);
+ parser.add(compatibilityGroup);
+
+ String[] urls = parser.parse(args);
+
+ // Print arguments.
+ printArguments(args);
+
+ args = urls;
+
+ if (dimensions.height < 0)
+ dimensions.height = 200;
+
+ if (dimensions.width < 0)
+ dimensions.width = (int) (1.6 * dimensions.height);
+
+ //System.setSecurityManager(new AppletSecurityManager(pluginMode));
+
+ if (pluginMode)
+ {
+ InputStream in;
+ OutputStream out;
+
+ in = new FileInputStream(pipeInName);
+ out = new FileOutputStream(pipeOutName);
+
+ PluginAppletViewer.start(in, out);
+ }
+ else
+ {
+ if (code == null)
+ {
+ // The --code option wasn't given and there are no URL
+ // arguments so we have nothing to work with.
+ if (args.length == 0)
+ {
+ System.err.println(Main.messages.getString("gcjwebplugin.no_input_files"));
+ System.exit(1);
+ }
+ // Create a standalone appletviewer from a list of URLs.
+ new StandaloneAppletViewer(args);
+ }
+ else
+ {
+ // Create a standalone appletviewer from the --code
+ // option.
+ new StandaloneAppletViewer(code, codebase, archive, parameters, dimensions);
+ }
+ }
+ }
+
+ static void printArguments(String[] args)
+ {
+ if (verbose)
+ {
+ System.out.println("raw arguments:");
+
+ for (int i = 0; i < args.length; i++)
+ System.out.println(" " + args[i]);
+ }
+ }
+}
diff --git a/tools/gnu/classpath/tools/appletviewer/PluginAppletContext.java b/tools/gnu/classpath/tools/appletviewer/PluginAppletContext.java
new file mode 100644
index 000000000..a0e6acd12
--- /dev/null
+++ b/tools/gnu/classpath/tools/appletviewer/PluginAppletContext.java
@@ -0,0 +1,72 @@
+/* PluginAppletContext.java -- an applet's context within a web browser
+ Copyright (C) 2003, 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.appletviewer;
+
+import java.net.URL;
+import java.io.IOException;
+
+/*
+ * PluginAppletContext represents the context within a webpage of a
+ * group of applets that all share the same codebase.
+ */
+class PluginAppletContext extends CommonAppletContext
+{
+ public void showDocument(URL url, String target)
+ {
+ try
+ {
+ PluginAppletViewer.write("url " + url + " " + target);
+ }
+ catch(IOException e)
+ {
+ System.err.println("showDocument failed: " + e);
+ }
+ }
+
+ public void showStatus(String status)
+ {
+ try
+ {
+ PluginAppletViewer.write("status " + status);
+ }
+ catch(IOException e)
+ {
+ System.err.println("showDocument failed: " + e);
+ }
+ }
+}
diff --git a/tools/gnu/classpath/tools/appletviewer/PluginAppletViewer.java b/tools/gnu/classpath/tools/appletviewer/PluginAppletViewer.java
new file mode 100644
index 000000000..fdb8097b4
--- /dev/null
+++ b/tools/gnu/classpath/tools/appletviewer/PluginAppletViewer.java
@@ -0,0 +1,172 @@
+/* PluginAppletViewer.java -- manages embeddable applet windows
+ Copyright (C) 2003, 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.appletviewer;
+
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.net.MalformedURLException;
+import java.nio.charset.Charset;
+import java.util.HashMap;
+
+
+/**
+ * PluginAppletViewer communicates through pipes with a web browser
+ * plugin. A PluginAppletViewer manages applet windows that may be
+ * embedded into web pages.
+ */
+class PluginAppletViewer
+{
+ // A mapping of instance IDs to PluginAppletWindows.
+ static HashMap appletWindows = new HashMap ();
+
+ private static BufferedReader pluginInputStream;
+ private static BufferedWriter pluginOutputStream;
+
+ static void start(InputStream inputStream, OutputStream outputStream)
+ throws MalformedURLException, IOException
+ {
+ // Set up input and output pipes. Use UTF-8 encoding.
+ pluginInputStream =
+ new BufferedReader(new InputStreamReader(inputStream,
+ Charset.forName("UTF-8")));
+ pluginOutputStream =
+ new BufferedWriter(new OutputStreamWriter(outputStream,
+ Charset.forName("UTF-8")));
+
+ write("running");
+
+ // Read first message.
+ String message = read();
+
+ PluginAppletWindow currentWindow = null;
+
+ while (true)
+ {
+ if (message.startsWith("instance"))
+ {
+ // Read applet instance identifier.
+ String key = message.substring(9);
+
+ if (appletWindows.get(key) == null)
+ appletWindows.put(key, new PluginAppletWindow());
+
+ currentWindow = (PluginAppletWindow) appletWindows.get(key);
+ }
+ else if (message.startsWith("tag"))
+ {
+ int pos = message.indexOf(' ', 4);
+ String documentbase = message.substring(4, pos);
+ String tag = message.substring(pos + 1);
+ currentWindow.setParser(tag, documentbase);
+ }
+ else if (message.startsWith("handle"))
+ {
+ long handle = Long.parseLong(message.substring(7));
+
+ currentWindow.setHandle(handle);
+ }
+ else if (message.startsWith("width"))
+ {
+ int width = Integer.parseInt(message.substring(6));
+
+ currentWindow.setSize(width, currentWindow.getHeight());
+ }
+ else if (message.startsWith("height"))
+ {
+ int height = Integer.parseInt(message.substring(7));
+
+ currentWindow.setSize(currentWindow.getWidth(), height);
+ }
+ else if (message.startsWith("destroy"))
+ {
+ appletWindows.remove(currentWindow);
+ currentWindow.dispose();
+ }
+
+ // Read next message.
+ message = read();
+ }
+ }
+
+ /**
+ * Write string to plugin.
+ *
+ * @param message the message to write
+ *
+ * @exception IOException if an error occurs
+ */
+ static void write(String message) throws IOException
+ {
+ pluginOutputStream.write(message, 0, message.length());
+ pluginOutputStream.newLine();
+ pluginOutputStream.flush();
+
+ System.err.println(" PIPE: applet viewer wrote: " + message);
+ }
+
+ /**
+ * Read string from plugin.
+ *
+ * @return the read string
+ *
+ * @exception IOException if an error occurs
+ */
+ static String read() throws IOException
+ {
+ String message = pluginInputStream.readLine();
+
+ System.err.println(" PIPE: applet viewer read: " + message);
+
+ if (message == null || message.equals("shutdown"))
+ {
+ // Close input/output channels to plugin.
+ pluginInputStream.close();
+ pluginOutputStream.close();
+
+ System.err.println("appletviewer: exiting plugin applet viewer");
+ System.exit(0);
+ }
+
+ return message;
+ }
+}
diff --git a/tools/gnu/classpath/tools/appletviewer/PluginAppletWindow.java b/tools/gnu/classpath/tools/appletviewer/PluginAppletWindow.java
new file mode 100644
index 000000000..6d36e1cf0
--- /dev/null
+++ b/tools/gnu/classpath/tools/appletviewer/PluginAppletWindow.java
@@ -0,0 +1,454 @@
+/* PluginAppletWindow.java -- an embeddable applet window
+ Copyright (C) 2003, 2004, 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.appletviewer;
+
+import gnu.java.awt.EmbeddedWindow;
+
+import java.applet.Applet;
+import java.applet.AppletContext;
+import java.awt.Dimension;
+import java.awt.event.ComponentEvent;
+import java.awt.event.ComponentListener;
+import java.awt.event.ContainerEvent;
+import java.awt.event.ContainerListener;
+import java.awt.event.HierarchyBoundsListener;
+import java.awt.event.HierarchyEvent;
+import java.awt.event.HierarchyListener;
+import java.awt.event.InputMethodEvent;
+import java.awt.event.InputMethodListener;
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseListener;
+import java.awt.event.MouseMotionListener;
+import java.io.IOException;
+import java.io.StringReader;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.HashMap;
+
+import javax.swing.JOptionPane;
+
+
+class PluginAppletWindow
+ extends EmbeddedWindow
+ implements ContainerListener, ComponentListener, MouseListener,
+ MouseMotionListener, InputMethodListener, HierarchyListener,
+ HierarchyBoundsListener
+{
+
+ // This class implements various listeners because the author of an applet
+ // may attach listeners to it, unaware of the applet's parent (this class).
+ // So, we must pass all listener events on this plugin applet window to the
+ // actual applet.
+
+ private static HashMap contexts = new HashMap();
+ private Applet applet;
+ private TagParser parser;
+ private AppletTag tag;
+
+ PluginAppletWindow()
+ {
+ super();
+ addContainerListener(this);
+ addComponentListener(this);
+ addMouseListener(this);
+ addMouseMotionListener(this);
+ addInputMethodListener(this);
+ addHierarchyListener(this);
+ addHierarchyBoundsListener(this);
+ }
+
+ ///////////////////////////////////
+ /// ContainerListener Methods /////
+ ///////////////////////////////////
+
+ /**
+ * This method is called when a component is added to the container.
+ *
+ * @param event the <code>ContainerEvent</code> indicating component
+ * addition
+ */
+ public void componentAdded(ContainerEvent event)
+ {
+ if (applet != null)
+ {
+ ContainerListener[] l = applet.getContainerListeners();
+ for (int i = 0; i < l.length; i++)
+ l[i].componentAdded(event);
+ }
+ }
+
+ /**
+ * This method is called when a component is removed from the container.
+ *
+ * @param event the <code>ContainerEvent</code> indicating component removal
+ */
+ public void componentRemoved(ContainerEvent event)
+ {
+ if (applet != null)
+ {
+ ContainerListener[] l = applet.getContainerListeners();
+ for (int i = 0; i < l.length; i++)
+ l[i].componentRemoved(event);
+ }
+ }
+
+ ///////////////////////////////////
+ /// ComponentListener Methods /////
+ ///////////////////////////////////
+
+ /**
+ * This method is called when the component is resized.
+ *
+ * @param event the <code>ComponentEvent</code> indicating the resize
+ */
+ public void componentResized(ComponentEvent event)
+ {
+ if (applet != null)
+ {
+ ComponentListener[] l = applet.getComponentListeners();
+ for (int i = 0; i < l.length; i++)
+ l[i].componentResized(event);
+ }
+ }
+
+ /**
+ * This method is called when the component is moved.
+ *
+ * @param event the <code>ComponentEvent</code> indicating the move
+ */
+ public void componentMoved(ComponentEvent event)
+ {
+ if (applet != null)
+ {
+ ComponentListener[] l = applet.getComponentListeners();
+ for (int i = 0; i < l.length; i++)
+ l[i].componentMoved(event);
+ }
+ }
+
+ /**
+ * This method is called when the component is made visible.
+ *
+ * @param event the <code>ComponentEvent</code> indicating the visibility
+ */
+ public void componentShown(ComponentEvent event)
+ {
+ if (applet != null)
+ {
+ ComponentListener[] l = applet.getComponentListeners();
+ for (int i = 0; i < l.length; i++)
+ l[i].componentShown(event);
+ }
+ }
+
+ /**
+ * This method is called when the component is hidden.
+ *
+ * @param event the <code>ComponentEvent</code> indicating the visibility
+ */
+ public void componentHidden(ComponentEvent event)
+ {
+ if (applet != null)
+ {
+ ComponentListener[] l = applet.getComponentListeners();
+ for (int i = 0; i < l.length; i++)
+ l[i].componentHidden(event);
+ }
+ }
+
+ ///////////////////////////////////
+ ////// MouseListener Methods //////
+ ///////////////////////////////////
+
+ /**
+ * This method is called when the mouse is clicked (pressed and released
+ * in short succession) on a component.
+ *
+ * @param event the <code>MouseEvent</code> indicating the click
+ */
+ public void mouseClicked(MouseEvent event)
+ {
+ if (applet != null)
+ {
+ MouseListener[] l = applet.getMouseListeners();
+ for (int i = 0; i < l.length; i++)
+ l[i].mouseClicked(event);
+ }
+ }
+
+ /**
+ * This method is called when the mouse is pressed over a component.
+ *
+ * @param event the <code>MouseEvent</code> for the press
+ */
+ public void mousePressed(MouseEvent event)
+ {
+ if (applet != null)
+ {
+ MouseListener[] l = applet.getMouseListeners();
+ for (int i = 0; i < l.length; i++)
+ l[i].mousePressed(event);
+ }
+ }
+
+ /**
+ * This method is called when the mouse is released over a component.
+ *
+ * @param event the <code>MouseEvent</code> for the release
+ */
+ public void mouseReleased(MouseEvent event)
+ {
+ if (applet != null)
+ {
+ MouseListener[] l = applet.getMouseListeners();
+ for (int i = 0; i < l.length; i++)
+ l[i].mouseReleased(event);
+ }
+ }
+
+ /**
+ * This method is called when the mouse enters a component.
+ *
+ * @param event the <code>MouseEvent</code> for the entry
+ */
+ public void mouseEntered(MouseEvent event)
+ {
+ if (applet != null)
+ {
+ MouseListener[] l = applet.getMouseListeners();
+ for (int i = 0; i < l.length; i++)
+ l[i].mouseEntered(event);
+ }
+ }
+
+ /**
+ * This method is called when the mouse exits a component.
+ *
+ * @param event the <code>MouseEvent</code> for the exit
+ */
+ public void mouseExited(MouseEvent event)
+ {
+ if (applet != null)
+ {
+ MouseListener[] l = applet.getMouseListeners();
+ for (int i = 0; i < l.length; i++)
+ l[i].mouseExited(event);
+ }
+ }
+
+ ///////////////////////////////////
+ /// MouseMotionListener Methods ///
+ ///////////////////////////////////
+
+ /**
+ * This method is called when the mouse is moved over a component
+ * while a button has been pressed.
+ *
+ * @param event the <code>MouseEvent</code> indicating the motion
+ */
+ public void mouseDragged(MouseEvent event)
+ {
+ if (applet != null)
+ {
+ MouseMotionListener[] l = applet.getMouseMotionListeners();
+ for (int i = 0; i < l.length; i++)
+ l[i].mouseDragged(event);
+ }
+ }
+
+ /**
+ * This method is called when the mouse is moved over a component
+ * while no button is pressed.
+ *
+ * @param event the <code>MouseEvent</code> indicating the motion
+ */
+ public void mouseMoved(MouseEvent event)
+ {
+ if (applet != null)
+ {
+ MouseMotionListener[] l = applet.getMouseMotionListeners();
+ for (int i = 0; i < l.length; i++)
+ l[i].mouseMoved(event);
+ }
+ }
+
+ ///////////////////////////////////
+ /// InputMethodListener Methods ///
+ ///////////////////////////////////
+
+ /**
+ * This method is called when the text is changed.
+ *
+ * @param event the <code>InputMethodEvent</code> indicating the text change
+ */
+ public void inputMethodTextChanged(InputMethodEvent event)
+ {
+ if (applet != null)
+ {
+ InputMethodListener[] l = applet.getInputMethodListeners();
+ for (int i = 0; i < l.length; i++)
+ l[i].inputMethodTextChanged(event);
+ }
+ }
+
+ /**
+ * This method is called when the cursor position within the text is changed.
+ *
+ * @param event the <code>InputMethodEvent</code> indicating the change
+ */
+ public void caretPositionChanged(InputMethodEvent event)
+ {
+ if (applet != null)
+ {
+ InputMethodListener[] l = applet.getInputMethodListeners();
+ for (int i = 0; i < l.length; i++)
+ l[i].caretPositionChanged(event);
+ }
+ }
+
+ ///////////////////////////////////
+ //// HierarchyListener Methods ////
+ ///////////////////////////////////
+
+ /**
+ * Called when the hierarchy of this component changes. Use
+ * <code>getChangeFlags()</code> on the event to see what exactly changed.
+ *
+ * @param e the event describing the change
+ */
+ public void hierarchyChanged(HierarchyEvent event)
+ {
+ if (applet != null)
+ {
+ HierarchyListener[] l = applet.getHierarchyListeners();
+ for (int i = 0; i < l.length; i++)
+ l[i].hierarchyChanged(event);
+ }
+ }
+
+ /////////////////////////////////////////
+ //// HierarchyBoundsListener Methods ////
+ /////////////////////////////////////////
+
+ /**
+ * Called when an ancestor component of the source is moved.
+ *
+ * @param e the event describing the ancestor's motion
+ */
+ public void ancestorMoved(HierarchyEvent e)
+ {
+ if (applet != null)
+ {
+ HierarchyBoundsListener[] l = applet.getHierarchyBoundsListeners();
+ for (int i = 0; i < l.length; i++)
+ l[i].ancestorMoved(e);
+ }
+ }
+
+ /**
+ * Called when an ancestor component is resized.
+ *
+ * @param e the event describing the ancestor's resizing
+ */
+ public void ancestorResized(HierarchyEvent e)
+ {
+ if (applet != null)
+ {
+ HierarchyBoundsListener[] l = applet.getHierarchyBoundsListeners();
+ for (int i = 0; i < l.length; i++)
+ l[i].ancestorResized(e);
+ }
+ }
+
+ void setParser(String tag, String documentbase) throws MalformedURLException, IOException
+ {
+ URL documentbaseURL = TagParser.getLocationToURL(documentbase);
+ StringReader in = new StringReader(tag);
+ this.parser = new TagParser(in, documentbaseURL);
+ }
+
+ // /////////////////////////////////
+ // //// EmbeddedWindow Method //////
+ // /////////////////////////////////
+
+ /**
+ * Set the native handle of the window system to embed the window in.
+ *
+ * @param handle the native handle.
+ */
+ public void setHandle(long handle)
+ {
+ super.setHandle(handle);
+ addNotify();
+
+ ArrayList l = parser.parseAppletTags();
+ int s = l.size();
+
+ for (int i = 0; i < s; i++)
+ {
+ tag = (AppletTag) l.get(i);
+ applet = Main.createApplet(tag);
+
+ if (contexts.get(tag.getCodeBase()) == null)
+ contexts.put(tag.getCodeBase(), new PluginAppletContext());
+
+ int result = AppletWarning.show();
+ if (result == JOptionPane.NO_OPTION)
+ return;
+
+ add(applet);
+
+ AppletContext context = (AppletContext) contexts.get(tag.getCodeBase());
+ ((PluginAppletContext) context).addApplet(applet);
+
+ applet.setStub(new CommonAppletStub(tag, context, applet));
+ Dimension size = getSize();
+ if (size.width == 0 || size.height == 0)
+ size = tag.getSize();
+ applet.setSize(size);
+
+ // Initialize the applet before showing this window so that
+ // the applet doesn't receive events before it has been
+ // initialized.
+ applet.init();
+ applet.start();
+ setVisible(true);
+ }
+ }
+}
diff --git a/tools/gnu/classpath/tools/appletviewer/StandaloneAppletContext.java b/tools/gnu/classpath/tools/appletviewer/StandaloneAppletContext.java
new file mode 100644
index 000000000..a779f068a
--- /dev/null
+++ b/tools/gnu/classpath/tools/appletviewer/StandaloneAppletContext.java
@@ -0,0 +1,75 @@
+/* StandaloneAppletContext.java -- an applet's context within the
+ standalone viewer
+ Copyright (C) 2003, 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.appletviewer;
+
+import java.net.URL;
+import java.util.Iterator;
+import java.util.List;
+
+
+/**
+ * StandaloneAppletContext represents the context within a webpage of a
+ * group of applets that all share the same codebase.
+ */
+class StandaloneAppletContext extends CommonAppletContext
+{
+ private List appletWindows;
+
+ StandaloneAppletContext(List appletWindows)
+ {
+ this.appletWindows = appletWindows;
+ }
+
+ public void showDocument(URL url, String target)
+ {
+ System.err.println("showDocument is not implemented in standalone mode");
+ }
+
+ // In standalone mode, there are potentially several windows, each
+ // with its own status bar. In plugin mode, all the applets in the
+ // same context (on the same page) share the browser's status bar.
+ // The best way to simulate the plugin mode behaviour in standalone
+ // mode is to show the same status on each window's status bar.
+ public void showStatus(String status)
+ {
+ Iterator window = appletWindows.iterator();
+ while (window.hasNext())
+ ((StandaloneAppletWindow) window.next()).showStatus(status);
+ }
+}
diff --git a/tools/gnu/classpath/tools/appletviewer/StandaloneAppletViewer.java b/tools/gnu/classpath/tools/appletviewer/StandaloneAppletViewer.java
new file mode 100644
index 000000000..2b58f4b87
--- /dev/null
+++ b/tools/gnu/classpath/tools/appletviewer/StandaloneAppletViewer.java
@@ -0,0 +1,144 @@
+/* StandaloneAppletViewer.java -- a standalone viewer for Java applets
+ Copyright (C) 2003, 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.appletviewer;
+
+import java.awt.Dimension;
+import java.io.File;
+import java.io.IOException;
+import java.io.StringReader;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.StringTokenizer;
+
+
+/**
+ * StandaloneAppletViewer displays an applet in its own Frame. Most
+ * of the context that is available to an applet within a webpage is
+ * available to it in StandaloneAppletViewer.
+ */
+class StandaloneAppletViewer extends Main
+{
+ static ArrayList appletTags = new ArrayList();
+ static ArrayList appletWindows = new ArrayList();
+
+ StandaloneAppletViewer(String[] urls)
+ throws MalformedURLException, IOException
+ {
+ // Handle each file specified on the command line.
+ for (int i = 0; i < urls.length; i++)
+ {
+ TagParser parser = new TagParser(urls[i]);
+ appletTags.addAll(parser.parseAppletTags());
+ }
+
+ printTags();
+ createWindows();
+ }
+
+ StandaloneAppletViewer(String code, String codebase, String archives,
+ List parameters, Dimension dimensions)
+ throws IOException
+ {
+ if (!(code.equals("") || code.endsWith(".class")))
+ {
+ System.err.println("appletviewer: option '--code' requires a class filename");
+ System.exit(1);
+ }
+
+ String tagString =
+ "<EMBED"
+ + " CODE=\"" + code + "\""
+ + " WIDTH=" + dimensions.width
+ + " HEIGHT=" + dimensions.height
+ + " CODEBASE=\"" + codebase + "\""
+ + " ARCHIVE=\"" + archives + "\">";
+
+ // Handle parameters.
+ Iterator pairs = parameters.iterator();
+ while (pairs.hasNext())
+ {
+ StringTokenizer paramTokenizer =
+ new StringTokenizer((String) pairs.next(), ",");
+ tagString +=
+ "<PARAM NAME=" + paramTokenizer.nextToken().trim() + " VALUE="
+ + paramTokenizer.nextToken().trim() + ">";
+ }
+
+ tagString += "</EMBED>";
+
+ StringReader reader = new StringReader(tagString);
+ String path = System.getProperty("user.dir") + File.separator;
+ TagParser parser = new TagParser(reader,
+ new URL("file", "", path));
+ appletTags.addAll(parser.parseAppletTags());
+
+ printTags();
+ createWindows();
+ }
+
+ void printTags()
+ {
+ if (verbose)
+ {
+ System.out.println("parsed applet tags:");
+
+ for (int i = 0; i < appletTags.size(); i++)
+ {
+ AppletTag tag = (AppletTag) appletTags.get(i);
+
+ System.out.println(" tag " + i + ":");
+ System.out.println(tag);
+ }
+ }
+ }
+
+ void createWindows()
+ {
+ for (int i = 0; i < appletTags.size(); i++)
+ {
+ AppletTag tag = (AppletTag) appletTags.get(i);
+
+ // Create a StandaloneAppletWindow and add it to the
+ // appletWindows list.
+ new StandaloneAppletWindow(tag, appletWindows);
+ }
+ }
+}
diff --git a/tools/gnu/classpath/tools/appletviewer/StandaloneAppletWindow.java b/tools/gnu/classpath/tools/appletviewer/StandaloneAppletWindow.java
new file mode 100644
index 000000000..3b337bf80
--- /dev/null
+++ b/tools/gnu/classpath/tools/appletviewer/StandaloneAppletWindow.java
@@ -0,0 +1,559 @@
+/* StandaloneAppletWindow.java -- an applet frame
+ Copyright (C) 2003, 2004, 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.appletviewer;
+
+import java.applet.Applet;
+import java.applet.AppletContext;
+import java.awt.BorderLayout;
+import java.awt.Dimension;
+import java.awt.Frame;
+import java.awt.Insets;
+import java.awt.Label;
+import java.awt.Menu;
+import java.awt.MenuBar;
+import java.awt.MenuItem;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.ComponentEvent;
+import java.awt.event.ComponentListener;
+import java.awt.event.ContainerEvent;
+import java.awt.event.ContainerListener;
+import java.awt.event.HierarchyBoundsListener;
+import java.awt.event.HierarchyEvent;
+import java.awt.event.HierarchyListener;
+import java.awt.event.InputMethodEvent;
+import java.awt.event.InputMethodListener;
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseListener;
+import java.awt.event.MouseMotionListener;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+import java.util.HashMap;
+import java.util.List;
+
+class StandaloneAppletWindow
+ extends Frame
+ implements ActionListener, ContainerListener, ComponentListener,
+ MouseListener, MouseMotionListener, InputMethodListener, HierarchyListener,
+ HierarchyBoundsListener
+{
+
+ // This class implements various listeners because the author of an applet
+ // may attach listeners to it, unaware of the applet's parent (this class).
+ // So, we must pass all listener events on this plugin applet window to the
+ // actual applet.
+
+ private static int testWindowCount;
+ private static HashMap contexts = new HashMap();
+ private Applet applet;
+ private Label status = new Label();
+
+ private MenuItem restartItem;
+ private MenuItem reloadItem;
+ private MenuItem cancelItem;
+ private MenuItem saveItem;
+ private MenuItem startItem;
+ private MenuItem cloneItem;
+ private MenuItem tagItem;
+ private MenuItem infoItem;
+ private MenuItem editItem;
+ private MenuItem encodingItem;
+ private MenuItem printItem;
+ private MenuItem propertiesItem;
+ private MenuItem closeItem;
+ private MenuItem quitItem;
+
+ StandaloneAppletWindow(AppletTag tag, List appletWindows)
+ {
+ appletWindows.add(this);
+ applet = Main.createApplet(tag);
+
+ if (contexts.get(tag.codebase) == null)
+ contexts.put(tag.codebase, new StandaloneAppletContext(appletWindows));
+
+ setLayout(new BorderLayout());
+ add(applet, BorderLayout.CENTER);
+ add(status, BorderLayout.SOUTH);
+
+ addWindowListener(new WindowAdapter()
+ {
+ public void windowClosing(WindowEvent event)
+ {
+ applet.stop();
+ StandaloneAppletWindow.this.hide();
+ System.exit(0);
+ }
+ });
+
+ addContainerListener(this);
+ addComponentListener(this);
+ addMouseListener(this);
+ addMouseMotionListener(this);
+ addInputMethodListener(this);
+ addHierarchyListener(this);
+ addHierarchyBoundsListener(this);
+
+ restartItem = new MenuItem(Main.messages.getString("gcjwebplugin.menu_restart"));
+ restartItem.setEnabled(false);
+ restartItem.addActionListener(this);
+ reloadItem = new MenuItem(Main.messages.getString("gcjwebplugin.menu_reload"));
+ reloadItem.setEnabled(false);
+ reloadItem.addActionListener(this);
+ cancelItem = new MenuItem(Main.messages.getString("gcjwebplugin.menu_cancel"));
+ cancelItem.setEnabled(false);
+ cancelItem.addActionListener(this);
+ saveItem = new MenuItem(Main.messages.getString("gcjwebplugin.menu_save"));
+ saveItem.setEnabled(false);
+ saveItem.addActionListener(this);
+ startItem = new MenuItem(Main.messages.getString("gcjwebplugin.menu_start"));
+ startItem.setEnabled(false);
+ startItem.addActionListener(this);
+ cloneItem = new MenuItem(Main.messages.getString("gcjwebplugin.menu_clone"));
+ cloneItem.setEnabled(false);
+ cloneItem.addActionListener(this);
+ closeItem = new MenuItem(Main.messages.getString("gcjwebplugin.menu_close"));
+ closeItem.setEnabled(false);
+ closeItem.addActionListener(this);
+ tagItem =
+ new MenuItem(Main.messages.getString("gcjwebplugin.menu_tag"));
+ tagItem.setEnabled(false);
+ tagItem.addActionListener(this);
+ infoItem =
+ new MenuItem(Main.messages.getString("gcjwebplugin.menu_info"));
+ infoItem.setEnabled(false);
+ infoItem.addActionListener(this);
+ editItem =
+ new MenuItem(Main.messages.getString("gcjwebplugin.menu_edit"));
+ editItem.setEnabled(false);
+ editItem.addActionListener(this);
+ editItem.setEnabled(false);
+ encodingItem =
+ new MenuItem(Main.messages.getString("gcjwebplugin.menu_encoding"));
+ encodingItem.setEnabled(false);
+ encodingItem.addActionListener(this);
+ printItem =
+ new MenuItem(Main.messages.getString("gcjwebplugin.menu_print"));
+ printItem.setEnabled(false);
+ printItem.addActionListener(this);
+ propertiesItem =
+ new MenuItem(Main.messages.getString("gcjwebplugin.menu_properties"));
+ propertiesItem.setEnabled(false);
+ propertiesItem.addActionListener(this);
+ quitItem = new MenuItem(Main.messages.getString("gcjwebplugin.menu_quit"));
+ quitItem.addActionListener(this);
+
+ MenuBar menuBar = new MenuBar();
+ Menu menuApplet = new Menu(Main.messages.getString("gcjwebplugin.menu_title"));
+ menuBar.add(menuApplet);
+ menuApplet.add(restartItem);
+ menuApplet.add(reloadItem);
+ menuApplet.add(cancelItem);
+ menuApplet.add(saveItem);
+ menuApplet.add(startItem);
+ menuApplet.add(cloneItem);
+ menuApplet.addSeparator();
+ menuApplet.add(tagItem);
+ menuApplet.add(infoItem);
+ menuApplet.add(editItem);
+ menuApplet.add(encodingItem);
+ menuApplet.addSeparator();
+ menuApplet.add(printItem);
+ menuApplet.addSeparator();
+ menuApplet.add(propertiesItem);
+ menuApplet.addSeparator();
+ menuApplet.add(closeItem);
+ menuApplet.add(quitItem);
+ setMenuBar(menuBar);
+ setTitle("GCJ Applet Viewer: " + tag.code);
+
+ AppletContext context = (AppletContext) contexts.get(tag.codebase);
+ ((StandaloneAppletContext) context).addApplet(applet);
+
+ applet.setStub(new CommonAppletStub(tag, context, applet));
+
+ // Create the frame's peer. Otherwise getPreferredSize will read
+ // its insets as 0.
+ addNotify();
+ Insets i = getInsets();
+ Dimension size = tag.getSize();
+ setSize(i.left + size.width + i.right,
+ i.top + size.height + status.getPreferredSize().height
+ + i.bottom);
+ applet.setSize(size);
+
+ // Initialize the applet before showing this window so that the
+ // applet doesn't receive events before it has been initialized.
+ applet.init();
+ applet.start();
+ setVisible(true);
+ }
+
+ private void closeWindow()
+ {
+ applet.stop();
+ StandaloneAppletViewer.appletWindows.remove(this);
+ StandaloneAppletWindow.this.hide();
+ }
+
+ public void actionPerformed(ActionEvent e)
+ {
+ if (e.getSource() == quitItem)
+ {
+ closeWindow();
+ System.exit(0);
+ }
+ else if (e.getSource() == closeItem)
+ {
+ // Close current window.
+ closeWindow();
+
+ // Exit if there are other windows left.
+ if (StandaloneAppletViewer.appletWindows.isEmpty())
+ System.exit(0);
+ }
+ }
+
+ void showStatus(String status)
+ {
+ this.status.setText(status);
+ }
+
+
+ ///////////////////////////////////
+ /// ContainerListener Methods /////
+ ///////////////////////////////////
+
+ /**
+ * This method is called when a component is added to the container.
+ *
+ * @param event the <code>ContainerEvent</code> indicating component
+ * addition
+ */
+ public void componentAdded(ContainerEvent event)
+ {
+ if (applet != null)
+ {
+ ContainerListener[] l = applet.getContainerListeners();
+ for (int i = 0; i < l.length; i++)
+ l[i].componentAdded(event);
+ }
+ }
+
+ /**
+ * This method is called when a component is removed from the container.
+ *
+ * @param event the <code>ContainerEvent</code> indicating component removal
+ */
+ public void componentRemoved(ContainerEvent event)
+ {
+ if (applet != null)
+ {
+ ContainerListener[] l = applet.getContainerListeners();
+ for (int i = 0; i < l.length; i++)
+ l[i].componentRemoved(event);
+ }
+ }
+
+ ///////////////////////////////////
+ /// ComponentListener Methods /////
+ ///////////////////////////////////
+
+ /**
+ * This method is called when the component is resized.
+ *
+ * @param event the <code>ComponentEvent</code> indicating the resize
+ */
+ public void componentResized(ComponentEvent event)
+ {
+ if (applet != null)
+ {
+ ComponentListener[] l = applet.getComponentListeners();
+ for (int i = 0; i < l.length; i++)
+ l[i].componentResized(event);
+ }
+ }
+
+ /**
+ * This method is called when the component is moved.
+ *
+ * @param event the <code>ComponentEvent</code> indicating the move
+ */
+ public void componentMoved(ComponentEvent event)
+ {
+ if (applet != null)
+ {
+ ComponentListener[] l = applet.getComponentListeners();
+ for (int i = 0; i < l.length; i++)
+ l[i].componentMoved(event);
+ }
+ }
+
+ /**
+ * This method is called when the component is made visible.
+ *
+ * @param event the <code>ComponentEvent</code> indicating the visibility
+ */
+ public void componentShown(ComponentEvent event)
+ {
+ if (applet != null)
+ {
+ ComponentListener[] l = applet.getComponentListeners();
+ for (int i = 0; i < l.length; i++)
+ l[i].componentShown(event);
+ }
+ }
+
+ /**
+ * This method is called when the component is hidden.
+ *
+ * @param event the <code>ComponentEvent</code> indicating the visibility
+ */
+ public void componentHidden(ComponentEvent event)
+ {
+ if (applet != null)
+ {
+ ComponentListener[] l = applet.getComponentListeners();
+ for (int i = 0; i < l.length; i++)
+ l[i].componentHidden(event);
+ }
+ }
+
+ ///////////////////////////////////
+ ////// MouseListener Methods //////
+ ///////////////////////////////////
+
+ /**
+ * This method is called when the mouse is clicked (pressed and released
+ * in short succession) on a component.
+ *
+ * @param event the <code>MouseEvent</code> indicating the click
+ */
+ public void mouseClicked(MouseEvent event)
+ {
+ if (applet != null)
+ {
+ MouseListener[] l = applet.getMouseListeners();
+ for (int i = 0; i < l.length; i++)
+ l[i].mouseClicked(event);
+ }
+ }
+
+ /**
+ * This method is called when the mouse is pressed over a component.
+ *
+ * @param event the <code>MouseEvent</code> for the press
+ */
+ public void mousePressed(MouseEvent event)
+ {
+ if (applet != null)
+ {
+ MouseListener[] l = applet.getMouseListeners();
+ for (int i = 0; i < l.length; i++)
+ l[i].mousePressed(event);
+ }
+ }
+
+ /**
+ * This method is called when the mouse is released over a component.
+ *
+ * @param event the <code>MouseEvent</code> for the release
+ */
+ public void mouseReleased(MouseEvent event)
+ {
+ if (applet != null)
+ {
+ MouseListener[] l = applet.getMouseListeners();
+ for (int i = 0; i < l.length; i++)
+ l[i].mouseReleased(event);
+ }
+ }
+
+ /**
+ * This method is called when the mouse enters a component.
+ *
+ * @param event the <code>MouseEvent</code> for the entry
+ */
+ public void mouseEntered(MouseEvent event)
+ {
+ if (applet != null)
+ {
+ MouseListener[] l = applet.getMouseListeners();
+ for (int i = 0; i < l.length; i++)
+ l[i].mouseEntered(event);
+ }
+ }
+
+ /**
+ * This method is called when the mouse exits a component.
+ *
+ * @param event the <code>MouseEvent</code> for the exit
+ */
+ public void mouseExited(MouseEvent event)
+ {
+ if (applet != null)
+ {
+ MouseListener[] l = applet.getMouseListeners();
+ for (int i = 0; i < l.length; i++)
+ l[i].mouseExited(event);
+ }
+ }
+
+ ///////////////////////////////////
+ /// MouseMotionListener Methods ///
+ ///////////////////////////////////
+
+ /**
+ * This method is called when the mouse is moved over a component
+ * while a button has been pressed.
+ *
+ * @param event the <code>MouseEvent</code> indicating the motion
+ */
+ public void mouseDragged(MouseEvent event)
+ {
+ if (applet != null)
+ {
+ MouseMotionListener[] l = applet.getMouseMotionListeners();
+ for (int i = 0; i < l.length; i++)
+ l[i].mouseDragged(event);
+ }
+ }
+
+ /**
+ * This method is called when the mouse is moved over a component
+ * while no button is pressed.
+ *
+ * @param event the <code>MouseEvent</code> indicating the motion
+ */
+ public void mouseMoved(MouseEvent event)
+ {
+ if (applet != null)
+ {
+ MouseMotionListener[] l = applet.getMouseMotionListeners();
+ for (int i = 0; i < l.length; i++)
+ l[i].mouseMoved(event);
+ }
+ }
+
+ ///////////////////////////////////
+ /// InputMethodListener Methods ///
+ ///////////////////////////////////
+
+ /**
+ * This method is called when the text is changed.
+ *
+ * @param event the <code>InputMethodEvent</code> indicating the text change
+ */
+ public void inputMethodTextChanged(InputMethodEvent event)
+ {
+ if (applet != null)
+ {
+ InputMethodListener[] l = applet.getInputMethodListeners();
+ for (int i = 0; i < l.length; i++)
+ l[i].inputMethodTextChanged(event);
+ }
+ }
+
+ /**
+ * This method is called when the cursor position within the text is changed.
+ *
+ * @param event the <code>InputMethodEvent</code> indicating the change
+ */
+ public void caretPositionChanged(InputMethodEvent event)
+ {
+ if (applet != null)
+ {
+ InputMethodListener[] l = applet.getInputMethodListeners();
+ for (int i = 0; i < l.length; i++)
+ l[i].caretPositionChanged(event);
+ }
+ }
+
+ ///////////////////////////////////
+ //// HierarchyListener Methods ////
+ ///////////////////////////////////
+
+ /**
+ * Called when the hierarchy of this component changes. Use
+ * <code>getChangeFlags()</code> on the event to see what exactly changed.
+ *
+ * @param e the event describing the change
+ */
+ public void hierarchyChanged(HierarchyEvent event)
+ {
+ if (applet != null)
+ {
+ HierarchyListener[] l = applet.getHierarchyListeners();
+ for (int i = 0; i < l.length; i++)
+ l[i].hierarchyChanged(event);
+ }
+ }
+
+ /////////////////////////////////////////
+ //// HierarchyBoundsListener Methods ////
+ /////////////////////////////////////////
+
+ /**
+ * Called when an ancestor component of the source is moved.
+ *
+ * @param e the event describing the ancestor's motion
+ */
+ public void ancestorMoved(HierarchyEvent e)
+ {
+ if (applet != null)
+ {
+ HierarchyBoundsListener[] l = applet.getHierarchyBoundsListeners();
+ for (int i = 0; i < l.length; i++)
+ l[i].ancestorMoved(e);
+ }
+ }
+
+ /**
+ * Called when an ancestor component is resized.
+ *
+ * @param e the event describing the ancestor's resizing
+ */
+ public void ancestorResized(HierarchyEvent e)
+ {
+ if (applet != null)
+ {
+ HierarchyBoundsListener[] l = applet.getHierarchyBoundsListeners();
+ for (int i = 0; i < l.length; i++)
+ l[i].ancestorResized(e);
+ }
+ }
+}
diff --git a/tools/gnu/classpath/tools/appletviewer/TagParser.java b/tools/gnu/classpath/tools/appletviewer/TagParser.java
new file mode 100644
index 000000000..68dce97e0
--- /dev/null
+++ b/tools/gnu/classpath/tools/appletviewer/TagParser.java
@@ -0,0 +1,302 @@
+/* TagParser.java -- a parser for applet tags
+ 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.appletviewer;
+
+import gnu.javax.swing.text.html.parser.HTML_401F;
+
+import gnu.xml.dom.DomNode;
+import gnu.xml.dom.html2.DomHTMLAppletElement;
+import gnu.xml.dom.html2.DomHTMLDocument;
+import gnu.xml.dom.html2.DomHTMLEmbedElement;
+import gnu.xml.dom.html2.DomHTMLObjectElement;
+import gnu.xml.dom.html2.DomHTMLParamElement;
+import gnu.xml.dom.html2.DomHTMLParser;
+
+import java.io.File;
+import java.io.InputStreamReader;
+import java.io.IOException;
+import java.io.Reader;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import java.util.ArrayList;
+import java.util.StringTokenizer;
+import java.util.Vector;
+
+import org.w3c.dom.NodeList;
+
+
+public class TagParser
+{
+
+ /**
+ * Parsed document.
+ */
+ DomHTMLDocument document;
+
+ /**
+ * The document base of this applet.
+ */
+ URL documentbase;
+
+ /**
+ * The document base of all the applets.
+ */
+ static URL db;
+
+ /**
+ * The tags in the document.
+ */
+ Vector tags = new Vector();
+
+ /**
+ * Default constructor.
+ */
+ TagParser()
+ {
+ // Do nothing.
+ }
+
+ /**
+ * Constructs and parses document using the given location.
+ *
+ * @param location - location of applet
+ */
+ TagParser(String location) throws IOException
+ {
+ documentbase = getLocationToURL(location);
+ db = documentbase;
+ InputStreamReader in = new InputStreamReader(documentbase.openStream());
+ document = (DomHTMLDocument) (new DomHTMLParser(HTML_401F.getInstance()).parseDocument(in));
+ }
+
+ /**
+ * Constructs and parses document.
+ *
+ * @param in - Reader to parse document from.
+ * @param documentBase - the URL of the applet
+ * @throws IOException - is thrown if any IO error occurs.
+ */
+ TagParser(Reader in, URL documentBase) throws IOException
+ {
+ documentbase = documentBase;
+ db = documentbase;
+ document = (DomHTMLDocument) (new DomHTMLParser(HTML_401F.getInstance()).parseDocument(in));
+ }
+
+ /**
+ * Parses all applet tags in document.
+ *
+ * @return a list of AppletTag objects representing the applet tags
+ * in document
+ */
+ ArrayList parseAppletTags()
+ {
+ ArrayList allTags = new ArrayList();
+ if (document == null)
+ return null;;
+
+ recurseDocument(document.getChildNodes());
+
+ int sz = tags.size();
+ for (int j = 0; j < sz; j++)
+ {
+ Object curr = tags.get(j);
+ // Order of checking is important here.
+ // Must check embed element before applet element
+ // because DomHTMLEmbedElement extends DomHTMLAppletElement
+ AppletTag a = null;
+ if (curr instanceof DomHTMLEmbedElement)
+ a = new AppletTag((DomHTMLEmbedElement) curr);
+ else if (curr instanceof DomHTMLAppletElement)
+ a = new AppletTag((DomHTMLAppletElement) curr);
+ else if (curr instanceof DomHTMLObjectElement)
+ a = new AppletTag((DomHTMLObjectElement) curr);
+ a.documentbase = documentbase;
+ allTags.add(a);
+ }
+
+ return allTags;
+ }
+
+ /**
+ * Recurses the document in search for the appropriate tags.
+ *
+ * @param list - the Node list.
+ */
+ private void recurseDocument(NodeList list)
+ {
+ // Recurse and store all APPLET, OBJECT and EMBED tags.
+ int length = list.getLength();
+ for (int i = 0; i < length; i++)
+ {
+ DomNode curr = (DomNode) list.item(i);
+ if ((curr instanceof DomHTMLEmbedElement) ||
+ (curr instanceof DomHTMLAppletElement) ||
+ (curr instanceof DomHTMLObjectElement))
+ tags.add(curr);
+ recurseDocument(curr.getChildNodes());
+ }
+ }
+
+ /**
+ * Parses the param elements for a given node.
+ *
+ * @param node - the node element to parse.
+ */
+ static void parseParams(DomNode node, AppletTag t)
+ {
+ boolean ja = false;
+ boolean jb = false;
+ boolean jc = false;
+ NodeList l = node.getChildNodes();
+ int size = l.getLength();
+
+ if (size != 0)
+ for (int i = 0; i < size; i++)
+ {
+ Object c = l.item(i);
+ if (! (c instanceof DomHTMLParamElement))
+ continue;
+ DomHTMLParamElement curr = (DomHTMLParamElement) c;
+ String key = curr.getName();
+ String val = curr.getValue();
+
+ if (key.equals("java_code"))
+ {
+ jc = true;
+ t.code = val;
+ }
+ else if (key.equals("java_codebase"))
+ {
+ jb = true;
+ t.codebase = val;
+ }
+ else if (!jc && key.equals("code"))
+ t.code = val;
+ else if (!jc && key.equals("classid"))
+ {
+ int x = val.indexOf(":");
+ if (x != -1)
+ val = val.substring(x + 1);
+ t.code = val;
+ }
+ else if (!jb && key.equals("codebase"))
+ t.codebase = val;
+ else if (key.equals("java_archive"))
+ {
+ ja = true;
+ t.archives = parseArchives(val, t);
+ val = t.archives.toString();
+ }
+ else if (!ja && key.equals("archive"))
+ {
+ t.archives = parseArchives(val, t);
+ val = t.archives.toString();
+ }
+
+ t.parameters.put(key.toLowerCase(), val);
+ }
+ }
+
+ /**
+ * Parses the archive string and returns a list.
+ *
+ * @param the list of archives (comma-separated) in a String.
+ */
+ static ArrayList parseArchives(String arcs, AppletTag t)
+ {
+ try
+ {
+ ArrayList list = new ArrayList();
+
+ StringTokenizer tagTokenizer = new StringTokenizer(arcs, ",");
+ while (tagTokenizer.hasMoreTokens())
+ list.add(t.prependCodeBase(tagTokenizer.nextToken().trim()));
+
+ return list;
+ }
+ catch (MalformedURLException e)
+ {
+ }
+ return null;
+ }
+
+ /**
+ * Gets the location to the URL, given a location.
+ *
+ * @param location - the given location.
+ * @return the URL.
+ */
+ static URL getLocationToURL(String location) throws IOException
+ {
+ URL tmpDocumentBase = null;
+
+ try
+ {
+ // Try parsing location as a URL.
+ tmpDocumentBase = new URL(location);
+
+ // If no file was specified in the URL the assume the user
+ // meant the root page.
+ String f = tmpDocumentBase.getFile();
+ if (f.indexOf(".") == -1 && !f.endsWith(File.separator))
+ if (new File(tmpDocumentBase.getFile()).isDirectory())
+ tmpDocumentBase = new URL(location.concat(File.separator));
+ }
+ catch (MalformedURLException e)
+ {
+ // location is not a URL. See if it is an HTML file.
+ String path;
+
+ if (location.startsWith(File.separator))
+ path = new File(location).getCanonicalPath();
+ else
+ path = new File(System.getProperty("user.dir") + File.separator
+ + location).getCanonicalPath();
+
+ tmpDocumentBase = new URL("file", "", path);
+
+ if (new File(tmpDocumentBase.getFile()).isDirectory())
+ tmpDocumentBase = new URL("file", "", path + File.separator);
+ }
+
+ return tmpDocumentBase;
+ }
+}
diff --git a/tools/gnu/classpath/tools/getopt/ClasspathToolParser.java b/tools/gnu/classpath/tools/getopt/ClasspathToolParser.java
new file mode 100644
index 000000000..e712056ef
--- /dev/null
+++ b/tools/gnu/classpath/tools/getopt/ClasspathToolParser.java
@@ -0,0 +1,73 @@
+/* ClasspathToolParser.java -- Parser subclass for classpath tools
+ 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.getopt;
+
+import java.text.MessageFormat;
+
+import gnu.classpath.Configuration;
+
+/**
+ * This is like the Parser class, but is specialized for use by
+ * tools distributed with GNU Classpath. In particular it automatically
+ * computes the version string using the program's name.
+ */
+public class ClasspathToolParser
+ extends Parser
+{
+ private static String getVersionString(String programName)
+ {
+ String fmt = (Messages.getString("ClasspathToolParser.VersionFormat")); //$NON-NLS-1$
+ return MessageFormat.format(fmt,
+ new Object[]
+ {
+ programName,
+ Configuration.CLASSPATH_VERSION
+ });
+ }
+
+ public ClasspathToolParser(String programName)
+ {
+ super(programName, getVersionString(programName));
+ }
+
+ public ClasspathToolParser(String programName, boolean longOnly)
+ {
+ super(programName, getVersionString(programName), longOnly);
+ }
+}
diff --git a/tools/gnu/classpath/tools/getopt/FileArgumentCallback.java b/tools/gnu/classpath/tools/getopt/FileArgumentCallback.java
new file mode 100644
index 000000000..0c44745c9
--- /dev/null
+++ b/tools/gnu/classpath/tools/getopt/FileArgumentCallback.java
@@ -0,0 +1,61 @@
+/* FileArgumentCallback.java - handle non-option command line arguments
+ 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.getopt;
+
+/**
+ * This is a callback class which is used when a "file name" is found by the
+ * command-line parser. A file name is any command-line argument which does not
+ * start with a dash and which is not the argument of some preceding option.
+ */
+public abstract class FileArgumentCallback
+{
+ /**
+ * Create a new instance.
+ */
+ protected FileArgumentCallback()
+ {
+ }
+
+ /**
+ * This is called when a file argument is seen.
+ *
+ * @param fileArgument the file name
+ */
+ public abstract void notifyFile(String fileArgument);
+}
diff --git a/tools/gnu/classpath/tools/getopt/Messages.java b/tools/gnu/classpath/tools/getopt/Messages.java
new file mode 100644
index 000000000..3c963d786
--- /dev/null
+++ b/tools/gnu/classpath/tools/getopt/Messages.java
@@ -0,0 +1,67 @@
+/* Messages.java -- i18n support for getopt
+ 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.getopt;
+
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
+public class Messages
+{
+ private static final String BUNDLE_NAME
+ = "gnu.classpath.tools.getopt.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 + '!';
+ }
+ }
+}
diff --git a/tools/gnu/classpath/tools/getopt/Option.java b/tools/gnu/classpath/tools/getopt/Option.java
new file mode 100644
index 000000000..6f775e4a1
--- /dev/null
+++ b/tools/gnu/classpath/tools/getopt/Option.java
@@ -0,0 +1,200 @@
+/* Option.java - represent a command-line option
+ 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.getopt;
+
+/**
+ * This is the base class representing an option. An option can have a short
+ * form. This is a single character, like '-x'. An option can have a long form,
+ * like '--verbose'; if the parser is working in "long option only" mode, then a
+ * long flag has a single dash, like '-verbose'. Both a long and a short form
+ * may be specified; it is not valid to have neither. A description is mandatory
+ * for options; this is used to automatically generate '--help' output.
+ */
+public abstract class Option
+{
+ private char shortName;
+
+ private String longName;
+
+ private String description;
+
+ private String argumentName;
+
+ /**
+ * Create a new option with the given short name and description.
+ *
+ * @param shortName the short name
+ * @param description the description
+ */
+ protected Option(char shortName, String description)
+ {
+ this.shortName = shortName;
+ this.description = description;
+ }
+
+ /**
+ * Create a new option with the given short name and description.
+ *
+ * @param shortName the short name
+ * @param description the description
+ * @param argumentName the descriptive name of the argument, if this option
+ * takes an argument; otherwise null
+ */
+ protected Option(char shortName, String description, String argumentName)
+ {
+ this.shortName = shortName;
+ this.description = description;
+ this.argumentName = argumentName;
+ }
+
+ /**
+ * Create a new option with the given long name and description. The long name
+ * should be specified without any leading dashes.
+ *
+ * @param longName the long name
+ * @param description the description
+ */
+ protected Option(String longName, String description)
+ {
+ this.longName = longName;
+ this.description = description;
+ }
+
+ /**
+ * Create a new option with the given long name and description. The long name
+ * should be specified without any leading dashes.
+ *
+ * @param longName the long name
+ * @param description the description
+ * @param argumentName the descriptive name of the argument, if this option
+ * takes an argument; otherwise null
+ */
+ protected Option(String longName, String description, String argumentName)
+ {
+ this.longName = longName;
+ this.description = description;
+ this.argumentName = argumentName;
+ }
+
+ /**
+ * Create a new option with the given short and long names and description.
+ * The long name should be specified without any leading dashes.
+ *
+ * @param longName the long name
+ * @param shortName the short name
+ * @param description the description
+ */
+ protected Option(String longName, char shortName, String description)
+ {
+ this.shortName = shortName;
+ this.longName = longName;
+ this.description = description;
+ }
+
+ /**
+ * Create a new option with the given short and long names and description.
+ * The long name should be specified without any leading dashes.
+ *
+ * @param longName the long name
+ * @param shortName the short name
+ * @param description the description
+ * @param argumentName the descriptive name of the argument, if this option
+ * takes an argument; otherwise null
+ */
+ protected Option(String longName, char shortName, String description,
+ String argumentName)
+ {
+ this.shortName = shortName;
+ this.longName = longName;
+ this.argumentName = argumentName;
+ this.description = description;
+ }
+
+ /**
+ * Return the short name of the option, or \0 if none.
+ */
+ public char getShortName()
+ {
+ return shortName;
+ }
+
+ /**
+ * Return the long name of the option, or null if none.
+ */
+ public String getLongName()
+ {
+ return longName;
+ }
+
+ /**
+ * Return true if the argument takes an option.
+ */
+ public boolean getTakesArgument()
+ {
+ return argumentName != null;
+ }
+
+ /**
+ * Return the name of the argument. If the option does not take an argument,
+ * returns null.
+ */
+ public String getArgumentName()
+ {
+ return argumentName;
+ }
+
+ /**
+ * Return the description of the option.
+ */
+ public String getDescription()
+ {
+ return description;
+ }
+
+ /**
+ * This is called by the parser when this option is recognized. It may be
+ * called multiple times during a single parse. If this option takes an
+ * argument, the argument will be passed in. Otherwise the argument will be
+ * null.
+ *
+ * @param argument the argument
+ * @throws OptionException if the option or its argument is somehow invalid
+ */
+ public abstract void parsed(String argument) throws OptionException;
+}
diff --git a/tools/gnu/classpath/tools/getopt/OptionException.java b/tools/gnu/classpath/tools/getopt/OptionException.java
new file mode 100644
index 000000000..a09d716f4
--- /dev/null
+++ b/tools/gnu/classpath/tools/getopt/OptionException.java
@@ -0,0 +1,52 @@
+/* OptionException.java - when command-line processing fails
+ 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.getopt;
+
+/**
+ * An OptionException is thrown internally when an error is seen when parsing a
+ * command line.
+ */
+public class OptionException
+ extends Exception
+{
+ public OptionException(String message)
+ {
+ super(message);
+ }
+}
diff --git a/tools/gnu/classpath/tools/getopt/OptionGroup.java b/tools/gnu/classpath/tools/getopt/OptionGroup.java
new file mode 100644
index 000000000..f7d966d94
--- /dev/null
+++ b/tools/gnu/classpath/tools/getopt/OptionGroup.java
@@ -0,0 +1,271 @@
+/* OptionGroup.java - a group of related command-line options
+ 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.getopt;
+
+import java.io.PrintStream;
+import java.text.BreakIterator;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.Locale;
+
+/**
+ * An option group holds a collection of Options. It also has a name. Option
+ * groups are primarily useful for grouping help output.
+ */
+public class OptionGroup
+{
+ /** An 80-character string of whitespaces to use as a source for padding. */
+ private static final String FILLER = " "
+ + " ";
+ private String name;
+
+ ArrayList options = new ArrayList();
+
+ /**
+ * Create a new nameless option group. This can only be used by Parser.
+ */
+ OptionGroup()
+ {
+ }
+
+ /**
+ * Create a new option group with the indicated name.
+ *
+ * @param name the name
+ */
+ public OptionGroup(String name)
+ {
+ this.name = name;
+ }
+
+ /**
+ * Print a designated text to a {@link PrintStream}, eventually wrapping the
+ * lines of text so as to ensure that the width of each line does not overflow
+ * {@link Parser#MAX_LINE_LENGTH} columns. The line-wrapping is done with a
+ * {@link BreakIterator} using the default {@link Locale}.
+ * <p>
+ * The text to print may contain <code>\n</code> characters. This method will
+ * force a line-break for each such character.
+ *
+ * @param out the {@link PrintStream} destination of the formatted text.
+ * @param text the text to print.
+ * @param leftMargin a positive value indicating the column position of the
+ * start of the first line. Continuation lines, if they exist, are
+ * printed starting at <code>leftMargin + 2</code> as per GNU
+ * convention.
+ * @see Parser#MAX_LINE_LENGTH
+ */
+ protected static void formatText(PrintStream out, String text, int leftMargin)
+ {
+ formatText(out, text, leftMargin, Locale.getDefault());
+ }
+
+ /**
+ * Similar to the method with the same name and three arguments, except that
+ * the caller MUST specify a non-null {@link Locale} instance.
+ * <p>
+ * Print a designated text to a {@link PrintStream}, eventually wrapping the
+ * lines of text so as to ensure that the width of each line does not overflow
+ * {@link Parser#MAX_LINE_LENGTH} columns. The line-wrapping is done with a
+ * {@link BreakIterator} using the designated {@link Locale}.
+ * <p>
+ * The text to print may contain <code>\n</code> characters. This method will
+ * force a line-break for each such character.
+ *
+ * @param out the {@link PrintStream} destination of the formatted text.
+ * @param text the text to print.
+ * @param leftMargin a positive value indicating the column position of the
+ * start of the first line. Continuation lines, if they exist, are
+ * printed starting at <code>leftMargin + 2</code> as per GNU
+ * convention.
+ * @param aLocale the {@link Locale} instance to use when constructing the
+ * {@link BreakIterator}.
+ * @see Parser#MAX_LINE_LENGTH
+ */
+ protected static void formatText(PrintStream out, String text, int leftMargin,
+ Locale aLocale)
+ {
+ BreakIterator bit = BreakIterator.getLineInstance(aLocale);
+ String[] lines = text.split("\n");
+ int length = leftMargin;
+ String leftPadding = FILLER.substring(0, leftMargin + 2);
+ for (int i = 0; i < lines.length; i++)
+ {
+ text = lines[i];
+ bit.setText(text);
+ int start = bit.first();
+ int finish;
+ while ((finish = bit.next()) != BreakIterator.DONE)
+ {
+ String word = text.substring(start, finish);
+ length += word.length();
+ if (length >= Parser.MAX_LINE_LENGTH)
+ {
+ out.println();
+ out.print(leftPadding);
+ length = word.length() + leftMargin + 2;
+ }
+ out.print(word);
+ start = finish;
+ }
+ out.println();
+ if (i != lines.length - 1)
+ {
+ length = leftMargin + 2;
+ out.print(leftPadding);
+ }
+ }
+ }
+
+ /**
+ * Add an option to this option group.
+ *
+ * @param opt the option to add
+ */
+ public void add(Option opt)
+ {
+ options.add(opt);
+ }
+
+ /**
+ * Print the help output for this option group.
+ *
+ * @param out the stream to which to print
+ */
+ public void printHelp(PrintStream out, boolean longOnly)
+ {
+ // Compute maximum lengths.
+ int maxArgLen = 0;
+ boolean shortOptionSeen = false;
+ Iterator it;
+
+ // The first pass only looks to see if we have a short option.
+ it = options.iterator();
+ while (it.hasNext())
+ {
+ Option option = (Option) it.next();
+ if (option.getShortName() != '\0')
+ {
+ shortOptionSeen = true;
+ break;
+ }
+ }
+
+ it = options.iterator();
+ while (it.hasNext())
+ {
+ Option option = (Option) it.next();
+ String argName = option.getArgumentName();
+ // First compute the width required for the short
+ // option. "2" is the initial indentation. In the
+ // GNU style we don't print an argument name for
+ // a short option if there is also a long name for
+ // the option.
+ int thisArgLen = 2;
+ if (shortOptionSeen)
+ thisArgLen += 4;
+ if (option.getLongName() != null)
+ {
+ // Handle either '-' or '--'.
+ thisArgLen += 1 + option.getLongName().length();
+ if (! longOnly)
+ ++thisArgLen;
+ }
+ // Add in the width of the argument name.
+ if (argName != null)
+ thisArgLen += 1 + argName.length();
+ maxArgLen = Math.max(maxArgLen, thisArgLen);
+ }
+
+ // Print the help.
+ if (name != null)
+ out.println(name + ":");
+ it = options.iterator();
+ while (it.hasNext())
+ {
+ Option option = (Option) it.next();
+ String argName = option.getArgumentName();
+ int column = 0;
+ if (option.getShortName() != '\0')
+ {
+ out.print(" -");
+ out.print(option.getShortName());
+ column += 4;
+ if (option.getLongName() == null)
+ {
+ if (argName != null)
+ {
+ // This is a silly hack just for '-J'. We don't
+ // support joined options in general, but this option
+ // is filtered out before argument processing can see it.
+ if (option.getShortName() != 'J')
+ {
+ out.print(' ');
+ ++column;
+ }
+ out.print(argName);
+ column += argName.length();
+ }
+ out.print(" ");
+ }
+ else
+ out.print(", ");
+ column += 2;
+ }
+ // Indent the long option past the short options, if one
+ // was seen.
+ for (; column < (shortOptionSeen ? 6 : 2); ++column)
+ out.print(' ');
+ if (option.getLongName() != null)
+ {
+ out.print(longOnly ? "-" : "--");
+ out.print(option.getLongName());
+ column += (longOnly ? 1 : 2) + option.getLongName().length();
+ if (argName != null)
+ {
+ out.print(" " + argName);
+ column += 1 + argName.length();
+ }
+ }
+ // FIXME: should have a better heuristic for padding.
+ out.print(FILLER.substring(0, maxArgLen + 4 - column));
+ formatText(out, option.getDescription(), maxArgLen + 4);
+ }
+ }
+}
diff --git a/tools/gnu/classpath/tools/getopt/Parser.java b/tools/gnu/classpath/tools/getopt/Parser.java
new file mode 100644
index 000000000..082cf8945
--- /dev/null
+++ b/tools/gnu/classpath/tools/getopt/Parser.java
@@ -0,0 +1,454 @@
+/* Parser.java - parse command line options
+ 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.getopt;
+
+import java.io.PrintStream;
+import java.text.BreakIterator;
+import java.text.MessageFormat;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.Locale;
+
+/**
+ * An instance of this class is used to parse command-line options. It does "GNU
+ * style" argument recognition and also automatically handles "--help" and
+ * "--version" processing. It can also be put in "long option only" mode. In
+ * this mode long options are recognized with a single dash (as well as a double
+ * dash) and strings of options like "-abc" are never parsed as a collection of
+ * short options.
+ */
+public class Parser
+{
+ /** The maximum right column position. */
+ public static final int MAX_LINE_LENGTH = 80;
+
+ private String programName;
+
+ private String headerText;
+
+ private String footerText;
+
+ private boolean longOnly;
+
+ private ArrayList options = new ArrayList();
+
+ private ArrayList optionGroups = new ArrayList();
+
+ private OptionGroup defaultGroup = new OptionGroup();
+
+ // These are used while parsing.
+ private int currentIndex;
+
+ private String[] args;
+
+ /**
+ * Create a new parser. The program name is used when printing error messages.
+ * The version string is printed verbatim in response to "--version".
+ *
+ * @param programName the name of the program
+ * @param versionString the program's version information
+ */
+ public Parser(String programName, String versionString)
+ {
+ this(programName, versionString, false);
+ }
+
+ /**
+ * Print a designated text to a {@link PrintStream}, eventually wrapping the
+ * lines of text so as to ensure that the width of each line does not overflow
+ * {@link #MAX_LINE_LENGTH} columns. The line-wrapping is done with a
+ * {@link BreakIterator} using the default {@link Locale}.
+ * <p>
+ * The text to print may contain <code>\n</code> characters. This method will
+ * force a line-break for each such character.
+ *
+ * @param out the {@link PrintStream} destination of the formatted text.
+ * @param text the text to print.
+ * @see Parser#MAX_LINE_LENGTH
+ */
+ protected static void formatText(PrintStream out, String text)
+ {
+ formatText(out, text, Locale.getDefault());
+ }
+
+ /**
+ * Similar to the method with the same name and two arguments, except that the
+ * caller MUST specify a non-null {@link Locale} instance.
+ * <p>
+ * Print a designated text to a {@link PrintStream}, eventually wrapping the
+ * lines of text so as to ensure that the width of each line does not overflow
+ * {@link #MAX_LINE_LENGTH} columns. The line-wrapping is done with a
+ * {@link BreakIterator} using the designated {@link Locale}.
+ * <p>
+ * The text to print may contain <code>\n</code> characters. This method will
+ * force a line-break for each such character.
+ *
+ * @param out the {@link PrintStream} destination of the formatted text.
+ * @param text the text to print.
+ * @param aLocale the {@link Locale} instance to use when constructing the
+ * {@link BreakIterator}.
+ * @see Parser#MAX_LINE_LENGTH
+ */
+ protected static void formatText(PrintStream out, String text, Locale aLocale)
+ {
+ BreakIterator bit = BreakIterator.getLineInstance(aLocale);
+ String[] lines = text.split("\n"); //$NON-NLS-1$
+ for (int i = 0; i < lines.length; i++)
+ {
+ text = lines[i];
+ bit.setText(text);
+ int length = 0;
+ int finish;
+ int start = bit.first();
+ while ((finish = bit.next()) != BreakIterator.DONE)
+ {
+ String word = text.substring(start, finish);
+ length += word.length();
+ if (length >= MAX_LINE_LENGTH)
+ {
+ out.println();
+ length = word.length();
+ }
+ out.print(word);
+ start = finish;
+ }
+ out.println();
+ }
+ }
+
+ /**
+ * Create a new parser. The program name is used when printing error messages.
+ * The version string is printed verbatim in response to "--version".
+ *
+ * @param programName the name of the program
+ * @param versionString the program's version information
+ * @param longOnly true if the parser should work in long-option-only mode
+ */
+ public Parser(String programName, final String versionString, boolean longOnly)
+ {
+ this.programName = programName;
+ this.longOnly = longOnly;
+
+ // Put standard options in their own section near the end.
+ OptionGroup finalGroup = new OptionGroup(Messages.getString("Parser.StdOptions")); //$NON-NLS-1$
+ finalGroup.add(new Option("help", Messages.getString("Parser.PrintHelp")) //$NON-NLS-1$ //$NON-NLS-2$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ printHelp(System.out);
+ System.exit(0);
+ }
+ });
+ finalGroup.add(new Option("version", Messages.getString("Parser.PrintVersion")) //$NON-NLS-1$ //$NON-NLS-2$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ System.out.println(versionString);
+ System.exit(0);
+ }
+ });
+ finalGroup.add(new Option('J', Messages.getString("Parser.JArgument"), Messages.getString("Parser.JName")) //$NON-NLS-1$ //$NON-NLS-2$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ // -J should be handled by the appletviewer wrapper binary.
+ // We add it here so that it shows up in the --help output.
+ // Note that there is a special case for this in OptionGroup.
+ }
+ });
+ add(finalGroup);
+
+ add(defaultGroup);
+ }
+
+ /**
+ * Set the header text that is printed by --help.
+ *
+ * @param headerText the header text
+ */
+ public void setHeader(String headerText)
+ {
+ this.headerText = headerText;
+ }
+
+ /**
+ * Set the footer text that is printed by --help.
+ *
+ * @param footerText the footer text
+ */
+ public void setFooter(String footerText)
+ {
+ this.footerText = footerText;
+ }
+
+ /**
+ * Add an option to this parser. The option is added to the default option
+ * group; this affects where it is placed in the help output.
+ *
+ * @param opt the option
+ */
+ public synchronized void add(Option opt)
+ {
+ options.add(opt);
+ defaultGroup.add(opt);
+ }
+
+ /**
+ * Add an option group to this parser. All the options in this group will be
+ * recognized by the parser.
+ *
+ * @param group the option group
+ */
+ public synchronized void add(OptionGroup group)
+ {
+ options.addAll(group.options);
+ // This ensures that the final group always appears at the end
+ // of the options.
+ if (optionGroups.isEmpty())
+ optionGroups.add(group);
+ else
+ optionGroups.add(optionGroups.size() - 1, group);
+ }
+
+ public void printHelp()
+ {
+ this.printHelp(System.out);
+ }
+
+ void printHelp(PrintStream out)
+ {
+ if (headerText != null)
+ {
+ formatText(out, headerText);
+ out.println();
+ }
+
+ Iterator it = optionGroups.iterator();
+ while (it.hasNext())
+ {
+ OptionGroup group = (OptionGroup) it.next();
+ // An option group might be empty, in which case we don't
+ // want to print it..
+ if (! group.options.isEmpty())
+ {
+ group.printHelp(out, longOnly);
+ out.println();
+ }
+ }
+
+ if (footerText != null)
+ formatText(out, footerText);
+ }
+
+ /**
+ * This method can be overridden by subclassses to provide some option
+ * validation. It is called by the parser after all options have been
+ * parsed. If an option validation problem is encountered, this should
+ * throw an {@link OptionException} whose message should be shown to
+ * the user.
+ * <p>
+ * It is better to do validation here than after {@link #parse(String[])}
+ * returns, because the parser will print a message referring the
+ * user to the <code>--help</code> option.
+ * <p>
+ * The base implementation does nothing.
+ *
+ * @throws OptionException the error encountered
+ */
+ protected void validate() throws OptionException
+ {
+ // Base implementation does nothing.
+ }
+
+ private String getArgument(String request) throws OptionException
+ {
+ ++currentIndex;
+ if (currentIndex >= args.length)
+ {
+ String message
+ = MessageFormat.format(Messages.getString("Parser.ArgReqd"), //$NON-NLS-1$
+ new Object[] { request });
+ throw new OptionException(request);
+ }
+ return args[currentIndex];
+ }
+
+ private void handleLongOption(String real, int index) throws OptionException
+ {
+ String option = real.substring(index);
+ String justName = option;
+ int eq = option.indexOf('=');
+ if (eq != - 1)
+ justName = option.substring(0, eq);
+ Option found = null;
+ for (int i = options.size() - 1; i >= 0; --i)
+ {
+ Option opt = (Option) options.get(i);
+ if (justName.equals(opt.getLongName()))
+ {
+ found = opt;
+ break;
+ }
+ }
+ if (found == null)
+ {
+ String msg = MessageFormat.format(Messages.getString("Parser.Unrecognized"), //$NON-NLS-1$
+ new Object[] { real });
+ throw new OptionException(msg);
+ }
+ String argument = null;
+ if (found.getTakesArgument())
+ {
+ if (eq == - 1)
+ argument = getArgument(real);
+ else
+ argument = option.substring(eq + 1);
+ }
+ else if (eq != - 1)
+ {
+ String msg
+ = MessageFormat.format(Messages.getString("Parser.NoArg"), //$NON-NLS-1$
+ new Object[] { real.substring(0, eq + index) });
+ throw new OptionException(msg);
+ }
+ found.parsed(argument);
+ }
+
+ private void handleShortOption(char option) throws OptionException
+ {
+ Option found = null;
+ for (int i = options.size() - 1; i >= 0; --i)
+ {
+ Option opt = (Option) options.get(i);
+ if (option == opt.getShortName())
+ {
+ found = opt;
+ break;
+ }
+ }
+ if (found == null)
+ {
+ String msg = MessageFormat.format(Messages.getString("Parser.UnrecDash"), //$NON-NLS-1$
+ new Object[] { "" + option }); //$NON-NLS-1$
+ throw new OptionException(msg);
+ }
+ String argument = null;
+ if (found.getTakesArgument())
+ argument = getArgument("-" + option); //$NON-NLS-1$
+ found.parsed(argument);
+ }
+
+ private void handleShortOptions(String option) throws OptionException
+ {
+ for (int i = 1; i < option.length(); ++i)
+ {
+ handleShortOption(option.charAt(i));
+ }
+ }
+
+ /**
+ * Parse a command line. Any files which are found will be passed to the file
+ * argument callback. This method will exit on error or when --help or
+ * --version is specified.
+ *
+ * @param inArgs the command-line arguments
+ * @param files the file argument callback
+ */
+ public synchronized void parse(String[] inArgs, FileArgumentCallback files)
+ {
+ try
+ {
+ args = inArgs;
+ for (currentIndex = 0; currentIndex < args.length; ++currentIndex)
+ {
+ if (args[currentIndex].length() == 0
+ || args[currentIndex].charAt(0) != '-'
+ || "-".equals(args[currentIndex])) //$NON-NLS-1$
+ {
+ files.notifyFile(args[currentIndex]);
+ continue;
+ }
+ if ("--".equals(args[currentIndex])) //$NON-NLS-1$
+ break;
+ if (args[currentIndex].charAt(1) == '-')
+ handleLongOption(args[currentIndex], 2);
+ else if (longOnly)
+ handleLongOption(args[currentIndex], 1);
+ else
+ handleShortOptions(args[currentIndex]);
+ }
+ // Add remaining arguments to leftovers.
+ for (++currentIndex; currentIndex < args.length; ++currentIndex)
+ files.notifyFile(args[currentIndex]);
+ // See if something went wrong.
+ validate();
+ }
+ catch (OptionException err)
+ {
+ System.err.println(programName + ": " + err.getMessage()); //$NON-NLS-1$
+ String fmt;
+ if (longOnly)
+ fmt = Messages.getString("Parser.TryHelpShort"); //$NON-NLS-1$
+ else
+ fmt = Messages.getString("Parser.TryHelpLong"); //$NON-NLS-1$
+ String msg = MessageFormat.format(fmt, new Object[] { programName });
+ System.err.println(programName + ": " + msg); //$NON-NLS-1$
+ System.exit(1);
+ }
+ }
+
+ /**
+ * Parse a command line. Any files which are found will be returned. This
+ * method will exit on error or when --help or --version is specified.
+ *
+ * @param inArgs the command-line arguments
+ */
+ public String[] parse(String[] inArgs)
+ {
+ final ArrayList fileResult = new ArrayList();
+ parse(inArgs, new FileArgumentCallback()
+ {
+ public void notifyFile(String fileArgument)
+ {
+ fileResult.add(fileArgument);
+ }
+ });
+ return (String[]) fileResult.toArray(new String[0]);
+ }
+}
diff --git a/tools/gnu/classpath/tools/giop/GRMIC.java b/tools/gnu/classpath/tools/giop/GRMIC.java
index a372cfd66..c910d7083 100644
--- a/tools/gnu/classpath/tools/giop/GRMIC.java
+++ b/tools/gnu/classpath/tools/giop/GRMIC.java
@@ -104,6 +104,17 @@ public class GRMIC
else
HelpPrinter.printHelpAndExit(HelpPath);
}
+ else if (c.equals("-classpath"))
+ {
+ int f = i + 1;
+ if (f < args.length)
+ {
+ compiler.setClassPath(args[f]);
+ i++;
+ }
+ else
+ HelpPrinter.printHelpAndExit(HelpPath);
+ }
else if (c.charAt(0) != '-')
// No more options - start of class list.
{
@@ -124,17 +135,7 @@ public class GRMIC
if (args[i].charAt(0) != '-')
{
compiler.reset();
- Class c = null;
- try
- {
- c = Thread.currentThread().getContextClassLoader().loadClass(
- args[i]);
- }
- catch (ClassNotFoundException e)
- {
- System.err.println(args[i] + " class not found.");
- System.exit(1);
- }
+ Class c = compiler.loadClass(args[i]);
compiler.compile(c);
String packag = compiler.getPackageName().replace('.', '/');
diff --git a/tools/gnu/classpath/tools/giop/GRMIC.txt b/tools/gnu/classpath/tools/giop/GRMIC.txt
index 08aaf148f..875bcdbcf 100644
--- a/tools/gnu/classpath/tools/giop/GRMIC.txt
+++ b/tools/gnu/classpath/tools/giop/GRMIC.txt
@@ -9,18 +9,20 @@ Please report bugs at http://www.gnu.org/software/classpath/bugs.html
Usage: grmic <options> <class names>
where <options> includes:
- -poa Generate the Servant based ties (default)
- -impl Generate the obsoleted ObjectImpl based ties
- (for backward compatibility)
- -nowarn Show no warnings
- -nowrite Do not write any files (check for errors only)
- -d <folder> Place generated files into the given folder
+ -poa Generate the Servant based ties (default)
+ -impl Generate the obsoleted ObjectImpl based ties
+ (for backward compatibility)
+ -nowarn Show no warnings
+ -nowrite Do not write any files (check for errors only)
+ -d <folder> Place generated files into the given folder
+ -classpath <path> Specifies the path, where to find the classes being
+ compiled
- -help Print this help text
- -v Print version
- -verbose Verbose output
- -force Try to generate code even if the input classes seem not
- consistent with RMI specification.
+ -help Print this help text
+ -v Print version
+ -verbose Verbose output
+ -force Try to generate code even if the input classes seem not
+ consistent with RMI specification.
and <class names> can include one or more non abstract classes that implement
diff --git a/tools/gnu/classpath/tools/giop/grmic/GiopRmicCompiler.java b/tools/gnu/classpath/tools/giop/grmic/GiopRmicCompiler.java
index 4beba1c9f..6d895a14c 100644
--- a/tools/gnu/classpath/tools/giop/grmic/GiopRmicCompiler.java
+++ b/tools/gnu/classpath/tools/giop/grmic/GiopRmicCompiler.java
@@ -23,7 +23,11 @@ package gnu.classpath.tools.giop.grmic;
import gnu.classpath.tools.AbstractMethodGenerator;
+import java.io.File;
import java.lang.reflect.Method;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLClassLoader;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.util.ArrayList;
@@ -33,6 +37,7 @@ import java.util.Comparator;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Properties;
+import java.util.StringTokenizer;
import java.util.TreeSet;
/**
@@ -104,6 +109,11 @@ public class GiopRmicCompiler
* Force mode - do not check the exceptions
*/
protected boolean force = false;
+
+ /**
+ * The class loader to load the class being compiled.
+ */
+ ClassLoader classLoader;
/**
* Clear data, preparing for the next compilation.
@@ -116,6 +126,78 @@ public class GiopRmicCompiler
methods.clear();
vars.clear();
}
+
+ /**
+ * Set the class path (handle the -classpath key)
+ *
+ * @param classPath the class path to set.
+ */
+ public void setClassPath(String classPath)
+ {
+ classLoader = Thread.currentThread().getContextClassLoader();
+ StringTokenizer tok = new StringTokenizer(classPath, File.pathSeparator,
+ true);
+ ArrayList urls = new ArrayList(tok.countTokens());
+ String s = null;
+ try
+ {
+ while (tok.hasMoreTokens())
+ {
+ s = tok.nextToken();
+ if (s.equals(File.pathSeparator))
+ urls.add(new File(".").toURL());
+ else
+ {
+ urls.add(new File(s).toURL());
+ if (tok.hasMoreTokens())
+ {
+ // Skip the separator.
+ tok.nextToken();
+ // If the classpath ended with a separator,
+ // append the current directory.
+ if (! tok.hasMoreTokens())
+ urls.add(new File(".").toURL());
+ }
+ }
+ }
+ }
+ catch (MalformedURLException ex)
+ {
+ System.err.println("Malformed path '" + s + "' in classpath '"
+ + classPath + "'");
+ System.exit(1);
+ }
+ URL[] u = new URL[urls.size()];
+ for (int i = 0; i < u.length; i++)
+ {
+ u[i] = (URL) urls.get(i);
+ }
+
+ classLoader = new URLClassLoader(u, classLoader);
+ }
+
+ /**
+ * Loads the class with the given name (uses class path, if applicable)
+ *
+ * @param name the name of the class.
+ */
+ public Class loadClass(String name)
+ {
+ ClassLoader loader = classLoader;
+ if (loader == null)
+ loader = Thread.currentThread().getContextClassLoader();
+ try
+ {
+ return loader.loadClass(name);
+ }
+ catch (ClassNotFoundException e)
+ {
+ System.err.println(name+" not found on "+loader);
+ System.exit(1);
+ // Unreacheable code.
+ return null;
+ }
+ }
/**
* Compile the given class (the instance of Remote), generating the stub and
@@ -193,12 +275,12 @@ public class GiopRmicCompiler
remEx = true;
break;
}
- if (! remEx && !force)
- throw new CompilationError(m[i].getName() + ", defined in "
- + c.getName()
- + ", does not throw "
- + RemoteException.class.getName());
- }
+ }
+ if (! remEx && !force)
+ throw new CompilationError(m[i].getName() + ", defined in "
+ + c.getName()
+ + ", does not throw "
+ + RemoteException.class.getName());
AbstractMethodGenerator mm = createMethodGenerator(m[i]);
methods.add(mm);
}
diff --git a/tools/gnu/classpath/tools/jar/Action.java b/tools/gnu/classpath/tools/jar/Action.java
new file mode 100644
index 000000000..6363157ae
--- /dev/null
+++ b/tools/gnu/classpath/tools/jar/Action.java
@@ -0,0 +1,51 @@
+/* Action.java - an action taken by the jar driver
+ 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.io.IOException;
+
+public abstract class Action
+{
+ protected Action()
+ {
+ }
+
+ public abstract void run(Main parameters)
+ throws IOException;
+}
diff --git a/tools/gnu/classpath/tools/jar/Creator.java b/tools/gnu/classpath/tools/jar/Creator.java
new file mode 100644
index 000000000..55159660d
--- /dev/null
+++ b/tools/gnu/classpath/tools/jar/Creator.java
@@ -0,0 +1,247 @@
+/* Creator.java - create a new jar file
+ 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.io.BufferedOutputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+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;
+import java.util.jar.JarFile;
+import java.util.jar.JarOutputStream;
+import java.util.jar.Manifest;
+import java.util.zip.CRC32;
+import java.util.zip.ZipEntry;
+
+public class Creator
+ extends Action
+{
+ JarOutputStream outputStream;
+ HashSet writtenItems = new HashSet();
+ // The manifest to use, or null if we don't want a manifest.
+ Manifest manifest;
+
+ private long copyFile(CRC32 crc, InputStream is, OutputStream output)
+ throws IOException
+ {
+ byte[] buffer = new byte[1024];
+ long size = 0;
+ while (true)
+ {
+ int len = is.read(buffer);
+ if (len == - 1)
+ break;
+ size += len;
+ output.write(buffer, 0, len);
+ crc.update(buffer, 0, len);
+ }
+ output.close();
+ return size;
+ }
+
+ protected void writeFile(boolean isDirectory, InputStream inputFile,
+ String filename, boolean verbose)
+ throws IOException
+ {
+ if (writtenItems.contains(filename))
+ {
+ if (verbose)
+ {
+ String msg = MessageFormat.format(Messages.getString("Creator.Ignoring"), //$NON-NLS-1$
+ new Object[] { filename });
+ System.err.println(msg);
+ }
+ return;
+ }
+
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ CRC32 crc = new CRC32();
+ long size;
+ if (isDirectory)
+ {
+ size = 0;
+ }
+ else
+ {
+ size = copyFile(crc, inputFile, out);
+ }
+
+ ZipEntry entry = new ZipEntry(filename);
+ entry.setCrc(crc.getValue());
+ entry.setSize(size);
+
+ outputStream.putNextEntry(entry);
+ out.writeTo(outputStream);
+ outputStream.closeEntry();
+ writtenItems.add(filename);
+
+ if (verbose)
+ {
+ long csize = entry.getCompressedSize();
+ long perc;
+ if (size == 0)
+ perc = 0;
+ else
+ perc = 100 - (100 * csize) / size;
+ 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);
+ }
+ }
+
+ protected void writeFile(File file, String filename, boolean verbose)
+ throws IOException
+ {
+ boolean isDirectory = file.isDirectory();
+ InputStream inputStream = null;
+ if (isDirectory)
+ {
+ if (filename.charAt(filename.length() - 1) != '/')
+ filename += '/';
+ }
+ else
+ inputStream = new FileInputStream(file);
+ writeFile(isDirectory, inputStream, filename, verbose);
+ }
+
+ private void addEntries(ArrayList result, Entry entry)
+ {
+ if (entry.file.isDirectory())
+ {
+ String name = entry.name;
+ if (name.charAt(name.length() - 1) != '/')
+ {
+ name += '/';
+ entry = new Entry(entry.file, name);
+ }
+ result.add(entry);
+ String[] files = entry.file.list();
+ for (int i = 0; i < files.length; ++i)
+ addEntries(result, new Entry(new File(entry.file, files[i]),
+ entry.name + files[i]));
+ }
+ else
+ result.add(entry);
+ }
+
+ private ArrayList getAllEntries(Main parameters)
+ {
+ Iterator it = parameters.entries.iterator();
+ ArrayList allEntries = new ArrayList();
+ while (it.hasNext())
+ {
+ Entry entry = (Entry) it.next();
+ addEntries(allEntries, entry);
+ }
+ return allEntries;
+ }
+
+ private void writeCommandLineEntries(Main parameters)
+ throws IOException
+ {
+ // We've already written the manifest, make sure to mark it.
+ writtenItems.add("META-INF/"); //$NON-NLS-1$
+ writtenItems.add(JarFile.MANIFEST_NAME);
+
+ ArrayList allEntries = getAllEntries(parameters);
+ Iterator it = allEntries.iterator();
+ while (it.hasNext())
+ {
+ Entry entry = (Entry) it.next();
+ writeFile(entry.file, entry.name, parameters.verbose);
+ }
+ }
+
+ protected Manifest createManifest(Main parameters)
+ throws IOException
+ {
+ if (! parameters.wantManifest)
+ return null;
+ if (parameters.manifestFile != null)
+ {
+ // User specified a manifest file.
+ InputStream contents = new FileInputStream(parameters.manifestFile);
+ return new Manifest(contents);
+ }
+ return new Manifest();
+ }
+
+ protected void writeCommandLineEntries(Main parameters, OutputStream os)
+ throws IOException
+ {
+ manifest = createManifest(parameters);
+ outputStream = new JarOutputStream(os, manifest);
+ // FIXME: in Classpath this sets the method too late for the
+ // manifest file.
+ outputStream.setMethod(parameters.storageMode);
+ writeCommandLineEntries(parameters);
+ }
+
+ protected void close() throws IOException
+ {
+ outputStream.finish();
+ outputStream.close();
+ }
+
+ public void run(Main parameters) throws IOException
+ {
+ if (parameters.archiveFile == null || parameters.archiveFile.equals("-")) //$NON-NLS-1$
+ writeCommandLineEntries(parameters, System.out);
+ else
+ {
+ OutputStream os
+ = new BufferedOutputStream(new FileOutputStream(parameters.archiveFile));
+ writeCommandLineEntries(parameters, os);
+ }
+ close();
+ }
+}
diff --git a/tools/gnu/classpath/tools/jar/Entry.java b/tools/gnu/classpath/tools/jar/Entry.java
new file mode 100644
index 000000000..aa8679aab
--- /dev/null
+++ b/tools/gnu/classpath/tools/jar/Entry.java
@@ -0,0 +1,60 @@
+/* Entry.java - represent a single file to write to a 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.io.File;
+
+public class Entry
+{
+ public File file;
+
+ public String name;
+
+ public Entry(File file, String name)
+ {
+ this.file = file;
+ this.name = name;
+ }
+
+ public Entry(File file)
+ {
+ this.file = file;
+ this.name = file.toString();
+ }
+}
diff --git a/tools/gnu/classpath/tools/jar/Extractor.java b/tools/gnu/classpath/tools/jar/Extractor.java
new file mode 100644
index 000000000..ed647cbfe
--- /dev/null
+++ b/tools/gnu/classpath/tools/jar/Extractor.java
@@ -0,0 +1,164 @@
+/* Extractor.java - action to extract from a jar file
+ 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.io.BufferedInputStream;
+import java.io.File;
+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;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipInputStream;
+
+public class Extractor
+ extends Action
+{
+ // This is a set of all the items specified on the command line.
+ // It is null if none were specified.
+ private HashSet allItems;
+
+ private void copyFile(InputStream input, File output) throws IOException
+ {
+ FileOutputStream os = new FileOutputStream(output);
+ byte[] buffer = new byte[1024];
+ while (true)
+ {
+ int len = input.read(buffer);
+ if (len == - 1)
+ break;
+ os.write(buffer, 0, len);
+ }
+ os.close();
+ }
+
+ private void initSet(ArrayList entries)
+ {
+ if (entries == null || entries.isEmpty())
+ return;
+ allItems = new HashSet();
+ Iterator it = entries.iterator();
+ while (it.hasNext())
+ {
+ Entry entry = (Entry) it.next();
+ int len = entry.name.length();
+ while (len > 0 && entry.name.charAt(len - 1) == '/')
+ --len;
+ String name = entry.name.substring(0, len);
+ allItems.add(name);
+ }
+ }
+
+ private boolean shouldExtract(String filename)
+ {
+ if (allItems == null)
+ return true;
+ while (filename.length() > 0)
+ {
+ if (allItems.contains(filename))
+ return true;
+ int index = filename.lastIndexOf('/');
+ if (index == -1)
+ break;
+ filename = filename.substring(0, index);
+ }
+ return false;
+ }
+
+ public void run(Main parameters) throws IOException
+ {
+ // Figure out what we want to extract.
+ initSet(parameters.entries);
+ // Open the input file.
+ ZipInputStream zis;
+ File zfile = parameters.archiveFile;
+ if (zfile == null || "-".equals(zfile.getName())) //$NON-NLS-1$
+ zis = new ZipInputStream(System.in);
+ else
+ {
+ InputStream ins = new BufferedInputStream(new FileInputStream(zfile));
+ zis = new ZipInputStream(ins);
+ }
+ // Extract stuff.
+ while (true)
+ {
+ ZipEntry entry = zis.getNextEntry();
+ if (entry == null)
+ break;
+ if (! shouldExtract(entry.getName()))
+ continue;
+ File file = new File(entry.getName());
+ if (entry.isDirectory())
+ {
+ if (file.mkdirs())
+ {
+ if (parameters.verbose)
+ {
+ String msg
+ = MessageFormat.format(Messages.getString("Extractor.Created"), //$NON-NLS-1$
+ new Object[] { file });
+ System.err.println(msg);
+ }
+ }
+ continue;
+ }
+
+ File parent = file.getParentFile();
+ if (parent != null)
+ parent.mkdirs();
+
+ copyFile(zis, file);
+
+ if (parameters.verbose)
+ {
+ 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
new file mode 100644
index 000000000..aae25f821
--- /dev/null
+++ b/tools/gnu/classpath/tools/jar/Indexer.java
@@ -0,0 +1,144 @@
+/* Indexer.java -- add index.list file to 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 gnu.java.net.IndexListParser;
+
+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.Iterator;
+import java.util.LinkedHashSet;
+import java.util.StringTokenizer;
+import java.util.jar.Attributes;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+import java.util.jar.Manifest;
+
+public class Indexer
+ extends Updater
+{
+ private void indexJarFile(StringBuffer result, File fileName,
+ boolean verbose)
+ throws IOException
+ {
+ if (verbose)
+ {
+ 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.
+ // The results look a little better if we keep them
+ // in insertion order.
+ LinkedHashSet entries = new LinkedHashSet();
+ Enumeration e = jf.entries();
+ while (e.hasMoreElements())
+ {
+ JarEntry entry = (JarEntry) e.nextElement();
+ String name = entry.getName();
+ if (name.startsWith("META-INF/")) //$NON-NLS-1$
+ continue;
+ int index = name.lastIndexOf('/');
+ if (index != -1)
+ name = name.substring(0, index);
+ entries.add(name);
+ }
+ if (! entries.isEmpty())
+ {
+ result.append(fileName);
+ // Any line ending will do.
+ result.append('\n');
+ Iterator i = entries.iterator();
+ while (i.hasNext())
+ {
+ result.append(i.next());
+ result.append('\n');
+ }
+ // Paragraph break.
+ result.append('\n');
+ }
+
+ // Now read pointed-to jars.
+ Manifest m = jf.getManifest();
+ if (m != null)
+ {
+ File parent = fileName.getParentFile();
+ Attributes attrs = m.getMainAttributes();
+ String jars = attrs.getValue(Attributes.Name.CLASS_PATH);
+ if (jars != null)
+ {
+ StringTokenizer st = new StringTokenizer(jars, " "); //$NON-NLS-1$
+ while (st.hasMoreTokens())
+ {
+ String name = st.nextToken();
+ indexJarFile(result, new File(parent, name), verbose);
+ }
+ }
+ }
+
+ jf.close();
+ }
+
+ protected void writeCommandLineEntries(Main parameters, OutputStream os)
+ throws IOException
+ {
+ // This is a pretty lame design. We know the super call will
+ // only have side effects and won't actually write anything important.
+ super.writeCommandLineEntries(parameters, os);
+
+ // Now compute our index file and write it.
+ StringBuffer contents = new StringBuffer();
+ indexJarFile(contents, parameters.archiveFile, parameters.verbose);
+ if (contents.length() != 0)
+ {
+ // Insert in reverse order to avoid computing anything.
+ 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());
+ writeFile(false, in, IndexListParser.JAR_INDEX_FILE, parameters.verbose);
+ }
+ }
+}
diff --git a/tools/gnu/classpath/tools/jar/Lister.java b/tools/gnu/classpath/tools/jar/Lister.java
new file mode 100644
index 000000000..ee4fb725e
--- /dev/null
+++ b/tools/gnu/classpath/tools/jar/Lister.java
@@ -0,0 +1,90 @@
+/* Lister.java - action to list contents of a jar file
+ 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.io.BufferedInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.text.MessageFormat;
+import java.util.Date;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipInputStream;
+
+public class Lister
+ extends Action
+{
+ private void listJar(ZipInputStream zis, boolean verbose) throws IOException
+ {
+ MessageFormat format = null;
+ if (verbose)
+ format = new MessageFormat(" {0,date,E M dd HH:mm:ss z yyyy} {1}");
+ while (true)
+ {
+ ZipEntry entry = zis.getNextEntry();
+ if (entry == null)
+ break;
+ if (verbose)
+ {
+ // No easy way to right-justify the size using
+ // MessageFormat -- how odd.
+ long size = entry.getSize();
+ String s = " " + size;
+ int index = Math.min(s.length() - 5, 5);
+ System.out.print(s.substring(index));
+ Object[] values = new Object[] { new Date(entry.getTime()),
+ entry.getName() };
+ System.out.println(format.format(values));
+ }
+ else
+ System.out.println(entry.getName());
+ }
+ }
+
+ public void run(Main parameters) throws IOException
+ {
+ File file = parameters.archiveFile;
+ ZipInputStream zis;
+ if (file == null || "-".equals(file.getName()))
+ zis = new ZipInputStream(System.in);
+ else
+ zis = new ZipInputStream(new BufferedInputStream(new FileInputStream(file)));
+ listJar(zis, parameters.verbose);
+ }
+}
diff --git a/tools/gnu/classpath/tools/jar/Main.java b/tools/gnu/classpath/tools/jar/Main.java
new file mode 100644
index 000000000..8ea770bb6
--- /dev/null
+++ b/tools/gnu/classpath/tools/jar/Main.java
@@ -0,0 +1,266 @@
+/* Main.java - jar program main()
+ 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 gnu.classpath.tools.getopt.ClasspathToolParser;
+import gnu.classpath.tools.getopt.FileArgumentCallback;
+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.File;
+import java.io.IOException;
+import java.text.MessageFormat;
+import java.util.ArrayList;
+import java.util.zip.ZipOutputStream;
+
+public class Main
+{
+ /** The mode of operation. This is the class representing
+ * the action; we make a new instance before using it. It
+ * must be a subclass of Action. 'null' means the mode
+ * has not yet been set. */
+ Class operationMode;
+
+ /** The archive file name. */
+ File archiveFile;
+
+ /** 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;
+
+ /** True if we want a manifest file. */
+ boolean wantManifest = true;
+
+ /** Name of manifest file to use. */
+ File manifestFile;
+
+ /** A list of Entry objects, each describing a file to write. */
+ ArrayList entries = new ArrayList();
+
+ /** Used only while parsing, holds the first argument for -C. */
+ String changedDirectory;
+
+ void setArchiveFile(String filename) throws OptionException
+ {
+ if (archiveFile != null)
+ {
+ String fmt = MessageFormat.format(Messages.getString("Main.ArchiveAlreadySet"), //$NON-NLS-1$
+ new Object[] { archiveFile });
+ throw new OptionException(fmt);
+ }
+ archiveFile = new File(filename);
+ }
+
+ class HandleFile
+ extends FileArgumentCallback
+ {
+ public void notifyFile(String fileArgument)
+ {
+ 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);
+ }
+ }
+
+ // An option that knows how to set the operation mode.
+ private class ModeOption
+ extends Option
+ {
+ private Class mode;
+
+ public ModeOption(char shortName, String description, Class mode)
+ {
+ super(shortName, description);
+ this.mode = mode;
+ }
+
+ public ModeOption(char shortName, String description, String argName,
+ Class mode)
+ {
+ super(shortName, description, argName);
+ this.mode = mode;
+ }
+
+ public void parsed(String argument) throws OptionException
+ {
+ if (operationMode != null)
+ throw new OptionException(Messages.getString("Main.ModeAlreaySet")); //$NON-NLS-1$
+ operationMode = mode;
+ // We know this is only the case for -i.
+ if (argument != null)
+ setArchiveFile(argument);
+ }
+ }
+
+ private class JarParser extends ClasspathToolParser
+ {
+ public JarParser(String name)
+ {
+ super(name);
+ }
+
+ protected void validate() throws OptionException
+ {
+ if (operationMode == null)
+ throw new OptionException(Messages.getString("Main.MustSpecify")); //$NON-NLS-1$
+ if (changedDirectory != null)
+ throw new OptionException(Messages.getString("Main.TwoArgsReqd")); //$NON-NLS-1$
+ if (! wantManifest && manifestFile != null)
+ 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(Messages.getString("Main.NoFilesWithi")); //$NON-NLS-1$
+ if (! wantManifest)
+ throw new OptionException(Messages.getString("Main.NoMAndi")); //$NON-NLS-1$
+ if (manifestFile != null)
+ throw new OptionException(Messages.getString("Main.AnotherNomAndi")); //$NON-NLS-1$
+ }
+ }
+ }
+
+ private Parser initializeParser()
+ {
+ 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', Messages.getString("Main.Index"), Messages.getString("Main.FileArg"), Indexer.class)); //$NON-NLS-1$ //$NON-NLS-2$
+ p.add(grp);
+
+ 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', Messages.getString("Main.NoZip")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ storageMode = ZipOutputStream.STORED;
+ }
+ });
+ 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', Messages.getString("Main.NoManifest")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ wantManifest = false;
+ }
+ });
+ 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
+ {
+ manifestFile = new File(argument);
+ }
+ });
+ // -@
+ p.add(grp);
+
+ 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
+ {
+ changedDirectory = argument;
+ }
+ });
+ p.add(grp);
+
+ return p;
+ }
+
+ private void run(String[] args)
+ throws InstantiationException, IllegalAccessException, IOException
+ {
+ Parser 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());
+ Action t = (Action) operationMode.newInstance();
+ t.run(this);
+ }
+
+ public static void main(String[] args)
+ {
+ Main jarprogram = new Main();
+ try
+ {
+ jarprogram.run(args);
+ }
+ catch (Exception e)
+ {
+ 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 + '!';
+ }
+ }
+}
diff --git a/tools/gnu/classpath/tools/jar/Updater.java b/tools/gnu/classpath/tools/jar/Updater.java
new file mode 100644
index 000000000..29586befd
--- /dev/null
+++ b/tools/gnu/classpath/tools/jar/Updater.java
@@ -0,0 +1,91 @@
+/* Updater.java - action to update a jar file
+ 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.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.Enumeration;
+import java.util.jar.JarFile;
+import java.util.jar.Manifest;
+import java.util.zip.ZipEntry;
+
+public class Updater
+ extends Creator
+{
+ JarFile inputJar;
+
+ protected Manifest createManifest(Main parameters) throws IOException
+ {
+ Manifest result = inputJar.getManifest();
+ if (result == null)
+ return super.createManifest(parameters);
+ if (parameters.manifestFile != null)
+ result.read(new FileInputStream(parameters.manifestFile));
+ return result;
+ }
+
+ public void run(Main parameters) throws IOException
+ {
+ // Set this early so that createManifest can use it.
+ inputJar = new JarFile(parameters.archiveFile);
+
+ // Write all the new entries to a temporary file.
+ File tmpFile = File.createTempFile("jarcopy", null);
+ OutputStream os = new BufferedOutputStream(new FileOutputStream(tmpFile));
+ writeCommandLineEntries(parameters, os);
+
+ // Now read the old file and copy extra entries to the new file.
+ Enumeration e = inputJar.entries();
+ while (e.hasMoreElements())
+ {
+ ZipEntry entry = (ZipEntry) e.nextElement();
+ if (writtenItems.contains(entry.getName()))
+ continue;
+ writeFile(entry.isDirectory(), inputJar.getInputStream(entry),
+ entry.getName(), parameters.verbose);
+ }
+
+ close();
+ tmpFile.renameTo(parameters.archiveFile);
+ }
+}
diff --git a/tools/gnu/classpath/tools/jarsigner/JarSigner.java b/tools/gnu/classpath/tools/jarsigner/JarSigner.java
index 40bee9fe9..8d3bc31af 100644
--- a/tools/gnu/classpath/tools/jarsigner/JarSigner.java
+++ b/tools/gnu/classpath/tools/jarsigner/JarSigner.java
@@ -141,7 +141,7 @@ public class JarSigner
main.isInternalSF());
log.finer("Created .DSA file"); //$NON-NLS-1$
if (main.isVerbose())
- System.out.println(Messages.getString("JarSigner.11") + dsaFileName); //$NON-NLS-1$
+ System.out.println(Messages.getString("JarSigner.8") + dsaFileName); //$NON-NLS-1$
// cleanup
outSignedJarFile.close();
diff --git a/tools/gnu/classpath/tools/jarsigner/Main.java b/tools/gnu/classpath/tools/jarsigner/Main.java
index f460a96cc..6928bce59 100644
--- a/tools/gnu/classpath/tools/jarsigner/Main.java
+++ b/tools/gnu/classpath/tools/jarsigner/Main.java
@@ -39,9 +39,13 @@ exception statement from your version. */
package gnu.classpath.tools.jarsigner;
import gnu.classpath.SystemProperties;
-import gnu.classpath.tools.HelpPrinter;
import gnu.classpath.tools.common.CallbackUtil;
import gnu.classpath.tools.common.ProviderUtil;
+import gnu.classpath.tools.getopt.ClasspathToolParser;
+import gnu.classpath.tools.getopt.FileArgumentCallback;
+import gnu.classpath.tools.getopt.Option;
+import gnu.classpath.tools.getopt.OptionException;
+import gnu.classpath.tools.getopt.OptionGroup;
import gnu.java.security.OID;
import gnu.java.security.Registry;
import gnu.javax.security.auth.callback.ConsoleCallbackHandler;
@@ -61,6 +65,7 @@ import java.security.Security;
import java.security.UnrecoverableKeyException;
import java.security.cert.Certificate;
import java.security.cert.CertificateException;
+import java.util.ArrayList;
import java.util.Locale;
import java.util.jar.Attributes.Name;
import java.util.logging.Logger;
@@ -81,8 +86,8 @@ import javax.security.auth.callback.UnsupportedCallbackException;
*/
public class Main
{
- private static final Logger log = Logger.getLogger(Main.class.getName());
- private static final String HELP_PATH = "jarsigner/jarsigner.txt"; //$NON-NLS-1$
+ protected static final Logger log = Logger.getLogger(Main.class.getName());
+ static final String KEYTOOL_TOOL = "jarsigner"; //$NON-NLS-1$
private static final Locale EN_US_LOCALE = new Locale("en", "US"); //$NON-NLS-1$ //$NON-NLS-2$
static final String DIGEST = "SHA1-Digest"; //$NON-NLS-1$
static final String DIGEST_MANIFEST = "SHA1-Digest-Manifest"; //$NON-NLS-1$
@@ -91,20 +96,20 @@ public class Main
static final OID DSA_SIGNATURE_OID = new OID(Registry.DSA_OID_STRING);
static final OID RSA_SIGNATURE_OID = new OID(Registry.RSA_OID_STRING);
- private boolean verify;
- private String ksURL;
- private String ksType;
- private String password;
- private String ksPassword;
- private String sigFileName;
- private String signedJarFileName;
- private boolean verbose;
- private boolean certs;
- private boolean internalSF;
- private boolean sectionsOnly;
- private String providerClassName;
- private String jarFileName;
- private String alias;
+ protected boolean verify;
+ protected String ksURL;
+ protected String ksType;
+ protected String password;
+ protected String ksPassword;
+ protected String sigFileName;
+ protected String signedJarFileName;
+ protected boolean verbose;
+ protected boolean certs;
+ protected boolean internalSF;
+ protected boolean sectionsOnly;
+ protected String providerClassName;
+ protected String jarFileName;
+ protected String alias;
protected Provider provider;
private boolean providerInstalled;
@@ -115,6 +120,9 @@ public class Main
private Certificate[] signerCertificateChain;
/** The callback handler to use when needing to interact with user. */
private CallbackHandler handler;
+ /** The command line parser. */
+ private ToolParser cmdLineParser;
+ protected ArrayList fileAndAlias = new ArrayList();;
private Main()
{
@@ -126,10 +134,12 @@ public class Main
log.entering(Main.class.getName(), "main", args); //$NON-NLS-1$
Main tool = new Main();
+ int result = 1;
try
{
tool.processArgs(args);
tool.start();
+ result = 0;
}
catch (SecurityException x)
{
@@ -141,11 +151,13 @@ public class Main
log.throwing(Main.class.getName(), "main", x); //$NON-NLS-1$
System.err.println(Messages.getString("Main.9") + x); //$NON-NLS-1$
}
+ finally
+ {
+ tool.teardown();
+ }
- tool.teardown();
-
- log.exiting(Main.class.getName(), "main"); //$NON-NLS-1$
- // System.exit(0);
+ log.exiting(Main.class.getName(), "main", Integer.valueOf(result)); //$NON-NLS-1$
+ System.exit(result);
}
// helper methods -----------------------------------------------------------
@@ -155,65 +167,15 @@ public class Main
* preparation for the user desired action.
*
* @param args an array of options (strings).
- * @throws Exception if an exceptio occurs during the process.
+ * @throws Exception if an exception occurs during the process.
*/
private void processArgs(String[] args) throws Exception
{
log.entering(this.getClass().getName(), "processArgs", args); //$NON-NLS-1$
- HelpPrinter.checkHelpKey(args, HELP_PATH);
- if (args == null || args.length == 0)
- HelpPrinter.printHelpAndExit(HELP_PATH);
-
- int limit = args.length;
- log.finest("args.length=" + limit); //$NON-NLS-1$
- int i = 0;
- String opt;
- while (i < limit)
- {
- opt = args[i++];
- log.finest("args[" + (i - 1) + "]=" + opt); //$NON-NLS-1$ //$NON-NLS-2$
- if (opt == null || opt.length() == 0)
- continue;
-
- if ("-verify".equals(opt)) // -verify //$NON-NLS-1$
- verify = true;
- else if ("-keystore".equals(opt)) // -keystore URL //$NON-NLS-1$
- ksURL = args[i++];
- else if ("-storetype".equals(opt)) // -storetype STORE_TYPE //$NON-NLS-1$
- ksType = args[i++];
- else if ("-storepass".equals(opt)) // -storepass PASSWORD //$NON-NLS-1$
- ksPassword = args[i++];
- else if ("-keypass".equals(opt)) // -keypass PASSWORD //$NON-NLS-1$
- password = args[i++];
- else if ("-sigfile".equals(opt)) // -sigfile NAME //$NON-NLS-1$
- sigFileName = args[i++];
- else if ("-signedjar".equals(opt)) // -signedjar FILE_NAME //$NON-NLS-1$
- signedJarFileName = args[i++];
- else if ("-verbose".equals(opt)) // -verbose //$NON-NLS-1$
- verbose = true;
- else if ("-certs".equals(opt)) // -certs //$NON-NLS-1$
- certs = true;
- else if ("-internalsf".equals(opt)) // -internalsf //$NON-NLS-1$
- internalSF = true;
- else if ("-sectionsonly".equals(opt)) // -sectionsonly //$NON-NLS-1$
- sectionsOnly = true;
- else if ("-provider".equals(opt)) // -provider PROVIDER_CLASS_NAME //$NON-NLS-1$
- providerClassName = args[i++];
- else
- {
- jarFileName = opt;
- if (! verify)
- alias = args[i++];
-
- break;
- }
- }
-
- if (i < limit) // more options than needed
- log.fine("Last argument is assumed at index #" + (i - 1) //$NON-NLS-1$
- + ". Remaining arguments (" + args[i] //$NON-NLS-1$
- + "...) will be ignored"); //$NON-NLS-1$
+ cmdLineParser = new ToolParser();
+ cmdLineParser.initializeParser();
+ cmdLineParser.parse(args, new ToolParserCallback());
setupCommonParams();
if (verify)
@@ -319,9 +281,6 @@ public class Main
{
log.entering(this.getClass().getName(), "setupCommonParams"); //$NON-NLS-1$
- if (jarFileName == null)
- HelpPrinter.printHelpAndExit(HELP_PATH);
-
File jar = new File(jarFileName);
if (! jar.exists())
throw new FileNotFoundException(jarFileName);
@@ -429,9 +388,6 @@ public class Main
InputStream stream = url.openStream();
store.load(stream, ksPasswordChars);
- if (alias == null)
- HelpPrinter.printHelpAndExit(HELP_PATH);
-
if (! store.containsAlias(alias))
throw new SecurityException(Messages.getFormattedString("Main.6", alias)); //$NON-NLS-1$
@@ -564,4 +520,155 @@ public class Main
return handler;
}
+
+ private class ToolParserCallback
+ extends FileArgumentCallback
+ {
+ public void notifyFile(String fileArgument)
+ {
+ fileAndAlias.add(fileArgument);
+ }
+ }
+
+ private class ToolParser
+ extends ClasspathToolParser
+ {
+ public ToolParser()
+ {
+ super(KEYTOOL_TOOL, true);
+ }
+
+ protected void validate() throws OptionException
+ {
+ if (fileAndAlias.size() < 1)
+ throw new OptionException(Messages.getString("Main.133")); //$NON-NLS-1$
+
+ jarFileName = (String) fileAndAlias.get(0);
+ if (! verify) // must have an ALIAS. use "mykey" if undefined
+ if (fileAndAlias.size() < 2)
+ {
+ log.finer("Missing ALIAS argument. Will use [mykey] instead"); //$NON-NLS-1$
+ alias = "mykey"; //$NON-NLS-1$
+ }
+ else
+ alias = (String) fileAndAlias.get(1);
+ }
+
+ public void initializeParser()
+ {
+ setHeader(Messages.getString("Main.2")); //$NON-NLS-1$
+ setFooter(Messages.getString("Main.1")); //$NON-NLS-1$
+ OptionGroup signGroup = new OptionGroup(Messages.getString("Main.0")); //$NON-NLS-1$
+ signGroup.add(new Option("keystore", //$NON-NLS-1$
+ Messages.getString("Main.101"), //$NON-NLS-1$
+ Messages.getString("Main.102")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ ksURL = argument;
+ }
+ });
+ signGroup.add(new Option("storetype", //$NON-NLS-1$
+ Messages.getString("Main.104"), //$NON-NLS-1$
+ Messages.getString("Main.105")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ ksType = argument;
+ }
+ });
+ signGroup.add(new Option("storepass", //$NON-NLS-1$
+ Messages.getString("Main.107"), //$NON-NLS-1$
+ Messages.getString("Main.108")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ ksPassword = argument;
+ }
+ });
+ signGroup.add(new Option("keypass", //$NON-NLS-1$
+ Messages.getString("Main.110"), //$NON-NLS-1$
+ Messages.getString("Main.111")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ password = argument;
+ }
+ });
+ signGroup.add(new Option("sigfile", //$NON-NLS-1$
+ Messages.getString("Main.113"), //$NON-NLS-1$
+ Messages.getString("Main.114")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ sigFileName = argument;
+ }
+ });
+ signGroup.add(new Option("signedjar", //$NON-NLS-1$
+ Messages.getString("Main.116"), //$NON-NLS-1$
+ Messages.getString("Main.117")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ signedJarFileName = argument;
+ }
+ });
+ add(signGroup);
+
+ OptionGroup verifyGroup = new OptionGroup(Messages.getString("Main.118")); //$NON-NLS-1$
+ verifyGroup.add(new Option("verify", //$NON-NLS-1$
+ Messages.getString("Main.120")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ verify = true;
+ }
+ });
+ verifyGroup.add(new Option("certs", //$NON-NLS-1$
+ Messages.getString("Main.122")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ certs = true;
+ }
+ });
+ add(verifyGroup);
+
+ OptionGroup commonGroup = new OptionGroup(Messages.getString("Main.123")); //$NON-NLS-1$
+ commonGroup.add(new Option("verbose", //$NON-NLS-1$
+ Messages.getString("Main.125")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ verbose = true;
+ }
+ });
+ commonGroup.add(new Option("internalsf", //$NON-NLS-1$
+ Messages.getString("Main.127")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ internalSF = true;
+ }
+ });
+ commonGroup.add(new Option("sectionsonly", //$NON-NLS-1$
+ Messages.getString("Main.129")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ sectionsOnly = true;
+ }
+ });
+ commonGroup.add(new Option("provider", //$NON-NLS-1$
+ Messages.getString("Main.131"), //$NON-NLS-1$
+ Messages.getString("Main.132")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ providerClassName = argument;
+ }
+ });
+ add(commonGroup);
+ }
+ }
}
diff --git a/tools/gnu/classpath/tools/jarsigner/jarsigner.txt b/tools/gnu/classpath/tools/jarsigner/jarsigner.txt
deleted file mode 100644
index e615609c1..000000000
--- a/tools/gnu/classpath/tools/jarsigner/jarsigner.txt
+++ /dev/null
@@ -1,116 +0,0 @@
-NAME
- jarsigner - Java ARchive (JAR) file signing and verification tool
-
-SYNOPSIS
- jarsigner [OPTION]... FILE ALIAS
- jarsigner -verify [OPTION]... FILE
-
-DESCRIPTION
- When the first form is used, the tool signs the designated JAR file.
- The second form, on the other hand, is used to verify a previously
- signed JAR file.
-
- FILE is the .JAR file to process; i.e. to sign if the first syntax form
- is used, or to verify if the second syntax form is used instead.
-
- ALIAS must be a known Alias of a Key Entry in the designated key store.
- The private key material associated with this Alias is then used for
- signing the designated .JAR file.
-
-SIGNING OPTIONS
- -keystore URL
- Use this option to specify the location of the key store to use.
- The default value is a file URL referencing the file named
- ".keystore" (all lower case and without the enclosing quotes)
- located in the path returned by the call to
- java.lang.System#getProperty(String) using "user.home" as
- argument.
-
- If a URL was specified, but was found to be malformed --e.g.
- missing protocol element-- the tool will attempt to use the URL
- value as a file-name (with absolute or relative path-name) of a
- key store --as if the protocol was "file:".
-
- -storetype STORE_TYPE
- Use this option to specify the type of the key store to use.
- The default value, if this option is omitted, is that of the
- property "keystore.type" in the security properties file, which
- is obtained by invoking the static method call getDefaultType()
- in java.security.KeyStore.
-
- -storepass PASSWORD
- Use this option to specify the password which will be used to
- unlock the key store. If this option is missing, the User will
- be prompted to provide a password.
-
- -keypass PASSWORD
- Use this option to specify the password which the tool will use
- to unlock the Key Entry associated with the designated Alias.
-
- If this option is omitted, the tool will first attempt to unlock
- the Key Entry using the same password protecting the key store.
- If this fails, you will then be prompted to provide a password.
-
- -sigfile NAME
- Use this option to designate a literal that will be used to
- construct file names for both the .SF and .DSA signature files.
- These files will be generated, by the tool, and placed in the
- META-INF directory of the signed JAR. Permissible characters
- for NAME must be in the range "a-zA-Z0-9_-". All characters
- will be converted to upper-case ones.
-
- If this option is missing, the first eight characters of the
- ALIAS argument will be used. When this is the case, any
- character in ALIAS that is outside the permissible range of
- characters will be replaced by an underscore.
-
- -signedjar FILE_NAME
- Use this option to specify the file name of the signed JAR. If
- this option is omitted, then the signed JAR will be named the
- same as FILE; i.e. the input JAR file will be replaced with the
- signed copy.
-
-VERIFICATION OPTIONS
- -verify
- Use this option to indicate that the tool is to be used for
- verification purposes.
-
- -certs This option is used in conjunction with the -verbose option.
- When present, along with the -verbose option, the tool will
- print more detailed information about the certificates of the
- signer(s) being processed.
-
-COMMON OPTIONS
- -verbose
- Use this option to force the tool to generate more verbose
- messages, during its processing.
-
- -internalsf
- When present, the tool will include --which otherwise it does
- not-- the .SF file in the .DSA generated file.
-
- -sectionsonly
- When present, the tool will include in the .SF generated file
- --which otherwise it does not-- a header containing a hash of
- the whole manifest file. When that header is included, the
- tool can quickly check, during verification, if the hash (in
- the header) matches or not the manifest file.
-
- -provider PROVIDER_CLASS_NAME
- A fully qualified class name of a Security Provider to add to
- the current list of Security Providers already installed in the
- JVM in-use. If a provider class is specified with this option,
- and was successfully added to the runtime --i.e. it was not
- already installed-- then the tool will attempt to remove this
- Security Provider before exiting.
-
- -help Prints this help text.
-
-REPORTING BUGS
- Please report bugs at http://www.gnu.org/software/classpath/bugs.html
-
-COPYRIGHT
- Copyright (C) 2006 Free Software Foundation, Inc.
- This is free software; see the source for copying conditions. There is
- NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR
- PURPOSE.
diff --git a/tools/gnu/classpath/tools/keytool/CertReqCmd.java b/tools/gnu/classpath/tools/keytool/CertReqCmd.java
index 0c64246e8..3de97e589 100644
--- a/tools/gnu/classpath/tools/keytool/CertReqCmd.java
+++ b/tools/gnu/classpath/tools/keytool/CertReqCmd.java
@@ -38,6 +38,11 @@ exception statement from your version. */
package gnu.classpath.tools.keytool;
+import gnu.classpath.tools.getopt.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 gnu.java.security.OID;
import gnu.java.security.der.BitString;
import gnu.java.security.der.DER;
@@ -170,15 +175,16 @@ import javax.security.auth.x500.X500Principal;
class CertReqCmd extends Command
{
private static final Logger log = Logger.getLogger(CertReqCmd.class.getName());
- private String _alias;
- private String _sigAlgorithm;
- private String _certReqFileName;
- private String _password;
- private String _ksType;
- private String _ksURL;
- private String _ksPassword;
- private String _providerClassName;
- private boolean nullAttributes;
+ private static final String ATTRIBUTES_OPT = "attributes"; //$NON-NLS-1$
+ protected String _alias;
+ protected String _sigAlgorithm;
+ protected String _certReqFileName;
+ protected String _password;
+ protected String _ksType;
+ protected String _ksURL;
+ protected String _ksPassword;
+ protected String _providerClassName;
+ protected boolean nullAttributes;
// default 0-arguments constructor
@@ -246,60 +252,19 @@ class CertReqCmd extends Command
// life-cycle methods -------------------------------------------------------
- int processArgs(String[] args, int i)
- {
- int limit = args.length;
- String opt;
- while (++i < limit)
- {
- opt = args[i];
- log.finest("args[" + i + "]=" + opt); //$NON-NLS-1$ //$NON-NLS-2$
- if (opt == null || opt.length() == 0)
- continue;
-
- if ("-alias".equals(opt)) // -alias ALIAS //$NON-NLS-1$
- _alias = args[++i];
- else if ("-sigalg".equals(opt)) // -sigalg ALGORITHM //$NON-NLS-1$
- _sigAlgorithm = args[++i];
- else if ("-file".equals(opt)) // -file FILE_NAME //$NON-NLS-1$
- _certReqFileName = args[++i];
- else if ("-keypass".equals(opt)) // -keypass PASSWORD //$NON-NLS-1$
- _password = args[++i];
- else if ("-storetype".equals(opt)) // -storetype STORE_TYPE //$NON-NLS-1$
- _ksType = args[++i];
- else if ("-keystore".equals(opt)) // -keystore URL //$NON-NLS-1$
- _ksURL = args[++i];
- else if ("-storepass".equals(opt)) // -storepass PASSWORD //$NON-NLS-1$
- _ksPassword = args[++i];
- else if ("-provider".equals(opt)) // -provider PROVIDER_CLASS_NAME //$NON-NLS-1$
- _providerClassName = args[++i];
- else if ("-v".equals(opt)) //$NON-NLS-1$
- verbose = true;
- else if ("-attributes".equals(opt)) //$NON-NLS-1$
- nullAttributes = true;
- else
- break;
- }
-
- return i;
- }
-
void setup() throws Exception
{
setOutputStreamParam(_certReqFileName);
setKeyStoreParams(_providerClassName, _ksType, _ksPassword, _ksURL);
setAliasParam(_alias);
setKeyPasswordNoPrompt(_password);
-// setSignatureAlgorithm(_sigAlgorithm);
log.finer("-certreq handler will use the following options:"); //$NON-NLS-1$
log.finer(" -alias=" + alias); //$NON-NLS-1$
log.finer(" -sigalg=" + _sigAlgorithm); //$NON-NLS-1$
log.finer(" -file=" + _certReqFileName); //$NON-NLS-1$
- log.finer(" -keypass=" + _password); //$NON-NLS-1$
log.finer(" -storetype=" + storeType); //$NON-NLS-1$
log.finer(" -keystore=" + storeURL); //$NON-NLS-1$
- log.finer(" -storepass=" + String.valueOf(storePasswordChars)); //$NON-NLS-1$
log.finer(" -provider=" + provider); //$NON-NLS-1$
log.finer(" -v=" + verbose); //$NON-NLS-1$
log.finer(" -attributes=" + nullAttributes); //$NON-NLS-1$
@@ -346,6 +311,108 @@ class CertReqCmd extends Command
// own methods --------------------------------------------------------------
+ Parser getParser()
+ {
+ log.entering(this.getClass().getName(), "getParser"); //$NON-NLS-1$
+
+ Parser result = new ClasspathToolParser(Main.CERTREQ_CMD, true);
+ result.setHeader(Messages.getString("CertReqCmd.25")); //$NON-NLS-1$
+ result.setFooter(Messages.getString("CertReqCmd.24")); //$NON-NLS-1$
+ OptionGroup options = new OptionGroup(Messages.getString("CertReqCmd.23")); //$NON-NLS-1$
+ options.add(new Option(Main.ALIAS_OPT,
+ Messages.getString("CertReqCmd.22"), //$NON-NLS-1$
+ Messages.getString("CertReqCmd.21")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ _alias = argument;
+ }
+ });
+ options.add(new Option(Main.SIGALG_OPT,
+ Messages.getString("CertReqCmd.20"), //$NON-NLS-1$
+ Messages.getString("CertReqCmd.19")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ _sigAlgorithm = argument;
+ }
+ });
+ options.add(new Option(Main.FILE_OPT,
+ Messages.getString("CertReqCmd.18"), //$NON-NLS-1$
+ Messages.getString("CertReqCmd.17")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ _certReqFileName = argument;
+ }
+ });
+ options.add(new Option(Main.KEYPASS_OPT,
+ Messages.getString("CertReqCmd.16"), //$NON-NLS-1$
+ Messages.getString("CertReqCmd.9")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ _password = argument;
+ }
+ });
+ options.add(new Option(Main.STORETYPE_OPT,
+ Messages.getString("CertReqCmd.14"), //$NON-NLS-1$
+ Messages.getString("CertReqCmd.13")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ _ksType = argument;
+ }
+ });
+ options.add(new Option(Main.KEYSTORE_OPT,
+ Messages.getString("CertReqCmd.12"), //$NON-NLS-1$
+ Messages.getString("CertReqCmd.11")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ _ksURL = argument;
+ }
+ });
+ options.add(new Option(Main.STOREPASS_OPT,
+ Messages.getString("CertReqCmd.10"), //$NON-NLS-1$
+ Messages.getString("CertReqCmd.9")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ _ksPassword = argument;
+ }
+ });
+ options.add(new Option(Main.PROVIDER_OPT,
+ Messages.getString("CertReqCmd.8"), //$NON-NLS-1$
+ Messages.getString("CertReqCmd.7")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ _providerClassName = argument;
+ }
+ });
+ options.add(new Option(Main.VERBOSE_OPT,
+ Messages.getString("CertReqCmd.6")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ verbose = true;
+ }
+ });
+ options.add(new Option(ATTRIBUTES_OPT,
+ Messages.getString("CertReqCmd.5")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ nullAttributes = true;
+ }
+ });
+ result.add(options);
+
+ log.exiting(this.getClass().getName(), "getParser", result); //$NON-NLS-1$
+ return result;
+ }
+
/**
* @param aliasName
* @param publicKey
diff --git a/tools/gnu/classpath/tools/keytool/Command.java b/tools/gnu/classpath/tools/keytool/Command.java
index a59614644..0d8c56334 100644
--- a/tools/gnu/classpath/tools/keytool/Command.java
+++ b/tools/gnu/classpath/tools/keytool/Command.java
@@ -42,6 +42,7 @@ import gnu.classpath.SystemProperties;
import gnu.classpath.tools.common.CallbackUtil;
import gnu.classpath.tools.common.ProviderUtil;
import gnu.classpath.tools.common.SecurityProviderInfo;
+import gnu.classpath.tools.getopt.Parser;
import gnu.java.security.OID;
import gnu.java.security.Registry;
import gnu.java.security.der.BitString;
@@ -193,14 +194,14 @@ abstract class Command
public void doCommand() throws Exception
{
try
- {
- setup();
- start();
- }
+ {
+ setup();
+ start();
+ }
finally
- {
- teardown();
- }
+ {
+ teardown();
+ }
}
/**
@@ -228,11 +229,18 @@ abstract class Command
*
* @param args an array of options for this handler and possibly other
* commands and their options.
- * @param startIndex the index of the first argument in <code>args</code> to
- * process.
- * @return the index of the first unprocessed argument in <code>args</code>.
+ * @return the remaining un-processed <code>args</code>.
*/
- abstract int processArgs(String[] args, int startIndex);
+ String[] processArgs(String[] args)
+ {
+ log.entering(this.getClass().getName(), "processArgs", args); //$NON-NLS-1$
+
+ Parser cmdOptionsParser = getParser();
+ String[] result = cmdOptionsParser.parse(args);
+
+ log.exiting(this.getClass().getName(), "processArgs", result); //$NON-NLS-1$
+ return result;
+ }
/**
* Initialize this concrete command handler for later invocation of the
@@ -346,6 +354,12 @@ abstract class Command
// parameter setup and validation methods -----------------------------------
/**
+ * @return a {@link Parser} that knows how to parse the concrete command's
+ * options.
+ */
+ abstract Parser getParser();
+
+ /**
* Convenience method to setup the key store given its type, its password, its
* location and portentially a specialized security provider.
*
@@ -486,7 +500,6 @@ abstract class Command
storePasswordChars = pcb.getPassword();
pcb.clearPassword();
}
- log.finest("storePasswordChars = [" + String.valueOf(storePasswordChars)+ "]"); //$NON-NLS-1$ //$NON-NLS-2$
}
/**
@@ -575,7 +588,7 @@ abstract class Command
catch (IOException x)
{
log.fine("Exception while closing the key store input stream: " + x //$NON-NLS-1$
- + ". Ignore"); //$NON-NLS-1$
+ + ". Ignore"); //$NON-NLS-1$
}
}
@@ -970,7 +983,7 @@ abstract class Command
protected void saveKeyStore(char[] password) throws IOException,
KeyStoreException, NoSuchAlgorithmException, CertificateException
{
- log.entering(this.getClass().getName(), "saveKeyStore", String.valueOf(password)); //$NON-NLS-1$
+ log.entering(this.getClass().getName(), "saveKeyStore"); //$NON-NLS-1$
URLConnection con = storeURL.openConnection();
con.setDoOutput(true);
diff --git a/tools/gnu/classpath/tools/keytool/DeleteCmd.java b/tools/gnu/classpath/tools/keytool/DeleteCmd.java
index 968af50f8..9022f1c20 100644
--- a/tools/gnu/classpath/tools/keytool/DeleteCmd.java
+++ b/tools/gnu/classpath/tools/keytool/DeleteCmd.java
@@ -38,6 +38,12 @@ exception statement from your version. */
package gnu.classpath.tools.keytool;
+import gnu.classpath.tools.getopt.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.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
@@ -106,11 +112,11 @@ import javax.security.auth.callback.UnsupportedCallbackException;
class DeleteCmd extends Command
{
private static final Logger log = Logger.getLogger(DeleteCmd.class.getName());
- private String _alias;
- private String _ksType;
- private String _ksURL;
- private String _ksPassword;
- private String _providerClassName;
+ protected String _alias;
+ protected String _ksType;
+ protected String _ksURL;
+ protected String _ksPassword;
+ protected String _providerClassName;
// default 0-arguments constructor
@@ -148,36 +154,6 @@ class DeleteCmd extends Command
// life-cycle methods -------------------------------------------------------
- int processArgs(String[] args, int i)
- {
- int limit = args.length;
- String opt;
- while (++i < limit)
- {
- opt = args[i];
- log.finest("args[" + i + "]=" + opt); //$NON-NLS-1$ //$NON-NLS-2$
- if (opt == null || opt.length() == 0)
- continue;
-
- if ("-alias".equals(opt)) // -alias ALIAS //$NON-NLS-1$
- _alias = args[++i];
- else if ("-storetype".equals(opt)) // -storetype STORE_TYPE //$NON-NLS-1$
- _ksType = args[++i];
- else if ("-keystore".equals(opt)) // -keystore URL //$NON-NLS-1$
- _ksURL = args[++i];
- else if ("-storepass".equals(opt)) // -storepass PASSWORD //$NON-NLS-1$
- _ksPassword = args[++i];
- else if ("-provider".equals(opt)) // -provider PROVIDER_CLASS_NAME //$NON-NLS-1$
- _providerClassName = args[++i];
- else if ("-v".equals(opt)) //$NON-NLS-1$
- verbose = true;
- else
- break;
- }
-
- return i;
- }
-
void setup() throws Exception
{
setKeyStoreParams(_providerClassName, _ksType, _ksPassword, _ksURL);
@@ -187,7 +163,6 @@ class DeleteCmd extends Command
log.finer(" -alias=" + alias); //$NON-NLS-1$
log.finer(" -storetype=" + storeType); //$NON-NLS-1$
log.finer(" -keystore=" + storeURL); //$NON-NLS-1$
- log.finer(" -storepass=" + String.valueOf(storePasswordChars)); //$NON-NLS-1$
log.finer(" -provider=" + provider); //$NON-NLS-1$
log.finer(" -v=" + verbose); //$NON-NLS-1$
}
@@ -206,6 +181,73 @@ class DeleteCmd extends Command
// own methods --------------------------------------------------------------
+ Parser getParser()
+ {
+ log.entering(this.getClass().getName(), "getParser"); //$NON-NLS-1$
+
+ Parser result = new ClasspathToolParser(Main.DELETE_CMD, true);
+ result.setHeader(Messages.getString("DeleteCmd.18")); //$NON-NLS-1$
+ result.setFooter(Messages.getString("DeleteCmd.17")); //$NON-NLS-1$
+ OptionGroup options = new OptionGroup(Messages.getString("DeleteCmd.16")); //$NON-NLS-1$
+ options.add(new Option(Main.ALIAS_OPT,
+ Messages.getString("DeleteCmd.15"), //$NON-NLS-1$
+ Messages.getString("DeleteCmd.14")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ _alias = argument;
+ }
+ });
+ options.add(new Option(Main.STORETYPE_OPT,
+ Messages.getString("DeleteCmd.13"), //$NON-NLS-1$
+ Messages.getString("DeleteCmd.12")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ _ksType = argument;
+ }
+ });
+ options.add(new Option(Main.KEYSTORE_OPT,
+ Messages.getString("DeleteCmd.11"), //$NON-NLS-1$
+ Messages.getString("DeleteCmd.10")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ _ksURL = argument;
+ }
+ });
+ options.add(new Option(Main.STOREPASS_OPT,
+ Messages.getString("DeleteCmd.9"), //$NON-NLS-1$
+ Messages.getString("DeleteCmd.8")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ _ksPassword = argument;
+ }
+ });
+ options.add(new Option(Main.PROVIDER_OPT,
+ Messages.getString("DeleteCmd.7"), //$NON-NLS-1$
+ Messages.getString("DeleteCmd.6")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ _providerClassName = argument;
+ }
+ });
+ options.add(new Option(Main.VERBOSE_OPT,
+ Messages.getString("DeleteCmd.5")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ verbose = true;
+ }
+ });
+ result.add(options);
+
+ log.exiting(this.getClass().getName(), "getParser", result); //$NON-NLS-1$
+ return result;
+ }
+
/**
* Set the alias to delete from the key store.
* <p>
diff --git a/tools/gnu/classpath/tools/keytool/ExportCmd.java b/tools/gnu/classpath/tools/keytool/ExportCmd.java
index c1c0d4f83..49582a944 100644
--- a/tools/gnu/classpath/tools/keytool/ExportCmd.java
+++ b/tools/gnu/classpath/tools/keytool/ExportCmd.java
@@ -38,6 +38,11 @@ exception statement from your version. */
package gnu.classpath.tools.keytool;
+import gnu.classpath.tools.getopt.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 gnu.java.security.util.Base64;
import java.io.IOException;
@@ -119,13 +124,13 @@ import java.util.logging.Logger;
class ExportCmd extends Command
{
private static final Logger log = Logger.getLogger(ExportCmd.class.getName());
- private String _alias;
- private String _certFileName;
- private String _ksType;
- private String _ksURL;
- private String _ksPassword;
- private String _providerClassName;
- private boolean rfc;
+ protected String _alias;
+ protected String _certFileName;
+ protected String _ksType;
+ protected String _ksURL;
+ protected String _ksPassword;
+ protected String _providerClassName;
+ protected boolean rfc;
// default 0-arguments constructor
@@ -178,72 +183,37 @@ class ExportCmd extends Command
// life-cycle methods -------------------------------------------------------
- int processArgs(String[] args, int i)
- {
- int limit = args.length;
- String opt;
- while (++i < limit)
- {
- opt = args[i];
- log.finest("args[" + i + "]=" + opt);
- if (opt == null || opt.length() == 0)
- continue;
-
- if ("-alias".equals(opt)) // -alias ALIAS
- _alias = args[++i];
- else if ("-file".equals(opt)) // -file FILE_NAME
- _certFileName = args[++i];
- else if ("-storetype".equals(opt)) // -storetype STORE_TYPE
- _ksType = args[++i];
- else if ("-keystore".equals(opt)) // -keystore URL
- _ksURL = args[++i];
- else if ("-storepass".equals(opt)) // -storepass PASSWORD
- _ksPassword = args[++i];
- else if ("-provider".equals(opt)) // -provider PROVIDER_CLASS_NAME
- _providerClassName = args[++i];
- else if ("-rfc".equals(opt))
- rfc = true;
- else if ("-v".equals(opt))
- verbose = true;
- else
- break;
- }
-
- return i;
- }
-
void setup() throws Exception
{
setOutputStreamParam(_certFileName);
setKeyStoreParams(_providerClassName, _ksType, _ksPassword, _ksURL);
setAliasParam(_alias);
- log.finer("-export handler will use the following options:");
- log.finer(" -alias=" + alias);
- log.finer(" -file=" + _certFileName);
- log.finer(" -storetype=" + storeType);
- log.finer(" -keystore=" + storeURL);
- log.finer(" -storepass=" + String.valueOf(storePasswordChars));
- log.finer(" -provider=" + provider);
- log.finer(" -rfc=" + rfc);
- log.finer(" -v=" + verbose);
+ log.finer("-export handler will use the following options:"); //$NON-NLS-1$
+ log.finer(" -alias=" + alias); //$NON-NLS-1$
+ log.finer(" -file=" + _certFileName); //$NON-NLS-1$
+ log.finer(" -storetype=" + storeType); //$NON-NLS-1$
+ log.finer(" -keystore=" + storeURL); //$NON-NLS-1$
+ log.finer(" -provider=" + provider); //$NON-NLS-1$
+ log.finer(" -rfc=" + rfc); //$NON-NLS-1$
+ log.finer(" -v=" + verbose); //$NON-NLS-1$
}
void start() throws KeyStoreException, CertificateEncodingException,
IOException
{
- log.entering(this.getClass().getName(), "start");
+ log.entering(this.getClass().getName(), "start"); //$NON-NLS-1$
ensureStoreContainsAlias();
Certificate certificate;
if (store.isCertificateEntry(alias))
{
- log.fine("Alias [" + alias + "] is a trusted certificate");
+ log.finer("Alias [" + alias + "] is a trusted certificate"); //$NON-NLS-1$ //$NON-NLS-2$
certificate = store.getCertificate(alias);
}
else
{
- log.fine("Alias [" + alias + "] is a key entry");
+ log.finer("Alias [" + alias + "] is a key entry"); //$NON-NLS-1$ //$NON-NLS-2$
Certificate[] chain = store.getCertificateChain(alias);
certificate = chain[0];
}
@@ -253,14 +223,100 @@ class ExportCmd extends Command
{
String encoded = Base64.encode(derBytes, 0, derBytes.length, true);
PrintWriter pw = new PrintWriter(outStream, true);
- pw.println("-----BEGIN CERTIFICATE-----");
+ pw.println("-----BEGIN CERTIFICATE-----"); //$NON-NLS-1$
pw.println(encoded);
- pw.println("-----END CERTIFICATE-----");
+ pw.println("-----END CERTIFICATE-----"); //$NON-NLS-1$
}
else
outStream.write(derBytes);
// stream is closed in Command.teardown()
- log.exiting(this.getClass().getName(), "start");
+ log.exiting(this.getClass().getName(), "start"); //$NON-NLS-1$
+ }
+
+ // own methods --------------------------------------------------------------
+
+ Parser getParser()
+ {
+ log.entering(this.getClass().getName(), "getParser"); //$NON-NLS-1$
+
+ Parser result = new ClasspathToolParser(Main.EXPORT_CMD, true);
+ result.setHeader(Messages.getString("ExportCmd.17")); //$NON-NLS-1$
+ result.setFooter(Messages.getString("ExportCmd.18")); //$NON-NLS-1$
+ OptionGroup options = new OptionGroup(Messages.getString("ExportCmd.19")); //$NON-NLS-1$
+ options.add(new Option(Main.ALIAS_OPT,
+ Messages.getString("ExportCmd.20"), //$NON-NLS-1$
+ Messages.getString("ExportCmd.21")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ _alias = argument;
+ }
+ });
+ options.add(new Option(Main.FILE_OPT,
+ Messages.getString("ExportCmd.22"), //$NON-NLS-1$
+ Messages.getString("ExportCmd.23")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ _certFileName = argument;
+ }
+ });
+ options.add(new Option(Main.STORETYPE_OPT,
+ Messages.getString("ExportCmd.24"), //$NON-NLS-1$
+ Messages.getString("ExportCmd.25")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ _ksType = argument;
+ }
+ });
+ options.add(new Option(Main.KEYSTORE_OPT,
+ Messages.getString("ExportCmd.26"), //$NON-NLS-1$
+ Messages.getString("ExportCmd.27")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ _ksURL = argument;
+ }
+ });
+ options.add(new Option(Main.STOREPASS_OPT,
+ Messages.getString("ExportCmd.28"), //$NON-NLS-1$
+ Messages.getString("ExportCmd.29")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ _ksPassword = argument;
+ }
+ });
+ options.add(new Option(Main.PROVIDER_OPT,
+ Messages.getString("ExportCmd.30"), //$NON-NLS-1$
+ Messages.getString("ExportCmd.31")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ _providerClassName = argument;
+ }
+ });
+ options.add(new Option(Main.RFC_OPT,
+ Messages.getString("ExportCmd.32")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ rfc = true;
+ }
+ });
+ options.add(new Option(Main.VERBOSE_OPT,
+ Messages.getString("ExportCmd.33")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ verbose = true;
+ }
+ });
+ result.add(options);
+
+ log.exiting(this.getClass().getName(), "getParser", result); //$NON-NLS-1$
+ return result;
}
}
diff --git a/tools/gnu/classpath/tools/keytool/GenKeyCmd.java b/tools/gnu/classpath/tools/keytool/GenKeyCmd.java
index 2d92134c2..4d4ca7a74 100644
--- a/tools/gnu/classpath/tools/keytool/GenKeyCmd.java
+++ b/tools/gnu/classpath/tools/keytool/GenKeyCmd.java
@@ -38,6 +38,11 @@ exception statement from your version. */
package gnu.classpath.tools.keytool;
+import gnu.classpath.tools.getopt.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 gnu.java.security.util.Util;
import gnu.java.security.x509.X500DistinguishedName;
@@ -198,19 +203,20 @@ class GenKeyCmd extends Command
/** Default key size in bits. */
private static final int DEFAULT_KEY_SIZE = 1024;
- private String _alias;
- private String _keyAlgorithm;
- private String _keySizeStr;
- private String _sigAlgorithm;
- private String _dName;
- private String _password;
- private String _validityStr;
- private String _ksType;
- private String _ksURL;
- private String _ksPassword;
- private String _providerClassName;
+ protected String _alias;
+ protected String _keyAlgorithm;
+ protected String _keySizeStr;
+ protected String _sigAlgorithm;
+ protected String _dName;
+ protected String _password;
+ protected String _validityStr;
+ protected String _ksType;
+ protected String _ksURL;
+ protected String _ksPassword;
+ protected String _providerClassName;
private int keySize;
private X500DistinguishedName distinguishedName;
+ private Parser cmdOptionsParser;
// default 0-arguments constructor
@@ -294,48 +300,6 @@ class GenKeyCmd extends Command
// life-cycle methods -------------------------------------------------------
- int processArgs(String[] args, int i)
- {
- int limit = args.length;
- String opt;
- while (++i < limit)
- {
- opt = args[i];
- log.finest("args[" + i + "]=" + opt); //$NON-NLS-1$ //$NON-NLS-2$
- if (opt == null || opt.length() == 0)
- continue;
-
- if ("-alias".equals(opt)) // -alias ALIAS //$NON-NLS-1$
- _alias = args[++i];
- else if ("-keyalg".equals(opt)) // -keyalg ALGORITHM //$NON-NLS-1$
- _keyAlgorithm = args[++i];
- else if ("-keysize".equals(opt)) // -keysize KEY_SIZE //$NON-NLS-1$
- _keySizeStr = args[++i];
- else if ("-sigalg".equals(opt)) // -sigalg ALGORITHM //$NON-NLS-1$
- _sigAlgorithm = args[++i];
- else if ("-dname".equals(opt)) // -dname NAME //$NON-NLS-1$
- _dName = args[++i];
- else if ("-keypass".equals(opt)) // -keypass PASSWORD //$NON-NLS-1$
- _password = args[++i];
- else if ("-validity".equals(opt)) // -validity DAY_COUNT //$NON-NLS-1$
- _validityStr = args[++i];
- else if ("-storetype".equals(opt)) // -storetype STORE_TYPE //$NON-NLS-1$
- _ksType = args[++i];
- else if ("-keystore".equals(opt)) // -keystore URL //$NON-NLS-1$
- _ksURL = args[++i];
- else if ("-storepass".equals(opt)) // -storepass PASSWORD //$NON-NLS-1$
- _ksPassword = args[++i];
- else if ("-provider".equals(opt)) // -provider PROVIDER_CLASS_NAME //$NON-NLS-1$
- _providerClassName = args[++i];
- else if ("-v".equals(opt)) //$NON-NLS-1$
- verbose = true;
- else
- break;
- }
-
- return i;
- }
-
void setup() throws Exception
{
setKeyStoreParams(_providerClassName, _ksType, _ksPassword, _ksURL);
@@ -352,11 +316,9 @@ class GenKeyCmd extends Command
log.finer(" -keysize=" + keySize); //$NON-NLS-1$
log.finer(" -sigalg=" + signatureAlgorithm.getAlgorithm()); //$NON-NLS-1$
log.finer(" -dname=" + distinguishedName); //$NON-NLS-1$
- log.finer(" -keypass=" + String.valueOf(keyPasswordChars)); //$NON-NLS-1$
log.finer(" -validity=" + validityInDays); //$NON-NLS-1$
log.finer(" -storetype=" + storeType); //$NON-NLS-1$
log.finer(" -keystore=" + storeURL); //$NON-NLS-1$
- log.finer(" -storepass=" + String.valueOf(storePasswordChars)); //$NON-NLS-1$
log.finer(" -provider=" + provider); //$NON-NLS-1$
log.finer(" -v=" + verbose); //$NON-NLS-1$
}
@@ -368,14 +330,14 @@ class GenKeyCmd extends Command
log.entering(this.getClass().getName(), "start"); //$NON-NLS-1$
// 1. generate a new key-pair
- log.fine("About to generate key-pair...");
+ log.finer("About to generate key-pair..."); //$NON-NLS-1$
keyPairGenerator.initialize(keySize);
KeyPair kp = keyPairGenerator.generateKeyPair();
PublicKey publicKey = kp.getPublic();
PrivateKey privateKey = kp.getPrivate();
// 2. generate a self-signed certificate
- log.fine("About to generate a self-signed certificate...");
+ log.finer("About to generate a self-signed certificate..."); //$NON-NLS-1$
byte[] derBytes = getSelfSignedCertificate(distinguishedName,
publicKey,
privateKey);
@@ -398,6 +360,127 @@ class GenKeyCmd extends Command
// own methods --------------------------------------------------------------
+ Parser getParser()
+ {
+ log.entering(this.getClass().getName(), "getParser"); //$NON-NLS-1$
+
+ Parser result = new ClasspathToolParser(Main.GENKEY_CMD, true);
+ result.setHeader(Messages.getString("GenKeyCmd.57")); //$NON-NLS-1$
+ result.setFooter(Messages.getString("GenKeyCmd.58")); //$NON-NLS-1$
+ OptionGroup options = new OptionGroup(Messages.getString("GenKeyCmd.59")); //$NON-NLS-1$
+ options.add(new Option(Main.ALIAS_OPT,
+ Messages.getString("GenKeyCmd.60"), //$NON-NLS-1$
+ Messages.getString("GenKeyCmd.61")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ _alias = argument;
+ }
+ });
+ options.add(new Option(Main.KEYALG_OPT,
+ Messages.getString("GenKeyCmd.62"), //$NON-NLS-1$
+ Messages.getString("GenKeyCmd.63")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ _keyAlgorithm = argument;
+ }
+ });
+ options.add(new Option(Main.KEYSIZE_OPT,
+ Messages.getString("GenKeyCmd.64"), //$NON-NLS-1$
+ Messages.getString("GenKeyCmd.65")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ _keySizeStr = argument;
+ }
+ });
+ options.add(new Option(Main.SIGALG_OPT,
+ Messages.getString("GenKeyCmd.66"), //$NON-NLS-1$
+ Messages.getString("GenKeyCmd.63")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ _sigAlgorithm = argument;
+ }
+ });
+ options.add(new Option(Main.DNAME_OPT,
+ Messages.getString("GenKeyCmd.68"), //$NON-NLS-1$
+ Messages.getString("GenKeyCmd.69")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ _dName = argument;
+ }
+ });
+ options.add(new Option(Main.KEYPASS_OPT,
+ Messages.getString("GenKeyCmd.70"), //$NON-NLS-1$
+ Messages.getString("GenKeyCmd.71")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ _password = argument;
+ }
+ });
+ options.add(new Option(Main.VALIDITY_OPT,
+ Messages.getString("GenKeyCmd.72"), //$NON-NLS-1$
+ Messages.getString("GenKeyCmd.73")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ _validityStr = argument;
+ }
+ });
+ options.add(new Option(Main.STORETYPE_OPT,
+ Messages.getString("GenKeyCmd.74"), //$NON-NLS-1$
+ Messages.getString("GenKeyCmd.75")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ _ksType = argument;
+ }
+ });
+ options.add(new Option(Main.KEYSTORE_OPT,
+ Messages.getString("GenKeyCmd.76"), //$NON-NLS-1$
+ Messages.getString("GenKeyCmd.77")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ _ksURL = argument;
+ }
+ });
+ options.add(new Option(Main.STOREPASS_OPT,
+ Messages.getString("GenKeyCmd.78"), //$NON-NLS-1$
+ Messages.getString("GenKeyCmd.71")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ _ksPassword = argument;
+ }
+ });
+ options.add(new Option(Main.PROVIDER_OPT,
+ Messages.getString("GenKeyCmd.80"), //$NON-NLS-1$
+ Messages.getString("GenKeyCmd.81")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ _providerClassName = argument;
+ }
+ });
+ options.add(new Option(Main.VERBOSE_OPT,
+ Messages.getString("GenKeyCmd.82")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ verbose = true;
+ }
+ });
+ result.add(options);
+
+ log.exiting(this.getClass().getName(), "getParser", result); //$NON-NLS-1$
+ return result;
+ }
+
/**
* @param size the desired key size as a string.
* @throws NumberFormatException if the string does not represent a valid
diff --git a/tools/gnu/classpath/tools/keytool/IdentityDBCmd.java b/tools/gnu/classpath/tools/keytool/IdentityDBCmd.java
index cb6b6dac2..11d0f68da 100644
--- a/tools/gnu/classpath/tools/keytool/IdentityDBCmd.java
+++ b/tools/gnu/classpath/tools/keytool/IdentityDBCmd.java
@@ -38,6 +38,12 @@ exception statement from your version. */
package gnu.classpath.tools.keytool;
+import gnu.classpath.tools.getopt.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.util.logging.Logger;
/**
@@ -97,11 +103,11 @@ import java.util.logging.Logger;
class IdentityDBCmd extends Command
{
private static final Logger log = Logger.getLogger(IdentityDBCmd.class.getName());
- private String _idbFileName;
- private String _ksType;
- private String _ksURL;
- private String _ksPassword;
- private String _providerClassName;
+ protected String _idbFileName;
+ protected String _ksType;
+ protected String _ksURL;
+ protected String _ksPassword;
+ protected String _providerClassName;
// default 0-arguments constructor
@@ -139,47 +145,85 @@ class IdentityDBCmd extends Command
// life-cycle methods -------------------------------------------------------
- int processArgs(String[] args, int i)
+ void setup() throws Exception
{
- int limit = args.length;
- String opt;
- while (++i < limit)
- {
- opt = args[i];
- log.finest("args[" + i + "]=" + opt);
- if (opt == null || opt.length() == 0)
- continue;
-
- if ("-file".equals(opt)) // -file FILE_NAME
- _idbFileName = args[++i];
- else if ("-storetype".equals(opt)) // -storetype STORE_TYPE
- _ksType = args[++i];
- else if ("-keystore".equals(opt)) // -keystore URL
- _ksURL = args[++i];
- else if ("-storepass".equals(opt)) // -storepass PASSWORD
- _ksPassword = args[++i];
- else if ("-provider".equals(opt)) // -provider PROVIDER_CLASS_NAME
- _providerClassName = args[++i];
- else if ("-v".equals(opt))
- verbose = true;
- else
- break;
- }
+ setInputStreamParam(_idbFileName);
+ setKeyStoreParams(_providerClassName, _ksType, _ksPassword, _ksURL);
- return i;
+ log.finer("-identitydb handler will use the following options:"); //$NON-NLS-1$
+ log.finer(" -file=" + _idbFileName); //$NON-NLS-1$
+ log.finer(" -storetype=" + storeType); //$NON-NLS-1$
+ log.finer(" -keystore=" + storeURL); //$NON-NLS-1$
+ log.finer(" -provider=" + provider); //$NON-NLS-1$
+ log.finer(" -v=" + verbose); //$NON-NLS-1$
}
- void setup() throws Exception
+ // own methods --------------------------------------------------------------
+
+ Parser getParser()
{
- setInputStreamParam(_idbFileName);
- setKeyStoreParams(_providerClassName, _ksType, _ksPassword, _ksURL);
+ log.entering(this.getClass().getName(), "getParser"); //$NON-NLS-1$
+
+ Parser result = new ClasspathToolParser(Main.IDENTITYDB_CMD, true);
+ result.setHeader(Messages.getString("IdentityDBCmd.7")); //$NON-NLS-1$
+ result.setFooter(Messages.getString("IdentityDBCmd.8")); //$NON-NLS-1$
+ OptionGroup options = new OptionGroup(Messages.getString("IdentityDBCmd.9")); //$NON-NLS-1$
+ options.add(new Option(Main.FILE_OPT,
+ Messages.getString("IdentityDBCmd.10"), //$NON-NLS-1$
+ Messages.getString("IdentityDBCmd.11")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ _idbFileName = argument;
+ }
+ });
+ options.add(new Option(Main.STORETYPE_OPT,
+ Messages.getString("IdentityDBCmd.12"), //$NON-NLS-1$
+ Messages.getString("IdentityDBCmd.13")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ _ksType = argument;
+ }
+ });
+ options.add(new Option(Main.KEYSTORE_OPT,
+ Messages.getString("IdentityDBCmd.14"), //$NON-NLS-1$
+ Messages.getString("IdentityDBCmd.15")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ _ksURL = argument;
+ }
+ });
+ options.add(new Option(Main.STOREPASS_OPT,
+ Messages.getString("IdentityDBCmd.16"), //$NON-NLS-1$
+ Messages.getString("IdentityDBCmd.17")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ _ksPassword = argument;
+ }
+ });
+ options.add(new Option(Main.PROVIDER_OPT,
+ Messages.getString("IdentityDBCmd.18"), //$NON-NLS-1$
+ Messages.getString("IdentityDBCmd.19")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ _providerClassName = argument;
+ }
+ });
+ options.add(new Option(Main.VERBOSE_OPT,
+ Messages.getString("IdentityDBCmd.20")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ verbose = true;
+ }
+ });
+ result.add(options);
- log.finer("-identitydb handler will use the following options:");
- log.finer(" -file=" + _idbFileName);
- log.finer(" -storetype=" + storeType);
- log.finer(" -keystore=" + storeURL);
- log.finer(" -storepass=" + new String(storePasswordChars));
- log.finer(" -provider=" + provider);
- log.finer(" -v=" + verbose);
+ log.exiting(this.getClass().getName(), "getParser", result); //$NON-NLS-1$
+ return result;
}
}
diff --git a/tools/gnu/classpath/tools/keytool/ImportCmd.java b/tools/gnu/classpath/tools/keytool/ImportCmd.java
index b5058b581..2d587be08 100644
--- a/tools/gnu/classpath/tools/keytool/ImportCmd.java
+++ b/tools/gnu/classpath/tools/keytool/ImportCmd.java
@@ -39,6 +39,11 @@ exception statement from your version. */
package gnu.classpath.tools.keytool;
import gnu.classpath.SystemProperties;
+import gnu.classpath.tools.getopt.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 gnu.java.security.x509.X509CertPath;
import java.io.FileInputStream;
@@ -181,15 +186,15 @@ import javax.security.auth.callback.UnsupportedCallbackException;
class ImportCmd extends Command
{
private static final Logger log = Logger.getLogger(ImportCmd.class.getName());
- private String _alias;
- private String _certFileName;
- private String _password;
- private boolean noPrompt;
- private boolean trustCACerts;
- private String _ksType;
- private String _ksURL;
- private String _ksPassword;
- private String _providerClassName;
+ protected String _alias;
+ protected String _certFileName;
+ protected String _password;
+ protected boolean noPrompt;
+ protected boolean trustCACerts;
+ protected String _ksType;
+ protected String _ksURL;
+ protected String _ksPassword;
+ protected String _providerClassName;
private CertificateFactory x509Factory;
private boolean imported;
@@ -259,44 +264,6 @@ class ImportCmd extends Command
// life-cycle methods -------------------------------------------------------
- int processArgs(String[] args, int i)
- {
- int limit = args.length;
- String opt;
- while (++i < limit)
- {
- opt = args[i];
- log.finest("args[" + i + "]=" + opt); //$NON-NLS-1$ //$NON-NLS-2$
- if (opt == null || opt.length() == 0)
- continue;
-
- if ("-alias".equals(opt)) // -alias ALIAS //$NON-NLS-1$
- _alias = args[++i];
- else if ("-file".equals(opt)) // -file FILE_NAME //$NON-NLS-1$
- _certFileName = args[++i];
- else if ("-keypass".equals(opt)) // -keypass PASSWORD //$NON-NLS-1$
- _password = args[++i];
- else if ("-noprompt".equals(opt)) //$NON-NLS-1$
- noPrompt = true;
- else if ("-trustcacerts".equals(opt)) //$NON-NLS-1$
- trustCACerts = true;
- else if ("-storetype".equals(opt)) // -storetype STORE_TYPE //$NON-NLS-1$
- _ksType = args[++i];
- else if ("-keystore".equals(opt)) // -keystore URL //$NON-NLS-1$
- _ksURL = args[++i];
- else if ("-storepass".equals(opt)) // -storepass PASSWORD //$NON-NLS-1$
- _ksPassword = args[++i];
- else if ("-provider".equals(opt)) // -provider PROVIDER_CLASS_NAME //$NON-NLS-1$
- _providerClassName = args[++i];
- else if ("-v".equals(opt)) //$NON-NLS-1$
- verbose = true;
- else
- break;
- }
-
- return i;
- }
-
void setup() throws Exception
{
setInputStreamParam(_certFileName);
@@ -307,12 +274,10 @@ class ImportCmd extends Command
log.finer("-import handler will use the following options:"); //$NON-NLS-1$
log.finer(" -alias=" + alias); //$NON-NLS-1$
log.finer(" -file=" + _certFileName); //$NON-NLS-1$
- log.finer(" -keypass=" + _password); //$NON-NLS-1$
log.finer(" -noprompt=" + noPrompt); //$NON-NLS-1$
log.finer(" -trustcacerts=" + trustCACerts); //$NON-NLS-1$
log.finer(" -storetype=" + storeType); //$NON-NLS-1$
log.finer(" -keystore=" + storeURL); //$NON-NLS-1$
- log.finer(" -storepass=" + String.valueOf(storePasswordChars)); //$NON-NLS-1$
log.finer(" -provider=" + provider); //$NON-NLS-1$
log.finer(" -v=" + verbose); //$NON-NLS-1$
}
@@ -339,6 +304,107 @@ class ImportCmd extends Command
// own methods --------------------------------------------------------------
+ Parser getParser()
+ {
+ log.entering(this.getClass().getName(), "getParser"); //$NON-NLS-1$
+
+ Parser result = new ClasspathToolParser(Main.IMPORT_CMD, true);
+ result.setHeader(Messages.getString("ImportCmd.27")); //$NON-NLS-1$
+ result.setFooter(Messages.getString("ImportCmd.26")); //$NON-NLS-1$
+ OptionGroup options = new OptionGroup(Messages.getString("ImportCmd.25")); //$NON-NLS-1$
+ options.add(new Option(Main.ALIAS_OPT,
+ Messages.getString("ImportCmd.24"), //$NON-NLS-1$
+ Messages.getString("ImportCmd.23")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ _alias = argument;
+ }
+ });
+ options.add(new Option(Main.FILE_OPT,
+ Messages.getString("ImportCmd.22"), //$NON-NLS-1$
+ Messages.getString("ImportCmd.21")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ _certFileName = argument;
+ }
+ });
+ options.add(new Option(Main.KEYPASS_OPT,
+ Messages.getString("ImportCmd.20"), //$NON-NLS-1$
+ Messages.getString("ImportCmd.19")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ _password = argument;
+ }
+ });
+ options.add(new Option("noprompt", //$NON-NLS-1$
+ Messages.getString("ImportCmd.18")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ noPrompt = true;
+ }
+ });
+ options.add(new Option("trustcacerts", //$NON-NLS-1$
+ Messages.getString("ImportCmd.17")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ trustCACerts = true;
+ }
+ });
+ options.add(new Option(Main.STORETYPE_OPT,
+ Messages.getString("ImportCmd.16"), //$NON-NLS-1$
+ Messages.getString("ImportCmd.15")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ _ksType = argument;
+ }
+ });
+ options.add(new Option(Main.KEYSTORE_OPT,
+ Messages.getString("ImportCmd.14"), //$NON-NLS-1$
+ Messages.getString("ImportCmd.13")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ _ksURL = argument;
+ }
+ });
+ options.add(new Option(Main.STOREPASS_OPT,
+ Messages.getString("ImportCmd.12"), //$NON-NLS-1$
+ Messages.getString("ImportCmd.11")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ _ksPassword = argument;
+ }
+ });
+ options.add(new Option(Main.PROVIDER_OPT,
+ Messages.getString("ImportCmd.10"), //$NON-NLS-1$
+ Messages.getString("ImportCmd.9")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ _providerClassName = argument;
+ }
+ });
+ options.add(new Option(Main.VERBOSE_OPT,
+ Messages.getString("ImportCmd.8")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ verbose = true;
+ }
+ });
+ result.add(options);
+
+ log.exiting(this.getClass().getName(), "getParser", result); //$NON-NLS-1$
+ return result;
+ }
+
/**
* When importing a new trusted certificate, <i>alias</i> MUST NOT yet exist
* in the key store.
@@ -607,7 +673,7 @@ class ImportCmd extends Command
log.entering(this.getClass().getName(), "orderChain"); //$NON-NLS-1$
LinkedList result = new LinkedList();
-
+ // FIXME: really order it!
log.entering(this.getClass().getName(), "orderChain", result); //$NON-NLS-1$
return result;
@@ -715,7 +781,7 @@ class ImportCmd extends Command
try
{
KeyStore cacerts = KeyStore.getInstance("jks"); //$NON-NLS-1$
- String cacertsPath = SystemProperties.getProperty("java.home");
+ String cacertsPath = SystemProperties.getProperty("java.home"); //$NON-NLS-1$
String fs = SystemProperties.getProperty("file.separator"); //$NON-NLS-1$
cacertsPath = new StringBuilder(cacertsPath).append(fs)
.append("lib").append(fs) //$NON-NLS-1$
diff --git a/tools/gnu/classpath/tools/keytool/KeyCloneCmd.java b/tools/gnu/classpath/tools/keytool/KeyCloneCmd.java
index 5936719f7..a60fef936 100644
--- a/tools/gnu/classpath/tools/keytool/KeyCloneCmd.java
+++ b/tools/gnu/classpath/tools/keytool/KeyCloneCmd.java
@@ -38,6 +38,12 @@ exception statement from your version. */
package gnu.classpath.tools.keytool;
+import gnu.classpath.tools.getopt.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.security.Key;
import java.security.KeyStoreException;
@@ -132,14 +138,14 @@ import javax.security.auth.callback.UnsupportedCallbackException;
class KeyCloneCmd extends Command
{
private static final Logger log = Logger.getLogger(KeyCloneCmd.class.getName());
- private String _alias;
- private String _destAlias;
- private String _password;
- private String _newPassword;
- private String _ksType;
- private String _ksURL;
- private String _ksPassword;
- private String _providerClassName;
+ protected String _alias;
+ protected String _destAlias;
+ protected String _password;
+ protected String _newPassword;
+ protected String _ksType;
+ protected String _ksURL;
+ protected String _ksPassword;
+ protected String _providerClassName;
private String destinationAlias;
private char[] newKeyPasswordChars;
@@ -197,58 +203,18 @@ class KeyCloneCmd extends Command
// life-cycle methods -------------------------------------------------------
- int processArgs(String[] args, int i)
- {
- int limit = args.length;
- String opt;
- while (++i < limit)
- {
- opt = args[i];
- log.finest("args[" + i + "]=" + opt); //$NON-NLS-1$ //$NON-NLS-2$
- if (opt == null || opt.length() == 0)
- continue;
-
- if ("-alias".equals(opt)) // -alias ALIAS //$NON-NLS-1$
- _alias = args[++i];
- else if ("-dest".equals(opt)) // -dest ALIAS //$NON-NLS-1$
- _destAlias = args[++i];
- else if ("-keypass".equals(opt)) // -keypass PASSWORD //$NON-NLS-1$
- _password = args[++i];
- else if ("-new".equals(opt)) // -new PASSWORD //$NON-NLS-1$
- _newPassword = args[++i];
- else if ("-storetype".equals(opt)) // -storetype STORE_TYPE //$NON-NLS-1$
- _ksType = args[++i];
- else if ("-keystore".equals(opt)) // -keystore URL //$NON-NLS-1$
- _ksURL = args[++i];
- else if ("-storepass".equals(opt)) // -storepass PASSWORD //$NON-NLS-1$
- _ksPassword = args[++i];
- else if ("-provider".equals(opt)) // -provider PROVIDER_CLASS_NAME //$NON-NLS-1$
- _providerClassName = args[++i];
- else if ("-v".equals(opt)) //$NON-NLS-1$
- verbose = true;
- else
- break;
- }
-
- return i;
- }
-
void setup() throws Exception
{
setKeyStoreParams(_providerClassName, _ksType, _ksPassword, _ksURL);
setAliasParam(_alias);
setKeyPasswordNoPrompt(_password);
setDestinationAlias(_destAlias);
-// setNewKeyPassword(_newPassword);
log.finer("-keyclone handler will use the following options:"); //$NON-NLS-1$
log.finer(" -alias=" + alias); //$NON-NLS-1$
log.finer(" -dest=" + destinationAlias); //$NON-NLS-1$
- log.finer(" -keypass=" + _password); //$NON-NLS-1$
- log.finer(" -new=" + _newPassword); //$NON-NLS-1$
log.finer(" -storetype=" + storeType); //$NON-NLS-1$
log.finer(" -keystore=" + storeURL); //$NON-NLS-1$
- log.finer(" -storepass=" + String.valueOf(storePasswordChars)); //$NON-NLS-1$
log.finer(" -provider=" + provider); //$NON-NLS-1$
log.finer(" -v=" + verbose); //$NON-NLS-1$
}
@@ -276,6 +242,100 @@ class KeyCloneCmd extends Command
// own methods --------------------------------------------------------------
+ Parser getParser()
+ {
+ log.entering(this.getClass().getName(), "getParser"); //$NON-NLS-1$
+
+ Parser result = new ClasspathToolParser(Main.KEYCLONE_CMD, true);
+ result.setHeader(Messages.getString("KeyCloneCmd.22")); //$NON-NLS-1$
+ result.setFooter(Messages.getString("KeyCloneCmd.21")); //$NON-NLS-1$
+ OptionGroup options = new OptionGroup(Messages.getString("KeyCloneCmd.20")); //$NON-NLS-1$
+ options.add(new Option(Main.ALIAS_OPT,
+ Messages.getString("KeyCloneCmd.19"), //$NON-NLS-1$
+ Messages.getString("KeyCloneCmd.16")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ _alias = argument;
+ }
+ });
+ options.add(new Option(Main.DEST_OPT,
+ Messages.getString("KeyCloneCmd.17"), //$NON-NLS-1$
+ Messages.getString("KeyCloneCmd.16")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ _destAlias = argument;
+ }
+ });
+ options.add(new Option(Main.KEYPASS_OPT,
+ Messages.getString("KeyCloneCmd.15"), //$NON-NLS-1$
+ Messages.getString("KeyCloneCmd.6")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ _password = argument;
+ }
+ });
+ options.add(new Option(Main.NEW_OPT,
+ Messages.getString("KeyCloneCmd.13"), //$NON-NLS-1$
+ Messages.getString("KeyCloneCmd.6")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ _newPassword = argument;
+ }
+ });
+ options.add(new Option(Main.STORETYPE_OPT,
+ Messages.getString("KeyCloneCmd.11"), //$NON-NLS-1$
+ Messages.getString("KeyCloneCmd.10")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ _ksType = argument;
+ }
+ });
+ options.add(new Option(Main.KEYSTORE_OPT,
+ Messages.getString("KeyCloneCmd.9"), //$NON-NLS-1$
+ Messages.getString("KeyCloneCmd.8")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ _ksURL = argument;
+ }
+ });
+ options.add(new Option(Main.STOREPASS_OPT,
+ Messages.getString("KeyCloneCmd.7"), //$NON-NLS-1$
+ Messages.getString("KeyCloneCmd.6")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ _ksPassword = argument;
+ }
+ });
+ options.add(new Option(Main.PROVIDER_OPT,
+ Messages.getString("KeyCloneCmd.5"), //$NON-NLS-1$
+ Messages.getString("KeyCloneCmd.4")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ _providerClassName = argument;
+ }
+ });
+ options.add(new Option(Main.VERBOSE_OPT,
+ Messages.getString("KeyCloneCmd.3")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ verbose = true;
+ }
+ });
+ result.add(options);
+
+ log.exiting(this.getClass().getName(), "getParser", result); //$NON-NLS-1$
+ return result;
+ }
+
private void setDestinationAlias(String name) throws IOException,
UnsupportedCallbackException
{
@@ -294,9 +354,9 @@ class KeyCloneCmd extends Command
private void setNewKeyPassword(String password) throws IOException,
UnsupportedCallbackException
{
- if (password != null) // ask user to provide one
+ if (password != null)
newKeyPasswordChars = password.toCharArray();
- else
+ else // ask user to provide one
{
boolean ok = false;
Callback[] prompts = new Callback[1];
diff --git a/tools/gnu/classpath/tools/keytool/KeyPasswdCmd.java b/tools/gnu/classpath/tools/keytool/KeyPasswdCmd.java
index 9dc7b8164..5cf25eb0f 100644
--- a/tools/gnu/classpath/tools/keytool/KeyPasswdCmd.java
+++ b/tools/gnu/classpath/tools/keytool/KeyPasswdCmd.java
@@ -39,6 +39,11 @@ exception statement from your version. */
package gnu.classpath.tools.keytool;
import gnu.classpath.SystemProperties;
+import gnu.classpath.tools.getopt.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.security.Key;
@@ -128,13 +133,13 @@ import javax.security.auth.callback.UnsupportedCallbackException;
class KeyPasswdCmd extends Command
{
private static final Logger log = Logger.getLogger(KeyPasswdCmd.class.getName());
- private String _alias;
- private String _password;
- private String _newPassword;
- private String _ksType;
- private String _ksURL;
- private String _ksPassword;
- private String _providerClassName;
+ protected String _alias;
+ protected String _password;
+ protected String _newPassword;
+ protected String _ksType;
+ protected String _ksURL;
+ protected String _ksPassword;
+ protected String _providerClassName;
private char[] newPasswordChars;
// default 0-arguments constructor
@@ -185,54 +190,17 @@ class KeyPasswdCmd extends Command
// life-cycle methods -------------------------------------------------------
- int processArgs(String[] args, int i)
- {
- int limit = args.length;
- String opt;
- while (++i < limit)
- {
- opt = args[i];
- log.finest("args[" + i + "]=" + opt); //$NON-NLS-1$ //$NON-NLS-2$
- if (opt == null || opt.length() == 0)
- continue;
-
- if ("-alias".equals(opt)) // -alias ALIAS //$NON-NLS-1$
- _alias = args[++i];
- else if ("-keypass".equals(opt)) // -keypass PASSWORD //$NON-NLS-1$
- _password = args[++i];
- else if ("-new".equals(opt)) // -new PASSWORD //$NON-NLS-1$
- _newPassword = args[++i];
- else if ("-storetype".equals(opt)) // -storetype STORE_TYPE //$NON-NLS-1$
- _ksType = args[++i];
- else if ("-keystore".equals(opt)) // -keystore URL //$NON-NLS-1$
- _ksURL = args[++i];
- else if ("-storepass".equals(opt)) // -storepass PASSWORD //$NON-NLS-1$
- _ksPassword = args[++i];
- else if ("-provider".equals(opt)) // -provider PROVIDER_CLASS_NAME //$NON-NLS-1$
- _providerClassName = args[++i];
- else if ("-v".equals(opt)) //$NON-NLS-1$
- verbose = true;
- else
- break;
- }
-
- return i;
- }
-
void setup() throws Exception
{
setKeyStoreParams(_providerClassName, _ksType, _ksPassword, _ksURL);
setAliasParam(_alias);
setKeyPasswordNoPrompt(_password);
-// setNewKeyPassword(_newPassword);
log.finer("-keypasswd handler will use the following options:"); //$NON-NLS-1$
log.finer(" -alias=" + alias); //$NON-NLS-1$
- log.finer(" -keypass=" + _password); //$NON-NLS-1$
log.finer(" -new=" + _newPassword); //$NON-NLS-1$
log.finer(" -storetype=" + storeType); //$NON-NLS-1$
log.finer(" -keystore=" + storeURL); //$NON-NLS-1$
- log.finer(" -storepass=" + String.valueOf(storePasswordChars)); //$NON-NLS-1$
log.finer(" -provider=" + provider); //$NON-NLS-1$
log.finer(" -v=" + verbose); //$NON-NLS-1$
}
@@ -259,6 +227,91 @@ class KeyPasswdCmd extends Command
// own methods --------------------------------------------------------------
+ Parser getParser()
+ {
+ log.entering(this.getClass().getName(), "getParser"); //$NON-NLS-1$
+
+ Parser result = new ClasspathToolParser(Main.KEYPASSWD_CMD, true);
+ result.setHeader(Messages.getString("KeyPasswdCmd.23")); //$NON-NLS-1$
+ result.setFooter(Messages.getString("KeyPasswdCmd.22")); //$NON-NLS-1$
+ OptionGroup options = new OptionGroup(Messages.getString("KeyPasswdCmd.21")); //$NON-NLS-1$
+ options.add(new Option(Main.ALIAS_OPT,
+ Messages.getString("KeyPasswdCmd.20"), //$NON-NLS-1$
+ Messages.getString("KeyPasswdCmd.19")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ _alias = argument;
+ }
+ });
+ options.add(new Option(Main.KEYPASS_OPT,
+ Messages.getString("KeyPasswdCmd.18"), //$NON-NLS-1$
+ Messages.getString("KeyPasswdCmd.9")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ _password = argument;
+ }
+ });
+ options.add(new Option(Main.NEW_OPT,
+ Messages.getString("KeyPasswdCmd.16"), //$NON-NLS-1$
+ Messages.getString("KeyPasswdCmd.9")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ _newPassword = argument;
+ }
+ });
+ options.add(new Option(Main.STORETYPE_OPT,
+ Messages.getString("KeyPasswdCmd.14"), //$NON-NLS-1$
+ Messages.getString("KeyPasswdCmd.13")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ _ksType = argument;
+ }
+ });
+ options.add(new Option(Main.KEYSTORE_OPT,
+ Messages.getString("KeyPasswdCmd.12"), //$NON-NLS-1$
+ Messages.getString("KeyPasswdCmd.11")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ _ksURL = argument;
+ }
+ });
+ options.add(new Option(Main.STOREPASS_OPT,
+ Messages.getString("KeyPasswdCmd.10"), //$NON-NLS-1$
+ Messages.getString("KeyPasswdCmd.9")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ _ksPassword = argument;
+ }
+ });
+ options.add(new Option(Main.PROVIDER_OPT,
+ Messages.getString("KeyPasswdCmd.8"), //$NON-NLS-1$
+ Messages.getString("KeyPasswdCmd.7")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ _providerClassName = argument;
+ }
+ });
+ options.add(new Option(Main.VERBOSE_OPT,
+ Messages.getString("KeyPasswdCmd.6")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ verbose = true;
+ }
+ });
+ result.add(options);
+
+ log.exiting(this.getClass().getName(), "getParser", result); //$NON-NLS-1$
+ return result;
+ }
+
/**
* Set the new password to use for protecting Alias's private key.
*
diff --git a/tools/gnu/classpath/tools/keytool/ListCmd.java b/tools/gnu/classpath/tools/keytool/ListCmd.java
index 655242785..674099307 100644
--- a/tools/gnu/classpath/tools/keytool/ListCmd.java
+++ b/tools/gnu/classpath/tools/keytool/ListCmd.java
@@ -38,6 +38,11 @@ exception statement from your version. */
package gnu.classpath.tools.keytool;
+import gnu.classpath.tools.getopt.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 gnu.java.security.util.Base64;
import java.io.IOException;
@@ -113,12 +118,12 @@ import java.util.logging.Logger;
class ListCmd extends Command
{
private static final Logger log = Logger.getLogger(ListCmd.class.getName());
- private String _alias;
- private String _ksType;
- private String _ksURL;
- private String _ksPassword;
- private String _providerClassName;
- private boolean rfc;
+ protected String _alias;
+ protected String _ksType;
+ protected String _ksURL;
+ protected String _ksPassword;
+ protected String _providerClassName;
+ protected boolean rfc;
private boolean all;
// default 0-arguments constructor
@@ -166,44 +171,11 @@ class ListCmd extends Command
// life-cycle methods -------------------------------------------------------
- int processArgs(String[] args, int i)
- {
- int limit = args.length;
- String opt;
- while (++i < limit)
- {
- opt = args[i];
- log.finest("args[" + i + "]=" + opt); //$NON-NLS-1$ //$NON-NLS-2$
- if (opt == null || opt.length() == 0)
- continue;
-
- if ("-alias".equals(opt)) // -alias ALIAS //$NON-NLS-1$
- _alias = args[++i];
- else if ("-storetype".equals(opt)) // -storetype STORE_TYPE //$NON-NLS-1$
- _ksType = args[++i];
- else if ("-keystore".equals(opt)) // -keystore URL //$NON-NLS-1$
- _ksURL = args[++i];
- else if ("-storepass".equals(opt)) // -storepass PASSWORD //$NON-NLS-1$
- _ksPassword = args[++i];
- else if ("-provider".equals(opt)) // -provider PROVIDER_CLASS_NAME //$NON-NLS-1$
- _providerClassName = args[++i];
- else if ("-v".equals(opt)) //$NON-NLS-1$
- verbose = true;
- else if ("-rfc".equals(opt)) //$NON-NLS-1$
- rfc = true;
- else
- break;
- }
-
- all = _alias == null;
-
- return i;
- }
-
void setup() throws Exception
{
setOutputStreamParam(null); // use stdout
setKeyStoreParams(_providerClassName, _ksType, _ksPassword, _ksURL);
+ all = _alias == null;
if (! all)
setAliasParam(_alias);
@@ -218,7 +190,6 @@ class ListCmd extends Command
log.finer(" -alias=" + alias); //$NON-NLS-1$
log.finer(" -storetype=" + storeType); //$NON-NLS-1$
log.finer(" -keystore=" + storeURL); //$NON-NLS-1$
- log.finer(" -storepass=" + String.valueOf(storePasswordChars)); //$NON-NLS-1$
log.finer(" -provider=" + provider); //$NON-NLS-1$
log.finer(" -v=" + verbose); //$NON-NLS-1$
log.finer(" -rfc=" + rfc); //$NON-NLS-1$
@@ -254,6 +225,81 @@ class ListCmd extends Command
// own methods --------------------------------------------------------------
+ Parser getParser()
+ {
+ log.entering(this.getClass().getName(), "getParser"); //$NON-NLS-1$
+
+ Parser result = new ClasspathToolParser(Main.LIST_CMD, true);
+ result.setHeader(Messages.getString("ListCmd.20")); //$NON-NLS-1$
+ result.setFooter(Messages.getString("ListCmd.19")); //$NON-NLS-1$
+ OptionGroup options = new OptionGroup(Messages.getString("ListCmd.18")); //$NON-NLS-1$
+ options.add(new Option(Main.ALIAS_OPT,
+ Messages.getString("ListCmd.17"), //$NON-NLS-1$
+ Messages.getString("ListCmd.16")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ _alias = argument;
+ }
+ });
+ options.add(new Option(Main.STORETYPE_OPT,
+ Messages.getString("ListCmd.15"), //$NON-NLS-1$
+ Messages.getString("ListCmd.14")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ _ksType = argument;
+ }
+ });
+ options.add(new Option(Main.KEYSTORE_OPT,
+ Messages.getString("ListCmd.13"), //$NON-NLS-1$
+ Messages.getString("ListCmd.12")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ _ksURL = argument;
+ }
+ });
+ options.add(new Option(Main.STOREPASS_OPT,
+ Messages.getString("ListCmd.11"), //$NON-NLS-1$
+ Messages.getString("ListCmd.10")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ _ksPassword = argument;
+ }
+ });
+ options.add(new Option(Main.PROVIDER_OPT,
+ Messages.getString("ListCmd.9"), //$NON-NLS-1$
+ Messages.getString("ListCmd.8")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ _providerClassName = argument;
+ }
+ });
+ options.add(new Option(Main.VERBOSE_OPT,
+ Messages.getString("ListCmd.7")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ verbose = true;
+ }
+ });
+ options.add(new Option(Main.RFC_OPT,
+ Messages.getString("ListCmd.6")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ rfc = true;
+ }
+ });
+ result.add(options);
+
+ log.exiting(this.getClass().getName(), "getParser", result); //$NON-NLS-1$
+ return result;
+ }
+
/**
* Prints the certificate(s) associated with the designated alias.
*
@@ -312,7 +358,7 @@ class ListCmd extends Command
private void print1Chain(Certificate[] chain, PrintWriter writer)
throws CertificateEncodingException
{
- if (!verbose && !rfc)
+ if (! verbose && ! rfc)
fingerprint(chain[0], writer);
else
{
diff --git a/tools/gnu/classpath/tools/keytool/Main.java b/tools/gnu/classpath/tools/keytool/Main.java
index fb7aa4509..582aba082 100644
--- a/tools/gnu/classpath/tools/keytool/Main.java
+++ b/tools/gnu/classpath/tools/keytool/Main.java
@@ -38,8 +38,12 @@ exception statement from your version. */
package gnu.classpath.tools.keytool;
-import gnu.classpath.tools.HelpPrinter;
import gnu.classpath.tools.common.ProviderUtil;
+import gnu.classpath.tools.getopt.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 gnu.java.security.Registry;
import gnu.javax.crypto.jce.GnuCrypto;
import gnu.javax.security.auth.callback.GnuCallbacks;
@@ -57,8 +61,51 @@ import java.util.logging.Logger;
public class Main
{
private static final Logger log = Logger.getLogger(Main.class.getName());
- /** The relative file path to the command tool's help text. */
- private static final String HELP_PATH = "keytool/keytool.txt"; //$NON-NLS-1$
+ static final String KEYTOOL_TOOL = "keytool"; //$NON-NLS-1$
+ static final String GENKEY_CMD = "genkey"; //$NON-NLS-1$
+ static final String IMPORT_CMD = "import"; //$NON-NLS-1$
+ static final String SELFCERT_CMD = "selfcert"; //$NON-NLS-1$
+ static final String IDENTITYDB_CMD = "identitydb"; //$NON-NLS-1$
+ static final String CERTREQ_CMD = "certreq"; //$NON-NLS-1$
+ static final String EXPORT_CMD = "export"; //$NON-NLS-1$
+ static final String LIST_CMD = "list"; //$NON-NLS-1$
+ static final String PRINTCERT_CMD = "printcert"; //$NON-NLS-1$
+ static final String KEYCLONE_CMD = "keyclone"; //$NON-NLS-1$
+ static final String STOREPASSWD_CMD = "storepasswd"; //$NON-NLS-1$
+ static final String KEYPASSWD_CMD = "keypasswd"; //$NON-NLS-1$
+ static final String DELETE_CMD = "delete"; //$NON-NLS-1$
+
+ static final String _GENKEY = "-" + GENKEY_CMD; //$NON-NLS-1$
+ static final String _IMPORT = "-" + IMPORT_CMD; //$NON-NLS-1$
+ static final String _SELFCERT = "-" + SELFCERT_CMD; //$NON-NLS-1$
+ static final String _IDENTITYDB = "-" + IDENTITYDB_CMD; //$NON-NLS-1$
+ static final String _CERTREQ = "-" + CERTREQ_CMD; //$NON-NLS-1$
+ static final String _EXPORT = "-" + EXPORT_CMD; //$NON-NLS-1$
+ static final String _LIST = "-" + LIST_CMD; //$NON-NLS-1$
+ static final String _PRINTCERT = "-" + PRINTCERT_CMD; //$NON-NLS-1$
+ static final String _KEYCLONE = "-" + KEYCLONE_CMD; //$NON-NLS-1$
+ static final String _STOREPASSWD = "-" + STOREPASSWD_CMD; //$NON-NLS-1$
+ static final String _KEYPASSWD = "-" + KEYPASSWD_CMD; //$NON-NLS-1$
+ static final String _DELETE = "-" + DELETE_CMD; //$NON-NLS-1$
+ static final String _HELP = "-help"; //$NON-NLS-1$
+
+ static final String ALIAS_OPT = "alias"; //$NON-NLS-1$
+ static final String SIGALG_OPT = "sigalg"; //$NON-NLS-1$
+ static final String KEYALG_OPT = "keyalg"; //$NON-NLS-1$
+ static final String KEYSIZE_OPT = "keysize"; //$NON-NLS-1$
+ static final String KEYPASS_OPT = "keypass"; //$NON-NLS-1$
+ static final String VALIDITY_OPT = "validity"; //$NON-NLS-1$
+ static final String STORETYPE_OPT = "storetype"; //$NON-NLS-1$
+ static final String STOREPASS_OPT = "storepass"; //$NON-NLS-1$
+ static final String KEYSTORE_OPT = "keystore"; //$NON-NLS-1$
+ static final String PROVIDER_OPT = "provider"; //$NON-NLS-1$
+ static final String FILE_OPT = "file"; //$NON-NLS-1$
+ static final String VERBOSE_OPT = "v"; //$NON-NLS-1$
+ static final String DEST_OPT = "dest"; //$NON-NLS-1$
+ static final String NEW_OPT = "new"; //$NON-NLS-1$
+ static final String RFC_OPT = "rfc"; //$NON-NLS-1$
+ static final String DNAME_OPT = "dname"; //$NON-NLS-1$
+
/** The Preferences key name for the last issued certificate serial nbr. */
static final String LAST_SERIAL_NUMBER = "lastSerialNumber"; //$NON-NLS-1$
/** Constant denoting the X.509 certificate type. */
@@ -70,6 +117,8 @@ public class Main
private int gnuCryptoProviderNdx = -2;
/** The new position of GNU Callbacks provider if it is not already installed. */
private int gnuCallbacksNdx = -2;
+ /** The command line parser. */
+ private Parser cmdLineParser;
private Main()
{
@@ -81,117 +130,140 @@ public class Main
log.entering(Main.class.getName(), "main", args); //$NON-NLS-1$
Main tool = new Main();
+ int result = 1;
try
{
tool.setup();
tool.start(args);
+ result = 0;
+ }
+ catch (OptionException x)
+ {
+ System.err.println(x.getMessage());
+ if (tool.cmdLineParser != null)
+ tool.cmdLineParser.printHelp();
}
catch (SecurityException x)
{
log.throwing(Main.class.getName(), "main", x); //$NON-NLS-1$
- System.err.println(Messages.getString("Main.6") + x.getMessage()); //$NON-NLS-1$
+ System.err.println(Messages.getFormattedString("Main.6", //$NON-NLS-1$
+ x.getMessage()));
}
catch (Exception x)
{
log.throwing(Main.class.getName(), "main", x); //$NON-NLS-1$
- System.err.println(Messages.getString("Main.8") + x); //$NON-NLS-1$
+ System.err.println(Messages.getFormattedString("Main.8", x)); //$NON-NLS-1$
}
finally
- {
- tool.teardown();
- }
+ {
+ tool.teardown();
+ }
- log.exiting(Main.class.getName(), "main"); //$NON-NLS-1$
- // System.exit(0);
+ log.exiting(Main.class.getName(), "main", Integer.valueOf(result)); //$NON-NLS-1$
+ System.exit(result);
}
// helper methods -----------------------------------------------------------
+ private void setup()
+ {
+ log.entering(this.getClass().getName(), "setup"); //$NON-NLS-1$
+
+ cmdLineParser = getParser();
+ gnuCryptoProviderNdx = ProviderUtil.addProvider(new GnuCrypto());
+ gnuCallbacksNdx = ProviderUtil.addProvider(new GnuCallbacks());
+
+ log.exiting(this.getClass().getName(), "setup"); //$NON-NLS-1$
+ }
+
private void start(String[] args) throws Exception
{
- log.entering(this.getClass().getName(), "start", args); //$NON-NLS-1$
+ log.entering(this.getClass().getName(), "start"); //$NON-NLS-1$
- if (args == null)
- args = new String[0];
+ if (args == null || args.length == 0)
+ throw new OptionException(""); //$NON-NLS-1$
- int limit = args.length;
- log.finest("args.length=" + limit); //$NON-NLS-1$
- int i = 0;
String opt;
Command cmd;
- while (i < limit)
+ while (args.length > 0)
{
- opt = args[i];
- log.finest("args[" + i + "]=" + opt); //$NON-NLS-1$ //$NON-NLS-2$
- if (opt == null || opt.length() == 0)
- continue;
-
+ opt = args[0];
cmd = null;
- if ("-genkey".equals(opt)) //$NON-NLS-1$
+ if (_GENKEY.equals(opt))
cmd = new GenKeyCmd();
- else if ("-import".equals(opt)) //$NON-NLS-1$
+ else if (_IMPORT.equals(opt))
cmd = new ImportCmd();
- else if ("-selfcert".equals(opt)) //$NON-NLS-1$
+ else if (_SELFCERT.equals(opt))
cmd = new SelfCertCmd();
- else if ("-identitydb".equals(opt)) //$NON-NLS-1$
+ else if (_IDENTITYDB.equals(opt))
cmd = new IdentityDBCmd();
- else if ("-certreq".equals(opt)) //$NON-NLS-1$
+ else if (_CERTREQ.equals(opt))
cmd = new CertReqCmd();
- else if ("-export".equals(opt)) //$NON-NLS-1$
+ else if (_EXPORT.equals(opt))
cmd = new ExportCmd();
- else if ("-list".equals(opt)) //$NON-NLS-1$
+ else if (_LIST.equals(opt))
cmd = new ListCmd();
- else if ("-printcert".equals(opt)) //$NON-NLS-1$
+ else if (_PRINTCERT.equals(opt))
cmd = new PrintCertCmd();
- else if ("-keyclone".equals(opt)) //$NON-NLS-1$
+ else if (_KEYCLONE.equals(opt))
cmd = new KeyCloneCmd();
- else if ("-storepasswd".equals(opt)) //$NON-NLS-1$
+ else if (_STOREPASSWD.equals(opt))
cmd = new StorePasswdCmd();
- else if ("-keypasswd".equals(opt)) //$NON-NLS-1$
+ else if (_KEYPASSWD.equals(opt))
cmd = new KeyPasswdCmd();
- else if ("-delete".equals(opt)) //$NON-NLS-1$
+ else if (_DELETE.equals(opt))
cmd = new DeleteCmd();
- else if ("-help".equals(opt)) //$NON-NLS-1$
- {
- printHelp();
- i++;
- }
+ else if (_HELP.equals(opt))
+ throw new OptionException(""); //$NON-NLS-1$
else
- {
- log.fine("Unknown command [" + opt + "] at index #" + i //$NON-NLS-1$ //$NON-NLS-2$
- + ". Arguments from that token onward will be ignored"); //$NON-NLS-1$
- break;
- }
-
- if (cmd != null)
- {
- i = cmd.processArgs(args, i);
- cmd.doCommand();
- }
- }
-
- // the -help command is the default; i.e.
- // keytool
- // is equivalent to:
- // keytool -help
- if (i == 0)
- printHelp();
+ throw new OptionException(Messages.getFormattedString("Main.18", //$NON-NLS-1$
+ opt));
- if (i < limit) // more options than needed
- log.fine("Last recognized argument is assumed at index #" + (i - 1) //$NON-NLS-1$
- + ". Remaining arguments (" + args[i] + "...) will be ignored"); //$NON-NLS-1$ //$NON-NLS-2$
+ String[] cmdArgs = new String[args.length - 1];
+ System.arraycopy(args, 1, cmdArgs, 0, cmdArgs.length);
+ args = cmd.processArgs(cmdArgs);
+ cmd.doCommand();
+ }
log.exiting(this.getClass().getName(), "start"); //$NON-NLS-1$
}
- private void setup()
+ private Parser getParser()
{
- log.entering(this.getClass().getName(), "setup"); //$NON-NLS-1$
-
- gnuCryptoProviderNdx = ProviderUtil.addProvider(new GnuCrypto());
- gnuCallbacksNdx = ProviderUtil.addProvider(new GnuCallbacks());
-
- log.exiting(this.getClass().getName(), "setup"); //$NON-NLS-1$
+ log.entering(this.getClass().getName(), "getParser"); //$NON-NLS-1$
+
+ Parser result = new ClasspathToolParser(KEYTOOL_TOOL, true);
+ result.setHeader(Messages.getString("Main.19")); //$NON-NLS-1$
+ result.setFooter(Messages.getString("Main.20")); //$NON-NLS-1$
+ OptionGroup cmdGroup = new OptionGroup(Messages.getString("Main.21")); //$NON-NLS-1$
+ cmdGroup.add(new NoParseOption(GENKEY_CMD,
+ Messages.getString("Main.22"))); //$NON-NLS-1$
+ cmdGroup.add(new NoParseOption(IMPORT_CMD,
+ Messages.getString("Main.23"))); //$NON-NLS-1$
+ cmdGroup.add(new NoParseOption(SELFCERT_CMD,
+ Messages.getString("Main.24"))); //$NON-NLS-1$
+ cmdGroup.add(new NoParseOption(IDENTITYDB_CMD,
+ Messages.getString("Main.25"))); //$NON-NLS-1$
+ cmdGroup.add(new NoParseOption(CERTREQ_CMD,
+ Messages.getString("Main.26"))); //$NON-NLS-1$
+ cmdGroup.add(new NoParseOption(EXPORT_CMD,
+ Messages.getString("Main.27"))); //$NON-NLS-1$
+ cmdGroup.add(new NoParseOption(LIST_CMD,
+ Messages.getString("Main.28"))); //$NON-NLS-1$
+ cmdGroup.add(new NoParseOption(PRINTCERT_CMD,
+ Messages.getString("Main.29"))); //$NON-NLS-1$
+ cmdGroup.add(new NoParseOption(KEYCLONE_CMD,
+ Messages.getString("Main.30"))); //$NON-NLS-1$
+ cmdGroup.add(new NoParseOption(STOREPASSWD_CMD,
+ Messages.getString("Main.31"))); //$NON-NLS-1$
+ cmdGroup.add(new NoParseOption(KEYPASSWD_CMD,
+ Messages.getString("Main.32"))); //$NON-NLS-1$
+ cmdGroup.add(new NoParseOption(DELETE_CMD,
+ Messages.getString("Main.33"))); //$NON-NLS-1$
+ result.add(cmdGroup);
+
+ log.exiting(this.getClass().getName(), "getParser", result); //$NON-NLS-1$
+ return result;
}
private void teardown()
@@ -213,7 +285,28 @@ public class Main
if (helpPrinted)
return;
- HelpPrinter.printHelp(HELP_PATH);
helpPrinted = true;
}
+
+ // Inner class(es)
+ // ==========================================================================
+
+ private class NoParseOption
+ extends Option
+ {
+ public NoParseOption(String name, String description)
+ {
+ super(name, description);
+ }
+
+ public NoParseOption(String name, String description, String param)
+ {
+ super(name, description, param);
+ }
+
+ public void parsed(String argument) throws OptionException
+ {
+ // do nothing
+ }
+ }
}
diff --git a/tools/gnu/classpath/tools/keytool/PrintCertCmd.java b/tools/gnu/classpath/tools/keytool/PrintCertCmd.java
index 9ba1d5970..d259258e7 100644
--- a/tools/gnu/classpath/tools/keytool/PrintCertCmd.java
+++ b/tools/gnu/classpath/tools/keytool/PrintCertCmd.java
@@ -38,6 +38,12 @@ exception statement from your version. */
package gnu.classpath.tools.keytool;
+import gnu.classpath.tools.getopt.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.PrintWriter;
import java.security.cert.Certificate;
import java.security.cert.CertificateException;
@@ -63,7 +69,7 @@ import java.util.logging.Logger;
class PrintCertCmd extends Command
{
private static final Logger log = Logger.getLogger(PrintCertCmd.class.getName());
- private String _certFileName;
+ protected String _certFileName;
// default 0-arguments constructor
@@ -77,40 +83,18 @@ class PrintCertCmd extends Command
// life-cycle methods -------------------------------------------------------
- int processArgs(String[] args, int i)
- {
- int limit = args.length;
- String opt;
- while (++i < limit)
- {
- opt = args[i];
- log.finest("args[" + i + "]=" + opt);
- if (opt == null || opt.length() == 0)
- continue;
-
- if ("-file".equals(opt)) // -file FILE_NAME
- _certFileName = args[++i];
- else if ("-v".equals(opt))
- verbose = true;
- else
- break;
- }
-
- return i;
- }
-
void setup() throws Exception
{
setInputStreamParam(_certFileName);
- log.finer("-printcert handler will use the following options:");
- log.finer(" -file=" + _certFileName);
- log.finer(" -v=" + verbose);
+ log.finer("-printcert handler will use the following options:"); //$NON-NLS-1$
+ log.finer(" -file=" + _certFileName); //$NON-NLS-1$
+ log.finer(" -v=" + verbose); //$NON-NLS-1$
}
void start() throws CertificateException
{
- log.entering(getClass().getName(), "start");
+ log.entering(getClass().getName(), "start"); //$NON-NLS-1$
CertificateFactory x509Factory = CertificateFactory.getInstance(Main.X_509);
Certificate certificate = x509Factory.generateCertificate(inStream);
@@ -118,6 +102,39 @@ class PrintCertCmd extends Command
writer.println();
printVerbose(certificate, writer);
- log.exiting(getClass().getName(), "start");
+ log.exiting(getClass().getName(), "start"); //$NON-NLS-1$
+ }
+
+ // own methods --------------------------------------------------------------
+
+ Parser getParser()
+ {
+ log.entering(this.getClass().getName(), "getParser"); //$NON-NLS-1$
+
+ Parser result = new ClasspathToolParser(Main.PRINTCERT_CMD, true);
+ result.setHeader(Messages.getString("PrintCertCmd.5")); //$NON-NLS-1$
+ result.setFooter(Messages.getString("PrintCertCmd.6")); //$NON-NLS-1$
+ OptionGroup options = new OptionGroup(Messages.getString("PrintCertCmd.7")); //$NON-NLS-1$
+ options.add(new Option(Main.FILE_OPT,
+ Messages.getString("PrintCertCmd.8"), //$NON-NLS-1$
+ Messages.getString("PrintCertCmd.9")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ _certFileName = argument;
+ }
+ });
+ options.add(new Option(Main.VERBOSE_OPT,
+ Messages.getString("PrintCertCmd.10")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ verbose = true;
+ }
+ });
+ result.add(options);
+
+ log.exiting(this.getClass().getName(), "getParser", result); //$NON-NLS-1$
+ return result;
}
}
diff --git a/tools/gnu/classpath/tools/keytool/SelfCertCmd.java b/tools/gnu/classpath/tools/keytool/SelfCertCmd.java
index db7d45994..418bce49f 100644
--- a/tools/gnu/classpath/tools/keytool/SelfCertCmd.java
+++ b/tools/gnu/classpath/tools/keytool/SelfCertCmd.java
@@ -38,6 +38,11 @@ exception statement from your version. */
package gnu.classpath.tools.keytool;
+import gnu.classpath.tools.getopt.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 gnu.java.security.x509.X500DistinguishedName;
import java.io.ByteArrayInputStream;
@@ -171,15 +176,15 @@ import javax.security.auth.x500.X500Principal;
class SelfCertCmd extends Command
{
private static final Logger log = Logger.getLogger(SelfCertCmd.class.getName());
- private String _alias;
- private String _sigAlgorithm;
- private String _dName;
- private String _password;
- private String _validityStr;
- private String _ksType;
- private String _ksURL;
- private String _ksPassword;
- private String _providerClassName;
+ protected String _alias;
+ protected String _sigAlgorithm;
+ protected String _dName;
+ protected String _password;
+ protected String _validityStr;
+ protected String _ksType;
+ protected String _ksURL;
+ protected String _ksPassword;
+ protected String _providerClassName;
private X500DistinguishedName distinguishedName;
private int validityInDays;
@@ -253,71 +258,29 @@ class SelfCertCmd extends Command
// life-cycle methods -------------------------------------------------------
- int processArgs(String[] args, int i)
- {
- int limit = args.length;
- String opt;
- while (++i < limit)
- {
- opt = args[i];
- log.finest("args[" + i + "]=" + opt);
- if (opt == null || opt.length() == 0)
- continue;
-
- if ("-alias".equals(opt)) // -alias ALIAS
- _alias = args[++i];
- else if ("-sigalg".equals(opt)) // -sigalg ALGORITHM
- _sigAlgorithm = args[++i];
- else if ("-dname".equals(opt)) // -dname NAME
- _dName = args[++i];
- else if ("-keypass".equals(opt)) // -keypass PASSWORD
- _password = args[++i];
- else if ("-validity".equals(opt)) // -validity DAY_COUNT
- _validityStr = args[++i];
- else if ("-storetype".equals(opt)) // -storetype STORE_TYPE
- _ksType = args[++i];
- else if ("-keystore".equals(opt)) // -keystore URL
- _ksURL = args[++i];
- else if ("-storepass".equals(opt)) // -storepass PASSWORD
- _ksPassword = args[++i];
- else if ("-provider".equals(opt)) // -provider PROVIDER_CLASS_NAME
- _providerClassName = args[++i];
- else if ("-v".equals(opt))
- verbose = true;
- else
- break;
- }
-
- return i;
- }
-
void setup() throws Exception
{
setKeyStoreParams(_providerClassName, _ksType, _ksPassword, _ksURL);
setAliasParam(_alias);
setKeyPasswordNoPrompt(_password);
-// setDName(_dName);
setValidityParam(_validityStr);
-// setSignatureAlgorithm(_sigAlgorithm);
-
- log.finer("-selfcert handler will use the following options:");
- log.finer(" -alias=" + alias);
- log.finer(" -sigalg=" + _sigAlgorithm);
- log.finer(" -dname=" + _dName);
- log.finer(" -keypass=" + _password);
- log.finer(" -validity=" + validityInDays);
- log.finer(" -storetype=" + storeType);
- log.finer(" -keystore=" + storeURL);
- log.finer(" -storepass=" + String.valueOf(storePasswordChars));
- log.finer(" -provider=" + provider);
- log.finer(" -v=" + verbose);
+
+ log.finer("-selfcert handler will use the following options:"); //$NON-NLS-1$
+ log.finer(" -alias=" + alias); //$NON-NLS-1$
+ log.finer(" -sigalg=" + _sigAlgorithm); //$NON-NLS-1$
+ log.finer(" -dname=" + _dName); //$NON-NLS-1$
+ log.finer(" -validity=" + validityInDays); //$NON-NLS-1$
+ log.finer(" -storetype=" + storeType); //$NON-NLS-1$
+ log.finer(" -keystore=" + storeURL); //$NON-NLS-1$
+ log.finer(" -provider=" + provider); //$NON-NLS-1$
+ log.finer(" -v=" + verbose); //$NON-NLS-1$
}
void start() throws KeyStoreException, NoSuchAlgorithmException,
UnrecoverableKeyException, IOException, UnsupportedCallbackException,
InvalidKeyException, SignatureException, CertificateException
{
- log.entering(getClass().getName(), "start");
+ log.entering(getClass().getName(), "start"); //$NON-NLS-1$
// 1. get the key entry and certificate chain associated to alias
Key privateKey = getAliasPrivateKey();
@@ -337,7 +300,7 @@ class SelfCertCmd extends Command
byte[] derBytes = getSelfSignedCertificate(distinguishedName,
publicKey,
(PrivateKey) privateKey);
- CertificateFactory x509Factory = CertificateFactory.getInstance("X.509");
+ CertificateFactory x509Factory = CertificateFactory.getInstance("X.509"); //$NON-NLS-1$
ByteArrayInputStream bais = new ByteArrayInputStream(derBytes);
Certificate certificate = x509Factory.generateCertificate(bais);
@@ -348,11 +311,114 @@ class SelfCertCmd extends Command
// 7. persist the key store
saveKeyStore();
- log.exiting(getClass().getName(), "start");
+ log.exiting(getClass().getName(), "start"); //$NON-NLS-1$
}
// own methods --------------------------------------------------------------
+ Parser getParser()
+ {
+ log.entering(this.getClass().getName(), "getParser"); //$NON-NLS-1$
+
+ Parser result = new ClasspathToolParser(Main.SELFCERT_CMD, true);
+ result.setHeader(Messages.getString("SelfCertCmd.14")); //$NON-NLS-1$
+ result.setFooter(Messages.getString("SelfCertCmd.15")); //$NON-NLS-1$
+ OptionGroup options = new OptionGroup(Messages.getString("SelfCertCmd.16")); //$NON-NLS-1$
+ options.add(new Option(Main.ALIAS_OPT,
+ Messages.getString("SelfCertCmd.17"), //$NON-NLS-1$
+ Messages.getString("SelfCertCmd.18")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ _alias = argument;
+ }
+ });
+ options.add(new Option(Main.SIGALG_OPT,
+ Messages.getString("SelfCertCmd.19"), //$NON-NLS-1$
+ Messages.getString("SelfCertCmd.20")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ _sigAlgorithm = argument;
+ }
+ });
+ options.add(new Option(Main.DNAME_OPT,
+ Messages.getString("SelfCertCmd.21"), //$NON-NLS-1$
+ Messages.getString("SelfCertCmd.22")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ _dName = argument;
+ }
+ });
+ options.add(new Option(Main.KEYPASS_OPT,
+ Messages.getString("SelfCertCmd.23"), //$NON-NLS-1$
+ Messages.getString("SelfCertCmd.24")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ _password = argument;
+ }
+ });
+ options.add(new Option(Main.VALIDITY_OPT,
+ Messages.getString("SelfCertCmd.25"), //$NON-NLS-1$
+ Messages.getString("SelfCertCmd.26")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ _validityStr = argument;
+ }
+ });
+ options.add(new Option(Main.STORETYPE_OPT,
+ Messages.getString("SelfCertCmd.27"), //$NON-NLS-1$
+ Messages.getString("SelfCertCmd.28")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ _ksType = argument;
+ }
+ });
+ options.add(new Option(Main.KEYSTORE_OPT,
+ Messages.getString("SelfCertCmd.29"), //$NON-NLS-1$
+ Messages.getString("SelfCertCmd.30")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ _ksURL = argument;
+ }
+ });
+ options.add(new Option(Main.STOREPASS_OPT,
+ Messages.getString("SelfCertCmd.31"), //$NON-NLS-1$
+ Messages.getString("SelfCertCmd.32")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ _ksPassword = argument;
+ }
+ });
+ options.add(new Option(Main.PROVIDER_OPT,
+ Messages.getString("SelfCertCmd.33"), //$NON-NLS-1$
+ Messages.getString("SelfCertCmd.34")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ _providerClassName = argument;
+ }
+ });
+ options.add(new Option(Main.VERBOSE_OPT,
+ Messages.getString("SelfCertCmd.35")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ verbose = true;
+ }
+ });
+ result.add(options);
+
+ log.exiting(this.getClass().getName(), "getParser", result); //$NON-NLS-1$
+ return result;
+ }
+
private void setDName(String name, X500Principal defaultName)
{
if (name != null && name.trim().length() > 0)
diff --git a/tools/gnu/classpath/tools/keytool/StorePasswdCmd.java b/tools/gnu/classpath/tools/keytool/StorePasswdCmd.java
index 1eb053c1c..e9262bd71 100644
--- a/tools/gnu/classpath/tools/keytool/StorePasswdCmd.java
+++ b/tools/gnu/classpath/tools/keytool/StorePasswdCmd.java
@@ -39,6 +39,11 @@ exception statement from your version. */
package gnu.classpath.tools.keytool;
import gnu.classpath.SystemProperties;
+import gnu.classpath.tools.getopt.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.security.KeyStoreException;
@@ -107,11 +112,11 @@ import javax.security.auth.callback.UnsupportedCallbackException;
class StorePasswdCmd extends Command
{
private static final Logger log = Logger.getLogger(StorePasswdCmd.class.getName());
- private String _newPassword;
- private String _ksType;
- private String _ksURL;
- private String _ksPassword;
- private String _providerClassName;
+ protected String _newPassword;
+ protected String _ksType;
+ protected String _ksURL;
+ protected String _ksPassword;
+ protected String _providerClassName;
private char[] newStorePasswordChars;
// default 0-arguments constructor
@@ -150,46 +155,14 @@ class StorePasswdCmd extends Command
// life-cycle methods -------------------------------------------------------
- int processArgs(String[] args, int i)
- {
- int limit = args.length;
- String opt;
- while (++i < limit)
- {
- opt = args[i];
- log.finest("args[" + i + "]=" + opt); //$NON-NLS-1$ //$NON-NLS-2$
- if (opt == null || opt.length() == 0)
- continue;
-
- if ("-new".equals(opt)) // -new PASSWORD //$NON-NLS-1$
- _newPassword = args[++i];
- else if ("-storetype".equals(opt)) // -storetype STORE_TYPE //$NON-NLS-1$
- _ksType = args[++i];
- else if ("-keystore".equals(opt)) // -keystore URL //$NON-NLS-1$
- _ksURL = args[++i];
- else if ("-storepass".equals(opt)) // -storepass PASSWORD //$NON-NLS-1$
- _ksPassword = args[++i];
- else if ("-provider".equals(opt)) // -provider PROVIDER_CLASS_NAME //$NON-NLS-1$
- _providerClassName = args[++i];
- else if ("-v".equals(opt)) //$NON-NLS-1$
- verbose = true;
- else
- break;
- }
-
- return i;
- }
-
void setup() throws Exception
{
setKeyStoreParams(_providerClassName, _ksType, _ksPassword, _ksURL);
setNewKeystorePassword(_newPassword);
log.finer("-storepasswd handler will use the following options:"); //$NON-NLS-1$
- log.finer(" -new=" + String.valueOf(newStorePasswordChars)); //$NON-NLS-1$
log.finer(" -storetype=" + storeType); //$NON-NLS-1$
log.finer(" -keystore=" + storeURL); //$NON-NLS-1$
- log.finer(" -storepass=" + String.valueOf(storePasswordChars)); //$NON-NLS-1$
log.finer(" -provider=" + provider); //$NON-NLS-1$
log.finer(" -v=" + verbose); //$NON-NLS-1$
}
@@ -206,6 +179,73 @@ class StorePasswdCmd extends Command
// own methods --------------------------------------------------------------
+ Parser getParser()
+ {
+ log.entering(this.getClass().getName(), "getParser"); //$NON-NLS-1$
+
+ Parser result = new ClasspathToolParser(Main.STOREPASSWD_CMD, true);
+ result.setHeader(Messages.getString("StorePasswdCmd.18")); //$NON-NLS-1$
+ result.setFooter(Messages.getString("StorePasswdCmd.17")); //$NON-NLS-1$
+ OptionGroup options = new OptionGroup(Messages.getString("StorePasswdCmd.16")); //$NON-NLS-1$
+ options.add(new Option(Main.NEW_OPT,
+ Messages.getString("StorePasswdCmd.15"), //$NON-NLS-1$
+ Messages.getString("StorePasswdCmd.8")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ _newPassword = argument;
+ }
+ });
+ options.add(new Option(Main.STORETYPE_OPT,
+ Messages.getString("StorePasswdCmd.13"), //$NON-NLS-1$
+ Messages.getString("StorePasswdCmd.12")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ _ksType = argument;
+ }
+ });
+ options.add(new Option(Main.KEYSTORE_OPT,
+ Messages.getString("StorePasswdCmd.11"), //$NON-NLS-1$
+ Messages.getString("StorePasswdCmd.10")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ _ksURL = argument;
+ }
+ });
+ options.add(new Option(Main.STOREPASS_OPT,
+ Messages.getString("StorePasswdCmd.9"), //$NON-NLS-1$
+ Messages.getString("StorePasswdCmd.8")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ _ksPassword = argument;
+ }
+ });
+ options.add(new Option(Main.PROVIDER_OPT,
+ Messages.getString("StorePasswdCmd.7"), //$NON-NLS-1$
+ Messages.getString("StorePasswdCmd.6")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ _providerClassName = argument;
+ }
+ });
+ options.add(new Option(Main.VERBOSE_OPT,
+ Messages.getString("StorePasswdCmd.5")) //$NON-NLS-1$
+ {
+ public void parsed(String argument) throws OptionException
+ {
+ verbose = true;
+ }
+ });
+ result.add(options);
+
+ log.exiting(this.getClass().getName(), "getParser", result); //$NON-NLS-1$
+ return result;
+ }
+
protected void setNewKeystorePassword(String password) throws IOException,
UnsupportedCallbackException
{
diff --git a/tools/gnu/classpath/tools/keytool/keytool.txt b/tools/gnu/classpath/tools/keytool/keytool.txt
deleted file mode 100644
index 15f9b96f9..000000000
--- a/tools/gnu/classpath/tools/keytool/keytool.txt
+++ /dev/null
@@ -1,616 +0,0 @@
-NAME
- keytool - manage private keys and public certificates
-
-SYNOPSIS
- keytool [COMMAND]...
-
-DESCRIPTION
- A Java-based tool for managing both Key Entries as well as Trusted
- Certificates.
-
- Multiple COMMANDs may be specified at once, each complete with its own
- options. keytool will parse all the arguments, before processing, and
- executing, each COMMAND. If an exception occurs while executing one
- COMMAND keytool will abort.
-
- A COMMAND can be one of the followings:
-
- -genkey [OPTION]...
- Generate a new Key Entry, eventually creating a new key store.
-
- -import [OPTION]...
- Add, to a key store, Key Entries (private keys and certificate
- chains authenticating the public keys) and Trusted Certificates
- (3rd party certificates which can be used as Trust anchors when
- building chains-of-trust).
-
- -selfcert [OPTION]...
- Generate a new self-signed Trusted Certificate.
-
- -identitydb [OPTION]...
- NOT IMPLEMENTED YET.
- Import a JDK 1.1 style Identity Database.
-
- -certreq [OPTION]...
- Issue a Certificate Signing Request (CSR) which can be then sent
- to a Certification Authority (CA) to issue a certificate signed
- (by the CA) and authenticating the Subject of the request.
-
- -export [OPTION]...
- Export a Certificate from a key store.
-
- -list [OPTION]...
- Print one or all Certificates in a key store to STDOUT.
-
- -printcert [OPTION]...
- Print a human-readable form of a Certificate in a designated
- file to STDOUT.
-
- -keyclone [OPTION]...
- Clone a Key Entry in a key store.
-
- -storepasswd [OPTION]...
- Change the password protecting a key store.
-
- -keypasswd [OPTION]...
- Change the password protecting a Key Entry in a key store.
-
- -delete [OPTION]...
- Delete a Key Entry or a Trusted Certificate from a key store.
-
- -help Display this text.
-
-OPTIONS COMMON TO MORE THAN ONE COMMAND
- The following OPTIONs are used in more than one COMMAND. They are
- described here to reduce redundancy.
-
- -alias ALIAS
- Every entry, be it a Key Entry or a Trusted Certificate, in a
- key store is uniquely identified by a user-defined Alias string.
- Use this option to specify the Alias to use when referring to an
- entry in the key store. Unless specified otherwise, a default
- value of "mykey" (all lower case, without the enclosing quotes)
- shall be used when this option is omitted from the command line.
-
- -keyalg ALGORITHM
- Use this option to specify the canonical name of the key-pair
- generation algorithm. The default value for this option is
- "DSS" (a synonym for the Digital Signature Algorithm also known
- as DSA).
-
- -keysize SIZE
- Use this option to specify the number of bits of the shared
- modulus (for both the public and private keys) to use when
- generating new keys. A default value of 1024 will be used if
- this option is omitted from the command line.
-
- -validity DAY_COUNT
- Use this option to specify the number of days a newly generated
- certificate will be valid for. The default value is 90 (days)
- if this option is omitted from the command line.
-
- -storetype STORE_TYPE
- Use this option to specify the type of the key store to use.
- The default value, if this option is omitted, is that of the
- property "keystore.type" in the security properties file, which
- is obtained by invoking the static method call getDefaultType()
- in java.security.KeyStore.
-
- -storepass PASSWORD
- Use this option to specify the password protecting the key
- store. If this option is omitted from the command line, you
- will be prompted to provide a password.
-
- -keystore URL
- Use this option to specify the location of the key store to use.
- The default value is a file URL referencing the file named
- ".keystore" (all lower case and without the enclosing quotes)
- located in the path returned by the call to
- java.lang.System#getProperty(String) using "user.home" as
- argument.
-
- If a URL was specified, but was found to be malformed --e.g.
- missing protocol element-- the tool will attempt to use the URL
- value as a file-name (with absolute or relative path-name) of a
- key store --as if the protocol was "file:".
-
- -provider PROVIDER_CLASS_NAME
- A fully qualified class name of a Security Provider to add to
- the current list of Security Providers already installed in the
- JVM in-use. If a provider class is specified with this option,
- and was successfully added to the runtime --i.e. it was not
- already installed-- then the tool will attempt to remove this
- Security Provider before exiting.
-
- -file FILE_NAME
- Use this option to designate a file to use with a command. When
- specified with this option, the value is expected to be the
- fully qualified path of a file accessible by the File System.
- Depending on the command, the file may be used as input or as
- output. When this option is omitted from the command line,
- STDIN will be used instead, as the source of input, and STDOUT
- will be used instead as the output destination.
-
- -v Unless specified otherwise, use this option to enable more
- verbose output.
-
-X.500 DISTINGUISHED NAME
- A Distinguished Name (or DN) MUST be supplied with some of the COMMANDs
- using a -dname option. The syntax of a valid value for this option MUST
- follow RFC-2253 specifications. Namely the following components (with
- their accepted meaning) will be recognized. Note that the component
- name is case-insensitive:
-
- CN The Common Name; e.g. "host.domain.com"
- OU The Organizational Unit; e.g. "IT Department"
- O The Organization Name; e.g. "The Sample Company"
- L The Locality Name; e.g. "Sydney"
- ST The State Name; e.g. "New South Wales"
- C The 2-letter Country identifier; e.g. "AU"
-
- When specified with a -dname option, each pair of component/value will
- be separated from the other with a comma. Each component and value pair
- MUST be separated by an equal sign. For example, the following is
- a valid DN value:
-
- CN=host.domain.com, O=The Sample Company, L=Sydney, ST=NSW, C=AU
-
- If the Distinguished Name is required, and no valid default value can be
- used, the tool will prompt you to enter the information through the
- console.
-
--genkey COMMAND
- Generate a new key-pair (both private and public keys), and save these
- credentials in the key store as a Key Entry, associated with the
- designated (if was specified in the -alias option) or default (if the
- -alias option is omitted) Alias.
-
- The private key material will be protected with a user-defined password
- (see -keypass option). The public key on the other hand will be part
- of a self-signed X.509 certificate, which will form a 1-element chain
- and will be saved in the key store.
-
- -alias ALIAS
- (see OPTIONS COMMON TO MORE THAN ONE COMMAND)
-
- -keyalg ALGORITHM
- (see OPTIONS COMMON TO MORE THAN ONE COMMAND)
-
- -keysize KEY_SIZE
- (see OPTIONS COMMON TO MORE THAN ONE COMMAND)
-
- -sigalg ALGORITHM
- The canonical name of the digital signature algorithm to use for
- signing certificates. If this option is omitted, a default
- value will be chosen based on the type of the key-pair; i.e. the
- algorithm that ends up being used by the -keyalg option. If the
- key-pair generation algorithm is "DSA", the value for the
- signature algorithm will be "SHA1withDSA". If on the other hand
- the key-pair generation algorithm is "RSA", then the tool will
- use "MD5withRSA" as the signature algorithm.
-
- -dname NAME
- This a mandatory value for the command. If no value is
- specified --i.e. the -dname option is omitted-- the tool will
- prompt you to enter a Distinguished Name to use as both the
- Owner and Issuer of the generated self-signed certificate.
-
- (see X.500 DISTINGUISHED NAME)
-
- -keypass PASSWORD
- Use this option to specify the password which the tool will use
- to protect the newly created Key Entry.
-
- If this option is omitted, you will be prompted to provide a
- password.
-
- -validity DAY_COUNT
- (see OPTIONS COMMON TO MORE THAN ONE COMMAND)
-
- -storetype STORE_TYPE
- (see OPTIONS COMMON TO MORE THAN ONE COMMAND)
-
- -keystore URL
- (see OPTIONS COMMON TO MORE THAN ONE COMMAND)
-
- -storepass PASSWORD
- (see OPTIONS COMMON TO MORE THAN ONE COMMAND)
-
- -provider PROVIDER_CLASS_NAME
- (see OPTIONS COMMON TO MORE THAN ONE COMMAND)
-
- -v (see OPTIONS COMMON TO MORE THAN ONE COMMAND)
-
--import COMMAND
- Read an X.509 certificate, or a PKCS#7 Certificate Reply from a
- designated input source and incorporate the certificates into the key
- store.
-
- If the Alias does not already exist in the key store, the tool treats
- the certificate read from the input source as a new Trusted Certificate.
- It then attempts to discover a chain-of-trust, starting from that
- certificate and ending at another Trusted Certificate, already stored in
- the key store. If the -trustcacerts option is present, an additional
- key store, of type "JKS" named "cacerts", and assumed to be present in
- ${JAVA_HOME}/lib/security will also be consulted if found --${JAVA_HOME}
- refers to the location of an installed Java Runtime Environment (JRE).
- If no chain-of-trust can be established, and unless the -noprompt option
- has been specified, the certificate is printed to STDOUT and the user is
- prompted for a confirmation.
-
- If Alias exists in the key store, the tool will treat the certificate(s)
- read from the input source as a Certificate Reply, which can be a chain
- of certificates, that eventually would replace the chain of certificates
- associated with the Key Entry of that Alias. The substitution of the
- certificates only occurs if a chain-of-trust can be established between
- the bottom certificate of the chain read from the input file and the
- Trusted Certificates already present in the key store. Again, if the
- -trustcacerts option is specified, additional Trusted Certificates in
- the same "cacerts" key store will be considered. If no chain-of-trust
- can be established, the operation will abort.
-
- -alias ALIAS
- (see OPTIONS COMMON TO MORE THAN ONE COMMAND)
-
- -file FILE_NAME
- (see OPTIONS COMMON TO MORE THAN ONE COMMAND)
-
- -keypass PASSWORD
- Use this option to specify the password which the tool will use
- to protect the Key Entry associated with the designated Alias,
- when replacing this Alias' chain of certificates with that found
- in the certificate reply.
-
- If this option is omitted, and the chain-of-trust for the
- certificate reply has been established, the tool will first
- attempt to unlock the Key Entry using the same password
- protecting the key store. If this fails, you will then be
- prompted to provide a password.
-
- -noprompt
- Use this option to prevent the tool from prompting the user.
-
- -trustcacerts
- Use this option to indicate to the tool that a key store, of
- type "JKS", named "cacerts", and usually located in lib/security
- in an installed Java Runtime Environment should be considered
- when trying to establish chain-of-trusts.
-
- -storetype STORE_TYPE
- (see OPTIONS COMMON TO MORE THAN ONE COMMAND)
-
- -keystore URL
- (see OPTIONS COMMON TO MORE THAN ONE COMMAND)
-
- -storepass PASSWORD
- (see OPTIONS COMMON TO MORE THAN ONE COMMAND)
-
- -provider PROVIDER_CLASS_NAME
- (see OPTIONS COMMON TO MORE THAN ONE COMMAND)
-
- -v (see OPTIONS COMMON TO MORE THAN ONE COMMAND)
-
--selfcert COMMAND
- Generate a self-signed X.509 version 1 certificate. The newly generated
- certificate will form a chain of one element which will replace the
- previous chain associated with the designated Alias (if -alias option
- was specified), or the default Alias (if -alias option was omitted).
-
- -alias ALIAS
- (see OPTIONS COMMON TO MORE THAN ONE COMMAND)
-
- -sigalg ALGORITHM
- The canonical name of the digital signature algorithm to use for
- signing the certificate. If this option is omitted, a default
- value will be chosen based on the type of the private key
- associated with the designated Alias. If the private key is a
- "DSA" one, the value for the signature algorithm will be
- "SHA1withDSA". If on the other hand the private key is an "RSA"
- one, then the tool will use "MD5withRSA" as the signature
- algorithm.
-
- -dname NAME
- Use this option to specify the Distinguished Name of the newly
- generated self-signed certificate. If this option is omitted,
- the existing Distinguished Name of the base certificate in the
- chain associated with the designated Alias will be used instead.
-
- (see X.500 DISTINGUISHED NAME)
-
- -validity DAY_COUNT
- (see OPTIONS COMMON TO MORE THAN ONE COMMAND)
-
- -keypass PASSWORD
- Use this option to specify the password which the tool will use
- to unlock the Key Entry associated with the designated Alias.
-
- If this option is omitted, the tool will first attempt to unlock
- the Key Entry using the same password protecting the key store.
- If this fails, you will then be prompted to provide a password.
-
- -storetype STORE_TYPE
- (see OPTIONS COMMON TO MORE THAN ONE COMMAND)
-
- -keystore URL
- (see OPTIONS COMMON TO MORE THAN ONE COMMAND)
-
- -storepass PASSWORD
- (see OPTIONS COMMON TO MORE THAN ONE COMMAND)
-
- -provider PROVIDER_CLASS_NAME
- (see OPTIONS COMMON TO MORE THAN ONE COMMAND)
-
- -v (see OPTIONS COMMON TO MORE THAN ONE COMMAND)
-
--identitydb COMMAND
- NOT IMPLEMENTED YET.
-
- Import a JDK 1.1 style Identity Database.
-
- -file FILE_NAME
- (see OPTIONS COMMON TO MORE THAN ONE COMMAND)
-
- -storetype STORE_TYPE
- (see OPTIONS COMMON TO MORE THAN ONE COMMAND)
-
- -keystore URL
- (see OPTIONS COMMON TO MORE THAN ONE COMMAND)
-
- -storepass PASSWORD
- (see OPTIONS COMMON TO MORE THAN ONE COMMAND)
-
- -provider PROVIDER_CLASS_NAME
- (see OPTIONS COMMON TO MORE THAN ONE COMMAND)
-
- -v (see OPTIONS COMMON TO MORE THAN ONE COMMAND)
-
--certreq COMMAND
- Generate a PKCS#10 Certificate Signing Request (CSR) and writes it to
- a designated output destination. The contents of the destination
- should look something like the following:
-
- -----BEGIN NEW CERTIFICATE REQUEST-----
- MIICYTCCAiECAQAwXzEUMBIGA1UEAwwLcnNuQGdudS5vcmcxGzAZBgNVBAoMElUg
- Q29tcGFueTEPMA0GA1UEBwwGU3lkbmV5MQwwCgYDVQQIDANOU1cxCzAJBgNVBACC
- ...
- FCTlKlok8KwGuIVwNVOfQLRX+O5kAhQ/a4RTZme2L8PnpvgRwrf7Eg8D6w==
- -----END NEW CERTIFICATE REQUEST-----
-
- IMPORTANT: Some documentation (e.g. RSA examples) claims that the
- Attributes field, in the CSR is OPTIONAL while RFC-2986 implies the
- opposite. This implementation considers this field, by default, as
- OPTIONAL, unless the option -attributes is specified on the command
- line.
-
- -alias ALIAS
- (see OPTIONS COMMON TO MORE THAN ONE COMMAND)
-
- -sigalg ALGORITHM
- The canonical name of the digital signature algorithm to use for
- signing the certificate. If this option is omitted, a default
- value will be chosen based on the type of the private key
- associated with the designated Alias. If the private key is a
- "DSA" one, the value for the signature algorithm will be
- "SHA1withDSA". If on the other hand the private key is an "RSA"
- one, then the tool will use "MD5withRSA" as the signature
- algorithm.
-
- -file FILE_NAME
- (see OPTIONS COMMON TO MORE THAN ONE COMMAND)
-
- -keypass PASSWORD
- Use this option to specify the password which the tool will use
- to unlock the Key Entry associated with the designated Alias.
-
- If this option is omitted, the tool will first attempt to unlock
- the Key Entry using the same password protecting the key store.
- If this fails, you will then be prompted to provide a password.
-
- -storetype STORE_TYPE
- (see OPTIONS COMMON TO MORE THAN ONE COMMAND)
-
- -keystore URL
- (see OPTIONS COMMON TO MORE THAN ONE COMMAND)
-
- -storepass PASSWORD
- (see OPTIONS COMMON TO MORE THAN ONE COMMAND)
-
- -provider PROVIDER_CLASS_NAME
- (see OPTIONS COMMON TO MORE THAN ONE COMMAND)
-
- -v (see OPTIONS COMMON TO MORE THAN ONE COMMAND)
-
- -attributes
- Use this option to force the tool to encode a NULL DER value in
- the CSR as the value of the Attributes field.
-
--export COMMAND
- Export a certificate stored in the key store to a designated output
- destination, either in binary format (if the -v option is specified),
- or in RFC-1421 compliant encoding (if the -rfc option is specified
- instead).
-
- -alias ALIAS
- (see OPTIONS COMMON TO MORE THAN ONE COMMAND)
-
- -file FILE_NAME
- (see OPTIONS COMMON TO MORE THAN ONE COMMAND)
-
- -storetype STORE_TYPE
- (see OPTIONS COMMON TO MORE THAN ONE COMMAND)
-
- -keystore URL
- (see OPTIONS COMMON TO MORE THAN ONE COMMAND)
-
- -storepass PASSWORD
- (see OPTIONS COMMON TO MORE THAN ONE COMMAND)
-
- -provider PROVIDER_CLASS_NAME
- (see OPTIONS COMMON TO MORE THAN ONE COMMAND)
-
- -rfc Use RFC-1421 specifications when encoding the output.
-
- -v Output the certificate in binary DER encoding. This is the
- default output format of the command if neither -rfc nor -v
- options were detected on the command line. If both this option
- and the -rfc option are detected on the command line, the tool
- will opt for the RFC-1421 style encoding.
-
--list COMMAND
- Print one or all of the key store entries to STDOUT. Usually this
- command will only print a fingerprint of the certificate, unless either
- the -rfc or the -v option is specified.
-
- -alias ALIAS
- If this option is omitted, the tool will print ALL the entries
- found in the key store.
-
- (see OPTIONS COMMON TO MORE THAN ONE COMMAND)
-
- -storetype STORE_TYPE
- (see OPTIONS COMMON TO MORE THAN ONE COMMAND)
-
- -keystore URL
- (see OPTIONS COMMON TO MORE THAN ONE COMMAND)
-
- -storepass PASSWORD
- (see OPTIONS COMMON TO MORE THAN ONE COMMAND)
-
- -provider PROVIDER_CLASS_NAME
- (see OPTIONS COMMON TO MORE THAN ONE COMMAND)
-
- -rfc Use RFC-1421 specifications when encoding the output.
-
- -v Output the certificate in human-readable format. If both this
- option and the -rfc option are detected on the command line,
- the tool will opt for the human-readable form and will not
- abort the command.
-
--printcert COMMAND
- Read a certificate from a designated input source and print it to STDOUT
- in a human-readable form.
-
- -file FILE_NAME
- (see OPTIONS COMMON TO MORE THAN ONE COMMAND)
-
- -v (see OPTIONS COMMON TO MORE THAN ONE COMMAND)
-
--keyclone COMMAND
- Clone an existing Key Entry and store it under a new (different) Alias
- protecting, its private key material with possibly a new password.
-
- -alias ALIAS
- (see OPTIONS COMMON TO MORE THAN ONE COMMAND)
-
- -dest ALIAS
- Use this option to specify the new Alias which will be used to
- identify the cloned copy of the Key Entry.
-
- -keypass PASSWORD
- Use this option to specify the password which the tool will use
- to unlock the Key Entry associated with the designated Alias.
-
- If this option is omitted, the tool will first attempt to unlock
- the Key Entry using the same password protecting the key store.
- If this fails, you will then be prompted to provide a password.
-
- -new PASSWORD
- Use this option to specify the password protecting the private
- key material of the newly cloned copy of the Key Entry.
-
- -storetype STORE_TYPE
- (see OPTIONS COMMON TO MORE THAN ONE COMMAND)
-
- -keystore URL
- (see OPTIONS COMMON TO MORE THAN ONE COMMAND)
-
- -storepass PASSWORD
- (see OPTIONS COMMON TO MORE THAN ONE COMMAND)
-
- -provider PROVIDER_CLASS_NAME
- (see OPTIONS COMMON TO MORE THAN ONE COMMAND)
-
- -v (see OPTIONS COMMON TO MORE THAN ONE COMMAND)
-
--storepasswd COMMAND
- Change the password protecting a key store.
-
- -new PASSWORD
- The new, and different, password which will be used to protect
- the designated key store.
-
- -storetype STORE_TYPE
- (see OPTIONS COMMON TO MORE THAN ONE COMMAND)
-
- -keystore URL
- (see OPTIONS COMMON TO MORE THAN ONE COMMAND)
-
- -storepass PASSWORD
- (see OPTIONS COMMON TO MORE THAN ONE COMMAND)
-
- -provider PROVIDER_CLASS_NAME
- (see OPTIONS COMMON TO MORE THAN ONE COMMAND)
-
- -v (see OPTIONS COMMON TO MORE THAN ONE COMMAND)
-
--keypasswd COMMAND
- Change the password protecting the private key material of a designated
- Key Entry.
-
- -alias ALIAS
- (see OPTIONS COMMON TO MORE THAN ONE COMMAND)
-
- -keypass PASSWORD
- Use this option to specify the password which the tool will use
- to unlock the Key Entry associated with the designated Alias.
-
- If this option is omitted, the tool will first attempt to unlock
- the Key Entry using the same password protecting the key store.
- If this fails, you will then be prompted to provide a password.
-
- -new PASSWORD
- The new, and different, password which will be used to protect
- the private key material of the designated Key Entry.
-
- -storetype STORE_TYPE
- (see OPTIONS COMMON TO MORE THAN ONE COMMAND)
-
- -keystore URL
- (see OPTIONS COMMON TO MORE THAN ONE COMMAND)
-
- -storepass PASSWORD
- (see OPTIONS COMMON TO MORE THAN ONE COMMAND)
-
- -provider PROVIDER_CLASS_NAME
- (see OPTIONS COMMON TO MORE THAN ONE COMMAND)
-
- -v (see OPTIONS COMMON TO MORE THAN ONE COMMAND)
-
--delete COMMAND
- Delete a designated key store entry.
-
- -alias ALIAS
- (see OPTIONS COMMON TO MORE THAN ONE COMMAND)
-
- -storetype STORE_TYPE
- (see OPTIONS COMMON TO MORE THAN ONE COMMAND)
-
- -keystore URL
- (see OPTIONS COMMON TO MORE THAN ONE COMMAND)
-
- -storepass PASSWORD
- (see OPTIONS COMMON TO MORE THAN ONE COMMAND)
-
- -provider PROVIDER_CLASS_NAME
- (see OPTIONS COMMON TO MORE THAN ONE COMMAND)
-
- -v (see OPTIONS COMMON TO MORE THAN ONE COMMAND)
-
-REPORTING BUGS
- Please report bugs at http://www.gnu.org/software/classpath/bugs.html
-
-COPYRIGHT
- Copyright (C) 2006 Free Software Foundation, Inc.
- This is free software; see the source for copying conditions. There is
- NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR
- PURPOSE.
diff --git a/tools/gnu/classpath/tools/rmi/RMIC.java b/tools/gnu/classpath/tools/rmi/RMIC.java
index c44453011..fa4d87c17 100644
--- a/tools/gnu/classpath/tools/rmi/RMIC.java
+++ b/tools/gnu/classpath/tools/rmi/RMIC.java
@@ -41,7 +41,7 @@ public class RMIC
/**
* The version of the compiler.
*/
- public static String VERSION = "0.0 alpha pre";
+ public static String VERSION = "0.01 alpha pre";
/**
* The GRMIC compiler methods
@@ -112,6 +112,17 @@ public class RMIC
else
HelpPrinter.printHelpAndExit(HelpPath);
}
+ else if (c.equals("-classpath"))
+ {
+ int f = i + 1;
+ if (f < args.length)
+ {
+ compiler.setClassPath(args[f]);
+ i++;
+ }
+ else
+ HelpPrinter.printHelpAndExit(HelpPath);
+ }
else if (c.charAt(0) != '-')
// No more options - start of class list.
{
@@ -132,17 +143,7 @@ public class RMIC
if (args[i].charAt(0) != '-')
{
compiler.reset();
- Class c = null;
- try
- {
- c = Thread.currentThread().getContextClassLoader().loadClass(
- args[i]);
- }
- catch (ClassNotFoundException e)
- {
- System.err.println(args[i] + " class not found.");
- System.exit(1);
- }
+ Class c = compiler.loadClass(args[i]);
compiler.compile(c);
String packag = compiler.getPackageName().replace('.', '/');
diff --git a/tools/gnu/classpath/tools/rmi/RMIC.txt b/tools/gnu/classpath/tools/rmi/RMIC.txt
index 7ec371e9a..882cca553 100644
--- a/tools/gnu/classpath/tools/rmi/RMIC.txt
+++ b/tools/gnu/classpath/tools/rmi/RMIC.txt
@@ -9,25 +9,29 @@ Please report bugs at http://www.gnu.org/software/classpath/bugs.html
Usage: rmic <options> <class names>
where <options> includes:
- -nowarn Show no warnings
- -nowrite Do not write any files (check for errors only)
- -d <folder> Place generated files into the given folder
+ -nowarn Show no warnings
+ -nowrite Do not write any files (check for errors only)
+ -d <folder> Place generated files into the given folder
+ -classpath <path> Specifies the path, where to find the classes being
+ compiled
- -help Print this help text
- -v Print version
- -verbose Verbose output
- -force Try to generate code even if the input classes seem not
- consistent with RMI specification.
+ -help Print this help text
+ -v Print version
+ -verbose Verbose output
+ -force Try to generate code even if the input classes seem not
+ consistent with RMI specification.
- -1.2 Generate v 1.2 stubs (default)*
+ -1.2 Generate v 1.2 stubs (default)*
- -iiop Generate stubs and ties for the GIOP based RMI package extension,
- javax.rmi. With this key, the two additional keys are accepted:
- -poa Generate the Servant based ties (default)
- -impl Generate the obsoleted ObjectImpl based ties
- (for backward compatibility)
- -help Show more details on the giop stub and tie generator options.
- -giop Same as -iiop*
+ -iiop Generate stubs and ties for the GIOP based RMI package
+ extension, javax.rmi. With this key, the two additional
+ keys are accepted:
+ -poa Generate the Servant based ties (default)
+ -impl Generate the obsoleted ObjectImpl based ties
+ (for backward compatibility)
+ -help Show more details on the giop stub and tie generator
+ options.
+ -giop Same as -iiop*
and <class names> can include one or more non abstract classes that implement