Merge with trank @ 137446
[official-gcc.git] / libjava / classpath / tools / gnu / classpath / tools / rmic / Main.java
blob28f4d1931449a0197a8ffc7c78a1d15b2b325663
1 /* Main.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.
22 package gnu.classpath.tools.rmic;
24 import gnu.classpath.tools.common.ClasspathToolParser;
25 import gnu.classpath.tools.getopt.Option;
26 import gnu.classpath.tools.getopt.OptionException;
27 import gnu.classpath.tools.getopt.Parser;
29 import java.util.ArrayList;
31 /**
32 * Generates the ordinary stubs (not GIOP based) for java.rmi.* package.
34 * @author Audrius Meskauskas (AudriusA@Bioinformatics.org)
36 public class Main
38 private boolean noWrite;
39 private boolean warnings = true;
40 private boolean verbose;
41 private boolean force;
42 private String classpath = ".";
43 private String outputDirectory = ".";
44 private boolean poa;
45 private boolean need11Stubs = false;
46 private boolean need12Stubs = true;
47 private boolean keep;
48 private boolean iiop;
49 /**
50 * Specifies whether or not JRMP mode was explicitly requested.
52 private boolean jrmp;
54 private Parser initializeParser()
56 Parser parser = new ClasspathToolParser("rmic", true); //$NON-NLS-1$
57 parser.setHeader(Messages.getString("Main.Usage")); //$NON-NLS-1$
59 parser.add(new Option("nowarn", //$NON-NLS-1$
60 Messages.getString("Main.NoWarn")) //$NON-NLS-1$
62 public void parsed(String argument) throws OptionException
64 warnings = false;
66 });
67 parser.add(new Option("nowrite", //$NON-NLS-1$
68 Messages.getString("Main.NoWrite")) //$NON-NLS-1$
70 public void parsed(String argument) throws OptionException
72 noWrite = true;
74 });
75 parser.add(new Option("verbose", //$NON-NLS-1$
76 Messages.getString("Main.Verbose")) //$NON-NLS-1$
78 public void parsed(String argument) throws OptionException
80 verbose = true;
82 });
83 parser.add(new Option("d", //$NON-NLS-1$
84 Messages.getString("Main.DirOpt"), //$NON-NLS-1$
85 Messages.getString("Main.DirArg")) //$NON-NLS-1$
87 public void parsed(String argument) throws OptionException
89 outputDirectory = argument;
91 });
92 parser.add(new Option("classpath", //$NON-NLS-1$
93 Messages.getString("Main.ClasspathOpt"), //$NON-NLS-1$
94 Messages.getString("Main.ClasspathArg")) //$NON-NLS-1$
96 public void parsed(String argument) throws OptionException
98 classpath = argument;
101 parser.add(new Option("bootclasspath", //$NON-NLS-1$
102 Messages.getString("Main.BootclasspathOpt"), //$NON-NLS-1$
103 Messages.getString("Main.BootclasspathArg")) //$NON-NLS-1$
105 public void parsed(String argument) throws OptionException
109 parser.add(new Option("extdirs", //$NON-NLS-1$
110 Messages.getString("Main.ExtdirsOpt"), //$NON-NLS-1$
111 Messages.getString("Main.ExtdirsArg")) //$NON-NLS-1$
113 public void parsed(String argument) throws OptionException
117 parser.add(new Option("iiop", //$NON-NLS-1$
118 Messages.getString("Main.IIOP")) //$NON-NLS-1$
120 public void parsed(String argument) throws OptionException
122 iiop = true;
125 parser.add(new Option("always", //$NON-NLS-1$
126 Messages.getString("Main.Always")) //$NON-NLS-1$
128 public void parsed(String argument) throws OptionException
130 force = true;
133 parser.add(new Option("alwaysgenerate", //$NON-NLS-1$
134 Messages.getString("Main.AlwaysGenerate")) //$NON-NLS-1$
136 public void parsed(String argument) throws OptionException
138 force = true;
141 parser.add(new Option("nolocalstubs", //$NON-NLS-1$
142 Messages.getString("Main.NoLocalStubs")) //$NON-NLS-1$
144 public void parsed(String argument) throws OptionException
148 parser.add(new Option("poa", //$NON-NLS-1$
149 Messages.getString("Main.POA")) //$NON-NLS-1$
151 public void parsed(String argument) throws OptionException
153 poa = true;
156 parser.add(new Option("keep", //$NON-NLS-1$
157 Messages.getString("Main.Keep")) //$NON-NLS-1$
159 public void parsed(String argument) throws OptionException
161 keep = true;
164 parser.add(new Option("keepgenerated", //$NON-NLS-1$
165 Messages.getString("Main.KeepGenerated")) //$NON-NLS-1$
167 public void parsed(String argument) throws OptionException
169 keep = true;
172 parser.add(new Option("v1.1", //$NON-NLS-1$
173 Messages.getString("Main.v11")) //$NON-NLS-1$
175 public void parsed(String argument) throws OptionException
177 need11Stubs = true;
178 need12Stubs = false;
179 jrmp = true;
182 parser.add(new Option("v1.2", //$NON-NLS-1$
183 Messages.getString("Main.v12")) //$NON-NLS-1$
185 public void parsed(String argument) throws OptionException
187 jrmp = true;
190 parser.add(new Option("vcompat", //$NON-NLS-1$
191 Messages.getString("Main.vcompat")) //$NON-NLS-1$
193 public void parsed(String argument) throws OptionException
195 need11Stubs = true;
196 need12Stubs = true;
197 jrmp = true;
200 parser.add(new Option("g", //$NON-NLS-1$
201 Messages.getString("Main.DebugInfo")) //$NON-NLS-1$
203 public void parsed(String argument) throws OptionException
208 return parser;
211 private void run(String[] args)
213 Parser p = initializeParser();
214 String[] files = p.parse(args);
216 if (files.length == 0)
218 p.printHelp();
219 System.exit(1);
222 ArrayList backends = new ArrayList();
224 // FIXME: need an IDL RmicBackend
225 // FIXME: need a ClassGiopRmicCompiler RmicBackend
226 if (iiop)
228 backends.add(new SourceGiopRmicCompiler());
230 if (jrmp)
232 // Both IIOP and JRMP stubs were requested.
233 backends.add(new ClassRmicCompiler());
234 // FIXME: SourceRmicCompiler should support v1.1
235 if (keep)
236 backends.add(new SourceRmicCompiler());
239 else
241 backends.add(new ClassRmicCompiler());
242 if (keep)
243 backends.add(new SourceRmicCompiler());
246 for (int i = 0; i < backends.size(); i++)
248 RmicBackend b = (RmicBackend) backends.get(i);
249 b.setup(keep, need11Stubs, need12Stubs,
250 iiop, poa, false, warnings,
251 noWrite, verbose, force, classpath,
252 null, null, outputDirectory);
253 if (!b.run(files))
254 System.exit(1);
259 * The RMI compiler entry point.
261 public static void main(String[] args)
263 Main rmicprogram = new Main();
266 rmicprogram.run(args);
268 catch (Exception e)
270 System.err.println(Messages.getString("Main.InternalError")); //$NON-NLS-1$
271 e.printStackTrace(System.err);
272 System.exit(1);