Imported GNU Classpath 0.90
[official-gcc.git] / libjava / classpath / tools / gnu / classpath / tools / rmi / RMIC.java
blobc44453011572e58dfa5b8dc8d9125e358fee17bb
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.
23 package gnu.classpath.tools.rmi;
25 import gnu.classpath.tools.HelpPrinter;
26 import gnu.classpath.tools.giop.GRMIC;
27 import gnu.classpath.tools.rmi.rmic.RmicCompiler;
29 import java.io.File;
30 import java.io.FileOutputStream;
31 import java.io.IOException;
32 import java.io.OutputStream;
34 /**
35 * Generates the ordinary stubs (not GIOP based) for java.rmi.* package.
37 * @author Audrius Meskauskas (AudriusA@Bioinformatics.org)
39 public class RMIC
41 /**
42 * The version of the compiler.
44 public static String VERSION = "0.0 alpha pre";
46 /**
47 * The GRMIC compiler methods
49 * @param args the compiler parameters.
51 public static void main(String[] args)
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++)
57 if (args[i].equals("-giop") || args[i].equals("-iiop"))
59 GRMIC.main(args);
60 return;
64 boolean noWrite = false;
65 boolean verbose = false;
67 String HelpPath = "rmi/RMIC.txt";
69 HelpPrinter.checkHelpKey(args, HelpPath);
71 File output = new File(".");
73 if (args.length == 0)
75 HelpPrinter.printHelpAndExit(HelpPath);
77 else
79 RmicCompiler compiler = new RmicCompiler();
81 int cl = - 1;
83 Options: for (int i = 0; i < args.length; i++)
85 String c = args[i];
86 if (c.equals("-v"))
88 printVersion();
89 System.exit(0);
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"))
97 verbose = true;
98 compiler.setVerbose(true);
100 else if (c.equals("-force"))
102 compiler.setForce(true);
104 else if (c.equals("-d"))
106 int f = i + 1;
107 if (f < args.length)
109 output = new File(args[f]);
110 i++;
112 else
113 HelpPrinter.printHelpAndExit(HelpPath);
115 else if (c.charAt(0) != '-')
116 // No more options - start of class list.
118 cl = i;
119 break Options;
123 if (cl < 0)
124 HelpPrinter.printHelpAndExit(HelpPath);
126 if (verbose)
127 System.out.println("Compiling to " + output.getAbsolutePath());
129 // Compile classes
130 Compile: for (int i = cl; i < args.length; i++)
132 if (args[i].charAt(0) != '-')
134 compiler.reset();
135 Class c = null;
138 c = Thread.currentThread().getContextClassLoader().loadClass(
139 args[i]);
141 catch (ClassNotFoundException e)
143 System.err.println(args[i] + " class not found.");
144 System.exit(1);
147 compiler.compile(c);
148 String packag = compiler.getPackageName().replace('.', '/');
149 File fw = new File(output, packag);
151 // Generate stub.
152 String stub = compiler.generateStub();
153 String subName = compiler.getStubName() + "_Stub.java";
155 if (noWrite)
156 continue Compile;
160 fw.mkdirs();
161 OutputStream out = new FileOutputStream(new File(fw,
162 subName));
163 out.write(stub.getBytes());
164 out.close();
166 catch (IOException ioex)
168 System.err.println("Output path not accessible");
169 ioex.printStackTrace();
170 System.exit(1);
178 * Print the version information.
180 public static void printVersion()
182 System.out.println
183 ("rmic v "+VERSION+" - RMI stub generator for java.rmi.* ");