hello all,
the attached patch --already committed-- replaces command line parsing
in the jarsigner tool with the newly added getopt classes.
2006-05-13 Raif S. Naffah [EMAIL PROTECTED]
* resource/gnu/classpath/tools/jarsigner/MessageBundle.properties:
Added help text.
* tools/Makefile.am (JARSIGNER_HELPS): Removed.
* tools/gnu/classpath/tools/jarsigner/jarsigner.txt: Removed.
* tools/gnu/classpath/tools/jarsigner/Main.java:
Increased visibility of fields used by parser anonymous classes.
(HELP_PATH): Removed.
(cmdLineParser): New field.
(main): Handle JVM exit status.
Handle command line parsing exceptions.
(processArgs): Use getopt command line parser.
(getParser): New method.
(setupCommonParams): Removed checks now handled by processArgs().
(setupSigningParams): Likewise.
* tools/gnu/classpath/tools/jarsigner/JarSigner.java (start):
Reuse an existing message-bundle constant.
cheers;
rsn
Index: JarSigner.java
===
RCS file: /cvsroot/classpath/classpath/tools/gnu/classpath/tools/jarsigner/JarSigner.java,v
retrieving revision 1.5
diff -u -r1.5 JarSigner.java
--- JarSigner.java 2 May 2006 01:00:22 - 1.5
+++ JarSigner.java 12 May 2006 23:58:21 -
@@ -141,7 +141,7 @@
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();
Index: Main.java
===
RCS file: /cvsroot/classpath/classpath/tools/gnu/classpath/tools/jarsigner/Main.java,v
retrieving revision 1.9
diff -u -r1.9 Main.java
--- Main.java 3 May 2006 05:40:24 - 1.9
+++ Main.java 13 May 2006 00:24:57 -
@@ -39,9 +39,13 @@
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.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.Registry;
import gnu.javax.security.auth.callback.ConsoleCallbackHandler;
@@ -82,7 +86,6 @@
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$
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,18 +94,18 @@
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;
+ 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;
private String jarFileName;
private String alias;
@@ -115,6 +118,8 @@
private Certificate[] signerCertificateChain;
/** The callback handler to use when needing to interact with user. */
private CallbackHandler handler;
+ /** The command line parser. */
+ private Parser cmdLineParser;
private Main()
{
@@ -126,11 +131,19 @@
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 (OptionException x)
+{
+ System.err.println(x.getMessage()); //$NON-NLS-1$
+ if (tool.cmdLineParser != null)
+tool.cmdLineParser.printHelp();
+}
catch (SecurityException x)
{
log.throwing(Main.class.getName(), main, x); //$NON-NLS-1$
@@ -141,11 +154,13 @@
log.throwing(Main.class.getName(), main, x); //$NON-NLS-1$