Thu, 18 Sep 2008 18:39:44 -0700
6744408: Extra ouput is appearing in stderr
Reviewed-by: bpatel
1 /*
2 * Copyright 2002-2003 Sun Microsystems, Inc. All Rights Reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Sun designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Sun in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
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
23 * have any questions.
24 */
27 package com.sun.tools.javah;
29 import com.sun.javadoc.*;
30 import java.io.*;
32 /**
33 * A doclet to parse and execute commandline options.
34 *
35 * @author Sucheta Dambalkar(using code from old javap)
36 */
37 public class MainDoclet{
39 public static String odir = null;
40 public static String ofile = null;
41 public static boolean stubs = false;
42 public static boolean jni = false;
43 public static boolean llni = false;
44 public static boolean doubleAlign = false;
45 public static boolean force = false;
46 public static String genclass = null;
49 /**
50 * Entry point.
51 */
52 public static boolean start(RootDoc root) {
54 int j = 0;
55 int k = 0;
56 /**
57 * Command line options.
58 */
59 String [][] cmdoptions = root.options();
60 /**
61 * Classes specified on command line.
62 */
63 ClassDoc[] classes = root.classes();
64 /**
65 * Generator used by javah. Default is JNI.
66 */
67 Gen g = new JNI(root);
69 validateOptions(cmdoptions);
71 /*
72 * Select native interface.
73 */
74 if (jni && llni) Util.error("jni.llni.mixed");
76 if (llni)
77 g = new LLNI(doubleAlign, root);
79 if (g instanceof JNI && stubs) Util.error("jni.no.stubs");
81 /*
82 * Arrange for output destination.
83 */
84 if (odir != null && ofile != null)
85 Util.error("dir.file.mixed");
87 if (odir != null)
88 g.setOutDir(odir);
90 if (ofile != null)
91 g.setOutFile(ofile);
93 /*
94 * Force set to false will turn off smarts about checking file
95 * content before writing.
96 */
97 g.setForce(force);
99 /*
100 * Grab the rest of argv[] ... this must be the classes.
101 */
102 if (classes.length == 0){
103 Util.error("no.classes.specified");
104 }
105 /*
106 * Set classes.
107 */
108 g.setClasses(classes);
110 try {
111 g.run();
112 } catch (ClassNotFoundException cnfe) {
113 Util.error("class.not.found", cnfe.getMessage());
114 } catch (IOException ioe) {
115 Util.error("io.exception", ioe.getMessage());
116 }
118 return true;
119 }
121 /**
122 * Required doclet method.
123 */
124 public static int optionLength(String option) {
125 if (option.equals("-o")) {
126 return 2;
127 } else if(option.equals("-d")){
128 return 2;
129 } else if (option.equals("-td")) {
130 return 1;
131 } else if (option.equals("-stubs")) {
132 return 1;
133 } else if(option.equals("-help")){
134 return 1;
135 } else if(option.equals("--help")){
136 return 1;
137 } else if(option.equals("-?")){
138 return 1;
139 } else if(option.equals("-h")){
140 return 1;
141 } else if(option.equals("-trace")){
142 return 1;
143 } else if(option.equals("-version")) {
144 return 1;
145 } else if(option.equals("-jni")){
146 return 1;
147 } else if(option.equals("-force")){
148 return 1;
149 } else if(option.equals("-Xllni")){
150 return 1;
151 } else if(option.equals("-llni")){
152 return 1;
153 } else if(option.equals("-llniDouble")){
154 return 1;
155 } else return 0;
156 }
158 /**
159 * Parse the command line options.
160 */
161 public static void validateOptions(String cmdoptions[][]) {
162 /* Default values for options, overridden by user options. */
163 String bootcp = System.getProperty("sun.boot.class.path");
164 String usercp = System.getProperty("env.class.path");
166 for(int p = 0; p < cmdoptions.length; p++){
168 if (cmdoptions[p][0].equals("-o")) {
169 ofile = cmdoptions[p][1];
170 } else if(cmdoptions[p][0].equals("-d")){
171 odir = cmdoptions[p][1];
172 } else if (cmdoptions[p][0].equals("-td")) {
173 if (p ==cmdoptions.length)
174 Util.usage(1);
175 } else if (cmdoptions[p][0].equals("-stubs")) {
176 stubs = true;
177 } else if (cmdoptions[p][0].equals("-verbose")) {
178 Util.verbose = true;
179 } else if((cmdoptions[p][0].equals("-help"))
180 || (cmdoptions[p][0].equals("--help"))
181 || (cmdoptions[p][0].equals("-?"))
182 || (cmdoptions[p][0].equals("-h"))) {
183 Util.usage(0);
184 } else if (cmdoptions[p][0].equals("-trace")) {
185 System.err.println(Util.getText("tracing.not.supported"));
186 } else if (cmdoptions[p][0].equals("-version")) {
187 Util.version();
188 } else if (cmdoptions[p][0].equals("-jni")) {
189 jni = true;
190 } else if (cmdoptions[p][0].equals("-force")) {
191 force = true;
192 } else if (cmdoptions[p][0].equals("-Xllni")) {
193 llni = true;
194 } else if (cmdoptions[p][0].equals("-llni")) {
195 llni = true;
196 } else if (cmdoptions[p][0].equals("-llniDouble")) {
197 llni = true; doubleAlign = true;
198 } else if (cmdoptions[p][0].equals("-classpath")) {
199 usercp = cmdoptions[p][1];
200 } else if (cmdoptions[p][0].equals("-bootclasspath")) {
201 bootcp = cmdoptions[p][1];
202 } else if((cmdoptions[p][0].charAt(0) == '-')
203 && (!cmdoptions[p][0].equals("-private"))){
204 Util.error("unknown.option", cmdoptions[p][0], null, true);
205 } else {
206 break; /* The rest must be classes. */
207 }
208 }
211 if (Util.verbose) {
212 System.err.println("[ Search Path: "
213 + bootcp
214 + System.getProperty("file.separator")
215 + usercp + " ]");
216 }
217 }
218 }