51 import sun.tools.java.ClassDeclaration;
52 import sun.tools.java.ClassNotFound;
53 import sun.tools.java.Identifier;
54 import sun.tools.java.ClassPath;
55
56 import sun.tools.javac.SourceClass;
57 import sun.tools.util.CommandLine;
58 import java.lang.reflect.Constructor;
59 import java.util.Properties;
60
61 /**
62 * Main "rmic" program.
63 *
64 * WARNING: The contents of this source file are not part of any
65 * supported API. Code that depends on them does so at its own risk:
66 * they are subject to change or removal without notice.
67 */
68 public class Main implements sun.rmi.rmic.Constants {
69 String sourcePathArg;
70 String sysClassPathArg;
71 String extDirsArg;
72 String classPathString;
73 File destDir;
74 int flags;
75 long tm;
76 Vector<String> classes;
77 boolean nowrite;
78 boolean nocompile;
79 boolean keepGenerated;
80 boolean status;
81 String[] generatorArgs;
82 Vector<Generator> generators;
83 Class<? extends BatchEnvironment> environmentClass =
84 BatchEnvironment.class;
85 boolean iiopGeneration = false;
86
87 /**
88 * Name of the program.
89 */
90 String program;
91
170 }
171 }
172 }
173
174 return doCompile();
175 }
176
177 /**
178 * Get the destination directory.
179 */
180 public File getDestinationDir() {
181 return destDir;
182 }
183
184 /**
185 * Parse the arguments for compile.
186 */
187 public boolean parseArgs(String argv[]) {
188 sourcePathArg = null;
189 sysClassPathArg = null;
190 extDirsArg = null;
191
192 classPathString = null;
193 destDir = null;
194 flags = F_WARNINGS;
195 tm = System.currentTimeMillis();
196 classes = new Vector<>();
197 nowrite = false;
198 nocompile = false;
199 keepGenerated = false;
200 generatorArgs = getArray("generator.args",true);
201 if (generatorArgs == null) {
202 return false;
203 }
204 generators = new Vector<>();
205
206 // Pre-process command line for @file arguments
207 try {
208 argv = CommandLine.parse(argv);
209 } catch (FileNotFoundException e) {
210 error("rmic.cant.read", e.getMessage());
283 } else {
284 error("rmic.option.requires.argument", "-sourcepath");
285 usage();
286 return false;
287 }
288 } else if (argv[i].equals("-bootclasspath")) {
289 if ((i + 1) < argv.length) {
290 if (sysClassPathArg != null) {
291 error("rmic.option.already.seen", "-bootclasspath");
292 usage();
293 return false;
294 }
295 argv[i] = null;
296 sysClassPathArg = argv[++i];
297 argv[i] = null;
298 } else {
299 error("rmic.option.requires.argument", "-bootclasspath");
300 usage();
301 return false;
302 }
303 } else if (argv[i].equals("-extdirs")) {
304 if ((i + 1) < argv.length) {
305 if (extDirsArg != null) {
306 error("rmic.option.already.seen", "-extdirs");
307 usage();
308 return false;
309 }
310 argv[i] = null;
311 extDirsArg = argv[++i];
312 argv[i] = null;
313 } else {
314 error("rmic.option.requires.argument", "-extdirs");
315 usage();
316 return false;
317 }
318 } else if (argv[i].equals("-d")) {
319 if ((i + 1) < argv.length) {
320 if (destDir != null) {
321 error("rmic.option.already.seen", "-d");
322 usage();
323 return false;
324 }
325 argv[i] = null;
326 destDir = new File(argv[++i]);
327 argv[i] = null;
328 if (!destDir.exists()) {
329 error("rmic.no.such.directory", destDir.getPath());
330 usage();
331 return false;
332 }
333 } else {
334 error("rmic.option.requires.argument", "-d");
335 usage();
336 return false;
337 }
482 }
483 }
484
485 StringTokenizer parser = new StringTokenizer(value,", \t\n\r", false);
486 int count = parser.countTokens();
487 result = new String[count];
488 for (int i = 0; i < count; i++) {
489 result[i] = parser.nextToken();
490 }
491
492 return result;
493 }
494
495 /**
496 * Get the correct type of BatchEnvironment
497 */
498 public BatchEnvironment getEnv() {
499
500 ClassPath classPath =
501 BatchEnvironment.createClassPath(classPathString,
502 sysClassPathArg,
503 extDirsArg);
504 BatchEnvironment result = null;
505 try {
506 Class<?>[] ctorArgTypes = {OutputStream.class,ClassPath.class,Main.class};
507 Object[] ctorArgs = {out,classPath,this};
508 Constructor<? extends BatchEnvironment> constructor =
509 environmentClass.getConstructor(ctorArgTypes);
510 result = constructor.newInstance(ctorArgs);
511 result.reset();
512 }
513 catch (Exception e) {
514 error("rmic.cannot.instantiate",environmentClass.getName());
515 }
516 return result;
517 }
518
519
520 /**
521 * Do the compile with the switches and files already supplied
522 */
523 public boolean doCompile() {
642 if (!keepGenerated) {
643 env.deleteGeneratedFiles();
644 }
645
646 // We're done
647 if (env.verbose()) {
648 tm = System.currentTimeMillis() - tm;
649 output(getText("rmic.done_in", Long.toString(tm)));
650 }
651
652 // Shutdown the environment object and release our resources.
653 // Note that while this is unneccessary when rmic is invoked
654 // the command line, there are environments in which rmic
655 // from is invoked within a server process, so resource
656 // reclamation is important...
657
658 env.shutdown();
659
660 sourcePathArg = null;
661 sysClassPathArg = null;
662 extDirsArg = null;
663 classPathString = null;
664 destDir = null;
665 classes = null;
666 generatorArgs = null;
667 generators = null;
668 environmentClass = null;
669 program = null;
670 out = null;
671
672 return status;
673 }
674
675 /*
676 * Compile all classes that need to be compiled.
677 */
678 public void compileAllClasses (BatchEnvironment env)
679 throws ClassNotFound,
680 IOException,
681 InterruptedException {
682 ByteArrayOutputStream buf = new ByteArrayOutputStream(4096);
|
51 import sun.tools.java.ClassDeclaration;
52 import sun.tools.java.ClassNotFound;
53 import sun.tools.java.Identifier;
54 import sun.tools.java.ClassPath;
55
56 import sun.tools.javac.SourceClass;
57 import sun.tools.util.CommandLine;
58 import java.lang.reflect.Constructor;
59 import java.util.Properties;
60
61 /**
62 * Main "rmic" program.
63 *
64 * WARNING: The contents of this source file are not part of any
65 * supported API. Code that depends on them does so at its own risk:
66 * they are subject to change or removal without notice.
67 */
68 public class Main implements sun.rmi.rmic.Constants {
69 String sourcePathArg;
70 String sysClassPathArg;
71 String classPathString;
72 File destDir;
73 int flags;
74 long tm;
75 Vector<String> classes;
76 boolean nowrite;
77 boolean nocompile;
78 boolean keepGenerated;
79 boolean status;
80 String[] generatorArgs;
81 Vector<Generator> generators;
82 Class<? extends BatchEnvironment> environmentClass =
83 BatchEnvironment.class;
84 boolean iiopGeneration = false;
85
86 /**
87 * Name of the program.
88 */
89 String program;
90
169 }
170 }
171 }
172
173 return doCompile();
174 }
175
176 /**
177 * Get the destination directory.
178 */
179 public File getDestinationDir() {
180 return destDir;
181 }
182
183 /**
184 * Parse the arguments for compile.
185 */
186 public boolean parseArgs(String argv[]) {
187 sourcePathArg = null;
188 sysClassPathArg = null;
189
190 classPathString = null;
191 destDir = null;
192 flags = F_WARNINGS;
193 tm = System.currentTimeMillis();
194 classes = new Vector<>();
195 nowrite = false;
196 nocompile = false;
197 keepGenerated = false;
198 generatorArgs = getArray("generator.args",true);
199 if (generatorArgs == null) {
200 return false;
201 }
202 generators = new Vector<>();
203
204 // Pre-process command line for @file arguments
205 try {
206 argv = CommandLine.parse(argv);
207 } catch (FileNotFoundException e) {
208 error("rmic.cant.read", e.getMessage());
281 } else {
282 error("rmic.option.requires.argument", "-sourcepath");
283 usage();
284 return false;
285 }
286 } else if (argv[i].equals("-bootclasspath")) {
287 if ((i + 1) < argv.length) {
288 if (sysClassPathArg != null) {
289 error("rmic.option.already.seen", "-bootclasspath");
290 usage();
291 return false;
292 }
293 argv[i] = null;
294 sysClassPathArg = argv[++i];
295 argv[i] = null;
296 } else {
297 error("rmic.option.requires.argument", "-bootclasspath");
298 usage();
299 return false;
300 }
301 } else if (argv[i].equals("-d")) {
302 if ((i + 1) < argv.length) {
303 if (destDir != null) {
304 error("rmic.option.already.seen", "-d");
305 usage();
306 return false;
307 }
308 argv[i] = null;
309 destDir = new File(argv[++i]);
310 argv[i] = null;
311 if (!destDir.exists()) {
312 error("rmic.no.such.directory", destDir.getPath());
313 usage();
314 return false;
315 }
316 } else {
317 error("rmic.option.requires.argument", "-d");
318 usage();
319 return false;
320 }
465 }
466 }
467
468 StringTokenizer parser = new StringTokenizer(value,", \t\n\r", false);
469 int count = parser.countTokens();
470 result = new String[count];
471 for (int i = 0; i < count; i++) {
472 result[i] = parser.nextToken();
473 }
474
475 return result;
476 }
477
478 /**
479 * Get the correct type of BatchEnvironment
480 */
481 public BatchEnvironment getEnv() {
482
483 ClassPath classPath =
484 BatchEnvironment.createClassPath(classPathString,
485 sysClassPathArg);
486 BatchEnvironment result = null;
487 try {
488 Class<?>[] ctorArgTypes = {OutputStream.class,ClassPath.class,Main.class};
489 Object[] ctorArgs = {out,classPath,this};
490 Constructor<? extends BatchEnvironment> constructor =
491 environmentClass.getConstructor(ctorArgTypes);
492 result = constructor.newInstance(ctorArgs);
493 result.reset();
494 }
495 catch (Exception e) {
496 error("rmic.cannot.instantiate",environmentClass.getName());
497 }
498 return result;
499 }
500
501
502 /**
503 * Do the compile with the switches and files already supplied
504 */
505 public boolean doCompile() {
624 if (!keepGenerated) {
625 env.deleteGeneratedFiles();
626 }
627
628 // We're done
629 if (env.verbose()) {
630 tm = System.currentTimeMillis() - tm;
631 output(getText("rmic.done_in", Long.toString(tm)));
632 }
633
634 // Shutdown the environment object and release our resources.
635 // Note that while this is unneccessary when rmic is invoked
636 // the command line, there are environments in which rmic
637 // from is invoked within a server process, so resource
638 // reclamation is important...
639
640 env.shutdown();
641
642 sourcePathArg = null;
643 sysClassPathArg = null;
644 classPathString = null;
645 destDir = null;
646 classes = null;
647 generatorArgs = null;
648 generators = null;
649 environmentClass = null;
650 program = null;
651 out = null;
652
653 return status;
654 }
655
656 /*
657 * Compile all classes that need to be compiled.
658 */
659 public void compileAllClasses (BatchEnvironment env)
660 throws ClassNotFound,
661 IOException,
662 InterruptedException {
663 ByteArrayOutputStream buf = new ByteArrayOutputStream(4096);
|