Imported GNU Classpath 0.90
[official-gcc.git] / libjava / classpath / tools / gnu / classpath / tools / rmi / RMIC.java
blob09021dd3f942083dd4ec7c0d038d00d68accb2cd
1 /* RMIC.java -- RMI stub generator.
2 Copyright (C) 2006 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 02110-1301 USA.
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
24 combination.
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
39 package gnu.classpath.tools.rmi;
41 import gnu.classpath.tools.HelpPrinter;
42 import gnu.classpath.tools.giop.GRMIC;
43 import gnu.classpath.tools.giop.grmic.GiopRmicCompiler;
44 import gnu.classpath.tools.rmi.rmic.RmicCompiler;
46 import java.io.File;
47 import java.io.FileOutputStream;
48 import java.io.IOException;
49 import java.io.OutputStream;
51 /**
52 * Generates the ordinary stubs (not GIOP based) for java.rmi.* package.
54 * @author Audrius Meskauskas (AudriusA@Bioinformatics.org)
56 public class RMIC
58 /**
59 * The version of the compiler.
61 public static String VERSION = "0.0 alpha pre";
63 /**
64 * The GRMIC compiler methods
66 * @param args the compiler parameters.
68 public static void main(String[] args)
70 // Check for the -iiop or -giop keys. If one of these keys is present,
71 // forward all call to GRMIC.
72 for (int i = 0; i < args.length; i++)
74 if (args[i].equals("-giop") || args[i].equals("-iiop"))
76 GRMIC.main(args);
77 return;
81 boolean noWrite = false;
82 boolean verbose = false;
84 String HelpPath = "rmi/RMIC.txt";
86 HelpPrinter.checkHelpKey(args, HelpPath);
88 File output = new File(".");
90 if (args.length == 0)
92 HelpPrinter.printHelpAndExit(HelpPath);
94 else
96 RmicCompiler compiler = new RmicCompiler();
98 int cl = - 1;
100 Options: for (int i = 0; i < args.length; i++)
102 String c = args[i];
103 if (c.equals("-v"))
105 printVersion();
106 System.exit(0);
108 else if (c.equals("-nowrite"))
109 noWrite = true;
110 else if (c.equals("-nowarn"))
111 compiler.setWarnings(false);
112 else if (c.equals("-verbose"))
114 verbose = true;
115 compiler.setVerbose(true);
117 else if (c.equals("-d"))
119 int f = i + 1;
120 if (f < args.length)
122 output = new File(args[f]);
123 i++;
125 else
126 HelpPrinter.printHelpAndExit(HelpPath);
128 else if (c.charAt(0) != '-')
129 // No more options - start of class list.
131 cl = i;
132 break Options;
136 if (cl < 0)
137 HelpPrinter.printHelpAndExit(HelpPath);
139 if (verbose)
140 System.out.println("Compiling to " + output.getAbsolutePath());
142 // Compile classes
143 Compile: for (int i = cl; i < args.length; i++)
145 if (args[i].charAt(0) != '-')
147 compiler.reset();
148 Class c = null;
151 c = Thread.currentThread().getContextClassLoader().loadClass(
152 args[i]);
154 catch (ClassNotFoundException e)
156 System.err.println(args[i] + " class not found.");
157 System.exit(1);
160 compiler.compile(c);
161 String packag = compiler.getPackageName().replace('.', '/');
162 File fw = new File(output, packag);
164 // Generate stub.
165 String stub = compiler.generateStub();
166 String subName = compiler.getStubName() + "_Stub.java";
168 if (noWrite)
169 continue Compile;
173 fw.mkdirs();
174 OutputStream out = new FileOutputStream(new File(fw,
175 subName));
176 out.write(stub.getBytes());
177 out.close();
179 catch (IOException ioex)
181 System.err.println("Output path not accessible");
182 ioex.printStackTrace();
183 System.exit(1);
191 * Print the version information.
193 public static void printVersion()
195 System.out.println
196 ("rmic v "+VERSION+" - RMI stub generator for java.rmi.* ");