1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
package com.sun.tools.javafx.main; |
27 | |
|
28 | |
import com.sun.tools.javac.util.Options; |
29 | |
import java.io.File; |
30 | |
import java.io.FilenameFilter; |
31 | |
import java.io.Reader; |
32 | |
import java.io.InputStream; |
33 | |
import java.io.InputStreamReader; |
34 | |
import java.io.IOException; |
35 | |
import java.io.PrintWriter; |
36 | |
import java.net.URL; |
37 | |
import java.net.URLClassLoader; |
38 | |
import java.util.ResourceBundle; |
39 | |
import java.util.MissingResourceException; |
40 | |
import com.sun.tools.javac.code.Source; |
41 | |
import com.sun.tools.javac.jvm.Target; |
42 | |
import com.sun.tools.javac.jvm.ClassReader; |
43 | |
import com.sun.tools.javafx.main.JavafxOption.Option; |
44 | |
import com.sun.tools.javac.util.*; |
45 | |
import com.sun.tools.javafx.main.RecognizedOptions.OptionHelper; |
46 | |
import com.sun.tools.javafx.util.JavafxFileManager; |
47 | |
import com.sun.tools.javafx.util.PlatformPlugin; |
48 | |
import com.sun.tools.javafx.util.MsgSym; |
49 | |
import javax.tools.Diagnostic; |
50 | |
import javax.tools.JavaFileManager; |
51 | |
import javax.tools.JavaFileObject; |
52 | |
import javax.tools.DiagnosticListener; |
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
public class Main { |
62 | |
|
63 | |
|
64 | |
|
65 | |
String ownName; |
66 | |
|
67 | |
|
68 | |
|
69 | |
PrintWriter out; |
70 | |
|
71 | |
|
72 | |
|
73 | |
|
74 | |
boolean fatalErrors; |
75 | |
|
76 | |
|
77 | |
|
78 | |
static final int |
79 | |
EXIT_OK = 0, |
80 | |
EXIT_ERROR = 1, |
81 | |
EXIT_CMDERR = 2, |
82 | |
EXIT_SYSERR = 3, |
83 | |
EXIT_ABNORMAL = 4; |
84 | |
|
85 | 459 | private Option[] recognizedOptions = RecognizedOptions.getJavaCompilerOptions(new OptionHelper() { |
86 | |
|
87 | |
public void setOut(PrintWriter out) { |
88 | 0 | Main.this.out = out; |
89 | 0 | } |
90 | |
|
91 | |
public void error(String key, Object... args) { |
92 | 0 | Main.this.error(key, args); |
93 | 0 | } |
94 | |
|
95 | |
public void printVersion() { |
96 | 0 | Log.printLines(out, getLocalizedString(MsgSym.MESSAGE_VERSION, ownName, JavafxCompiler.version())); |
97 | 0 | } |
98 | |
|
99 | |
public void printFullVersion() { |
100 | 0 | Log.printLines(out, getLocalizedString(MsgSym.MESSAGE_FULLVERSION, ownName, JavafxCompiler.fullVersion())); |
101 | 0 | } |
102 | |
|
103 | |
public void printHelp() { |
104 | 0 | help(); |
105 | 0 | } |
106 | |
|
107 | |
public void printXhelp() { |
108 | 0 | xhelp(); |
109 | 0 | } |
110 | |
|
111 | |
public void addFile(File f) { |
112 | 365 | if (!filenames.contains(f)) |
113 | 363 | filenames.append(f); |
114 | 365 | } |
115 | |
|
116 | |
public void addClassName(String s) { |
117 | 0 | classnames.append(s); |
118 | 0 | } |
119 | |
|
120 | |
}); |
121 | |
|
122 | |
|
123 | |
|
124 | |
|
125 | |
public Main(String name) { |
126 | 0 | this(name, new PrintWriter(System.err, true)); |
127 | 0 | } |
128 | |
|
129 | |
|
130 | |
|
131 | |
|
132 | 459 | public Main(String name, PrintWriter out) { |
133 | 459 | this.ownName = name; |
134 | 459 | this.out = out; |
135 | 459 | } |
136 | |
|
137 | 459 | private Options options = null; |
138 | |
|
139 | |
|
140 | |
|
141 | 459 | public ListBuffer<File> filenames = null; |
142 | |
|
143 | |
|
144 | |
|
145 | 459 | public ListBuffer<String> classnames = null; |
146 | |
|
147 | |
|
148 | |
|
149 | |
void help() { |
150 | 0 | Log.printLines(out, getLocalizedString(MsgSym.MESSAGE_MSG_USAGE_HEADER, ownName)); |
151 | 0 | for (int i=0; i<recognizedOptions.length; i++) { |
152 | 0 | recognizedOptions[i].help(out); |
153 | |
} |
154 | 0 | out.println(); |
155 | 0 | } |
156 | |
|
157 | |
|
158 | |
|
159 | |
void xhelp() { |
160 | 0 | for (int i=0; i<recognizedOptions.length; i++) { |
161 | 0 | recognizedOptions[i].xhelp(out); |
162 | |
} |
163 | 0 | out.println(); |
164 | 0 | Log.printLines(out, getLocalizedString(MsgSym.MESSAGE_MSG_USAGE_NONSTANDARD_FOOTER)); |
165 | 0 | } |
166 | |
|
167 | |
|
168 | |
|
169 | |
void error(String key, Object... args) { |
170 | 0 | if (fatalErrors) { |
171 | 0 | String msg = getLocalizedString(key, args); |
172 | 0 | throw new PropagatedException(new IllegalStateException(msg)); |
173 | |
} |
174 | 0 | warning(key, args); |
175 | 0 | Log.printLines(out, getLocalizedString(MsgSym.MESSAGE_MSG_USAGE, ownName)); |
176 | 0 | } |
177 | |
|
178 | |
|
179 | |
|
180 | |
void warning(String key, Object... args) { |
181 | 0 | Log.printLines(out, ownName + ": " |
182 | |
+ getLocalizedString(key, args)); |
183 | 0 | } |
184 | |
|
185 | |
public Option getOption(String flag) { |
186 | 0 | for (Option option : recognizedOptions) { |
187 | 0 | if (option.matches(flag)) |
188 | 0 | return option; |
189 | |
} |
190 | 0 | return null; |
191 | |
} |
192 | |
|
193 | |
public void setOptions(Options options) { |
194 | 75 | if (options == null) |
195 | 0 | throw new NullPointerException(); |
196 | 75 | this.options = options; |
197 | 75 | } |
198 | |
|
199 | |
public void setFatalErrors(boolean fatalErrors) { |
200 | 0 | this.fatalErrors = fatalErrors; |
201 | 0 | } |
202 | |
|
203 | |
|
204 | |
|
205 | |
|
206 | |
|
207 | |
public List<File> processArgs(String[] flags) { |
208 | 399 | int ac = 0; |
209 | 1989 | while (ac < flags.length) { |
210 | 1590 | String flag = flags[ac]; |
211 | 1590 | ac++; |
212 | |
|
213 | |
int j; |
214 | |
|
215 | |
|
216 | |
|
217 | 1590 | int firstOptionToCheck = flag.charAt(0) == '-' ? 0 : recognizedOptions.length-1; |
218 | 24667 | for (j=firstOptionToCheck; j<recognizedOptions.length; j++) |
219 | 24667 | if (recognizedOptions[j].matches(flag)) break; |
220 | |
|
221 | 1590 | if (j == recognizedOptions.length) { |
222 | 0 | error(MsgSym.MESSAGE_ERR_INVALID_FLAG, flag); |
223 | 0 | return null; |
224 | |
} |
225 | |
|
226 | 1590 | Option option = recognizedOptions[j]; |
227 | 1590 | if (option.hasArg()) { |
228 | 1109 | if (ac == flags.length) { |
229 | 0 | error(MsgSym.MESSAGE_ERR_REQ_ARG, flag); |
230 | 0 | return null; |
231 | |
} |
232 | 1109 | String operand = flags[ac]; |
233 | 1109 | ac++; |
234 | 1109 | if (option.process(options, flag, operand)) |
235 | 0 | return null; |
236 | 1109 | } else { |
237 | 481 | if (option.process(options, flag)) |
238 | 0 | return null; |
239 | |
} |
240 | 1590 | } |
241 | |
|
242 | 399 | if (!checkDirectory("-d")) |
243 | 0 | return null; |
244 | 399 | if (!checkDirectory("-s")) |
245 | 0 | return null; |
246 | |
|
247 | 399 | String sourceString = options.get("-source"); |
248 | 399 | Source source = (sourceString != null) |
249 | |
? Source.lookup(sourceString) |
250 | |
: Source.DEFAULT; |
251 | 399 | String targetString = options.get("-target"); |
252 | 399 | Target target = (targetString != null) |
253 | |
? Target.lookup(targetString) |
254 | |
: Target.DEFAULT; |
255 | |
|
256 | |
|
257 | |
|
258 | |
|
259 | |
|
260 | 399 | if (Character.isDigit(target.name.charAt(0))) { |
261 | 399 | if (target.compareTo(source.requiredTarget()) < 0) { |
262 | 0 | if (targetString != null) { |
263 | 0 | if (sourceString == null) { |
264 | 0 | warning(MsgSym.MESSAGE_WARN_TARGET_DEFAULT_SOURCE_CONFLICT, |
265 | |
targetString, |
266 | |
source.requiredTarget().name); |
267 | |
} else { |
268 | 0 | warning(MsgSym.MESSAGE_WARN_SOURCE_TARGET_CONFLICT, |
269 | |
sourceString, |
270 | |
source.requiredTarget().name); |
271 | |
} |
272 | 0 | return null; |
273 | |
} else { |
274 | 0 | options.put("-target", source.requiredTarget().name); |
275 | |
} |
276 | |
} else { |
277 | 399 | if (targetString == null && !source.allowGenerics()) { |
278 | 0 | options.put("-target", Target.JDK1_4.name); |
279 | |
} |
280 | |
} |
281 | |
} |
282 | 399 | return filenames.toList(); |
283 | |
} |
284 | |
|
285 | |
private boolean checkDirectory(String optName) { |
286 | 798 | String value = options.get(optName); |
287 | 798 | if (value == null) |
288 | 447 | return true; |
289 | 351 | File file = new File(value); |
290 | 351 | if (!file.exists()) { |
291 | 0 | error(MsgSym.MESSAGE_ERR_DIR_NOT_FOUND, value); |
292 | 0 | return false; |
293 | |
} |
294 | 351 | if (!file.isDirectory()) { |
295 | 0 | error(MsgSym.MESSAGE_ERR_FILE_NOT_DIRECTORY, value); |
296 | 0 | return false; |
297 | |
} |
298 | 351 | return true; |
299 | |
} |
300 | |
|
301 | |
|
302 | |
|
303 | |
|
304 | |
public int compile(String[] args) { |
305 | 351 | Context context = new Context(); |
306 | 351 | int result = compile(args, context, List.<JavaFileObject>nil()); |
307 | 351 | if (fileManager instanceof JavacFileManager) { |
308 | |
|
309 | 351 | ((JavacFileManager)fileManager).close(); |
310 | |
} |
311 | 351 | return result; |
312 | |
} |
313 | |
|
314 | |
public void registerServices(Context context, String[] args) { |
315 | 399 | Context backEndContext = new Context(); |
316 | 399 | backEndContext.put(DiagnosticListener.class, new DiagnosticForwarder(context)); |
317 | |
|
318 | 399 | options = Options.instance(backEndContext); |
319 | |
try { |
320 | 399 | String[] allArgs = CommandLine.parse(args); |
321 | 2719 | for (int i = 0; i < allArgs.length; i++) { |
322 | 2320 | if (allArgs[i].endsWith("-target") && ++i < allArgs.length) |
323 | 379 | options.put("-target", allArgs[i]); |
324 | |
} |
325 | 0 | } catch (IOException e) { |
326 | |
|
327 | 399 | } |
328 | 399 | options = null; |
329 | 399 | filenames = null; |
330 | |
|
331 | 399 | com.sun.tools.javafx.comp.JavafxFlow.preRegister(backEndContext); |
332 | 399 | com.sun.tools.javafx.code.JavafxLint.preRegister(backEndContext); |
333 | 399 | com.sun.tools.javafx.code.BlockExprSymtab.preRegister(backEndContext); |
334 | 399 | com.sun.tools.javafx.comp.BlockExprAttr.preRegister(backEndContext); |
335 | 399 | com.sun.tools.javafx.comp.BlockExprEnter.preRegister(backEndContext); |
336 | 399 | com.sun.tools.javafx.comp.BlockExprMemberEnter.preRegister(backEndContext); |
337 | 399 | com.sun.tools.javafx.comp.BlockExprResolve.preRegister(backEndContext); |
338 | 399 | com.sun.tools.javafx.comp.BlockExprLower.preRegister(backEndContext); |
339 | 399 | com.sun.tools.javafx.comp.BlockExprTransTypes.preRegister(backEndContext); |
340 | 399 | com.sun.tools.javafx.comp.BlockExprGen.preRegister(backEndContext); |
341 | |
|
342 | 399 | JavaFileManager currentFileManager = context.get(JavaFileManager.class); |
343 | 399 | if (currentFileManager == null) |
344 | 351 | JavacFileManager.preRegister(backEndContext); |
345 | |
else |
346 | 48 | backEndContext.put(JavaFileManager.class, currentFileManager); |
347 | |
|
348 | |
|
349 | |
|
350 | 399 | JavafxJavaCompiler javafxJavaCompiler = JavafxJavaCompiler.instance(backEndContext); |
351 | |
|
352 | 399 | context.put(JavafxJavaCompiler.javafxJavaCompilerKey, javafxJavaCompiler); |
353 | |
|
354 | |
|
355 | 399 | context.put(Name.Table.namesKey, backEndContext.get(Name.Table.namesKey)); |
356 | |
|
357 | |
|
358 | 399 | context.put(Options.optionsKey, (Options)null); |
359 | 399 | context.put(Options.optionsKey, backEndContext.get(Options.optionsKey)); |
360 | |
|
361 | 399 | ClassReader jreader = ClassReader.instance(backEndContext); |
362 | 399 | com.sun.tools.javafx.comp.JavafxClassReader.preRegister(context, jreader); |
363 | |
|
364 | 399 | if (currentFileManager == null) |
365 | 351 | JavafxFileManager.preRegister(context); |
366 | 399 | com.sun.tools.javafx.code.JavafxLint.preRegister(context); |
367 | 399 | } |
368 | |
|
369 | |
|
370 | |
|
371 | |
|
372 | |
|
373 | |
|
374 | |
private void loadPlatformPlugin(Context context, Options options) |
375 | |
{ |
376 | 380 | String platform = options.get("-platform"); |
377 | 380 | if (platform == null) |
378 | 380 | return; |
379 | |
|
380 | |
|
381 | 0 | String path = this.getClass().getCanonicalName(); |
382 | 0 | path = path.substring(path.lastIndexOf('.') + 1); |
383 | 0 | path = this.getClass().getResource(path + ".class").toString(); |
384 | 0 | path = path.substring(0, path.lastIndexOf(".jar!")); |
385 | 0 | path = path.substring("jar:file:".length(), path.lastIndexOf("/")); |
386 | 0 | File dir = new File(path); |
387 | 0 | File[] jars = dir.listFiles(new FilenameFilter() { |
388 | |
public boolean accept(File dir, String name) { |
389 | 0 | return name.endsWith(".jar"); |
390 | |
} |
391 | |
}); |
392 | |
|
393 | 0 | PlatformPlugin plugin = null; |
394 | 0 | URL urls[] = new URL[1]; |
395 | 0 | for (File jar : jars) { |
396 | |
try { |
397 | 0 | plugin = null; |
398 | 0 | urls[0] = jar.toURL(); |
399 | 0 | URLClassLoader loader = new URLClassLoader(urls); |
400 | 0 | InputStream stream = loader.getResourceAsStream( |
401 | |
"META-INF/services/" + PlatformPlugin.SERVICE); |
402 | 0 | if (stream == null) |
403 | 0 | continue; |
404 | |
|
405 | 0 | Reader reader = new InputStreamReader(stream); |
406 | 0 | String pname = Main.readServiceProvider(reader); |
407 | |
try { |
408 | 0 | reader.close(); |
409 | 0 | } catch (IOException ioe) { |
410 | 0 | } |
411 | 0 | if (pname == null) { |
412 | 0 | Log.instance(context).warning( |
413 | |
MsgSym.MESSAGE_PLUGIN_CANNOT_LOAD_PLUGIN, urls[0].getPath()); |
414 | 0 | continue; |
415 | |
} |
416 | |
|
417 | 0 | Class pclass = loader.loadClass(pname); |
418 | 0 | plugin = (PlatformPlugin)pclass.newInstance(); |
419 | 0 | if (!plugin.isSupported(platform)) |
420 | 0 | continue; |
421 | |
try { |
422 | |
|
423 | 0 | Class mclass = loader.loadClass(PlatformPlugin.MESSAGE); |
424 | 0 | ResourceBundle msgs = (ResourceBundle)mclass.newInstance(); |
425 | 0 | Messages.instance(context).add(msgs); |
426 | 0 | } catch (java.lang.ClassNotFoundException cnfe) { |
427 | 0 | } catch (java.lang.InstantiationException ie) { |
428 | 0 | } |
429 | 0 | plugin.initialize(options, Log.instance(context)); |
430 | |
|
431 | 0 | context.put(PlatformPlugin.pluginKey, plugin); |
432 | 0 | break; |
433 | |
|
434 | 0 | } catch (java.net.MalformedURLException murle) { |
435 | |
|
436 | 0 | } catch (java.lang.ClassNotFoundException cnfe) { |
437 | |
|
438 | 0 | Log.instance(context).warning( |
439 | |
MsgSym.MESSAGE_PLUGIN_CANNOT_LOAD_PLUGIN, urls[0].getPath()); |
440 | 0 | } catch (java.lang.InstantiationException ie) { |
441 | |
|
442 | 0 | Log.instance(context).warning( |
443 | |
MsgSym.MESSAGE_PLUGIN_CANNOT_LOAD_PLUGIN, urls[0].getPath()); |
444 | 0 | } catch (java.lang.IllegalAccessException iae) { |
445 | |
|
446 | 0 | Log.instance(context).warning( |
447 | |
MsgSym.MESSAGE_PLUGIN_CANNOT_LOAD_PLUGIN, urls[0].getPath()); |
448 | 0 | } |
449 | |
} |
450 | |
|
451 | 0 | if (plugin == null) { |
452 | 0 | Log.instance(context).error( |
453 | |
MsgSym.MESSAGE_PLUGIN_CANNOT_FIND_PLUGIN, platform); |
454 | |
} |
455 | 0 | } |
456 | |
|
457 | |
|
458 | |
|
459 | |
|
460 | |
|
461 | |
|
462 | |
private static String readServiceProvider(Reader reader) |
463 | |
{ |
464 | 0 | StringBuffer name = new StringBuffer(128); |
465 | 0 | int st = 0; |
466 | |
try { |
467 | |
int ch; |
468 | 0 | while ((ch = reader.read()) >= 0) { |
469 | 0 | switch (st) { |
470 | |
case 0: |
471 | 0 | switch (ch) { |
472 | |
case ' ': |
473 | |
case '\t': |
474 | |
case '\r': |
475 | |
case '\n': |
476 | 0 | break; |
477 | |
|
478 | |
case '#': |
479 | 0 | st = 1; |
480 | 0 | break; |
481 | |
|
482 | |
default: |
483 | 0 | name.append((char)ch); |
484 | 0 | st = 2; |
485 | 0 | break; |
486 | |
} |
487 | |
break; |
488 | |
|
489 | |
case 1: |
490 | 0 | switch (ch) { |
491 | |
case '\r': |
492 | |
case '\n': |
493 | 0 | st = 0; |
494 | 0 | break; |
495 | |
|
496 | |
default: |
497 | 0 | break; |
498 | |
} |
499 | |
break; |
500 | |
|
501 | |
case 2: |
502 | 0 | switch (ch) { |
503 | |
case ' ': |
504 | |
case '\t': |
505 | |
case '\r': |
506 | |
case '\n': |
507 | |
case '#': |
508 | 0 | return name.toString(); |
509 | |
|
510 | |
default: |
511 | 0 | name.append((char)ch); |
512 | 0 | break; |
513 | |
} |
514 | |
break; |
515 | |
|
516 | |
default: |
517 | 0 | return null; |
518 | |
} |
519 | |
} |
520 | 0 | } catch (IOException ioe) { |
521 | 0 | return null; |
522 | 0 | } |
523 | 0 | return (st == 2)? name.toString(): null; |
524 | |
} |
525 | |
|
526 | |
|
527 | |
|
528 | |
|
529 | |
public int compile(String[] args, |
530 | |
Context context, |
531 | |
List<JavaFileObject> fileObjects) |
532 | |
{ |
533 | 380 | registerServices(context, args); |
534 | 380 | if (options == null) |
535 | 380 | options = Options.instance(context); |
536 | |
|
537 | 380 | filenames = new ListBuffer<File>(); |
538 | 380 | classnames = new ListBuffer<String>(); |
539 | 380 | JavafxCompiler comp = null; |
540 | |
|
541 | |
|
542 | |
|
543 | |
|
544 | |
|
545 | |
try { |
546 | 380 | if (args.length == 0 && fileObjects.isEmpty()) { |
547 | 0 | help(); |
548 | 0 | return EXIT_CMDERR; |
549 | |
} |
550 | |
|
551 | |
List<File> fnames; |
552 | |
try { |
553 | 380 | fnames = processArgs(CommandLine.parse(args)); |
554 | 380 | if (fnames == null) { |
555 | |
|
556 | 0 | return EXIT_CMDERR; |
557 | 380 | } else if (fnames.isEmpty() && fileObjects.isEmpty() && classnames.isEmpty()) { |
558 | |
|
559 | 0 | if (options.get("-help") != null |
560 | |
|| options.get("-X") != null |
561 | |
|| options.get("-version") != null |
562 | |
|| options.get("-fullversion") != null) |
563 | 0 | return EXIT_OK; |
564 | 0 | error(MsgSym.MESSAGE_ERR_NO_SOURCE_FILES); |
565 | 0 | return EXIT_CMDERR; |
566 | |
} |
567 | 0 | } catch (java.io.FileNotFoundException e) { |
568 | 0 | Log.printLines(out, ownName + ": " + |
569 | |
getLocalizedString(MsgSym.MESSAGE_ERR_FILE_NOT_FOUND, |
570 | |
e.getMessage())); |
571 | 0 | return EXIT_SYSERR; |
572 | 380 | } |
573 | |
|
574 | 380 | boolean forceStdOut = options.get("stdout") != null; |
575 | 380 | if (forceStdOut) { |
576 | 0 | out.flush(); |
577 | 0 | out = new PrintWriter(System.out, true); |
578 | |
} |
579 | |
|
580 | 380 | context.put(Log.outKey, out); |
581 | |
|
582 | 380 | fileManager = context.get(JavaFileManager.class); |
583 | |
|
584 | 380 | comp = JavafxCompiler.instance(context); |
585 | 380 | if (comp == null) return EXIT_SYSERR; |
586 | |
|
587 | 380 | loadPlatformPlugin(context, options); |
588 | |
|
589 | 380 | if (!fnames.isEmpty()) { |
590 | |
|
591 | 351 | comp = JavafxCompiler.instance(context); |
592 | 351 | List<JavaFileObject> otherFiles = List.nil(); |
593 | 351 | JavacFileManager dfm = (JavacFileManager)fileManager; |
594 | 351 | for (JavaFileObject fo : dfm.getJavaFileObjectsFromFiles(fnames)) |
595 | 363 | otherFiles = otherFiles.prepend(fo); |
596 | 351 | for (JavaFileObject fo : otherFiles) |
597 | 363 | fileObjects = fileObjects.prepend(fo); |
598 | |
} |
599 | 380 | comp.compile(fileObjects, |
600 | |
classnames.toList()); |
601 | |
|
602 | 377 | if (comp.errorCount() != 0 || |
603 | |
options.get("-Werror") != null && comp.warningCount() != 0) |
604 | 51 | return EXIT_ERROR; |
605 | 0 | } catch (IOException ex) { |
606 | 0 | ioMessage(ex); |
607 | 0 | return EXIT_SYSERR; |
608 | 0 | } catch (OutOfMemoryError ex) { |
609 | 0 | resourceMessage(ex); |
610 | 0 | return EXIT_SYSERR; |
611 | 0 | } catch (StackOverflowError ex) { |
612 | 0 | resourceMessage(ex); |
613 | 0 | return EXIT_SYSERR; |
614 | 0 | } catch (FatalError ex) { |
615 | 0 | feMessage(ex); |
616 | 0 | return EXIT_SYSERR; |
617 | 0 | } catch (ClientCodeException ex) { |
618 | |
|
619 | |
|
620 | 0 | throw new RuntimeException(ex.getCause()); |
621 | 0 | } catch (PropagatedException ex) { |
622 | 0 | throw ex.getCause(); |
623 | 3 | } catch (Throwable ex) { |
624 | |
|
625 | |
|
626 | |
|
627 | 3 | if (comp == null || comp.errorCount() == 0 || |
628 | |
options == null || options.get("dev") != null) |
629 | 0 | bugMessage(ex); |
630 | 3 | return EXIT_ABNORMAL; |
631 | |
} finally { |
632 | 380 | if (comp != null) comp.close(); |
633 | 380 | filenames = null; |
634 | 380 | options = null; |
635 | 326 | } |
636 | 326 | return EXIT_OK; |
637 | |
} |
638 | |
|
639 | |
|
640 | |
|
641 | |
void bugMessage(Throwable ex) { |
642 | 0 | Log.printLines(out, getJavafxLocalizedString(MsgSym.MESSAGE_JAVAFX_MSG_BUG, |
643 | |
JavafxCompiler.version())); |
644 | 0 | ex.printStackTrace(out); |
645 | 0 | } |
646 | |
|
647 | |
|
648 | |
|
649 | |
void feMessage(Throwable ex) { |
650 | 0 | Log.printLines(out, ex.getMessage()); |
651 | 0 | } |
652 | |
|
653 | |
|
654 | |
|
655 | |
void ioMessage(Throwable ex) { |
656 | 0 | Log.printLines(out, getLocalizedString(MsgSym.MESSAGE_MSG_IO)); |
657 | 0 | ex.printStackTrace(out); |
658 | 0 | } |
659 | |
|
660 | |
|
661 | |
|
662 | |
void resourceMessage(Throwable ex) { |
663 | 0 | Log.printLines(out, getLocalizedString(MsgSym.MESSAGE_MSG_RESOURCE)); |
664 | |
|
665 | 0 | ex.printStackTrace(out); |
666 | 0 | } |
667 | |
|
668 | |
private JavaFileManager fileManager; |
669 | |
|
670 | |
|
671 | |
|
672 | |
|
673 | |
|
674 | |
|
675 | |
|
676 | |
|
677 | |
public static String getLocalizedString(String key, Object... args) { |
678 | |
try { |
679 | 0 | if (messages == null) |
680 | 0 | messages = new Messages(javacBundleName); |
681 | 0 | return messages.getLocalizedString(MsgSym.MESSAGEPREFIX_JAVAC + key, args); |
682 | |
} |
683 | 0 | catch (MissingResourceException e) { |
684 | 0 | throw new Error("Fatal Error: Resource for javac is missing", e); |
685 | |
} |
686 | |
} |
687 | |
|
688 | |
|
689 | |
|
690 | |
|
691 | |
public static String getJavafxLocalizedString(String key, Object... args) { |
692 | |
try { |
693 | 0 | Messages fxmessages = new Messages(javafxBundleName); |
694 | 0 | return fxmessages.getLocalizedString(key, args); |
695 | |
} |
696 | 0 | catch (MissingResourceException e) { |
697 | 0 | throw new Error("Fatal Error: Resource for javac is missing", e); |
698 | |
} |
699 | |
} |
700 | |
|
701 | |
public static void useRawMessages(boolean enable) { |
702 | 0 | if (enable) { |
703 | 0 | messages = new Messages(javacBundleName) { |
704 | |
@Override |
705 | |
public String getLocalizedString(String key, Object... args) { |
706 | 0 | return key; |
707 | |
} |
708 | |
}; |
709 | |
} else { |
710 | 0 | messages = new Messages(javacBundleName); |
711 | |
} |
712 | 0 | } |
713 | |
|
714 | |
private static final String javacBundleName = |
715 | |
"com.sun.tools.javac.resources.javac"; |
716 | |
|
717 | |
private static final String javafxBundleName = |
718 | |
"com.sun.tools.javafx.resources.javafxcompiler"; |
719 | |
|
720 | |
private static Messages messages; |
721 | |
|
722 | |
private static class DiagnosticForwarder implements DiagnosticListener { |
723 | |
Context otherContext; |
724 | |
|
725 | 399 | public DiagnosticForwarder(Context context) { |
726 | 399 | otherContext = context; |
727 | 399 | } |
728 | |
|
729 | |
public void report(Diagnostic diag) { |
730 | 5 | Log log = Log.instance(otherContext); |
731 | 5 | log.report((JCDiagnostic)diag); |
732 | 5 | } |
733 | |
} |
734 | |
} |