Blame SOURCES/txw2-20110809-args4j.patch

483f59
diff -Naur txw2-20110809/compiler/src/main/java/com/sun/tools/txw2/Main.java txw2-20110809-work/compiler/src/main/java/com/sun/tools/txw2/Main.java
483f59
--- txw2-20110809/compiler/src/main/java/com/sun/tools/txw2/Main.java	2011-03-29 02:59:19.000000000 -0400
483f59
+++ txw2-20110809-work/compiler/src/main/java/com/sun/tools/txw2/Main.java	2012-01-19 13:06:40.049998255 -0500
483f59
@@ -43,10 +43,10 @@
483f59
 import com.sun.codemodel.writer.FileCodeWriter;
483f59
 import com.sun.codemodel.writer.SingleStreamCodeWriter;
483f59
 import com.sun.tools.txw2.model.NodeSet;
483f59
+import org.kohsuke.args4j.Argument;
483f59
+import org.kohsuke.args4j.Option;
483f59
 import org.kohsuke.args4j.CmdLineException;
483f59
 import org.kohsuke.args4j.CmdLineParser;
483f59
-import org.kohsuke.args4j.opts.BooleanOption;
483f59
-import org.kohsuke.args4j.opts.StringOption;
483f59
 import org.kohsuke.rngom.parse.IllegalSchemaException;
483f59
 import org.kohsuke.rngom.parse.Parseable;
483f59
 import org.kohsuke.rngom.parse.compact.CompactParseable;
483f59
@@ -60,6 +60,8 @@
483f59
 import java.io.IOException;
483f59
 import java.net.MalformedURLException;
483f59
 import java.util.Properties;
483f59
+import java.util.List;
483f59
+import java.util.ArrayList;
483f59
 
483f59
 /**
483f59
  * Programatic entry point to the TXW compiler.
483f59
@@ -73,26 +75,39 @@
483f59
         this.opts = opts;
483f59
     }
483f59
 
483f59
-    public static void main(String[] args) {
483f59
-        System.exit(run(args));
483f59
+    public static class Options {
483f59
+        @Argument
483f59
+        public List<String> arguments = new ArrayList<String>();
483f59
+
483f59
+        @Option(name="-o")
483f59
+        public String output;
483f59
+
483f59
+        @Option(name="-p")
483f59
+        public String pkg;
483f59
+
483f59
+        @Option(name="-c")
483f59
+        public boolean compact;
483f59
+
483f59
+        @Option(name="-x")
483f59
+        public boolean xml;
483f59
+
483f59
+        @Option(name="-xsd")
483f59
+        public boolean xsd;
483f59
+
483f59
+        @Option(name="-h")
483f59
+        public boolean chain;
483f59
     }
483f59
 
483f59
-    public static class Options {
483f59
-        public StringOption output = new StringOption("-o");
483f59
-        public StringOption pkg = new StringOption("-p");
483f59
-        public BooleanOption compact = new BooleanOption("-c");
483f59
-        public BooleanOption xml = new BooleanOption("-x");
483f59
-        public BooleanOption xsd = new BooleanOption("-xsd");
483f59
-        public BooleanOption chain = new BooleanOption("-h");
483f59
+    public static void main(String[] args) {
483f59
+        System.exit(run(args));
483f59
     }
483f59
 
483f59
     public static int run(String[] args) {
483f59
         Options opts = new Options();
483f59
-        CmdLineParser parser = new CmdLineParser();
483f59
-        parser.addOptionClass(opts);
483f59
+        CmdLineParser parser = new CmdLineParser(opts);
483f59
 
483f59
         try {
483f59
-            parser.parse(args);
483f59
+            parser.parseArgument(args);
483f59
         } catch (CmdLineException e) {
483f59
             System.out.println(e.getMessage());
483f59
             printUsage();
483f59
@@ -102,9 +117,9 @@
483f59
         TxwOptions topts = new TxwOptions();
483f59
         topts.errorListener = new ConsoleErrorReporter(System.out);
483f59
 
483f59
-        if(opts.output.value!=null) {
483f59
+        if(opts.output != null) {
483f59
             try {
483f59
-                topts.codeWriter = new FileCodeWriter(new File(opts.output.value));
483f59
+                topts.codeWriter = new FileCodeWriter(new File(opts.output));
483f59
             } catch( IOException e ) {
483f59
                 System.out.println(e.getMessage());
483f59
                 printUsage();
483f59
@@ -114,12 +129,12 @@
483f59
             topts.codeWriter = new SingleStreamCodeWriter(System.out);
483f59
         }
483f59
 
483f59
-        if(opts.chain.isOn()) {
483f59
+        if(opts.chain) {
483f59
             topts.chainMethod = true;
483f59
         }
483f59
 
483f59
-        if(opts.pkg.value!=null) {
483f59
-            topts._package = topts.codeModel._package(opts.pkg.value);
483f59
+        if(opts.pkg != null) {
483f59
+            topts._package = topts.codeModel._package(opts.pkg);
483f59
         } else {
483f59
             topts._package = topts.codeModel.rootPackage();
483f59
         }
483f59
@@ -146,21 +161,21 @@
483f59
      * out of the specified schema file.
483f59
      */
483f59
     private static SchemaBuilder makeSourceSchema(CmdLineParser parser, Options opts, ErrorHandler eh) throws MalformedURLException {
483f59
-        File f = new File((String)parser.getArguments().get(0));
483f59
+        File f = new File(opts.arguments.get(0));
483f59
         final InputSource in = new InputSource(f.toURL().toExternalForm());
483f59
 
483f59
-        if(opts.xsd.isOff() && opts.xml.isOff() && opts.compact.isOff()) {
483f59
+        if(!opts.xsd && !opts.xml && !opts.compact) {
483f59
             // auto detect
483f59
             if(in.getSystemId().endsWith(".rnc"))
483f59
-                opts.compact.value=true;
483f59
+                opts.compact = true;
483f59
             else
483f59
             if(in.getSystemId().endsWith(".rng"))
483f59
-                opts.xml.value=true;
483f59
+                opts.xml = true;
483f59
             else
483f59
-                opts.xsd.value=true;
483f59
+                opts.xsd = true;
483f59
         }
483f59
 
483f59
-        if(opts.xsd.isOn())
483f59
+        if(opts.xsd)
483f59
             return new XmlSchemaLoader(in);
483f59
 
483f59
         final Parseable parseable = makeRELAXNGSource(opts, in, eh, f);
483f59
@@ -169,10 +184,10 @@
483f59
     }
483f59
 
483f59
     private static Parseable makeRELAXNGSource(Options opts, final InputSource in, ErrorHandler eh, File f) {
483f59
-        if(opts.compact.isOn())
483f59
+        if(opts.compact)
483f59
             return new CompactParseable(in,eh);
483f59
 
483f59
-        if(opts.xml.isOn())
483f59
+        if(opts.xml)
483f59
             return new SAXParseable(in,eh);
483f59
 
483f59
         // otherwise sniff from the file extension