src/share/classes/com/sun/tools/javac/main/Main.java

Thu, 06 Oct 2011 18:39:31 +0100

author
mcimadamore
date
Thu, 06 Oct 2011 18:39:31 +0100
changeset 1103
47147081d5b4
parent 1097
497571d34112
child 1135
36553cb94345
permissions
-rw-r--r--

7090499: missing rawtypes warnings in anonymous inner class
Summary: javac does not detect raw types inside anonymous inner classes
Reviewed-by: jjg

duke@1 1 /*
jjg@902 2 * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
duke@1 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@1 4 *
duke@1 5 * This code is free software; you can redistribute it and/or modify it
duke@1 6 * under the terms of the GNU General Public License version 2 only, as
ohair@554 7 * published by the Free Software Foundation. Oracle designates this
duke@1 8 * particular file as subject to the "Classpath" exception as provided
ohair@554 9 * by Oracle in the LICENSE file that accompanied this code.
duke@1 10 *
duke@1 11 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@1 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@1 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@1 14 * version 2 for more details (a copy is included in the LICENSE file that
duke@1 15 * accompanied this code).
duke@1 16 *
duke@1 17 * You should have received a copy of the GNU General Public License version
duke@1 18 * 2 along with this work; if not, write to the Free Software Foundation,
duke@1 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@1 20 *
ohair@554 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohair@554 22 * or visit www.oracle.com if you need additional information or have any
ohair@554 23 * questions.
duke@1 24 */
duke@1 25
duke@1 26 package com.sun.tools.javac.main;
duke@1 27
duke@1 28 import java.io.File;
duke@1 29 import java.io.IOException;
duke@1 30 import java.io.PrintWriter;
jjg@535 31 import java.net.URL;
jjg@535 32 import java.security.DigestInputStream;
jjg@535 33 import java.security.MessageDigest;
jjg@1055 34 import java.util.Collection;
jjg@1055 35 import java.util.LinkedHashSet;
duke@1 36 import java.util.MissingResourceException;
jjg@1055 37 import java.util.Set;
jjg@700 38 import javax.tools.JavaFileManager;
jjg@700 39 import javax.tools.JavaFileObject;
jjg@700 40 import javax.annotation.processing.Processor;
duke@1 41
duke@1 42 import com.sun.tools.javac.code.Source;
jjg@106 43 import com.sun.tools.javac.file.CacheFSInfo;
jjg@50 44 import com.sun.tools.javac.file.JavacFileManager;
duke@1 45 import com.sun.tools.javac.jvm.Target;
duke@1 46 import com.sun.tools.javac.main.JavacOption.Option;
duke@1 47 import com.sun.tools.javac.main.RecognizedOptions.OptionHelper;
duke@1 48 import com.sun.tools.javac.util.*;
duke@1 49 import com.sun.tools.javac.processing.AnnotationProcessingError;
jjg@700 50
jjg@700 51 import static com.sun.tools.javac.main.OptionName.*;
duke@1 52
duke@1 53 /** This class provides a commandline interface to the GJC compiler.
duke@1 54 *
jjg@581 55 * <p><b>This is NOT part of any supported API.
jjg@581 56 * If you write code that depends on this, you do so at your own risk.
duke@1 57 * This code and its internal interfaces are subject to change or
duke@1 58 * deletion without notice.</b>
duke@1 59 */
duke@1 60 public class Main {
duke@1 61
duke@1 62 /** The name of the compiler, for use in diagnostics.
duke@1 63 */
duke@1 64 String ownName;
duke@1 65
duke@1 66 /** The writer to use for diagnostic output.
duke@1 67 */
duke@1 68 PrintWriter out;
duke@1 69
duke@1 70 /**
jjg@946 71 * If true, certain errors will cause an exception, such as command line
jjg@946 72 * arg errors, or exceptions in user provided code.
duke@1 73 */
jjg@946 74 boolean apiMode;
jjg@946 75
duke@1 76
duke@1 77 /** Result codes.
duke@1 78 */
jjg@1097 79 public enum Result {
jjg@1097 80 OK(0), // Compilation completed with no errors.
jjg@1097 81 ERROR(1), // Completed but reported errors.
jjg@1097 82 CMDERR(2), // Bad command-line arguments
jjg@1097 83 SYSERR(3), // System error or resource exhaustion.
jjg@1097 84 ABNORMAL(4); // Compiler terminated abnormally
jjg@1097 85
jjg@1097 86 Result(int exitCode) {
jjg@1097 87 this.exitCode = exitCode;
jjg@1097 88 }
jjg@1097 89
jjg@1097 90 public boolean isOK() {
jjg@1097 91 return (exitCode == 0);
jjg@1097 92 }
jjg@1097 93
jjg@1097 94 public final int exitCode;
jjg@1097 95 }
duke@1 96
duke@1 97 private Option[] recognizedOptions = RecognizedOptions.getJavaCompilerOptions(new OptionHelper() {
duke@1 98
duke@1 99 public void setOut(PrintWriter out) {
duke@1 100 Main.this.out = out;
duke@1 101 }
duke@1 102
duke@1 103 public void error(String key, Object... args) {
duke@1 104 Main.this.error(key, args);
duke@1 105 }
duke@1 106
duke@1 107 public void printVersion() {
duke@1 108 Log.printLines(out, getLocalizedString("version", ownName, JavaCompiler.version()));
duke@1 109 }
duke@1 110
duke@1 111 public void printFullVersion() {
duke@1 112 Log.printLines(out, getLocalizedString("fullVersion", ownName, JavaCompiler.fullVersion()));
duke@1 113 }
duke@1 114
duke@1 115 public void printHelp() {
duke@1 116 help();
duke@1 117 }
duke@1 118
duke@1 119 public void printXhelp() {
duke@1 120 xhelp();
duke@1 121 }
duke@1 122
duke@1 123 public void addFile(File f) {
jjg@1055 124 filenames.add(f);
duke@1 125 }
duke@1 126
duke@1 127 public void addClassName(String s) {
duke@1 128 classnames.append(s);
duke@1 129 }
duke@1 130
duke@1 131 });
duke@1 132
duke@1 133 /**
duke@1 134 * Construct a compiler instance.
duke@1 135 */
duke@1 136 public Main(String name) {
duke@1 137 this(name, new PrintWriter(System.err, true));
duke@1 138 }
duke@1 139
duke@1 140 /**
duke@1 141 * Construct a compiler instance.
duke@1 142 */
duke@1 143 public Main(String name, PrintWriter out) {
duke@1 144 this.ownName = name;
duke@1 145 this.out = out;
duke@1 146 }
duke@1 147 /** A table of all options that's passed to the JavaCompiler constructor. */
duke@1 148 private Options options = null;
duke@1 149
duke@1 150 /** The list of source files to process
duke@1 151 */
jjg@1055 152 public Set<File> filenames = null; // XXX sb protected
duke@1 153
duke@1 154 /** List of class files names passed on the command line
duke@1 155 */
duke@1 156 public ListBuffer<String> classnames = null; // XXX sb protected
duke@1 157
duke@1 158 /** Print a string that explains usage.
duke@1 159 */
duke@1 160 void help() {
duke@1 161 Log.printLines(out, getLocalizedString("msg.usage.header", ownName));
duke@1 162 for (int i=0; i<recognizedOptions.length; i++) {
duke@1 163 recognizedOptions[i].help(out);
duke@1 164 }
duke@1 165 out.println();
duke@1 166 }
duke@1 167
duke@1 168 /** Print a string that explains usage for X options.
duke@1 169 */
duke@1 170 void xhelp() {
duke@1 171 for (int i=0; i<recognizedOptions.length; i++) {
duke@1 172 recognizedOptions[i].xhelp(out);
duke@1 173 }
duke@1 174 out.println();
duke@1 175 Log.printLines(out, getLocalizedString("msg.usage.nonstandard.footer"));
duke@1 176 }
duke@1 177
duke@1 178 /** Report a usage error.
duke@1 179 */
duke@1 180 void error(String key, Object... args) {
jjg@946 181 if (apiMode) {
duke@1 182 String msg = getLocalizedString(key, args);
duke@1 183 throw new PropagatedException(new IllegalStateException(msg));
duke@1 184 }
duke@1 185 warning(key, args);
duke@1 186 Log.printLines(out, getLocalizedString("msg.usage", ownName));
duke@1 187 }
duke@1 188
duke@1 189 /** Report a warning.
duke@1 190 */
duke@1 191 void warning(String key, Object... args) {
duke@1 192 Log.printLines(out, ownName + ": "
duke@1 193 + getLocalizedString(key, args));
duke@1 194 }
duke@1 195
duke@1 196 public Option getOption(String flag) {
duke@1 197 for (Option option : recognizedOptions) {
duke@1 198 if (option.matches(flag))
duke@1 199 return option;
duke@1 200 }
duke@1 201 return null;
duke@1 202 }
duke@1 203
duke@1 204 public void setOptions(Options options) {
duke@1 205 if (options == null)
duke@1 206 throw new NullPointerException();
duke@1 207 this.options = options;
duke@1 208 }
duke@1 209
jjg@946 210 public void setAPIMode(boolean apiMode) {
jjg@946 211 this.apiMode = apiMode;
duke@1 212 }
duke@1 213
duke@1 214 /** Process command line arguments: store all command line options
duke@1 215 * in `options' table and return all source filenames.
duke@1 216 * @param flags The array of command line arguments.
duke@1 217 */
jjg@1055 218 public Collection<File> processArgs(String[] flags) { // XXX sb protected
duke@1 219 int ac = 0;
duke@1 220 while (ac < flags.length) {
duke@1 221 String flag = flags[ac];
duke@1 222 ac++;
duke@1 223
duke@1 224 Option option = null;
duke@1 225
duke@1 226 if (flag.length() > 0) {
duke@1 227 // quick hack to speed up file processing:
duke@1 228 // if the option does not begin with '-', there is no need to check
duke@1 229 // most of the compiler options.
duke@1 230 int firstOptionToCheck = flag.charAt(0) == '-' ? 0 : recognizedOptions.length-1;
duke@1 231 for (int j=firstOptionToCheck; j<recognizedOptions.length; j++) {
duke@1 232 if (recognizedOptions[j].matches(flag)) {
duke@1 233 option = recognizedOptions[j];
duke@1 234 break;
duke@1 235 }
duke@1 236 }
duke@1 237 }
duke@1 238
duke@1 239 if (option == null) {
duke@1 240 error("err.invalid.flag", flag);
duke@1 241 return null;
duke@1 242 }
duke@1 243
duke@1 244 if (option.hasArg()) {
duke@1 245 if (ac == flags.length) {
duke@1 246 error("err.req.arg", flag);
duke@1 247 return null;
duke@1 248 }
duke@1 249 String operand = flags[ac];
duke@1 250 ac++;
duke@1 251 if (option.process(options, flag, operand))
duke@1 252 return null;
duke@1 253 } else {
duke@1 254 if (option.process(options, flag))
duke@1 255 return null;
duke@1 256 }
duke@1 257 }
duke@1 258
jjg@700 259 if (!checkDirectory(D))
duke@1 260 return null;
jjg@700 261 if (!checkDirectory(S))
duke@1 262 return null;
duke@1 263
jjg@700 264 String sourceString = options.get(SOURCE);
duke@1 265 Source source = (sourceString != null)
duke@1 266 ? Source.lookup(sourceString)
duke@1 267 : Source.DEFAULT;
jjg@700 268 String targetString = options.get(TARGET);
duke@1 269 Target target = (targetString != null)
duke@1 270 ? Target.lookup(targetString)
duke@1 271 : Target.DEFAULT;
duke@1 272 // We don't check source/target consistency for CLDC, as J2ME
duke@1 273 // profiles are not aligned with J2SE targets; moreover, a
duke@1 274 // single CLDC target may have many profiles. In addition,
duke@1 275 // this is needed for the continued functioning of the JSR14
duke@1 276 // prototype.
duke@1 277 if (Character.isDigit(target.name.charAt(0))) {
duke@1 278 if (target.compareTo(source.requiredTarget()) < 0) {
duke@1 279 if (targetString != null) {
duke@1 280 if (sourceString == null) {
duke@1 281 warning("warn.target.default.source.conflict",
duke@1 282 targetString,
duke@1 283 source.requiredTarget().name);
duke@1 284 } else {
duke@1 285 warning("warn.source.target.conflict",
duke@1 286 sourceString,
duke@1 287 source.requiredTarget().name);
duke@1 288 }
duke@1 289 return null;
duke@1 290 } else {
jrose@267 291 target = source.requiredTarget();
jrose@267 292 options.put("-target", target.name);
duke@1 293 }
duke@1 294 } else {
duke@1 295 if (targetString == null && !source.allowGenerics()) {
jrose@267 296 target = Target.JDK1_4;
jrose@267 297 options.put("-target", target.name);
duke@1 298 }
duke@1 299 }
duke@1 300 }
jjg@535 301
jjg@535 302 // handle this here so it works even if no other options given
jjg@535 303 String showClass = options.get("showClass");
jjg@535 304 if (showClass != null) {
jjg@535 305 if (showClass.equals("showClass")) // no value given for option
jjg@535 306 showClass = "com.sun.tools.javac.Main";
jjg@535 307 showClass(showClass);
jjg@535 308 }
jjg@535 309
jjg@1055 310 return filenames;
duke@1 311 }
duke@1 312 // where
jjg@700 313 private boolean checkDirectory(OptionName optName) {
duke@1 314 String value = options.get(optName);
duke@1 315 if (value == null)
duke@1 316 return true;
duke@1 317 File file = new File(value);
duke@1 318 if (!file.exists()) {
duke@1 319 error("err.dir.not.found", value);
duke@1 320 return false;
duke@1 321 }
duke@1 322 if (!file.isDirectory()) {
duke@1 323 error("err.file.not.directory", value);
duke@1 324 return false;
duke@1 325 }
duke@1 326 return true;
duke@1 327 }
duke@1 328
duke@1 329 /** Programmatic interface for main function.
duke@1 330 * @param args The command line parameters.
duke@1 331 */
jjg@1097 332 public Result compile(String[] args) {
duke@1 333 Context context = new Context();
duke@1 334 JavacFileManager.preRegister(context); // can't create it until Log has been set up
jjg@1097 335 Result result = compile(args, context);
duke@1 336 if (fileManager instanceof JavacFileManager) {
duke@1 337 // A fresh context was created above, so jfm must be a JavacFileManager
duke@1 338 ((JavacFileManager)fileManager).close();
duke@1 339 }
duke@1 340 return result;
duke@1 341 }
duke@1 342
jjg@1097 343 public Result compile(String[] args, Context context) {
duke@1 344 return compile(args, context, List.<JavaFileObject>nil(), null);
duke@1 345 }
duke@1 346
duke@1 347 /** Programmatic interface for main function.
duke@1 348 * @param args The command line parameters.
duke@1 349 */
jjg@1097 350 public Result compile(String[] args,
duke@1 351 Context context,
duke@1 352 List<JavaFileObject> fileObjects,
duke@1 353 Iterable<? extends Processor> processors)
duke@1 354 {
duke@1 355 if (options == null)
duke@1 356 options = Options.instance(context); // creates a new one
duke@1 357
jjg@1055 358 filenames = new LinkedHashSet<File>();
duke@1 359 classnames = new ListBuffer<String>();
duke@1 360 JavaCompiler comp = null;
duke@1 361 /*
duke@1 362 * TODO: Logic below about what is an acceptable command line
duke@1 363 * should be updated to take annotation processing semantics
duke@1 364 * into account.
duke@1 365 */
duke@1 366 try {
duke@1 367 if (args.length == 0 && fileObjects.isEmpty()) {
duke@1 368 help();
jjg@1097 369 return Result.CMDERR;
duke@1 370 }
duke@1 371
jjg@1055 372 Collection<File> files;
duke@1 373 try {
jjg@194 374 files = processArgs(CommandLine.parse(args));
jjg@194 375 if (files == null) {
duke@1 376 // null signals an error in options, abort
jjg@1097 377 return Result.CMDERR;
jjg@194 378 } else if (files.isEmpty() && fileObjects.isEmpty() && classnames.isEmpty()) {
duke@1 379 // it is allowed to compile nothing if just asking for help or version info
jjg@700 380 if (options.isSet(HELP)
jjg@700 381 || options.isSet(X)
jjg@700 382 || options.isSet(VERSION)
jjg@700 383 || options.isSet(FULLVERSION))
jjg@1097 384 return Result.OK;
jjg@902 385 if (JavaCompiler.explicitAnnotationProcessingRequested(options)) {
jjg@902 386 error("err.no.source.files.classes");
jjg@902 387 } else {
jjg@902 388 error("err.no.source.files");
jjg@902 389 }
jjg@1097 390 return Result.CMDERR;
duke@1 391 }
duke@1 392 } catch (java.io.FileNotFoundException e) {
duke@1 393 Log.printLines(out, ownName + ": " +
duke@1 394 getLocalizedString("err.file.not.found",
duke@1 395 e.getMessage()));
jjg@1097 396 return Result.SYSERR;
duke@1 397 }
duke@1 398
jjg@700 399 boolean forceStdOut = options.isSet("stdout");
duke@1 400 if (forceStdOut) {
duke@1 401 out.flush();
duke@1 402 out = new PrintWriter(System.out, true);
duke@1 403 }
duke@1 404
duke@1 405 context.put(Log.outKey, out);
duke@1 406
jjg@106 407 // allow System property in following line as a Mustang legacy
jjg@700 408 boolean batchMode = (options.isUnset("nonBatchMode")
jjg@106 409 && System.getProperty("nonBatchMode") == null);
jjg@106 410 if (batchMode)
jjg@106 411 CacheFSInfo.preRegister(context);
jjg@106 412
duke@1 413 fileManager = context.get(JavaFileManager.class);
duke@1 414
duke@1 415 comp = JavaCompiler.instance(context);
jjg@1097 416 if (comp == null) return Result.SYSERR;
duke@1 417
jjg@194 418 Log log = Log.instance(context);
jjg@194 419
jjg@194 420 if (!files.isEmpty()) {
duke@1 421 // add filenames to fileObjects
duke@1 422 comp = JavaCompiler.instance(context);
duke@1 423 List<JavaFileObject> otherFiles = List.nil();
duke@1 424 JavacFileManager dfm = (JavacFileManager)fileManager;
jjg@194 425 for (JavaFileObject fo : dfm.getJavaFileObjectsFromFiles(files))
duke@1 426 otherFiles = otherFiles.prepend(fo);
duke@1 427 for (JavaFileObject fo : otherFiles)
duke@1 428 fileObjects = fileObjects.prepend(fo);
duke@1 429 }
duke@1 430 comp.compile(fileObjects,
duke@1 431 classnames.toList(),
duke@1 432 processors);
duke@1 433
jjg@194 434 if (log.expectDiagKeys != null) {
jjg@757 435 if (log.expectDiagKeys.isEmpty()) {
jjg@194 436 Log.printLines(log.noticeWriter, "all expected diagnostics found");
jjg@1097 437 return Result.OK;
jjg@194 438 } else {
jjg@194 439 Log.printLines(log.noticeWriter, "expected diagnostic keys not found: " + log.expectDiagKeys);
jjg@1097 440 return Result.ERROR;
jjg@194 441 }
jjg@194 442 }
jjg@194 443
jjg@215 444 if (comp.errorCount() != 0)
jjg@1097 445 return Result.ERROR;
duke@1 446 } catch (IOException ex) {
duke@1 447 ioMessage(ex);
jjg@1097 448 return Result.SYSERR;
duke@1 449 } catch (OutOfMemoryError ex) {
duke@1 450 resourceMessage(ex);
jjg@1097 451 return Result.SYSERR;
duke@1 452 } catch (StackOverflowError ex) {
duke@1 453 resourceMessage(ex);
jjg@1097 454 return Result.SYSERR;
duke@1 455 } catch (FatalError ex) {
duke@1 456 feMessage(ex);
jjg@1097 457 return Result.SYSERR;
jjg@946 458 } catch (AnnotationProcessingError ex) {
jjg@946 459 if (apiMode)
jjg@946 460 throw new RuntimeException(ex.getCause());
duke@1 461 apMessage(ex);
jjg@1097 462 return Result.SYSERR;
duke@1 463 } catch (ClientCodeException ex) {
duke@1 464 // as specified by javax.tools.JavaCompiler#getTask
duke@1 465 // and javax.tools.JavaCompiler.CompilationTask#call
duke@1 466 throw new RuntimeException(ex.getCause());
duke@1 467 } catch (PropagatedException ex) {
duke@1 468 throw ex.getCause();
duke@1 469 } catch (Throwable ex) {
duke@1 470 // Nasty. If we've already reported an error, compensate
duke@1 471 // for buggy compiler error recovery by swallowing thrown
duke@1 472 // exceptions.
duke@1 473 if (comp == null || comp.errorCount() == 0 ||
jjg@700 474 options == null || options.isSet("dev"))
duke@1 475 bugMessage(ex);
jjg@1097 476 return Result.ABNORMAL;
duke@1 477 } finally {
jjg@946 478 if (comp != null) {
jjg@946 479 try {
jjg@946 480 comp.close();
jjg@946 481 } catch (ClientCodeException ex) {
jjg@946 482 throw new RuntimeException(ex.getCause());
jjg@946 483 }
jjg@946 484 }
duke@1 485 filenames = null;
duke@1 486 options = null;
duke@1 487 }
jjg@1097 488 return Result.OK;
duke@1 489 }
duke@1 490
duke@1 491 /** Print a message reporting an internal error.
duke@1 492 */
duke@1 493 void bugMessage(Throwable ex) {
duke@1 494 Log.printLines(out, getLocalizedString("msg.bug",
duke@1 495 JavaCompiler.version()));
duke@1 496 ex.printStackTrace(out);
duke@1 497 }
duke@1 498
jjg@663 499 /** Print a message reporting a fatal error.
duke@1 500 */
duke@1 501 void feMessage(Throwable ex) {
duke@1 502 Log.printLines(out, ex.getMessage());
jjg@700 503 if (ex.getCause() != null && options.isSet("dev")) {
jjg@663 504 ex.getCause().printStackTrace(out);
jjg@663 505 }
duke@1 506 }
duke@1 507
duke@1 508 /** Print a message reporting an input/output error.
duke@1 509 */
duke@1 510 void ioMessage(Throwable ex) {
duke@1 511 Log.printLines(out, getLocalizedString("msg.io"));
duke@1 512 ex.printStackTrace(out);
duke@1 513 }
duke@1 514
duke@1 515 /** Print a message reporting an out-of-resources error.
duke@1 516 */
duke@1 517 void resourceMessage(Throwable ex) {
duke@1 518 Log.printLines(out, getLocalizedString("msg.resource"));
duke@1 519 // System.out.println("(name buffer len = " + Name.names.length + " " + Name.nc);//DEBUG
duke@1 520 ex.printStackTrace(out);
duke@1 521 }
duke@1 522
duke@1 523 /** Print a message reporting an uncaught exception from an
duke@1 524 * annotation processor.
duke@1 525 */
duke@1 526 void apMessage(AnnotationProcessingError ex) {
duke@1 527 Log.printLines(out,
duke@1 528 getLocalizedString("msg.proc.annotation.uncaught.exception"));
jjg@757 529 ex.getCause().printStackTrace(out);
duke@1 530 }
duke@1 531
jjg@535 532 /** Display the location and checksum of a class. */
jjg@535 533 void showClass(String className) {
jjg@535 534 out.println("javac: show class: " + className);
jjg@535 535 URL url = getClass().getResource('/' + className.replace('.', '/') + ".class");
jjg@535 536 if (url == null)
jjg@535 537 out.println(" class not found");
jjg@535 538 else {
jjg@535 539 out.println(" " + url);
jjg@535 540 try {
jjg@535 541 final String algorithm = "MD5";
jjg@535 542 byte[] digest;
jjg@535 543 MessageDigest md = MessageDigest.getInstance(algorithm);
jjg@535 544 DigestInputStream in = new DigestInputStream(url.openStream(), md);
jjg@535 545 try {
jjg@535 546 byte[] buf = new byte[8192];
jjg@535 547 int n;
jjg@535 548 do { n = in.read(buf); } while (n > 0);
jjg@535 549 digest = md.digest();
jjg@535 550 } finally {
jjg@535 551 in.close();
jjg@535 552 }
jjg@535 553 StringBuilder sb = new StringBuilder();
jjg@535 554 for (byte b: digest)
jjg@535 555 sb.append(String.format("%02x", b));
jjg@535 556 out.println(" " + algorithm + " checksum: " + sb);
jjg@535 557 } catch (Exception e) {
jjg@535 558 out.println(" cannot compute digest: " + e);
jjg@535 559 }
jjg@535 560 }
jjg@535 561 }
jjg@535 562
duke@1 563 private JavaFileManager fileManager;
duke@1 564
duke@1 565 /* ************************************************************************
duke@1 566 * Internationalization
duke@1 567 *************************************************************************/
duke@1 568
duke@1 569 /** Find a localized string in the resource bundle.
duke@1 570 * @param key The key for the localized string.
duke@1 571 */
duke@1 572 public static String getLocalizedString(String key, Object... args) { // FIXME sb private
duke@1 573 try {
duke@1 574 if (messages == null)
mcimadamore@136 575 messages = new JavacMessages(javacBundleName);
duke@1 576 return messages.getLocalizedString("javac." + key, args);
duke@1 577 }
duke@1 578 catch (MissingResourceException e) {
duke@1 579 throw new Error("Fatal Error: Resource for javac is missing", e);
duke@1 580 }
duke@1 581 }
duke@1 582
duke@1 583 public static void useRawMessages(boolean enable) {
duke@1 584 if (enable) {
mcimadamore@136 585 messages = new JavacMessages(javacBundleName) {
jjg@757 586 @Override
duke@1 587 public String getLocalizedString(String key, Object... args) {
duke@1 588 return key;
duke@1 589 }
duke@1 590 };
duke@1 591 } else {
mcimadamore@136 592 messages = new JavacMessages(javacBundleName);
duke@1 593 }
duke@1 594 }
duke@1 595
duke@1 596 private static final String javacBundleName =
duke@1 597 "com.sun.tools.javac.resources.javac";
duke@1 598
mcimadamore@136 599 private static JavacMessages messages;
duke@1 600 }

mercurial