21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
22 * CA 95054 USA or visit www.sun.com if you need additional information or |
22 * CA 95054 USA or visit www.sun.com if you need additional information or |
23 * have any questions. |
23 * have any questions. |
24 */ |
24 */ |
25 |
25 |
26 |
|
27 package com.sun.tools.javah; |
26 package com.sun.tools.javah; |
28 |
27 |
29 |
28 import java.io.PrintWriter; |
30 import java.io.*; |
|
31 |
29 |
32 /** |
30 /** |
33 * Javah generates support files for native methods. |
31 * Main entry point. |
34 * Parse commandline options & Invokes javadoc to execute those commands. |
|
35 * |
32 * |
36 * @author Sucheta Dambalkar |
33 * <p><b>This is NOT part of any API supported by Sun Microsystems. If |
|
34 * you write code that depends on this, you do so at your own risk. |
|
35 * This code and its internal interfaces are subject to change or |
|
36 * deletion without notice.</b> |
37 */ |
37 */ |
38 public class Main{ |
38 public class Main { |
39 /* |
39 /** |
40 * Parse arguments given for javah to give proper error messages. |
40 * Main entry point for the launcher. |
|
41 * Note: This method calls System.exit. |
|
42 * @param args command line arguments |
41 */ |
43 */ |
42 public static void main(String[] args){ |
44 public static void main(String[] args) { |
43 |
45 JavahTask t = new JavahTask(); |
44 if (args.length == 0) { |
46 int rc = t.run(args); |
45 Util.usage(1); |
|
46 } |
|
47 for ( int i = 0; i < args.length; i++) { |
|
48 if (args[i].equals("-o")) { |
|
49 i++; |
|
50 if(i >= args.length){ |
|
51 Util.usage(1); |
|
52 }else if(args[i].charAt(0) == '-'){ |
|
53 Util.error("no.outputfile.specified"); |
|
54 }else if((i+1) >= args.length){ |
|
55 Util.error("no.classes.specified"); |
|
56 } |
|
57 } else if (args[i].equals("-d")) { |
|
58 i++; |
|
59 if(i >= args.length){ |
|
60 Util.usage(1); |
|
61 }else if(args[i].charAt(0) == '-') { |
|
62 Util.error("no.outputdir.specified"); |
|
63 }else if((i+1) >= args.length){ |
|
64 Util.error("no.classes.specified"); |
|
65 } |
|
66 } else if (args[i].equals("-td")) { |
|
67 /* Ignored. Generate tmp files to memory. */ |
|
68 i++; |
|
69 if (i == args.length) |
|
70 Util.usage(1); |
|
71 } else if (args[i].equals("-stubs")) { |
|
72 if((i+1) >= args.length){ |
|
73 Util.error("no.classes.specified"); |
|
74 } |
|
75 } else if (args[i].equals("-v") || args[i].equals("-verbose")) { |
|
76 if((i+1) >= args.length){ |
|
77 Util.error("no.classes.specified"); |
|
78 } |
|
79 args[i] = "-verbose"; |
|
80 } else if ((args[i].equals("-help")) || (args[i].equals("--help")) |
|
81 || (args[i].equals("-?")) || (args[i].equals("-h"))) { |
|
82 Util.usage(0); |
|
83 } else if (args[i].equals("-trace")) { |
|
84 System.err.println(Util.getText("tracing.not.supported")); |
|
85 } else if (args[i].equals("-version")) { |
|
86 if((i+1) >= args.length){ |
|
87 Util.version(); |
|
88 } |
|
89 } else if (args[i].equals("-jni")) { |
|
90 if((i+1) >= args.length){ |
|
91 Util.error("no.classes.specified"); |
|
92 } |
|
93 } else if (args[i].equals("-force")) { |
|
94 if((i+1) >= args.length){ |
|
95 Util.error("no.classes.specified"); |
|
96 } |
|
97 } else if (args[i].equals("-Xnew")) { |
|
98 // we're already using the new javah |
|
99 } else if (args[i].equals("-old")) { |
|
100 System.err.println(Util.getText("old.not.supported")); |
|
101 Util.usage(1); |
|
102 } else if (args[i].equals("-Xllni")) { |
|
103 if((i+1) >= args.length){ |
|
104 Util.error("no.classes.specified"); |
|
105 } |
|
106 } else if (args[i].equals("-llni")) { |
|
107 if((i+1) >= args.length){ |
|
108 Util.error("no.classes.specified"); |
|
109 } |
|
110 } else if (args[i].equals("-llniDouble")) { |
|
111 if((i+1) >= args.length){ |
|
112 Util.error("no.classes.specified"); |
|
113 } |
|
114 } else if (args[i].equals("-classpath")) { |
|
115 i++; |
|
116 if(i >= args.length){ |
|
117 Util.usage(1); |
|
118 }else if(args[i].charAt(0) == '-') { |
|
119 Util.error("no.classpath.specified"); |
|
120 }else if((i+1) >= args.length){ |
|
121 Util.error("no.classes.specified"); |
|
122 } |
|
123 } else if (args[i].equals("-bootclasspath")) { |
|
124 i++; |
|
125 if(i >= args.length){ |
|
126 Util.usage(1); |
|
127 }else if(args[i].charAt(0) == '-'){ |
|
128 Util.error("no.bootclasspath.specified"); |
|
129 }else if((i+1) >= args.length){ |
|
130 Util.error("no.classes.specified"); |
|
131 } |
|
132 } else if (args[i].charAt(0) == '-') { |
|
133 Util.error("unknown.option", args[i], null, true); |
|
134 |
|
135 } else { |
|
136 //break; /* The rest must be classes. */ |
|
137 } |
|
138 } |
|
139 |
|
140 /* Invoke javadoc */ |
|
141 |
|
142 String[] javadocargs = new String[args.length + 2]; |
|
143 int i = 0; |
|
144 |
|
145 for(; i < args.length; i++) { |
|
146 javadocargs[i] = args[i]; |
|
147 } |
|
148 |
|
149 javadocargs[i] = "-private"; |
|
150 i++; |
|
151 javadocargs[i] = "-Xclasses"; |
|
152 |
|
153 int rc = com.sun.tools.javadoc.Main.execute("javadoc", "com.sun.tools.javah.MainDoclet", javadocargs); |
|
154 System.exit(rc); |
47 System.exit(rc); |
155 } |
48 } |
|
49 |
|
50 /** |
|
51 * Entry point that does <i>not</i> call System.exit. |
|
52 * @param args command line arguments |
|
53 * @param out output stream |
|
54 * @return an exit code. 0 means success, non-zero means an error occurred. |
|
55 */ |
|
56 public static int run(String[] args, PrintWriter out) { |
|
57 JavahTask t = new JavahTask(); |
|
58 t.setLog(out); |
|
59 return t.run(args); |
|
60 } |
156 } |
61 } |