Print this page
Split |
Close |
Expand all |
Collapse all |
--- old/src/share/classes/sun/rmi/rmic/Main.java
+++ new/src/share/classes/sun/rmi/rmic/Main.java
1 1 /*
2 2 * Copyright (c) 1996, 2007, Oracle and/or its affiliates. All rights reserved.
3 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 4 *
5 5 * This code is free software; you can redistribute it and/or modify it
6 6 * under the terms of the GNU General Public License version 2 only, as
7 7 * published by the Free Software Foundation. Oracle designates this
8 8 * particular file as subject to the "Classpath" exception as provided
9 9 * by Oracle in the LICENSE file that accompanied this code.
10 10 *
11 11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 14 * version 2 for more details (a copy is included in the LICENSE file that
15 15 * accompanied this code).
16 16 *
17 17 * You should have received a copy of the GNU General Public License version
18 18 * 2 along with this work; if not, write to the Free Software Foundation,
19 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 20 *
21 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 22 * or visit www.oracle.com if you need additional information or have any
23 23 * questions.
24 24 */
25 25
26 26 /*
27 27 * Licensed Materials - Property of IBM
28 28 * RMI-IIOP v1.0
29 29 * Copyright IBM Corp. 1998 1999 All Rights Reserved
30 30 *
31 31 */
32 32
33 33 package sun.rmi.rmic;
34 34
35 35 import java.util.Vector;
36 36 import java.util.Enumeration;
37 37 import java.util.ResourceBundle;
38 38 import java.util.StringTokenizer;
39 39 import java.util.MissingResourceException;
40 40
41 41 import java.io.OutputStream;
42 42 import java.io.PrintStream;
43 43 import java.io.IOException;
44 44 import java.io.File;
45 45 import java.io.FileNotFoundException;
46 46 import java.io.FileOutputStream;
47 47 import java.io.ByteArrayOutputStream;
48 48
49 49 import sun.tools.java.ClassFile;
50 50 import sun.tools.java.ClassDefinition;
51 51 import sun.tools.java.ClassDeclaration;
52 52 import sun.tools.java.ClassNotFound;
53 53 import sun.tools.java.Identifier;
54 54 import sun.tools.java.ClassPath;
55 55
56 56 import sun.tools.javac.SourceClass;
57 57 import sun.tools.util.CommandLine;
58 58 import java.lang.reflect.Constructor;
59 59 import java.util.Properties;
60 60
61 61 /**
62 62 * Main "rmic" program.
63 63 *
64 64 * WARNING: The contents of this source file are not part of any
65 65 * supported API. Code that depends on them does so at its own risk:
↓ open down ↓ |
65 lines elided |
↑ open up ↑ |
66 66 * they are subject to change or removal without notice.
67 67 */
68 68 public class Main implements sun.rmi.rmic.Constants {
69 69 String sourcePathArg;
70 70 String sysClassPathArg;
71 71 String extDirsArg;
72 72 String classPathString;
73 73 File destDir;
74 74 int flags;
75 75 long tm;
76 - Vector classes;
76 + Vector<String> classes;
77 77 boolean nowrite;
78 78 boolean nocompile;
79 79 boolean keepGenerated;
80 80 boolean status;
81 81 String[] generatorArgs;
82 - Vector generators;
83 - Class environmentClass = BatchEnvironment.class;
82 + Vector<Generator> generators;
83 + Class<?> environmentClass = BatchEnvironment.class;
84 84 boolean iiopGeneration = false;
85 85
86 86 /**
87 87 * Name of the program.
88 88 */
89 89 String program;
90 90
91 91 /**
92 92 * The stream where error message are printed.
93 93 */
94 94 OutputStream out;
95 95
96 96 /**
97 97 * Constructor.
98 98 */
99 99 public Main(OutputStream out, String program) {
100 100 this.out = out;
101 101 this.program = program;
102 102 }
103 103
104 104 /**
105 105 * Output a message.
106 106 */
107 107 public void output(String msg) {
108 108 PrintStream out =
109 109 this.out instanceof PrintStream ? (PrintStream)this.out
110 110 : new PrintStream(this.out, true);
111 111 out.println(msg);
112 112 }
113 113
114 114 /**
115 115 * Top level error message. This method is called when the
116 116 * environment could not be set up yet.
117 117 */
118 118 public void error(String msg) {
119 119 output(getText(msg));
120 120 }
121 121
122 122 public void error(String msg, String arg1) {
123 123 output(getText(msg, arg1));
124 124 }
125 125
126 126 public void error(String msg, String arg1, String arg2) {
127 127 output(getText(msg, arg1, arg2));
128 128 }
129 129
130 130 /**
131 131 * Usage
132 132 */
133 133 public void usage() {
134 134 error("rmic.usage", program);
135 135 }
136 136
137 137 /**
138 138 * Run the compiler
139 139 */
140 140 public synchronized boolean compile(String argv[]) {
141 141
142 142 /*
143 143 * Handle internal option to use the new (and incomplete) rmic
144 144 * implementation. This option is handled here, rather than
145 145 * in parseArgs, so that none of the arguments will be nulled
146 146 * before delegating to the new implementation.
147 147 */
148 148 for (int i = 0; i < argv.length; i++) {
149 149 if (argv[i].equals("-Xnew")) {
150 150 return (new sun.rmi.rmic.newrmic.Main(out,
151 151 program)).compile(argv);
152 152 }
153 153 }
154 154
155 155 if (!parseArgs(argv)) {
156 156 return false;
157 157 }
158 158
159 159 if (classes.size() == 0) {
160 160 usage();
161 161 return false;
162 162 }
163 163
164 164 return doCompile();
165 165 }
166 166
167 167 /**
168 168 * Get the destination directory.
169 169 */
170 170 public File getDestinationDir() {
171 171 return destDir;
172 172 }
173 173
174 174 /**
175 175 * Parse the arguments for compile.
↓ open down ↓ |
82 lines elided |
↑ open up ↑ |
176 176 */
177 177 public boolean parseArgs(String argv[]) {
178 178 sourcePathArg = null;
179 179 sysClassPathArg = null;
180 180 extDirsArg = null;
181 181
182 182 classPathString = null;
183 183 destDir = null;
184 184 flags = F_WARNINGS;
185 185 tm = System.currentTimeMillis();
186 - classes = new Vector();
186 + classes = new Vector<String>();
187 187 nowrite = false;
188 188 nocompile = false;
189 189 keepGenerated = false;
190 190 generatorArgs = getArray("generator.args",true);
191 191 if (generatorArgs == null) {
192 192 return false;
193 193 }
194 - generators = new Vector();
194 + generators = new Vector<Generator>();
195 195
196 196 // Pre-process command line for @file arguments
197 197 try {
198 198 argv = CommandLine.parse(argv);
199 199 } catch (FileNotFoundException e) {
200 200 error("rmic.cant.read", e.getMessage());
201 201 return false;
202 202 } catch (IOException e) {
203 203 e.printStackTrace(out instanceof PrintStream ?
204 204 (PrintStream) out :
205 205 new PrintStream(out, true));
206 206 return false;
207 207 }
208 208
209 209 // Parse arguments
210 210 for (int i = 0 ; i < argv.length ; i++) {
211 211 if (argv[i] != null) {
212 212 if (argv[i].equals("-g")) {
213 213 flags &= ~F_OPT;
214 214 flags |= F_DEBUG_LINES | F_DEBUG_VARS;
215 215 argv[i] = null;
216 216 } else if (argv[i].equals("-O")) {
217 217 flags &= ~F_DEBUG_LINES;
218 218 flags &= ~F_DEBUG_VARS;
219 219 flags |= F_OPT | F_DEPENDENCIES;
220 220 argv[i] = null;
221 221 } else if (argv[i].equals("-nowarn")) {
222 222 flags &= ~F_WARNINGS;
223 223 argv[i] = null;
224 224 } else if (argv[i].equals("-debug")) {
225 225 flags |= F_DUMP;
226 226 argv[i] = null;
227 227 } else if (argv[i].equals("-depend")) {
228 228 flags |= F_DEPENDENCIES;
229 229 argv[i] = null;
230 230 } else if (argv[i].equals("-verbose")) {
231 231 flags |= F_VERBOSE;
232 232 argv[i] = null;
233 233 } else if (argv[i].equals("-nowrite")) {
234 234 nowrite = true;
235 235 argv[i] = null;
236 236 } else if (argv[i].equals("-Xnocompile")) {
237 237 nocompile = true;
238 238 keepGenerated = true;
239 239 argv[i] = null;
240 240 } else if (argv[i].equals("-keep") ||
241 241 argv[i].equals("-keepgenerated")) {
242 242 keepGenerated = true;
243 243 argv[i] = null;
244 244 } else if (argv[i].equals("-show")) {
245 245 error("rmic.option.unsupported", "-show");
246 246 usage();
247 247 return false;
248 248 } else if (argv[i].equals("-classpath")) {
249 249 if ((i + 1) < argv.length) {
250 250 if (classPathString != null) {
251 251 error("rmic.option.already.seen", "-classpath");
252 252 usage();
253 253 return false;
254 254 }
255 255 argv[i] = null;
256 256 classPathString = argv[++i];
257 257 argv[i] = null;
258 258 } else {
259 259 error("rmic.option.requires.argument", "-classpath");
260 260 usage();
261 261 return false;
262 262 }
263 263 } else if (argv[i].equals("-sourcepath")) {
264 264 if ((i + 1) < argv.length) {
265 265 if (sourcePathArg != null) {
266 266 error("rmic.option.already.seen", "-sourcepath");
267 267 usage();
268 268 return false;
269 269 }
270 270 argv[i] = null;
271 271 sourcePathArg = argv[++i];
272 272 argv[i] = null;
273 273 } else {
274 274 error("rmic.option.requires.argument", "-sourcepath");
275 275 usage();
276 276 return false;
277 277 }
278 278 } else if (argv[i].equals("-bootclasspath")) {
279 279 if ((i + 1) < argv.length) {
280 280 if (sysClassPathArg != null) {
281 281 error("rmic.option.already.seen", "-bootclasspath");
282 282 usage();
283 283 return false;
284 284 }
285 285 argv[i] = null;
286 286 sysClassPathArg = argv[++i];
287 287 argv[i] = null;
288 288 } else {
289 289 error("rmic.option.requires.argument", "-bootclasspath");
290 290 usage();
291 291 return false;
292 292 }
293 293 } else if (argv[i].equals("-extdirs")) {
294 294 if ((i + 1) < argv.length) {
295 295 if (extDirsArg != null) {
296 296 error("rmic.option.already.seen", "-extdirs");
297 297 usage();
298 298 return false;
299 299 }
300 300 argv[i] = null;
301 301 extDirsArg = argv[++i];
302 302 argv[i] = null;
303 303 } else {
304 304 error("rmic.option.requires.argument", "-extdirs");
305 305 usage();
306 306 return false;
307 307 }
308 308 } else if (argv[i].equals("-d")) {
309 309 if ((i + 1) < argv.length) {
310 310 if (destDir != null) {
311 311 error("rmic.option.already.seen", "-d");
312 312 usage();
313 313 return false;
314 314 }
315 315 argv[i] = null;
316 316 destDir = new File(argv[++i]);
317 317 argv[i] = null;
318 318 if (!destDir.exists()) {
319 319 error("rmic.no.such.directory", destDir.getPath());
320 320 usage();
321 321 return false;
322 322 }
323 323 } else {
324 324 error("rmic.option.requires.argument", "-d");
325 325 usage();
326 326 return false;
327 327 }
328 328 } else {
329 329 if (!checkGeneratorArg(argv,i)) {
330 330 usage();
331 331 return false;
332 332 }
333 333 }
334 334 }
335 335 }
336 336
337 337
338 338 // Now that all generators have had a chance at the args,
339 339 // scan what's left for classes and illegal args...
340 340
341 341 for (int i = 0; i < argv.length; i++) {
342 342 if (argv[i] != null) {
343 343 if (argv[i].startsWith("-")) {
344 344 error("rmic.no.such.option", argv[i]);
345 345 usage();
346 346 return false;
347 347 } else {
348 348 classes.addElement(argv[i]);
349 349 }
350 350 }
351 351 }
352 352
353 353
354 354 // If the generators vector is empty, add the default generator...
355 355
356 356 if (generators.size() == 0) {
357 357 addGenerator("default");
358 358 }
359 359
360 360 return true;
361 361 }
362 362
363 363 /**
364 364 * If this argument is for a generator, instantiate it, call
365 365 * parseArgs(...) and add generator to generators vector.
366 366 * Returns false on error.
367 367 */
368 368 protected boolean checkGeneratorArg(String[] argv, int currentIndex) {
369 369 boolean result = true;
370 370 if (argv[currentIndex].startsWith("-")) {
371 371 String arg = argv[currentIndex].substring(1).toLowerCase(); // Remove '-'
372 372 for (int i = 0; i < generatorArgs.length; i++) {
373 373 if (arg.equalsIgnoreCase(generatorArgs[i])) {
374 374 // Got a match, add Generator and call parseArgs...
375 375 Generator gen = addGenerator(arg);
376 376 if (gen == null) {
377 377 return false;
378 378 }
379 379 result = gen.parseArgs(argv,this);
380 380 break;
381 381 }
382 382 }
383 383 }
384 384 return result;
385 385 }
386 386
387 387 /**
388 388 * Instantiate and add a generator to the generators array.
389 389 */
390 390 protected Generator addGenerator(String arg) {
391 391
392 392 Generator gen;
393 393
394 394 // Create an instance of the generator and add it to
395 395 // the array...
396 396
397 397 String className = getString("generator.class." + arg);
398 398 if (className == null) {
399 399 error("rmic.missing.property",arg);
400 400 return null;
401 401 }
402 402
403 403 try {
↓ open down ↓ |
199 lines elided |
↑ open up ↑ |
404 404 gen = (Generator) Class.forName(className).newInstance();
405 405 } catch (Exception e) {
406 406 error("rmic.cannot.instantiate",className);
407 407 return null;
408 408 }
409 409
410 410 generators.addElement(gen);
411 411
412 412 // Get the environment required by this generator...
413 413
414 - Class envClass = BatchEnvironment.class;
414 + Class<?> envClass = BatchEnvironment.class;
415 415 String env = getString("generator.env." + arg);
416 416 if (env != null) {
417 417 try {
418 418 envClass = Class.forName(env);
419 419
420 420 // Is the new class a subclass of the current one?
421 421
422 422 if (environmentClass.isAssignableFrom(envClass)) {
423 423
424 424 // Yes, so switch to the new one...
425 425
426 426 environmentClass = envClass;
427 427
428 428 } else {
429 429
430 430 // No. Is the current class a subclass of the
431 431 // new one?
432 432
433 433 if (!envClass.isAssignableFrom(environmentClass)) {
434 434
435 435 // No, so it's a conflict...
436 436
437 437 error("rmic.cannot.use.both",environmentClass.getName(),envClass.getName());
438 438 return null;
439 439 }
440 440 }
441 441 } catch (ClassNotFoundException e) {
442 442 error("rmic.class.not.found",env);
443 443 return null;
444 444 }
445 445 }
446 446
447 447 // If this is the iiop stub generator, cache
448 448 // that fact for the jrmp generator...
449 449
450 450 if (arg.equals("iiop")) {
451 451 iiopGeneration = true;
452 452 }
453 453 return gen;
454 454 }
455 455
456 456 /**
457 457 * Grab a resource string and parse it into an array of strings. Assumes
458 458 * comma separated list.
459 459 * @param name The resource name.
460 460 * @param mustExist If true, throws error if resource does not exist. If
461 461 * false and resource does not exist, returns zero element array.
462 462 */
463 463 protected String[] getArray(String name, boolean mustExist) {
464 464 String[] result = null;
465 465 String value = getString(name);
466 466 if (value == null) {
467 467 if (mustExist) {
468 468 error("rmic.resource.not.found",name);
469 469 return null;
470 470 } else {
471 471 return new String[0];
472 472 }
473 473 }
474 474
475 475 StringTokenizer parser = new StringTokenizer(value,", \t\n\r", false);
476 476 int count = parser.countTokens();
477 477 result = new String[count];
478 478 for (int i = 0; i < count; i++) {
479 479 result[i] = parser.nextToken();
480 480 }
481 481
482 482 return result;
483 483 }
484 484
485 485 /**
486 486 * Get the correct type of BatchEnvironment
487 487 */
↓ open down ↓ |
63 lines elided |
↑ open up ↑ |
488 488 public BatchEnvironment getEnv() {
489 489
490 490 ClassPath classPath =
491 491 BatchEnvironment.createClassPath(classPathString,
492 492 sysClassPathArg,
493 493 extDirsArg);
494 494 BatchEnvironment result = null;
495 495 try {
496 496 Class[] ctorArgTypes = {OutputStream.class,ClassPath.class,Main.class};
497 497 Object[] ctorArgs = {out,classPath,this};
498 - Constructor constructor = environmentClass.getConstructor(ctorArgTypes);
498 + Constructor<?> constructor = environmentClass.getConstructor(ctorArgTypes);
499 499 result = (BatchEnvironment) constructor.newInstance(ctorArgs);
500 500 result.reset();
501 501 }
502 502 catch (Exception e) {
503 503 error("rmic.cannot.instantiate",environmentClass.getName());
504 504 }
505 505 return result;
506 506 }
507 507
508 508
509 509 /**
510 510 * Do the compile with the switches and files already supplied
511 511 */
512 512 public boolean doCompile() {
513 513 // Create batch environment
514 514 BatchEnvironment env = getEnv();
515 515 env.flags |= flags;
516 516
517 517 // Set the classfile version numbers
518 518 // Compat and 1.1 stubs must retain the old version number.
519 519 env.majorVersion = 45;
520 520 env.minorVersion = 3;
521 521
522 522 // Preload the "out of memory" error string just in case we run
↓ open down ↓ |
14 lines elided |
↑ open up ↑ |
523 523 // out of memory during the compile.
524 524 String noMemoryErrorString = getText("rmic.no.memory");
525 525 String stackOverflowErrorString = getText("rmic.stack.overflow");
526 526
527 527 try {
528 528 /** Load the classes on the command line
529 529 * Replace the entries in classes with the ClassDefinition for the class
530 530 */
531 531 for (int i = classes.size()-1; i >= 0; i-- ) {
532 532 Identifier implClassName =
533 - Identifier.lookup((String)classes.elementAt(i));
533 + Identifier.lookup(classes.elementAt(i));
534 534
535 535 /*
536 536 * Fix bugid 4049354: support using '.' as an inner class
537 537 * qualifier on the command line (previously, only mangled
538 538 * inner class names were understood, like "pkg.Outer$Inner").
539 539 *
540 540 * The following method, also used by "javap", resolves the
541 541 * given unmangled inner class name to the appropriate
542 542 * internal identifier. For example, it translates
543 543 * "pkg.Outer.Inner" to "pkg.Outer. Inner".
544 544 */
545 545 implClassName = env.resolvePackageQualifiedName(implClassName);
546 546 /*
547 547 * But if we use such an internal inner class name identifier
548 548 * to load the class definition, the Java compiler will notice
549 549 * if the impl class is a "private" inner class and then deny
550 550 * skeletons (needed unless "-v1.2" is used) the ability to
↓ open down ↓ |
7 lines elided |
↑ open up ↑ |
551 551 * cast to it. To work around this problem, we mangle inner
552 552 * class name identifiers to their binary "outer" class name:
553 553 * "pkg.Outer. Inner" becomes "pkg.Outer$Inner".
554 554 */
555 555 implClassName = Names.mangleClass(implClassName);
556 556
557 557 ClassDeclaration decl = env.getClassDeclaration(implClassName);
558 558 try {
559 559 ClassDefinition def = decl.getClassDefinition(env);
560 560 for (int j = 0; j < generators.size(); j++) {
561 - Generator gen = (Generator)generators.elementAt(j);
561 + Generator gen = generators.elementAt(j);
562 562 gen.generate(env, def, destDir);
563 563 }
564 564 } catch (ClassNotFound ex) {
565 565 env.error(0, "rmic.class.not.found", implClassName);
566 566 }
567 567
568 568 }
569 569
570 570 // compile all classes that need compilation
571 571 if (!nocompile) {
572 572 compileAllClasses(env);
573 573 }
574 574 } catch (OutOfMemoryError ee) {
575 575 // The compiler has run out of memory. Use the error string
576 576 // which we preloaded.
577 577 env.output(noMemoryErrorString);
578 578 return false;
579 579 } catch (StackOverflowError ee) {
580 580 env.output(stackOverflowErrorString);
581 581 return false;
582 582 } catch (Error ee) {
583 583 // We allow the compiler to take an exception silently if a program
584 584 // error has previously been detected. Presumably, this makes the
585 585 // compiler more robust in the face of bad error recovery.
586 586 if (env.nerrors == 0 || env.dump()) {
587 587 env.error(0, "fatal.error");
588 588 ee.printStackTrace(out instanceof PrintStream ?
589 589 (PrintStream) out :
590 590 new PrintStream(out, true));
591 591 }
592 592 } catch (Exception ee) {
593 593 if (env.nerrors == 0 || env.dump()) {
594 594 env.error(0, "fatal.exception");
595 595 ee.printStackTrace(out instanceof PrintStream ?
596 596 (PrintStream) out :
597 597 new PrintStream(out, true));
598 598 }
599 599 }
600 600
601 601 env.flushErrors();
602 602
603 603 boolean status = true;
604 604 if (env.nerrors > 0) {
605 605 String msg = "";
606 606 if (env.nerrors > 1) {
607 607 msg = getText("rmic.errors", env.nerrors);
608 608 } else {
609 609 msg = getText("rmic.1error");
610 610 }
611 611 if (env.nwarnings > 0) {
612 612 if (env.nwarnings > 1) {
613 613 msg += ", " + getText("rmic.warnings", env.nwarnings);
614 614 } else {
615 615 msg += ", " + getText("rmic.1warning");
616 616 }
617 617 }
618 618 output(msg);
619 619 status = false;
620 620 } else {
621 621 if (env.nwarnings > 0) {
622 622 if (env.nwarnings > 1) {
623 623 output(getText("rmic.warnings", env.nwarnings));
624 624 } else {
625 625 output(getText("rmic.1warning"));
626 626 }
627 627 }
628 628 }
629 629
630 630 // last step is to delete generated source files
631 631 if (!keepGenerated) {
632 632 env.deleteGeneratedFiles();
633 633 }
634 634
635 635 // We're done
636 636 if (env.verbose()) {
637 637 tm = System.currentTimeMillis() - tm;
638 638 output(getText("rmic.done_in", Long.toString(tm)));
639 639 }
640 640
641 641 // Shutdown the environment object and release our resources.
642 642 // Note that while this is unneccessary when rmic is invoked
643 643 // the command line, there are environments in which rmic
644 644 // from is invoked within a server process, so resource
645 645 // reclamation is important...
646 646
647 647 env.shutdown();
648 648
649 649 sourcePathArg = null;
650 650 sysClassPathArg = null;
651 651 extDirsArg = null;
652 652 classPathString = null;
653 653 destDir = null;
654 654 classes = null;
655 655 generatorArgs = null;
656 656 generators = null;
657 657 environmentClass = null;
658 658 program = null;
659 659 out = null;
660 660
661 661 return status;
662 662 }
663 663
664 664 /*
665 665 * Compile all classes that need to be compiled.
↓ open down ↓ |
94 lines elided |
↑ open up ↑ |
666 666 */
667 667 public void compileAllClasses (BatchEnvironment env)
668 668 throws ClassNotFound,
669 669 IOException,
670 670 InterruptedException {
671 671 ByteArrayOutputStream buf = new ByteArrayOutputStream(4096);
672 672 boolean done;
673 673
674 674 do {
675 675 done = true;
676 - for (Enumeration e = env.getClasses() ; e.hasMoreElements() ; ) {
676 + for (Enumeration<?> e = env.getClasses() ; e.hasMoreElements() ; ) {
677 677 ClassDeclaration c = (ClassDeclaration)e.nextElement();
678 678 done = compileClass(c,buf,env);
679 679 }
680 680 } while (!done);
681 681 }
682 682
683 683 /*
684 684 * Compile a single class.
685 + * Fallthrough is intentional
685 686 */
687 + @SuppressWarnings("fallthrough")
686 688 public boolean compileClass (ClassDeclaration c,
687 689 ByteArrayOutputStream buf,
688 690 BatchEnvironment env)
689 691 throws ClassNotFound,
690 692 IOException,
691 693 InterruptedException {
692 694 boolean done = true;
693 695 env.flushErrors();
694 696 SourceClass src;
695 697
696 698 switch (c.getStatus()) {
697 699 case CS_UNDEFINED:
698 700 {
699 701 if (!env.dependencies()) {
700 702 break;
701 703 }
702 704 // fall through
703 705 }
704 706
705 707 case CS_SOURCE:
706 708 {
707 709 done = false;
708 710 env.loadDefinition(c);
709 711 if (c.getStatus() != CS_PARSED) {
710 712 break;
711 713 }
712 714 // fall through
713 715 }
714 716
715 717 case CS_PARSED:
716 718 {
717 719 if (c.getClassDefinition().isInsideLocal()) {
718 720 break;
719 721 }
720 722 // If we get to here, then compilation is going
721 723 // to occur. If the -Xnocompile switch is set
722 724 // then fail. Note that this check is required
723 725 // here because this method is called from
724 726 // generators, not just from within this class...
725 727
726 728 if (nocompile) {
727 729 throw new IOException("Compilation required, but -Xnocompile option in effect");
728 730 }
729 731
730 732 done = false;
731 733
732 734 src = (SourceClass)c.getClassDefinition(env);
733 735 src.check(env);
734 736 c.setDefinition(src, CS_CHECKED);
735 737 // fall through
736 738 }
737 739
738 740 case CS_CHECKED:
739 741 {
740 742 src = (SourceClass)c.getClassDefinition(env);
741 743 // bail out if there were any errors
742 744 if (src.getError()) {
743 745 c.setDefinition(src, CS_COMPILED);
744 746 break;
745 747 }
746 748 done = false;
747 749 buf.reset();
748 750 src.compile(buf);
749 751 c.setDefinition(src, CS_COMPILED);
750 752 src.cleanup(env);
751 753
752 754 if (src.getError() || nowrite) {
753 755 break;
754 756 }
755 757
756 758 String pkgName = c.getName().getQualifier().toString().replace('.', File.separatorChar);
757 759 String className = c.getName().getFlatName().toString().replace('.', SIGC_INNERCLASS) + ".class";
758 760
759 761 File file;
760 762 if (destDir != null) {
761 763 if (pkgName.length() > 0) {
762 764 file = new File(destDir, pkgName);
763 765 if (!file.exists()) {
764 766 file.mkdirs();
765 767 }
766 768 file = new File(file, className);
767 769 } else {
768 770 file = new File(destDir, className);
769 771 }
770 772 } else {
771 773 ClassFile classfile = (ClassFile)src.getSource();
772 774 if (classfile.isZipped()) {
773 775 env.error(0, "cant.write", classfile.getPath());
774 776 break;
775 777 }
776 778 file = new File(classfile.getPath());
777 779 file = new File(file.getParent(), className);
778 780 }
779 781
780 782 // Create the file
781 783 try {
782 784 FileOutputStream out = new FileOutputStream(file.getPath());
783 785 buf.writeTo(out);
784 786 out.close();
785 787 if (env.verbose()) {
786 788 output(getText("rmic.wrote", file.getPath()));
787 789 }
788 790 } catch (IOException ee) {
789 791 env.error(0, "cant.write", file.getPath());
790 792 }
791 793 }
792 794 }
793 795 return done;
794 796 }
795 797
796 798 /**
797 799 * Main program
798 800 */
799 801 public static void main(String argv[]) {
800 802 Main compiler = new Main(System.out, "rmic");
801 803 System.exit(compiler.compile(argv) ? 0 : 1);
802 804 }
803 805
804 806 /**
805 807 * Return the string value of a named resource in the rmic.properties
806 808 * resource bundle. If the resource is not found, null is returned.
807 809 */
808 810 public static String getString(String key) {
809 811 if (!resourcesInitialized) {
810 812 initResources();
811 813 }
812 814
813 815 // To enable extensions, search the 'resourcesExt'
814 816 // bundle first, followed by the 'resources' bundle...
815 817
816 818 if (resourcesExt != null) {
817 819 try {
818 820 return resourcesExt.getString(key);
819 821 } catch (MissingResourceException e) {}
820 822 }
821 823
822 824 try {
823 825 return resources.getString(key);
824 826 } catch (MissingResourceException ignore) {
825 827 }
826 828 return null;
827 829 }
828 830
829 831 private static boolean resourcesInitialized = false;
830 832 private static ResourceBundle resources;
831 833 private static ResourceBundle resourcesExt = null;
832 834
833 835 private static void initResources() {
834 836 try {
835 837 resources =
836 838 ResourceBundle.getBundle("sun.rmi.rmic.resources.rmic");
837 839 resourcesInitialized = true;
838 840 try {
839 841 resourcesExt =
840 842 ResourceBundle.getBundle("sun.rmi.rmic.resources.rmicext");
841 843 } catch (MissingResourceException e) {}
842 844 } catch (MissingResourceException e) {
843 845 throw new Error("fatal: missing resource bundle: " +
844 846 e.getClassName());
845 847 }
846 848 }
847 849
848 850 public static String getText(String key) {
849 851 String message = getString(key);
850 852 if (message == null) {
851 853 message = "no text found: \"" + key + "\"";
852 854 }
853 855 return message;
854 856 }
855 857
856 858 public static String getText(String key, int num) {
857 859 return getText(key, Integer.toString(num), null, null);
858 860 }
859 861
860 862 public static String getText(String key, String arg0) {
861 863 return getText(key, arg0, null, null);
862 864 }
863 865
864 866 public static String getText(String key, String arg0, String arg1) {
865 867 return getText(key, arg0, arg1, null);
866 868 }
867 869
868 870 public static String getText(String key,
869 871 String arg0, String arg1, String arg2)
870 872 {
871 873 String format = getString(key);
↓ open down ↓ |
176 lines elided |
↑ open up ↑ |
872 874 if (format == null) {
873 875 format = "no text found: key = \"" + key + "\", " +
874 876 "arguments = \"{0}\", \"{1}\", \"{2}\"";
875 877 }
876 878
877 879 String[] args = new String[3];
878 880 args[0] = (arg0 != null ? arg0.toString() : "null");
879 881 args[1] = (arg1 != null ? arg1.toString() : "null");
880 882 args[2] = (arg2 != null ? arg2.toString() : "null");
881 883
882 - return java.text.MessageFormat.format(format, args);
884 + return java.text.MessageFormat.format(format, (Object[]) args);
883 885 }
884 886 }
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX