Source code: gnu/classpath/tools/rmi/RMIC.java
1 /* RMIC.java -- RMI stub generator.
2 Copyright (C) 2006 Free Software Foundation, Inc.
3
4 This file is part of GNU Classpath.
5
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.
10
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.
15
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.
20 */
21
22
23 package gnu.classpath.tools.rmi;
24
25 import gnu.classpath.tools.HelpPrinter;
26 import gnu.classpath.tools.giop.GRMIC;
27 import gnu.classpath.tools.rmi.rmic.RmicCompiler;
28
29 import java.io.File;
30 import java.io.FileOutputStream;
31 import java.io.IOException;
32 import java.io.OutputStream;
33
34 /**
35 * Generates the ordinary stubs (not GIOP based) for java.rmi.* package.
36 *
37 * @author Audrius Meskauskas (AudriusA@Bioinformatics.org)
38 */
39 public class RMIC
40 {
41 /**
42 * The version of the compiler.
43 */
44 public static String VERSION = "0.0 alpha pre";
45
46 /**
47 * The GRMIC compiler methods
48 *
49 * @param args the compiler parameters.
50 */
51 public static void main(String[] args)
52 {
53 // Check for the -iiop or -giop keys. If one of these keys is present,
54 // forward all call to GRMIC.
55 for (int i = 0; i < args.length; i++)
56 {
57 if (args[i].equals("-giop") || args[i].equals("-iiop"))
58 {
59 GRMIC.main(args);
60 return;
61 }
62 }
63
64 boolean noWrite = false;
65 boolean verbose = false;
66
67 String HelpPath = "rmi/RMIC.txt";
68
69 HelpPrinter.checkHelpKey(args, HelpPath);
70
71 File output = new File(".");
72
73 if (args.length == 0)
74 {
75 HelpPrinter.printHelpAndExit(HelpPath);
76 }
77 else
78 {
79 RmicCompiler compiler = new RmicCompiler();
80
81 int cl = - 1;
82
83 Options: for (int i = 0; i < args.length; i++)
84 {
85 String c = args[i];
86 if (c.equals("-v"))
87 {
88 printVersion();
89 System.exit(0);
90 }
91 else if (c.equals("-nowrite"))
92 noWrite = true;
93 else if (c.equals("-nowarn"))
94 compiler.setWarnings(false);
95 else if (c.equals("-verbose"))
96 {
97 verbose = true;
98 compiler.setVerbose(true);
99 }
100 else if (c.equals("-force"))
101 {
102 compiler.setForce(true);
103 }
104 else if (c.equals("-d"))
105 {
106 int f = i + 1;
107 if (f < args.length)
108 {
109 output = new File(args[f]);
110 i++;
111 }
112 else
113 HelpPrinter.printHelpAndExit(HelpPath);
114 }
115 else if (c.charAt(0) != '-')
116 // No more options - start of class list.
117 {
118 cl = i;
119 break Options;
120 }
121 }
122
123 if (cl < 0)
124 HelpPrinter.printHelpAndExit(HelpPath);
125
126 if (verbose)
127 System.out.println("Compiling to " + output.getAbsolutePath());
128
129 // Compile classes
130 Compile: for (int i = cl; i < args.length; i++)
131 {
132 if (args[i].charAt(0) != '-')
133 {
134 compiler.reset();
135 Class c = null;
136 try
137 {
138 c = Thread.currentThread().getContextClassLoader().loadClass(
139 args[i]);
140 }
141 catch (ClassNotFoundException e)
142 {
143 System.err.println(args[i] + " class not found.");
144 System.exit(1);
145 }
146
147 compiler.compile(c);
148 String packag = compiler.getPackageName().replace('.', '/');
149 File fw = new File(output, packag);
150
151 // Generate stub.
152 String stub = compiler.generateStub();
153 String subName = compiler.getStubName() + "_Stub.java";
154
155 if (noWrite)
156 continue Compile;
157
158 try
159 {
160 fw.mkdirs();
161 OutputStream out = new FileOutputStream(new File(fw,
162 subName));
163 out.write(stub.getBytes());
164 out.close();
165 }
166 catch (IOException ioex)
167 {
168 System.err.println("Output path not accessible");
169 ioex.printStackTrace();
170 System.exit(1);
171 }
172 }
173 }
174 }
175 }
176
177 /**
178 * Print the version information.
179 */
180 public static void printVersion()
181 {
182 System.out.println
183 ("rmic v "+VERSION+" - RMI stub generator for java.rmi.* ");
184 }
185 }