OSDN Git Service

2006-06-09 Thomas Fitzsimmons <fitzsim@redhat.com>
[pf3gnuchains/gcc-fork.git] / libjava / classpath / tools / gnu / classpath / tools / giop / GRMIC.java
1 /* GRMIC.java -- GIOP support for RMIC.
2    Copyright (C) 2006 Free Software Foundation
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 package gnu.classpath.tools.giop;
23
24 import gnu.classpath.tools.HelpPrinter;
25 import gnu.classpath.tools.giop.grmic.GiopRmicCompiler;
26
27 import java.io.File;
28 import java.io.FileOutputStream;
29 import java.io.IOException;
30 import java.io.OutputStream;
31
32 /**
33  * The main class of the GIOP compiler to generate stubs and ties for 
34  * javax.rmi package.
35  * 
36  * @author Audrius Meskauskas (AudriusA@Bioinformatics.org)  
37  */
38 public class GRMIC
39 {
40   /**
41    * The version of the compiler.
42    */
43   public static String VERSION = "0.0 alpha pre";
44   
45   /**
46    * The GRMIC compiler methods
47    * 
48    * @param args the compiler parameters.
49    */
50   public static void main(String[] args)
51   {
52     boolean noWrite = false;
53     boolean verbose = false;
54
55     String HelpPath = "giop/GRMIC.txt";
56
57     HelpPrinter.checkHelpKey(args, HelpPath);
58
59     File output = new File(".");
60
61     if (args.length == 0)
62       {
63         HelpPrinter.printHelpAndExit(HelpPath);
64       }
65     else
66       {
67         GiopRmicCompiler compiler = new GiopRmicCompiler();
68
69         int cl = - 1;
70
71         Options: for (int i = 0; i < args.length; i++)
72           {
73             String c = args[i];
74             if (c.equals("-poa"))
75               compiler.setPoaMode(true);
76             else if (c.equals("-impl"))
77               compiler.setPoaMode(false);
78             else if (c.equals("-v"))
79               {
80                 printVersion();
81                 System.exit(0);
82               }
83             else if (c.equals("-nowrite"))
84               noWrite = true;
85             else if (c.equals("-nowarn"))
86               compiler.setWarnings(false);
87             else if (c.equals("-verbose"))
88               {
89                 verbose = true;
90                 compiler.setVerbose(true);
91               }
92             else if (c.equals("-force"))
93               {
94                 compiler.setForce(true);
95               }
96             else if (c.equals("-d"))
97               {
98                 int f = i + 1;
99                 if (f < args.length)
100                   {
101                     output = new File(args[f]);
102                     i++;
103                   }
104                 else
105                   HelpPrinter.printHelpAndExit(HelpPath);
106               }
107             else if (c.equals("-classpath"))
108               {
109                 int f = i + 1;
110                 if (f < args.length)
111                   {
112                     compiler.setClassPath(args[f]);
113                     i++;
114                   }
115                 else
116                   HelpPrinter.printHelpAndExit(HelpPath);
117               }
118             else if (c.charAt(0) != '-')
119             // No more options - start of class list.
120               {
121                 cl = i;
122                 break Options;
123               }
124           }
125
126         if (cl < 0)
127           HelpPrinter.printHelpAndExit(HelpPath);
128
129         if (verbose)
130           System.out.println("Compiling to " + output.getAbsolutePath());
131
132         // Compile classes
133         Compile: for (int i = cl; i < args.length; i++)
134           {
135             if (args[i].charAt(0) != '-')
136               {
137                 compiler.reset();
138                 Class c = compiler.loadClass(args[i]);
139
140                 compiler.compile(c);
141                 String packag = compiler.getPackageName().replace('.', '/');
142                 File fw = new File(output, packag);
143
144                 // Generate stub.
145                 String stub = compiler.generateStub();
146                 String subName = "_" + compiler.getStubName() + "_Stub.java";
147
148                 compiler.reset();
149                 compiler.compile(c);
150
151                 // Generate tie
152                 String tie = compiler.generateTie();
153                 String tieName = "_" + compiler.name(c) + "_Tie.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                     out = new FileOutputStream(new File(fw, tieName));
167                     out.write(tie.getBytes());
168                     out.close();
169                   }
170                 catch (IOException ioex)
171                   {
172                     System.err.println("Output path not accessible");
173                     ioex.printStackTrace();
174                     System.exit(1);
175                   }
176               }
177           }
178       }
179   }
180   
181   /**
182    * Print the version information.
183    */
184   public static void printVersion()
185   {
186     System.out.println
187       ("grmic v "+VERSION+" - GIOP stub and tie generator for javax.rmi.* ");
188   }
189 }