1 13 package org.eclipse.jdt.internal.compiler.batch; 14 15 import java.io.ByteArrayInputStream ; 16 import java.io.File ; 17 import java.io.FileNotFoundException ; 18 import java.io.FileOutputStream ; 19 import java.io.FilenameFilter ; 20 import java.io.IOException ; 21 import java.io.InputStreamReader ; 22 import java.io.LineNumberReader ; 23 import java.io.PrintWriter ; 24 import java.io.StringReader ; 25 import java.io.StringWriter ; 26 import java.io.UnsupportedEncodingException ; 27 import java.lang.reflect.Field ; 28 import java.text.DateFormat ; 29 import java.text.MessageFormat ; 30 import java.util.ArrayList ; 31 import java.util.Arrays ; 32 import java.util.Comparator ; 33 import java.util.Date ; 34 import java.util.HashMap ; 35 import java.util.Iterator ; 36 import java.util.Locale ; 37 import java.util.Map ; 38 import java.util.MissingResourceException ; 39 import java.util.ResourceBundle ; 40 import java.util.Set ; 41 import java.util.StringTokenizer ; 42 43 import org.eclipse.jdt.core.compiler.CategorizedProblem; 44 import org.eclipse.jdt.core.compiler.CharOperation; 45 import org.eclipse.jdt.core.compiler.InvalidInputException; 46 import org.eclipse.jdt.core.compiler.IProblem; 47 import org.eclipse.jdt.internal.compiler.AbstractAnnotationProcessorManager; 48 import org.eclipse.jdt.internal.compiler.ClassFile; 49 import org.eclipse.jdt.internal.compiler.CompilationResult; 50 import org.eclipse.jdt.internal.compiler.Compiler; 51 import org.eclipse.jdt.internal.compiler.ICompilerRequestor; 52 import org.eclipse.jdt.internal.compiler.IErrorHandlingPolicy; 53 import org.eclipse.jdt.internal.compiler.IProblemFactory; 54 import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration; 55 import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; 56 import org.eclipse.jdt.internal.compiler.env.AccessRule; 57 import org.eclipse.jdt.internal.compiler.env.AccessRuleSet; 58 import org.eclipse.jdt.internal.compiler.env.ICompilationUnit; 59 import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; 60 import org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment; 61 import org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding; 62 import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory; 63 import org.eclipse.jdt.internal.compiler.problem.ProblemReporter; 64 import org.eclipse.jdt.internal.compiler.problem.ProblemSeverities; 65 import org.eclipse.jdt.internal.compiler.util.GenericXMLWriter; 66 import org.eclipse.jdt.internal.compiler.util.HashtableOfInt; 67 import org.eclipse.jdt.internal.compiler.util.Messages; 68 import org.eclipse.jdt.internal.compiler.util.SuffixConstants; 69 import org.eclipse.jdt.internal.compiler.util.HashtableOfObject; 70 import org.eclipse.jdt.internal.compiler.util.Util; 71 72 public class Main implements ProblemSeverities, SuffixConstants { 73 76 public static class ResourceBundleFactory { 77 private static HashMap Cache = new HashMap (); 78 public static synchronized ResourceBundle getBundle(Locale locale) { 79 ResourceBundle bundle = (ResourceBundle ) Cache.get(locale); 80 if (bundle == null) { 81 bundle = ResourceBundle.getBundle(Main.bundleName, locale); 82 Cache.put(locale, bundle); 83 } 84 return bundle; 85 } 86 } 87 88 public static class Logger { 89 private static final String CLASS = "class"; private static final String CLASS_FILE = "classfile"; private static final String CLASSPATH = "classpath"; private static final String CLASSPATH_FILE = "FILE"; private static final String CLASSPATH_FOLDER = "FOLDER"; private static final String CLASSPATH_ID = "id"; private static final String CLASSPATH_JAR = "JAR"; private static final String CLASSPATHS = "classpaths"; private static final String COMMAND_LINE_ARGUMENT = "argument"; private static final String COMMAND_LINE_ARGUMENTS = "command_line"; private static final String COMPILER = "compiler"; private static final String COMPILER_COPYRIGHT = "copyright"; private static final String COMPILER_NAME = "name"; private static final String COMPILER_VERSION = "version"; public static final int EMACS = 2; 104 private static final String ERROR = "ERROR"; private static final String ERROR_TAG = "error"; private static final String EXCEPTION = "exception"; private static final String EXTRA_PROBLEM_TAG = "extra_problem"; private static final String EXTRA_PROBLEMS = "extra_problems"; private static final HashtableOfInt FIELD_TABLE = new HashtableOfInt(); 110 private static final String KEY = "key"; private static final String MESSAGE = "message"; private static final String NUMBER_OF_CLASSFILES = "number_of_classfiles"; private static final String NUMBER_OF_ERRORS = "errors"; private static final String NUMBER_OF_LINES = "number_of_lines"; private static final String NUMBER_OF_PROBLEMS = "problems"; private static final String NUMBER_OF_TASKS = "tasks"; private static final String NUMBER_OF_WARNINGS = "warnings"; private static final String OPTION = "option"; private static final String OPTIONS = "options"; private static final String OUTPUT = "output"; private static final String PACKAGE = "package"; private static final String PATH = "path"; private static final String PROBLEM_ARGUMENT = "argument"; private static final String PROBLEM_ARGUMENT_VALUE = "value"; private static final String PROBLEM_ARGUMENTS = "arguments"; private static final String PROBLEM_CATEGORY_ID = "categoryID"; private static final String ID = "id"; private static final String PROBLEM_ID = "problemID"; private static final String PROBLEM_LINE = "line"; private static final String PROBLEM_OPTION_KEY = "optionKey"; private static final String PROBLEM_MESSAGE = "message"; private static final String PROBLEM_SEVERITY = "severity"; private static final String PROBLEM_SOURCE_END = "charEnd"; private static final String PROBLEM_SOURCE_START = "charStart"; private static final String PROBLEM_SUMMARY = "problem_summary"; private static final String PROBLEM_TAG = "problem"; private static final String PROBLEMS = "problems"; private static final String SOURCE = "source"; private static final String SOURCE_CONTEXT = "source_context"; private static final String SOURCE_END = "sourceEnd"; private static final String SOURCE_START = "sourceStart"; private static final String SOURCES = "sources"; private static final String STATS = "stats"; private static final String TASK = "task"; private static final String TASKS = "tasks"; private static final String TIME = "time"; private static final String VALUE = "value"; private static final String WARNING = "WARNING"; 150 public static final int XML = 1; 151 152 private static final String XML_DTD_DECLARATION = "<!DOCTYPE compiler PUBLIC \"-//Eclipse.org//DTD Eclipse JDT 3.2.003 Compiler//EN\" \"http://www.eclipse.org/jdt/core/compiler_32_003.dtd\">"; static { 154 try { 155 Class c = IProblem.class; 156 Field [] fields = c.getFields(); 157 for (int i = 0, max = fields.length; i < max; i++) { 158 Field field = fields[i]; 159 if (field.getType().equals(Integer.TYPE)) { 160 Integer value = (Integer ) field.get(null); 161 Logger.FIELD_TABLE.put(value.intValue() & IProblem.IgnoreCategoriesMask, field.getName()); 162 } 163 } 164 } catch (SecurityException e) { 165 e.printStackTrace(); 166 } catch (IllegalArgumentException e) { 167 e.printStackTrace(); 168 } catch (IllegalAccessException e) { 169 e.printStackTrace(); 170 } 171 } 172 private PrintWriter err; 173 private PrintWriter log; 174 private Main main; 175 private PrintWriter out; 176 private HashMap parameters; 177 int tagBits; 178 public Logger(Main main, PrintWriter out, PrintWriter err) { 179 this.out = out; 180 this.err = err; 181 this.parameters = new HashMap (); 182 this.main = main; 183 } 184 185 public String buildFileName( 186 String outputPath, 187 String relativeFileName) { 188 char fileSeparatorChar = File.separatorChar; 189 String fileSeparator = File.separator; 190 191 outputPath = outputPath.replace('/', fileSeparatorChar); 192 StringBuffer outDir = new StringBuffer (outputPath); 194 if (!outputPath.endsWith(fileSeparator)) { 195 outDir.append(fileSeparator); 196 } 197 StringTokenizer tokenizer = 198 new StringTokenizer (relativeFileName, fileSeparator); 199 String token = tokenizer.nextToken(); 200 while (tokenizer.hasMoreTokens()) { 201 outDir.append(token).append(fileSeparator); 202 token = tokenizer.nextToken(); 203 } 204 return outDir.append(token).toString(); 206 } 207 208 public void close() { 209 if (this.log != null) { 210 if ((this.tagBits & Logger.XML) != 0) { 211 this.endTag(Logger.COMPILER); 212 this.flush(); 213 } 214 this.log.close(); 215 } 216 } 217 218 221 public void compiling() { 222 this.printlnOut(this.main.bind("progress.compiling")); } 224 225 229 private void endLoggingProblems() { 230 this.endTag(Logger.PROBLEMS); 231 } 232 private void endLoggingExtraProblems() { 233 this.endTag(Logger.EXTRA_PROBLEMS); 234 } 235 public void endLoggingSource() { 236 if ((this.tagBits & Logger.XML) != 0) { 237 this.endTag(Logger.SOURCE); 238 } 239 } 240 241 public void endLoggingSources() { 242 if ((this.tagBits & Logger.XML) != 0) { 243 this.endTag(Logger.SOURCES); 244 } 245 } 246 247 public void endLoggingTasks() { 248 if ((this.tagBits & Logger.XML) != 0) { 249 this.endTag(Logger.TASKS); 250 } 251 } 252 private void endTag(String name) { 253 ((GenericXMLWriter) this.log).endTag(name, true, true); 254 } 255 private void extractContext(CategorizedProblem problem, char[] unitSource) { 256 int startPosition = problem.getSourceStart(); 258 int endPosition = problem.getSourceEnd(); 259 if (unitSource == null) { 260 if (problem.getOriginatingFileName() != null) { 261 try { 262 unitSource = Util.getFileCharContent(new File (new String (problem.getOriginatingFileName())), null); 263 } catch(IOException e) { 264 } 266 } 267 } 268 int length = unitSource== null ? 0 : unitSource.length; 269 if ((startPosition > endPosition) 270 || ((startPosition < 0) && (endPosition < 0)) 271 || (length <= 0) 272 || (endPosition > length)) { 273 this.parameters.put(Logger.VALUE, Messages.problem_noSourceInformation); 274 this.parameters.put(Logger.SOURCE_START, "-1"); this.parameters.put(Logger.SOURCE_END, "-1"); this.printTag(Logger.SOURCE_CONTEXT, this.parameters, true, true); 277 return; 278 } 279 280 char c; 281 286 int begin, end; 288 for (begin = startPosition >= length ? length - 1 : startPosition; begin > 0; begin--) { 289 if ((c = unitSource[begin - 1]) == '\n' || c == '\r') break; 290 } 291 for (end = endPosition >= length ? length - 1 : endPosition ; end+1 < length; end++) { 292 if ((c = unitSource[end + 1]) == '\r' || c == '\n') break; 293 } 294 295 while ((c = unitSource[begin]) == ' ' || c == '\t') begin++; 297 while ((c = unitSource[end]) == ' ' || c == '\t') end--; 298 299 StringBuffer buffer = new StringBuffer (); 301 buffer.append(unitSource, begin, end - begin + 1); 302 303 this.parameters.put(Logger.VALUE, String.valueOf(buffer)); 304 this.parameters.put(Logger.SOURCE_START, Integer.toString(startPosition - begin)); 305 this.parameters.put(Logger.SOURCE_END, Integer.toString(endPosition - begin)); 306 this.printTag(Logger.SOURCE_CONTEXT, this.parameters, true, true); 307 } 308 309 public void flush() { 310 this.out.flush(); 311 this.err.flush(); 312 if (this.log != null) { 313 this.log.flush(); 314 } 315 } 316 private String getFieldName(int id) { 317 return (String ) Logger.FIELD_TABLE.get(id & IProblem.IgnoreCategoriesMask); 318 } 319 320 private String getProblemOptionKey(int problemID) { 322 long irritant = ProblemReporter.getIrritant(problemID); 323 return CompilerOptions.optionKeyFromIrritant(irritant); 324 } 325 326 public void logAverage(long[] times, long lineCount) { 327 Arrays.sort(times); 328 final int length = times.length; 329 long sum = 0; 330 for (int i = 1, max = length - 1; i < max; i++) { 331 sum += times[i]; 332 } 333 long time = sum / (length - 2); 334 this.printlnOut(this.main.bind( 335 "compile.averageTime", new String [] { 337 String.valueOf(lineCount), 338 String.valueOf(time), 339 String.valueOf(((int) (lineCount * 10000.0 / time)) / 10.0) })); 340 } 341 342 public void logClassFile(boolean generatePackagesStructure, String outputPath, String relativeFileName) { 343 if ((this.tagBits & Logger.XML) != 0) { 344 String fileName = null; 345 if (generatePackagesStructure) { 346 fileName = buildFileName(outputPath, relativeFileName); 347 } else { 348 char fileSeparatorChar = File.separatorChar; 349 String fileSeparator = File.separator; 350 outputPath = outputPath.replace('/', fileSeparatorChar); 352 int indexOfPackageSeparator = relativeFileName.lastIndexOf(fileSeparatorChar); 354 if (indexOfPackageSeparator == -1) { 355 if (outputPath.endsWith(fileSeparator)) { 356 fileName = outputPath + relativeFileName; 357 } else { 358 fileName = outputPath + fileSeparator + relativeFileName; 359 } 360 } else { 361 int length = relativeFileName.length(); 362 if (outputPath.endsWith(fileSeparator)) { 363 fileName = outputPath + relativeFileName.substring(indexOfPackageSeparator + 1, length); 364 } else { 365 fileName = outputPath + fileSeparator + relativeFileName.substring(indexOfPackageSeparator + 1, length); 366 } 367 } 368 } 369 File f = new File (fileName); 370 try { 371 this.parameters.put(Logger.PATH, f.getCanonicalPath()); 372 this.printTag(Logger.CLASS_FILE, this.parameters, true, true); 373 } catch (IOException e) { 374 this.logNoClassFileCreated(outputPath, relativeFileName, e); 375 } 376 } 377 } 378 public void logClasspath(FileSystem.Classpath[] classpaths) { 379 if (classpaths == null) return; 380 if ((this.tagBits & Logger.XML) != 0) { 381 final int length = classpaths.length; 382 if (length != 0) { 383 this.printTag(Logger.CLASSPATHS, null, true, false); 385 for (int i = 0; i < length; i++) { 386 String classpath = classpaths[i].getPath(); 387 this.parameters.put(Logger.PATH, classpath); 388 File f = new File (classpath); 389 String id = null; 390 if (f.isFile()) { 391 if (Util.isArchiveFileName(classpath)) { 392 id = Logger.CLASSPATH_JAR; 393 } else { 394 id = Logger.CLASSPATH_FILE; 395 } 396 } else if (f.isDirectory()) { 397 id = Logger.CLASSPATH_FOLDER; 398 } 399 if (id != null) { 400 this.parameters.put(Logger.CLASSPATH_ID, id); 401 this.printTag(Logger.CLASSPATH, this.parameters, true, true); 402 } 403 } 404 this.endTag(Logger.CLASSPATHS); 405 } 406 } 407 408 } 409 public void logCommandLineArguments(String [] commandLineArguments) { 410 if (commandLineArguments == null) return; 411 if ((this.tagBits & Logger.XML) != 0) { 412 final int length = commandLineArguments.length; 413 if (length != 0) { 414 this.printTag(Logger.COMMAND_LINE_ARGUMENTS, null, true, false); 416 for (int i = 0; i < length; i++) { 417 this.parameters.put(Logger.VALUE, commandLineArguments[i]); 418 this.printTag(Logger.COMMAND_LINE_ARGUMENT, this.parameters, true, true); 419 } 420 this.endTag(Logger.COMMAND_LINE_ARGUMENTS); 421 } 422 } 423 } 424 425 428 public void logException(Exception e) { 429 StringWriter writer = new StringWriter (); 430 PrintWriter printWriter = new PrintWriter (writer); 431 e.printStackTrace(printWriter); 432 printWriter.flush(); 433 printWriter.close(); 434 final String stackTrace = writer.getBuffer().toString(); 435 if ((this.tagBits & Logger.XML) != 0) { 436 LineNumberReader reader = new LineNumberReader (new StringReader (stackTrace)); 437 String line; 438 int i = 0; 439 StringBuffer buffer = new StringBuffer (); 440 String message = e.getMessage(); 441 if (message != null) { 442 buffer.append(message).append(Util.LINE_SEPARATOR); 443 } 444 try { 445 while ((line = reader.readLine()) != null && i < 4) { 446 buffer.append(line).append(Util.LINE_SEPARATOR); 447 i++; 448 } 449 reader.close(); 450 } catch (IOException e1) { 451 } 453 message = buffer.toString(); 454 this.parameters.put(Logger.MESSAGE, message); 455 this.parameters.put(Logger.CLASS, e.getClass()); 456 this.printTag(Logger.EXCEPTION, this.parameters, true, true); 457 } 458 String message = e.getMessage(); 459 if (message == null) { 460 this.printlnErr(stackTrace); 461 } else { 462 this.printlnErr(message); 463 } 464 } 465 466 470 public void logIncorrectClasspath(String wrongClasspath) { 471 if ((this.tagBits & Logger.XML) != 0) { 472 this.parameters.put(Logger.MESSAGE, this.main.bind("configure.incorrectClasspath", wrongClasspath)); this.printTag(Logger.ERROR_TAG, this.parameters, true, true); 474 } 475 this.printlnErr(this.main.bind( 476 "configure.incorrectClasspath", wrongClasspath)); } 478 479 483 public void logIncorrectEndorsedDirsEntry(String wrongPath) { 484 if ((this.tagBits & Logger.XML) != 0) { 485 this.parameters.put(Logger.MESSAGE, this.main.bind("configure.incorrectEndorsedDirsEntry", wrongPath)); this.printTag(Logger.ERROR_TAG, this.parameters, true, true); 487 } 488 this.printlnErr(this.main.bind( 489 "configure.incorrectEndorsedDirsEntry", wrongPath)); } 491 492 496 public void logIncorrectExtDirsEntry(String wrongPath) { 497 if ((this.tagBits & Logger.XML) != 0) { 498 this.parameters.put(Logger.MESSAGE, this.main.bind("configure.incorrectExtDirsEntry", wrongPath)); this.printTag(Logger.ERROR_TAG, this.parameters, true, true); 500 } 501 this.printlnErr(this.main.bind( 502 "configure.incorrectExtDirsEntry", wrongPath)); } 504 505 public void logIncorrectVMVersionForAnnotationProcessing() { 506 if ((this.tagBits & Logger.XML) != 0) { 507 this.parameters.put(Logger.MESSAGE, this.main.bind("configure.incorrectVMVersionforAPT")); this.printTag(Logger.ERROR_TAG, this.parameters, true, true); 509 } 510 this.printlnErr(this.main.bind("configure.incorrectVMVersionforAPT")); } 512 513 516 public void logNoClassFileCreated(String outputDir, String relativeFileName, IOException e) { 517 if ((this.tagBits & Logger.XML) != 0) { 518 this.parameters.put(Logger.MESSAGE, this.main.bind("output.noClassFileCreated", new String [] { 520 outputDir, 521 relativeFileName, 522 e.getMessage() 523 })); 524 this.printTag(Logger.ERROR_TAG, this.parameters, true, true); 525 } 526 this.printlnErr(this.main.bind("output.noClassFileCreated", new String [] { 528 outputDir, 529 relativeFileName, 530 e.getMessage() 531 })); 532 } 533 534 public void logNoClasspath() { 535 if ((this.tagBits & Logger.XML) != 0) { 536 this.parameters.put(Logger.MESSAGE, this.main.bind("configure.noClasspath")); this.printTag(Logger.ERROR_TAG, this.parameters, true, true); 538 } 539 this.printlnErr(this.main.bind("configure.noClasspath")); } 541 542 545 public void logNumberOfClassFilesGenerated(int exportedClassFilesCounter) { 546 if ((this.tagBits & Logger.XML) != 0) { 547 this.parameters.put(Logger.VALUE, new Integer (exportedClassFilesCounter)); 548 this.printTag(Logger.NUMBER_OF_CLASSFILES, this.parameters, true, true); 549 } 550 if (exportedClassFilesCounter == 1) { 551 this.printlnOut(this.main.bind("compile.oneClassFileGenerated")); } else { 553 this.printlnOut(this.main.bind("compile.severalClassFilesGenerated", String.valueOf(exportedClassFilesCounter))); 555 } 556 } 557 558 561 public void logOptions(Map options) { 562 if ((this.tagBits & Logger.XML) != 0) { 563 this.printTag(Logger.OPTIONS, null, true, false); 564 final Set entriesSet = options.entrySet(); 565 Object [] entries = entriesSet.toArray(); 566 Arrays.sort(entries, new Comparator () { 567 public int compare(Object o1, Object o2) { 568 Map.Entry entry1 = (Map.Entry ) o1; 569 Map.Entry entry2 = (Map.Entry ) o2; 570 return ((String ) entry1.getKey()).compareTo((String ) entry2.getKey()); 571 } 572 }); 573 for (int i = 0, max = entries.length; i < max; i++) { 574 Map.Entry entry = (Map.Entry ) entries[i]; 575 String key = (String ) entry.getKey(); 576 this.parameters.put(Logger.KEY, key); 577 this.parameters.put(Logger.VALUE, entry.getValue()); 578 this.printTag(Logger.OPTION, this.parameters, true, true); 579 } 580 this.endTag(Logger.OPTIONS); 581 } 582 } 583 584 private void logProblem(CategorizedProblem problem, int localErrorCount, 585 int globalErrorCount, char[] unitSource) { 586 if ((this.tagBits & Logger.EMACS) != 0) { 587 String result = (new String (problem.getOriginatingFileName()) 588 + ":" + problem.getSourceLineNumber() 590 + ": " + (problem.isError() ? this.main.bind("output.emacs.error") : this.main.bind("output.emacs.warning")) + ": " + problem.getMessage()); 594 this.printlnErr(result); 595 final String errorReportSource = errorReportSource(problem, unitSource, this.tagBits); 596 if (errorReportSource.length() != 0) this.printlnErr(errorReportSource); 597 } else { 598 if (localErrorCount == 0) { 599 this.printlnErr("----------"); } 601 this.printErr(problem.isError() ? 602 this.main.bind( 603 "requestor.error", Integer.toString(globalErrorCount), 605 new String (problem.getOriginatingFileName())) 606 : this.main.bind( 607 "requestor.warning", Integer.toString(globalErrorCount), 609 new String (problem.getOriginatingFileName()))); 610 try { 611 final String errorReportSource = errorReportSource(problem, unitSource, 0); 612 this.printlnErr(errorReportSource); 613 this.printlnErr(problem.getMessage()); 614 } catch (Exception e) { 615 this.printlnErr(this.main.bind( 616 "requestor.notRetrieveErrorMessage", problem.toString())); } 618 this.printlnErr("----------"); } 620 } 621 622 public int logProblems(CategorizedProblem[] problems, char[] unitSource, Main currentMain) { 623 final int count = problems.length; 624 int localErrorCount = 0; 625 int localProblemCount = 0; 626 if (count != 0) { 627 int errors = 0; 628 int warnings = 0; 629 int tasks = 0; 630 for (int i = 0; i < count; i++) { 631 CategorizedProblem problem = problems[i]; 632 if (problem != null) { 633 currentMain.globalProblemsCount++; 634 this.logProblem(problem, localProblemCount, currentMain.globalProblemsCount, unitSource); 635 localProblemCount++; 636 if (problem.isError()) { 637 localErrorCount++; 638 errors++; 639 currentMain.globalErrorsCount++; 640 } else if (problem.getID() == IProblem.Task) { 641 currentMain.globalTasksCount++; 642 tasks++; 643 } else { 644 currentMain.globalWarningsCount++; 645 warnings++; 646 } 647 } 648 } 649 if ((this.tagBits & Logger.XML) != 0) { 650 if ((errors + warnings) != 0) { 651 this.startLoggingProblems(errors, warnings); 652 for (int i = 0; i < count; i++) { 653 CategorizedProblem problem = problems[i]; 654 if (problem!= null) { 655 if (problem.getID() != IProblem.Task) { 656 this.logXmlProblem(problem, unitSource); 657 } 658 } 659 } 660 this.endLoggingProblems(); 661 } 662 if (tasks != 0) { 663 this.startLoggingTasks(tasks); 664 for (int i = 0; i < count; i++) { 665 CategorizedProblem problem = problems[i]; 666 if (problem!= null) { 667 if (problem.getID() == IProblem.Task) { 668 this.logXmlTask(problem, unitSource); 669 } 670 } 671 } 672 this.endLoggingTasks(); 673 } 674 } 675 } 676 return localErrorCount; 677 } 678 679 684 public void logProblemsSummary(int globalProblemsCount, 685 int globalErrorsCount, int globalWarningsCount, int globalTasksCount) { 686 if ((this.tagBits & Logger.XML) != 0) { 687 this.parameters.put(Logger.NUMBER_OF_PROBLEMS, new Integer (globalProblemsCount)); 689 this.parameters.put(Logger.NUMBER_OF_ERRORS, new Integer (globalErrorsCount)); 690 this.parameters.put(Logger.NUMBER_OF_WARNINGS, new Integer (globalWarningsCount)); 691 this.parameters.put(Logger.NUMBER_OF_TASKS, new Integer (globalTasksCount)); 692 this.printTag(Logger.PROBLEM_SUMMARY, this.parameters, true, true); 693 } 694 if (globalProblemsCount == 1) { 695 String message = null; 696 if (globalErrorsCount == 1) { 697 message = this.main.bind("compile.oneError"); } else { 699 message = this.main.bind("compile.oneWarning"); } 701 this.printErr(this.main.bind("compile.oneProblem", message)); } else { 703 String errorMessage = null; 704 String warningMessage = null; 705 if (globalErrorsCount > 0) { 706 if (globalErrorsCount == 1) { 707 errorMessage = this.main.bind("compile.oneError"); } else { 709 errorMessage = this.main.bind("compile.severalErrors", String.valueOf(globalErrorsCount)); } 711 } 712 int warningsNumber = globalWarningsCount + globalTasksCount; 713 if (warningsNumber > 0) { 714 if (warningsNumber == 1) { 715 warningMessage = this.main.bind("compile.oneWarning"); } else { 717 warningMessage = this.main.bind("compile.severalWarnings", String.valueOf(warningsNumber)); } 719 } 720 if (errorMessage == null || warningMessage == null) { 721 if (errorMessage == null) { 722 this.printErr(this.main.bind( 723 "compile.severalProblemsErrorsOrWarnings", String.valueOf(globalProblemsCount), 725 warningMessage)); 726 } else { 727 this.printErr(this.main.bind( 728 "compile.severalProblemsErrorsOrWarnings", String.valueOf(globalProblemsCount), 730 errorMessage)); 731 } 732 } else { 733 this.printErr(this.main.bind( 734 "compile.severalProblemsErrorsAndWarnings", new String [] { 736 String.valueOf(globalProblemsCount), 737 errorMessage, 738 warningMessage 739 })); 740 } 741 } 742 if ((this.tagBits & Logger.EMACS) != 0) { 743 this.printlnErr(); 744 } 745 } 746 747 750 public void logProgress() { 751 this.printOut('.'); 752 } 753 754 760 public void logRepetition(int i, int repetitions) { 761 this.printlnOut(this.main.bind("compile.repetition", String.valueOf(i + 1), String.valueOf(repetitions))); 763 } 764 765 769 public void logTiming(long time, long lineCount) { 770 if ((this.tagBits & Logger.XML) != 0) { 771 this.parameters.put(Logger.VALUE, new Long (time)); 772 this.printTag(Logger.TIME, this.parameters, true, true); 773 this.parameters.put(Logger.VALUE, new Long (lineCount)); 774 this.printTag(Logger.NUMBER_OF_LINES, this.parameters, true, true); 775 } 776 if (lineCount != 0) { 777 this.printlnOut(this.main.bind( 778 "compile.instantTime", new String [] { 780 String.valueOf(lineCount), 781 String.valueOf(time), 782 String.valueOf(((int) (lineCount * 10000.0 / time)) / 10.0) })); 783 } else { 784 this.printlnOut(this.main.bind("compile.totalTime", String.valueOf(time))); } 786 } 787 788 792 public void logUsage(String usage) { 793 this.printlnOut(usage); 794 } 795 796 799 public void logVersion(final boolean printToOut) { 800 if (this.log != null && (this.tagBits & Logger.XML) == 0) { 801 final String version = this.main.bind("misc.version", new String [] { 803 this.main.bind("compiler.name"), this.main.bind("compiler.version"), this.main.bind("compiler.copyright") } 807 ); 808 this.log.println("# " + version); if (printToOut) { 810 this.out.println(version); 811 this.out.flush(); 812 } 813 } else if (printToOut) { 814 final String version = this.main.bind("misc.version", new String [] { 816 this.main.bind("compiler.name"), this.main.bind("compiler.version"), this.main.bind("compiler.copyright") } 820 ); 821 this.out.println(version); 822 this.out.flush(); 823 } 824 } 825 828 public void logWrongJDK() { 829 if ((this.tagBits & Logger.XML) != 0) { 830 this.parameters.put(Logger.MESSAGE, this.main.bind("configure.requiresJDK1.2orAbove")); this.printTag(Logger.ERROR, this.parameters, true, true); 832 } 833 this.printlnErr(this.main.bind("configure.requiresJDK1.2orAbove")); } 835 836 842 private void logXmlProblem(CategorizedProblem problem, char[] unitSource) { 843 final int sourceStart = problem.getSourceStart(); 844 final int sourceEnd = problem.getSourceEnd(); 845 final int id = problem.getID(); 846 this.parameters.put(Logger.ID, getFieldName(id)); this.parameters.put(Logger.PROBLEM_ID, new Integer (id)); boolean isError = problem.isError(); 849 int severity = isError ? ProblemSeverities.Error : ProblemSeverities.Warning; 850 this.parameters.put(Logger.PROBLEM_SEVERITY, isError ? Logger.ERROR : Logger.WARNING); 851 this.parameters.put(Logger.PROBLEM_LINE, new Integer (problem.getSourceLineNumber())); 852 this.parameters.put(Logger.PROBLEM_SOURCE_START, new Integer (sourceStart)); 853 this.parameters.put(Logger.PROBLEM_SOURCE_END, new Integer (sourceEnd)); 854 String problemOptionKey = getProblemOptionKey(id); 855 if (problemOptionKey != null) { 856 this.parameters.put(Logger.PROBLEM_OPTION_KEY, problemOptionKey); 857 } 858 int categoryID = ProblemReporter.getProblemCategory(severity, id); 859 this.parameters.put(Logger.PROBLEM_CATEGORY_ID, new Integer (categoryID)); 860 this.printTag(Logger.PROBLEM_TAG, this.parameters, true, false); 861 this.parameters.put(Logger.VALUE, problem.getMessage()); 862 this.printTag(Logger.PROBLEM_MESSAGE, this.parameters, true, true); 863 extractContext(problem, unitSource); 864 String [] arguments = problem.getArguments(); 865 final int length = arguments.length; 866 if (length != 0) { 867 this.printTag(Logger.PROBLEM_ARGUMENTS, null, true, false); 868 for (int i = 0; i < length; i++) { 869 this.parameters.put(Logger.PROBLEM_ARGUMENT_VALUE, arguments[i]); 870 this.printTag(Logger.PROBLEM_ARGUMENT, this.parameters, true, true); 871 } 872 this.endTag(Logger.PROBLEM_ARGUMENTS); 873 } 874 this.endTag(Logger.PROBLEM_TAG); 875 } 876 877 883 private void logXmlTask(CategorizedProblem problem, char[] unitSource) { 884 this.parameters.put(Logger.PROBLEM_LINE, new Integer (problem.getSourceLineNumber())); 885 this.parameters.put(Logger.PROBLEM_SOURCE_START, new Integer (problem.getSourceStart())); 886 this.parameters.put(Logger.PROBLEM_SOURCE_END, new Integer (problem.getSourceEnd())); 887 String problemOptionKey = getProblemOptionKey(problem.getID()); 888 if (problemOptionKey != null) { 889 this.parameters.put(Logger.PROBLEM_OPTION_KEY, problemOptionKey); 890 } 891 this.printTag(Logger.TASK, this.parameters, true, false); 892 this.parameters.put(Logger.VALUE, problem.getMessage()); 893 this.printTag(Logger.PROBLEM_MESSAGE, this.parameters, true, true); 894 extractContext(problem, unitSource); 895 this.endTag(Logger.TASK); 896 } 897 898 private void printErr(String s) { 899 this.err.print(s); 900 if ((this.tagBits & Logger.XML) == 0 && this.log != null) { 901 this.log.print(s); 902 } 903 } 904 905 private void printlnErr() { 906 this.err.println(); 907 if ((this.tagBits & Logger.XML) == 0 && this.log != null) { 908 this.log.println(); 909 } 910 } 911 private void printlnErr(String s) { 912 this.err.println(s); 913 if ((this.tagBits & Logger.XML) == 0 && this.log != null) { 914 this.log.println(s); 915 } 916 } 917 private void printlnOut(String s) { 918 this.out.println(s); 919 if ((this.tagBits & Logger.XML) == 0 && this.log != null) { 920 this.log.println(s); 921 } 922 } 923 924 927 public void printNewLine() { 928 this.out.println(); 929 } 930 931 private void printOut(char c) { 932 this.out.print(c); 933 } 934 935 public void printStats() { 936 final boolean isTimed = this.main.timing; 937 if ((this.tagBits & Logger.XML) != 0) { 938 this.printTag(Logger.STATS, null, true, false); 939 } 940 if (isTimed) { 941 long time = System.currentTimeMillis() - this.main.startTime; 942 this.logTiming(time, this.main.lineCount); 943 if (this.main.times != null) { 944 this.main.times[this.main.timesCounter++] = time; 945 } 946 } 947 if (this.main.globalProblemsCount > 0) { 948 this.logProblemsSummary(this.main.globalProblemsCount, this.main.globalErrorsCount, this.main.globalWarningsCount, main.globalTasksCount); 949 } 950 if (this.main.exportedClassFilesCounter != 0 951 && (this.main.showProgress || isTimed || this.main.verbose)) { 952 this.logNumberOfClassFilesGenerated(this.main.exportedClassFilesCounter); 953 } 954 if ((this.tagBits & Logger.XML) != 0) { 955 this.endTag(Logger.STATS); 956 } 957 } 958 959 private void printTag(String name, HashMap params, boolean insertNewLine, boolean closeTag) { 960 ((GenericXMLWriter) this.log).printTag(name, parameters, true, insertNewLine, closeTag); 961 this.parameters.clear(); 962 } 963 964 public void setEmacs() { 965 this.tagBits |= Logger.EMACS; 966 } 967 968 public void setLog(String logFileName) throws InvalidInputException { 969 final Date date = new Date (); 970 final DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.LONG, Locale.getDefault()); 971 try { 972 int index = logFileName.lastIndexOf('.'); 973 if (index != -1) { 974 if (logFileName.substring(index).toLowerCase().equals(".xml")) { this.log = new GenericXMLWriter(new FileOutputStream (logFileName, false), Util.LINE_SEPARATOR, true); 976 this.tagBits |= Logger.XML; 977 try { 979 this.log.println("<!-- " + new String (dateFormat.format(date).getBytes(), "UTF-8") + " -->"); } catch (UnsupportedEncodingException e) { 981 e.printStackTrace(); 982 } 983 this.log.println(Logger.XML_DTD_DECLARATION); 984 this.parameters.put(Logger.COMPILER_NAME, this.main.bind("compiler.name")); this.parameters.put(Logger.COMPILER_VERSION, this.main.bind("compiler.version")); this.parameters.put(Logger.COMPILER_COPYRIGHT, this.main.bind("compiler.copyright")); this.printTag(Logger.COMPILER, this.parameters, true, false); 988 } else { 989 this.log = new PrintWriter (new FileOutputStream (logFileName, false)); 990 this.log.println("# " + dateFormat.format(date)); } 992 } else { 993 this.log = new PrintWriter (new FileOutputStream (logFileName, false)); 994 this.log.println("# " + dateFormat.format(date)); } 996 } catch (FileNotFoundException e) { 997 throw new InvalidInputException(this.main.bind("configure.cannotOpenLog", logFileName)); } 999 } 1000 1001 1005 private void startLoggingProblems(int errors, int warnings) { 1006 this.parameters.put(Logger.NUMBER_OF_PROBLEMS, new Integer (errors + warnings)); 1007 this.parameters.put(Logger.NUMBER_OF_ERRORS, new Integer (errors)); 1008 this.parameters.put(Logger.NUMBER_OF_WARNINGS, new Integer (warnings)); 1009 this.printTag(Logger.PROBLEMS, this.parameters, true, false); 1010 } 1011 1012 private void startLoggingExtraProblems(int count) { 1013 this.parameters.put(Logger.NUMBER_OF_PROBLEMS, new Integer (count)); 1014 this.printTag(Logger.EXTRA_PROBLEMS, this.parameters, true, false); 1015 } 1016 1017 public void startLoggingSource(CompilationResult compilationResult) { 1018 if ((this.tagBits & Logger.XML) != 0) { 1019 ICompilationUnit compilationUnit = compilationResult.compilationUnit; 1020 if (compilationUnit != null) { 1021 char[] fileName = compilationUnit.getFileName(); 1022 File f = new File (new String (fileName)); 1023 if (fileName != null) { 1024 this.parameters.put(Logger.PATH, f.getAbsolutePath()); 1025 } 1026 char[][] packageName = compilationResult.packageName; 1027 if (packageName != null) { 1028 this.parameters.put( 1029 Logger.PACKAGE, 1030 new String (CharOperation.concatWith(packageName, File.separatorChar))); 1031 } 1032 CompilationUnit unit = (CompilationUnit) compilationUnit; 1033 String destinationPath = unit.destinationPath; 1034 if (destinationPath == null) { 1035 destinationPath = this.main.destinationPath; 1036 } 1037 if (destinationPath != null && destinationPath != NONE) { 1038 if (File.separatorChar == '/') { 1039 this.parameters.put(Logger.OUTPUT, destinationPath); 1040 } else { 1041 this.parameters.put(Logger.OUTPUT, destinationPath.replace('/', File.separatorChar)); 1042 } 1043 } 1044 } 1045 this.printTag(Logger.SOURCE, this.parameters, true, false); 1046 } 1047 } 1048 public void startLoggingSources() { 1049 if ((this.tagBits & Logger.XML) != 0) { 1050 this.printTag(Logger.SOURCES, null, true, false); 1051 } 1052 } 1053 public void startLoggingTasks(int tasks) { 1054 if ((this.tagBits & Logger.XML) != 0) { 1055 this.parameters.put(Logger.NUMBER_OF_TASKS, new Integer (tasks)); 1056 this.printTag(Logger.TASKS, this.parameters, true, false); 1057 } 1058 } 1059 1060 public void loggingExtraProblems(Main currentMain) { 1061 ArrayList problems = currentMain.extraProblems; 1062 final int count = problems.size(); 1063 int localErrorCount = 0; 1064 int localProblemCount = 0; 1065 if (count != 0) { 1066 int errors = 0; 1067 int warnings = 0; 1068 for (int i = 0; i < count; i++) { 1069 CategorizedProblem problem = (CategorizedProblem) problems.get(i); 1070 if (problem != null) { 1071 currentMain.globalProblemsCount++; 1072 this.logExtraProblem(problem, localProblemCount, currentMain.globalProblemsCount); 1073 localProblemCount++; 1074 if (problem.isError()) { 1075 localErrorCount++; 1076 errors++; 1077 currentMain.globalErrorsCount++; 1078 } else if (problem.isWarning()) { 1079 currentMain.globalWarningsCount++; 1080 warnings++; 1081 } 1082 } 1083 } 1084 if ((this.tagBits & Logger.XML) != 0) { 1085 if ((errors + warnings) != 0) { 1086 this.startLoggingExtraProblems(count); 1087 for (int i = 0; i < count; i++) { 1088 CategorizedProblem problem = (CategorizedProblem) problems.get(i); 1089 if (problem!= null) { 1090 if (problem.getID() != IProblem.Task) { 1091 this.logXmlExtraProblem(problem, localProblemCount, currentMain.globalProblemsCount); 1092 } 1093 } 1094 } 1095 this.endLoggingExtraProblems(); 1096 } 1097 } 1098 } 1099 } 1100 1101 private void logXmlExtraProblem(CategorizedProblem problem, int globalErrorCount, int localErrorCount) { 1102 final int sourceStart = problem.getSourceStart(); 1103 final int sourceEnd = problem.getSourceEnd(); 1104 boolean isError = problem.isError(); 1105 this.parameters.put(Logger.PROBLEM_SEVERITY, isError ? Logger.ERROR : Logger.WARNING); 1106 this.parameters.put(Logger.PROBLEM_LINE, new Integer (problem.getSourceLineNumber())); 1107 this.parameters.put(Logger.PROBLEM_SOURCE_START, new Integer (sourceStart)); 1108 this.parameters.put(Logger.PROBLEM_SOURCE_END, new Integer (sourceEnd)); 1109 this.printTag(Logger.EXTRA_PROBLEM_TAG, this.parameters, true, false); 1110 this.parameters.put(Logger.VALUE, problem.getMessage()); 1111 this.printTag(Logger.PROBLEM_MESSAGE, this.parameters, true, true); 1112 extractContext(problem, null); 1113 this.endTag(Logger.EXTRA_PROBLEM_TAG); 1114 } 1115 1116 private void logExtraProblem(CategorizedProblem problem, int localErrorCount, int globalErrorCount) { 1117 char[] originatingFileName = problem.getOriginatingFileName(); 1118 String fileName = 1119 originatingFileName == null 1120 ? this.main.bind("requestor.noFileNameSpecified") : new String (originatingFileName); 1122 if ((this.tagBits & Logger.EMACS) != 0) { 1123 String result = fileName 1124 + ":" + problem.getSourceLineNumber() 1126 + ": " + (problem.isError() ? this.main.bind("output.emacs.error") : this.main.bind("output.emacs.warning")) + ": " + problem.getMessage(); 1130 this.printlnErr(result); 1131 final String errorReportSource = errorReportSource(problem, null, this.tagBits); 1132 this.printlnErr(errorReportSource); 1133 } else { 1134 if (localErrorCount == 0) { 1135 this.printlnErr("----------"); } 1137 this.printErr(problem.isError() ? 1138 this.main.bind( 1139 "requestor.error", Integer.toString(globalErrorCount), 1141 new String (fileName)) 1142 : this.main.bind( 1143 "requestor.warning", Integer.toString(globalErrorCount), 1145 new String (fileName))); 1146 final String errorReportSource = errorReportSource(problem, null, 0); 1147 this.printlnErr(errorReportSource); 1148 this.printlnErr(problem.getMessage()); 1149 this.printlnErr("----------"); } 1151 } 1152 1153 private String errorReportSource(CategorizedProblem problem, char[] unitSource, int bits) { 1154 1158 1160 int startPosition = problem.getSourceStart(); 1162 int endPosition = problem.getSourceEnd(); 1163 if (unitSource == null) { 1164 if (problem.getOriginatingFileName() != null) { 1165 try { 1166 unitSource = Util.getFileCharContent(new File (new String (problem.getOriginatingFileName())), null); 1167 } catch (IOException e) { 1168 } 1170 } 1171 } 1172 int length = unitSource == null ? 0 : unitSource.length; 1173 if ((startPosition > endPosition) 1174 || ((startPosition < 0) && (endPosition < 0)) 1175 || length == 0) 1176 return Messages.problem_noSourceInformation; 1177 1178 StringBuffer errorBuffer = new StringBuffer (); 1179 if ((bits & Main.Logger.EMACS) == 0) { 1180 errorBuffer.append(' ').append(Messages.bind(Messages.problem_atLine, String.valueOf(problem.getSourceLineNumber()))); 1181 errorBuffer.append(Util.LINE_SEPARATOR); 1182 } 1183 errorBuffer.append('\t'); 1184 1185 char c; 1186 final char SPACE = '\u0020'; 1187 final char MARK = '^'; 1188 final char TAB = '\t'; 1189 1194 int begin; 1196 int end; 1197 for (begin = startPosition >= length ? length - 1 : startPosition; begin > 0; begin--) { 1198 if ((c = unitSource[begin - 1]) == '\n' || c == '\r') break; 1199 } 1200 for (end = endPosition >= length ? length - 1 : endPosition ; end+1 < length; end++) { 1201 if ((c = unitSource[end + 1]) == '\r' || c == '\n') break; 1202 } 1203 1204 while ((c = unitSource[begin]) == ' ' || c == '\t') begin++; 1206 1208 errorBuffer.append(unitSource, begin, end-begin+1); 1210 errorBuffer.append(Util.LINE_SEPARATOR).append("\t"); 1212 for (int i = begin; i <startPosition; i++) { 1214 errorBuffer.append((unitSource[i] == TAB) ? TAB : SPACE); 1215 } 1216 for (int i = startPosition; i <= (endPosition >= length ? length - 1 : endPosition); i++) { 1217 errorBuffer.append(MARK); 1218 } 1219 return errorBuffer.toString(); 1220 } 1221 } 1222 public final static String bundleName = "org.eclipse.jdt.internal.compiler.batch.messages"; 1224 public static final int DEFAULT_SIZE_CLASSPATH = 4; 1227 public static final String NONE = "none"; 1229 1232 public static boolean compile(String commandLine) { 1233 1234 return compile(commandLine, new PrintWriter (System.out), new PrintWriter (System.err)); 1235 } 1236 1239 public static boolean compile(String commandLine, PrintWriter outWriter, PrintWriter errWriter) { 1240 1241 return new Main(outWriter, errWriter, false).compile(tokenize(commandLine)); 1242 } 1243 public static File [][] getLibrariesFiles(File [] files) { 1244 FilenameFilter filter = new FilenameFilter () { 1245 public boolean accept(File dir, String name) { 1246 String lowerCaseName = name.toLowerCase(); 1247 if (lowerCaseName.endsWith(SuffixConstants.SUFFIX_STRING_jar) || lowerCaseName.endsWith(SuffixConstants.SUFFIX_STRING_zip)) { 1248 return true; 1249 } 1250 return false; 1251 } 1252 }; 1253 final int filesLength = files.length; 1254 File [][] result = new File [filesLength][]; 1255 for (int i = 0; i < filesLength; i++) { 1256 File currentFile = files[i]; 1257 if (currentFile.exists() && currentFile.isDirectory()) { 1258 result[i] = currentFile.listFiles(filter); 1259 } 1260 } 1261 return result; 1262 } 1263 public static void main(String [] argv) { 1264 new Main(new PrintWriter (System.out), new PrintWriter (System.err), true).compile(argv); 1265 } 1266 public static String [] tokenize(String commandLine) { 1267 1268 int count = 0; 1269 String [] arguments = new String [10]; 1270 StringTokenizer tokenizer = new StringTokenizer (commandLine, " \"", true); String token = Util.EMPTY_STRING; 1272 boolean insideQuotes = false; 1273 boolean startNewToken = true; 1274 1275 while (tokenizer.hasMoreTokens()) { 1281 token = tokenizer.nextToken(); 1282 1283 if (token.equals(" ")) { if (insideQuotes) { 1285 arguments[count - 1] += token; 1286 startNewToken = false; 1287 } else { 1288 startNewToken = true; 1289 } 1290 } else if (token.equals("\"")) { if (!insideQuotes && startNewToken) { 1292 if (count == arguments.length) 1293 System.arraycopy(arguments, 0, (arguments = new String [count * 2]), 0, count); 1294 arguments[count++] = Util.EMPTY_STRING; 1295 } 1296 insideQuotes = !insideQuotes; 1297 startNewToken = false; 1298 } else { 1299 if (insideQuotes) { 1300 arguments[count - 1] += token; 1301 } else { 1302 if (token.length() > 0 && !startNewToken) { 1303 arguments[count - 1] += token; 1304 } else { 1305 if (count == arguments.length) 1306 System.arraycopy(arguments, 0, (arguments = new String [count * 2]), 0, count); 1307 String trimmedToken = token.trim(); 1308 if (trimmedToken.length() != 0) { 1309 arguments[count++] = trimmedToken; 1310 } 1311 } 1312 } 1313 startNewToken = false; 1314 } 1315 } 1316 System.arraycopy(arguments, 0, arguments = new String [count], 0, count); 1317 return arguments; 1318 } 1319 public Compiler batchCompiler; 1320 1321 public ResourceBundle bundle; 1322 protected FileSystem.Classpath[] checkedClasspaths; 1323 public Locale compilerLocale; 1324 public CompilerOptions compilerOptions; public String destinationPath; 1326 public String [] destinationPaths; 1327 private boolean didSpecifySource; 1336 private boolean didSpecifyTarget; 1337 1338 public String [] encodings; 1339 1340 public int exportedClassFilesCounter; 1341 public String [] filenames; 1342 1343 public String [] classNames; 1344 1345 public int globalErrorsCount; 1347 public int globalProblemsCount; 1348 public int globalTasksCount; 1349 public int globalWarningsCount; 1350 private File javaHomeCache; 1351 private boolean javaHomeChecked = false; 1352 public long lineCount; 1353 public String log; 1354 public Logger logger; 1355 public int maxProblems; 1356 public boolean noWarn = false; 1357 public Map options; 1358 protected PrintWriter out; 1359 public boolean proceed = true; 1360 public boolean proceedOnError = false; 1361 public boolean produceRefInfo = false; 1362 public int repetitions; 1363 1364 public boolean showProgress = false; 1365 public long startTime; 1366 1367public boolean systemExitWhenFinished = true; 1368 1369public long[] times; 1370 1371public int timesCounter; 1372 1373public boolean timing = false; 1374 1375public boolean verbose = false; 1376 1377private String [] expandedCommandLine; 1378 1379private PrintWriter err; 1380 1381ArrayList extraProblems; 1382 1383public Main(PrintWriter outWriter, PrintWriter errWriter, boolean systemExitWhenFinished) { 1384 this(outWriter, errWriter, systemExitWhenFinished, null); 1385} 1386 1387public Main(PrintWriter outWriter, PrintWriter errWriter, boolean systemExitWhenFinished, Map customDefaultOptions) { 1388 this.initialize(outWriter, errWriter, systemExitWhenFinished, customDefaultOptions); 1389 this.relocalize(); 1390} 1391public void addExtraProblems(CategorizedProblem problem) { 1392 if (this.extraProblems == null) { 1393 this.extraProblems = new ArrayList (); 1394 } 1395 this.extraProblems.add(problem); 1396} 1397protected void addNewEntry(ArrayList paths, String currentClasspathName, 1398 ArrayList currentRuleSpecs, String customEncoding, 1399 String destPath, boolean isSourceOnly, 1400 boolean rejectDestinationPathOnJars) throws InvalidInputException { 1401 1402 int rulesSpecsSize = currentRuleSpecs.size(); 1403 AccessRuleSet accessRuleSet = null; 1404 if (rulesSpecsSize != 0) { 1405 AccessRule[] accessRules = new AccessRule[currentRuleSpecs.size()]; 1406 boolean rulesOK = true; 1407 Iterator i = currentRuleSpecs.iterator(); 1408 int j = 0; 1409 while (i.hasNext()) { 1410 String ruleSpec = (String ) i.next(); 1411 char key = ruleSpec.charAt(0); 1412 String pattern = ruleSpec.substring(1); 1413 if (pattern.length() > 0) { 1414 switch (key) { 1415 case '+': 1416 accessRules[j++] = new AccessRule(pattern 1417 .toCharArray(), 0); 1418 break; 1419 case '~': 1420 accessRules[j++] = new AccessRule(pattern 1421 .toCharArray(), 1422 IProblem.DiscouragedReference); 1423 break; 1424 case '-': 1425 accessRules[j++] = new AccessRule(pattern 1426 .toCharArray(), 1427 IProblem.ForbiddenReference); 1428 break; 1429 case '?': 1430 accessRules[j++] = new AccessRule(pattern 1431 .toCharArray(), 1432 IProblem.ForbiddenReference, true); 1433 break; 1434 default: 1435 rulesOK = false; 1436 } 1437 } else { 1438 rulesOK = false; 1439 } 1440 } 1441 if (rulesOK) { 1442 String templates[] = new String [AccessRuleSet.MESSAGE_TEMPLATES_LENGTH]; 1443 templates[0] = this.bind( 1444 "template.restrictedAccess.type", new String [] {"{0}", currentClasspathName}); templates[1] = this.bind( 1447 "template.restrictedAccess.constructor", new String [] {"{0}", currentClasspathName}); templates[2] = this.bind( 1450 "template.restrictedAccess.method", new String [] {"{0}", "{1}", currentClasspathName}); templates[3] = this.bind( 1453 "template.restrictedAccess.field", new String [] {"{0}", "{1}", currentClasspathName}); accessRuleSet = new AccessRuleSet(accessRules, templates); 1456 } else { 1457 if (currentClasspathName.length() != 0) { 1458 this.logger.logIncorrectClasspath(currentClasspathName); 1460 } 1461 return; 1462 } 1463 } 1464 if (NONE.equals(destPath)) { 1465 destPath = NONE; } 1467 if (rejectDestinationPathOnJars && destPath != null && 1468 (currentClasspathName.endsWith(".jar") || currentClasspathName.endsWith(".zip"))) { throw new InvalidInputException( 1471 this.bind("configure.unexpectedDestinationPathEntryFile", currentClasspathName)); 1473 } 1474 FileSystem.Classpath currentClasspath = FileSystem.getClasspath( 1475 currentClasspathName, 1476 customEncoding, 1477 isSourceOnly, 1478 accessRuleSet, 1479 destPath); 1480 if (currentClasspath != null) { 1481 paths.add(currentClasspath); 1482 } else if (currentClasspathName.length() != 0) { 1483 this.logger.logIncorrectClasspath(currentClasspathName); 1485 } 1486} 1487 1490public String bind(String id) { 1491 return bind(id, (String []) null); 1492} 1493 1497public String bind(String id, String binding) { 1498 return bind(id, new String [] { binding }); 1499} 1500 1501 1505public String bind(String id, String binding1, String binding2) { 1506 return bind(id, new String [] { binding1, binding2 }); 1507} 1508 1509 1513public String bind(String id, String [] arguments) { 1514 if (id == null) 1515 return "No message available"; String message = null; 1517 try { 1518 message = this.bundle.getString(id); 1519 } catch (MissingResourceException e) { 1520 return "Missing message: " + id + " in: " + Main.bundleName; } 1524 return MessageFormat.format(message, arguments); 1525} 1526 1543private boolean checkVMVersion(long minimalSupportedVersion) { 1544 String classFileVersion = System.getProperty("java.class.version"); if (classFileVersion == null) { 1547 return false; 1549 } 1550 int index = classFileVersion.indexOf('.'); 1551 if (index == -1) { 1552 return false; 1554 } 1555 int majorVersion; 1556 try { 1557 majorVersion = Integer.parseInt(classFileVersion.substring(0, index)); 1558 } catch (NumberFormatException e) { 1559 return false; 1561 } 1562 switch(majorVersion) { 1563 case 45 : return ClassFileConstants.JDK1_1 >= minimalSupportedVersion; 1565 case 46 : return ClassFileConstants.JDK1_2 >= minimalSupportedVersion; 1567 case 47 : return ClassFileConstants.JDK1_3 >= minimalSupportedVersion; 1569 case 48 : return ClassFileConstants.JDK1_4 >= minimalSupportedVersion; 1571 case 49 : return ClassFileConstants.JDK1_5 >= minimalSupportedVersion; 1573 case 50 : return ClassFileConstants.JDK1_6 >= minimalSupportedVersion; 1575 case 51 : return ClassFileConstants.JDK1_7 >= minimalSupportedVersion; 1577 } 1578 return false; 1580} 1581 1584public boolean compile(String [] argv) { 1585 1586 try { 1588 configure(argv); 1589 if (this.proceed) { 1590 if (this.showProgress) this.logger.compiling(); 1594 for (int i = 0; i < this.repetitions; i++) { 1595 this.globalProblemsCount = 0; 1596 this.globalErrorsCount = 0; 1597 this.globalWarningsCount = 0; 1598 this.globalTasksCount = 0; 1599 this.lineCount = 0; 1600 this.exportedClassFilesCounter = 0; 1601 1602 if (this.repetitions > 1) { 1603 this.logger.flush(); 1604 this.logger.logRepetition(i, this.repetitions); 1605 } 1606 performCompilation(); 1608 } 1609 if (this.times != null) { 1610 this.logger.logAverage(this.times, this.lineCount); 1611 } 1612 if (this.showProgress) this.logger.printNewLine(); 1613 } 1614 if (this.systemExitWhenFinished) { 1615 this.logger.flush(); 1616 this.logger.close(); 1617 System.exit(this.globalErrorsCount > 0 ? -1 : 0); 1618 } 1619 } catch (InvalidInputException e) { 1620 this.logger.logException(e); 1621 if (this.systemExitWhenFinished) { 1622 this.logger.flush(); 1623 this.logger.close(); 1624 System.exit(-1); 1625 } 1626 return false; 1627 } catch (RuntimeException e) { this.logger.logException(e); 1629 if (this.systemExitWhenFinished) { 1630 this.logger.flush(); 1631 this.logger.close(); 1632 System.exit(-1); 1633 } 1634 return false; 1635 } finally { 1636 this.logger.flush(); 1637 this.logger.close(); 1638 } 1639 if (this.globalErrorsCount == 0) 1640 return true; 1641 return false; 1642} 1643 1644 1648protected void handleWarningToken(String token, boolean isEnabling, boolean useEnableJavadoc) throws InvalidInputException { 1649 if (token.equals("constructorName")) { this.options.put( 1651 CompilerOptions.OPTION_ReportMethodWithConstructorName, 1652 isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE); 1653 } else if (token.equals("pkgDefaultMethod") || token.equals("packageDefaultMethod") ) { this.options.put( 1655 CompilerOptions.OPTION_ReportOverridingPackageDefaultMethod, 1656 isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE); 1657 } else if (token.equals("maskedCatchBlock") || token.equals("maskedCatchBlocks")) { this.options.put( 1659 CompilerOptions.OPTION_ReportHiddenCatchBlock, 1660 isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE); 1661 } else if (token.equals("deprecation")) { this.options.put( 1663 CompilerOptions.OPTION_ReportDeprecation, 1664 isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE); 1665 this.options.put( 1666 CompilerOptions.OPTION_ReportDeprecationInDeprecatedCode, 1667 CompilerOptions.DISABLED); 1668 this.options.put( 1669 CompilerOptions.OPTION_ReportDeprecationWhenOverridingDeprecatedMethod, 1670 CompilerOptions.DISABLED); 1671 } else if (token.equals("allDeprecation")) { this.options.put( 1673 CompilerOptions.OPTION_ReportDeprecation, 1674 isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE); 1675 this.options.put( 1676 CompilerOptions.OPTION_ReportDeprecationInDeprecatedCode, 1677 isEnabling ? CompilerOptions.ENABLED : CompilerOptions.DISABLED); 1678 this.options.put( 1679 CompilerOptions.OPTION_ReportDeprecationWhenOverridingDeprecatedMethod, 1680 isEnabling ? CompilerOptions.ENABLED : CompilerOptions.DISABLED); 1681 } else if (token.equals("unusedLocal") || token.equals("unusedLocals")) { this.options.put( 1683 CompilerOptions.OPTION_ReportUnusedLocal, 1684 isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE); 1685 } else if (token.equals("unusedArgument") || token.equals("unusedArguments")) { this.options.put( 1687 CompilerOptions.OPTION_ReportUnusedParameter, 1688 isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE); 1689 } else if (token.equals("unusedImport") || token.equals("unusedImports")) { this.options.put( 1691 CompilerOptions.OPTION_ReportUnusedImport, 1692 isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE); 1693 } else if (token.equals("unusedPrivate")) { this.options.put( 1695 CompilerOptions.OPTION_ReportUnusedPrivateMember, 1696 isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE); 1697 } else if (token.equals("unusedLabel")) { this.options.put( 1699 CompilerOptions.OPTION_ReportUnusedLabel, 1700 isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE); 1701 } else if (token.equals("localHiding")) { this.options.put( 1703 CompilerOptions.OPTION_ReportLocalVariableHiding, 1704 isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE); 1705 } else if (token.equals("fieldHiding")) { this.options.put( 1707 CompilerOptions.OPTION_ReportFieldHiding, 1708 isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE); 1709 } else if (token.equals("specialParamHiding")) { this.options.put( 1711 CompilerOptions.OPTION_ReportSpecialParameterHidingField, 1712 isEnabling ? CompilerOptions.ENABLED : CompilerOptions.DISABLED); 1713 } else if (token.equals("conditionAssign")) { this.options.put( 1715 CompilerOptions.OPTION_ReportPossibleAccidentalBooleanAssignment, 1716 isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE); 1717 } else if (token.equals("syntheticAccess") || token.equals("synthetic-access")) { this.options.put( 1720 CompilerOptions.OPTION_ReportSyntheticAccessEmulation, 1721 isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE); 1722 } else if (token.equals("nls")) { this.options.put( 1724 CompilerOptions.OPTION_ReportNonExternalizedStringLiteral, 1725 isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE); 1726 } else if (token.equals("staticReceiver")) { this.options.put( 1728 CompilerOptions.OPTION_ReportNonStaticAccessToStatic, 1729 isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE); 1730 } else if (token.equals("indirectStatic")) { this.options.put( 1732 CompilerOptions.OPTION_ReportIndirectStaticAccess, 1733 isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE); 1734 } else if (token.equals("noEffectAssign")) { this.options.put( 1736 CompilerOptions.OPTION_ReportNoEffectAssignment, 1737 isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE); 1738 } else if (token.equals("intfNonInherited") || token.equals("interfaceNonInherited")) { this.options.put( 1740 CompilerOptions.OPTION_ReportIncompatibleNonInheritedInterfaceMethod, 1741 isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE); 1742 } else if (token.equals("charConcat") || token.equals("noImplicitStringConversion")) { this.options.put( 1744 CompilerOptions.OPTION_ReportNoImplicitStringConversion, 1745 isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE); 1746 } else if (token.equals("semicolon")) { this.options.put( 1748 CompilerOptions.OPTION_ReportEmptyStatement, 1749 isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE); 1750 } else if (token.equals("serial")) { this.options.put( 1752 CompilerOptions.OPTION_ReportMissingSerialVersion, 1753 isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE); 1754 } else if (token.equals("emptyBlock")) { this.options.put( 1756 CompilerOptions.OPTION_ReportUndocumentedEmptyBlock, 1757 isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE); 1758 } else if (token.equals("uselessTypeCheck")) { this.options.put( 1760 CompilerOptions.OPTION_ReportUnnecessaryTypeCheck, 1761 isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE); 1762 } else if (token.equals("unchecked") || token.equals("unsafe")) { this.options.put( 1764 CompilerOptions.OPTION_ReportUncheckedTypeOperation, 1765 isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE); 1766 } else if (token.equals("raw")) { this.options.put( 1768 CompilerOptions.OPTION_ReportRawTypeReference, 1769 isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE); 1770 } else if (token.equals("finalBound")) { this.options.put( 1772 CompilerOptions.OPTION_ReportFinalParameterBound, 1773 isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE); 1774 } else if (token.equals("suppress")) { this.options.put( 1776 CompilerOptions.OPTION_SuppressWarnings, 1777 isEnabling ? CompilerOptions.ENABLED : CompilerOptions.DISABLED); 1778 } else if (token.equals("warningToken")) { this.options.put( 1780 CompilerOptions.OPTION_ReportUnhandledWarningToken, 1781 isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE); 1782 } else if (token.equals("unnecessaryElse")) { this.options.put( 1784 CompilerOptions.OPTION_ReportUnnecessaryElse, 1785 isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE); 1786 } else if (token.equals("javadoc")) { if (!useEnableJavadoc) { 1788 this.options.put( 1789 CompilerOptions.OPTION_DocCommentSupport, 1790 isEnabling ? CompilerOptions.ENABLED: CompilerOptions.DISABLED); 1791 } 1792 if (isEnabling) { 1794 this.options.put( 1795 CompilerOptions.OPTION_ReportInvalidJavadoc, 1796 CompilerOptions.WARNING); 1797 this.options.put( 1798 CompilerOptions.OPTION_ReportInvalidJavadocTags, 1799 CompilerOptions.ENABLED); 1800 this.options.put( 1801 CompilerOptions.OPTION_ReportInvalidJavadocTagsDeprecatedRef, 1802 CompilerOptions.DISABLED); 1803 this.options.put( 1804 CompilerOptions.OPTION_ReportInvalidJavadocTagsNotVisibleRef, 1805 CompilerOptions.DISABLED); 1806 this.options.put( 1807 CompilerOptions.OPTION_ReportInvalidJavadocTagsVisibility, 1808 CompilerOptions.PRIVATE); 1809 this.options.put( 1810 CompilerOptions.OPTION_ReportMissingJavadocTags, 1811 CompilerOptions.WARNING); 1812 this.options.put( 1813 CompilerOptions.OPTION_ReportMissingJavadocTagsVisibility, 1814 CompilerOptions.PRIVATE); 1815 } 1816 } else if (token.equals("allJavadoc")) { if (!useEnableJavadoc) { 1818 this.options.put( 1819 CompilerOptions.OPTION_DocCommentSupport, 1820 isEnabling ? CompilerOptions.ENABLED: CompilerOptions.DISABLED); 1821 } 1822 if (isEnabling) { 1824 this.options.put( 1825 CompilerOptions.OPTION_ReportInvalidJavadoc, 1826 CompilerOptions.WARNING); 1827 this.options.put( 1828 CompilerOptions.OPTION_ReportInvalidJavadocTags, 1829 CompilerOptions.ENABLED); 1830 this.options.put( 1831 CompilerOptions.OPTION_ReportInvalidJavadocTagsVisibility, 1832 CompilerOptions.PRIVATE); 1833 this.options.put( 1834 CompilerOptions.OPTION_ReportMissingJavadocTags, 1835 CompilerOptions.WARNING); 1836 this.options.put( 1837 CompilerOptions.OPTION_ReportMissingJavadocTagsVisibility, 1838 CompilerOptions.PRIVATE); 1839 this.options.put( 1840 CompilerOptions.OPTION_ReportMissingJavadocComments, 1841 CompilerOptions.WARNING); 1842 } 1843 } else if (token.startsWith("tasks")) { String taskTags = Util.EMPTY_STRING; 1845 int start = token.indexOf('('); 1846 int end = token.indexOf(')'); 1847 if (start >= 0 && end >= 0 && start < end){ 1848 taskTags = token.substring(start+1, end).trim(); 1849 taskTags = taskTags.replace('|',','); 1850 } 1851 if (taskTags.length() == 0){ 1852 throw new InvalidInputException(this.bind("configure.invalidTaskTag", token)); } 1854 this.options.put( 1855 CompilerOptions.OPTION_TaskTags, 1856 isEnabling ? taskTags : Util.EMPTY_STRING); 1857 } else if (token.equals("assertIdentifier")) { this.options.put( 1859 CompilerOptions.OPTION_ReportAssertIdentifier, 1860 isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE); 1861 } else if (token.equals("enumIdentifier")) { this.options.put( 1863 CompilerOptions.OPTION_ReportEnumIdentifier, 1864 isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE); 1865 } else if (token.equals("finally")) { this.options.put( 1867 CompilerOptions.OPTION_ReportFinallyBlockNotCompletingNormally, 1868 isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE); 1869 } else if (token.equals("unusedThrown")) { this.options.put( 1871 CompilerOptions.OPTION_ReportUnusedDeclaredThrownException, 1872 isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE); 1873 } else if (token.equals("unqualifiedField") || token.equals("unqualified-field-access")) { this.options.put( 1876 CompilerOptions.OPTION_ReportUnqualifiedFieldAccess, 1877 isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE); 1878 } else if (token.equals("typeHiding")) { this.options.put( 1880 CompilerOptions.OPTION_ReportTypeParameterHiding, 1881 isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE); 1882 } else if (token.equals("varargsCast")) { this.options.put( 1884 CompilerOptions.OPTION_ReportVarargsArgumentNeedCast, 1885 isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE); 1886 } else if (token.equals("null")) { if (isEnabling) { 1888 this.options.put(CompilerOptions.OPTION_ReportNullReference, 1889 CompilerOptions.WARNING); 1890 this.options.put(CompilerOptions.OPTION_ReportPotentialNullReference, 1891 CompilerOptions.WARNING); 1892 this.options.put(CompilerOptions.OPTION_ReportRedundantNullCheck, 1893 CompilerOptions.WARNING); 1894 } else { 1895 this.options.put(CompilerOptions.OPTION_ReportNullReference, 1896 CompilerOptions.IGNORE); 1897 this.options.put(CompilerOptions.OPTION_ReportPotentialNullReference, 1898 CompilerOptions.IGNORE); 1899 this.options.put(CompilerOptions.OPTION_ReportRedundantNullCheck, 1900 CompilerOptions.IGNORE); 1901 } 1902 } else if (token.equals("nullDereference")) { if (isEnabling) { 1904 this.options.put(CompilerOptions.OPTION_ReportNullReference, 1905 CompilerOptions.WARNING); 1906 } else { 1907 this.options.put(CompilerOptions.OPTION_ReportNullReference, 1908 CompilerOptions.IGNORE); 1909 this.options.put(CompilerOptions.OPTION_ReportPotentialNullReference, 1910 CompilerOptions.IGNORE); 1911 this.options.put(CompilerOptions.OPTION_ReportRedundantNullCheck, 1912 CompilerOptions.IGNORE); 1913 } 1914 } else if (token.equals("boxing")) { this.options.put( 1916 CompilerOptions.OPTION_ReportAutoboxing, 1917 isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE); 1918 } else if (token.equals("over-ann")) { this.options.put( 1920 CompilerOptions.OPTION_ReportMissingOverrideAnnotation, 1921 isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE); 1922 } else if (token.equals("dep-ann")) { this.options.put( 1924 CompilerOptions.OPTION_ReportMissingDeprecatedAnnotation, 1925 isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE); 1926 } else if (token.equals("intfAnnotation")) { this.options.put( 1928 CompilerOptions.OPTION_ReportAnnotationSuperInterface, 1929 isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE); 1930 } else if (token.equals("enumSwitch") || token.equals("incomplete-switch")) { this.options.put( 1933 CompilerOptions.OPTION_ReportIncompleteEnumSwitch, 1934 isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE); 1935 } else if (token.equals("hiding")) { this.options.put( 1937 CompilerOptions.OPTION_ReportHiddenCatchBlock, 1938 isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE); 1939 this.options.put( 1940 CompilerOptions.OPTION_ReportLocalVariableHiding, 1941 isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE); 1942 this.options.put( 1943 CompilerOptions.OPTION_ReportFieldHiding, 1944 isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE); 1945 this.options.put( 1946 CompilerOptions.OPTION_ReportTypeParameterHiding, 1947 isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE); 1948 } else if (token.equals("static-access")) { this.options.put( 1950 CompilerOptions.OPTION_ReportNonStaticAccessToStatic, 1951 isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE); 1952 this.options.put( 1953 CompilerOptions.OPTION_ReportIndirectStaticAccess, 1954 isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE); 1955 } else if (token.equals("unused")) { this.options.put( 1957 CompilerOptions.OPTION_ReportUnusedLocal, 1958 isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE); 1959 this.options.put( 1960 CompilerOptions.OPTION_ReportUnusedParameter, 1961 isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE); 1962 this.options.put( 1963 CompilerOptions.OPTION_ReportUnusedImport, 1964 isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE); 1965 this.options.put( 1966 CompilerOptions.OPTION_ReportUnusedPrivateMember, 1967 isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE); 1968 this.options.put( 1969 CompilerOptions.OPTION_ReportUnusedDeclaredThrownException, 1970 isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE); 1971 this.options.put( 1972 CompilerOptions.OPTION_ReportUnusedLabel, 1973 isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE); 1974 } else if (token.equals("paramAssign")) { this.options.put( 1976 CompilerOptions.OPTION_ReportParameterAssignment, 1977 isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE); 1978 } else if (token.equals("discouraged")) { this.options.put( 1980 CompilerOptions.OPTION_ReportDiscouragedReference, 1981 isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE); 1982 } else if (token.equals("forbidden")) { this.options.put( 1984 CompilerOptions.OPTION_ReportForbiddenReference, 1985 isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE); 1986 } else if (token.equals("fallthrough")) { this.options.put( 1988 CompilerOptions.OPTION_ReportFallthroughCase, 1989 isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE); 1990 } else if (token.equals("super")) { this.options.put( 1992 CompilerOptions.OPTION_ReportOverridingMethodWithoutSuperInvocation, 1993 isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE); 1994 } else { 1995 throw new InvalidInputException(this.bind("configure.invalidWarning", token)); } 1997} 1998 2001protected ArrayList handleBootclasspath(ArrayList bootclasspaths, String customEncoding) throws InvalidInputException { 2002 final int bootclasspathsSize = bootclasspaths == null ? 0 : bootclasspaths.size(); 2003 if (bootclasspathsSize != 0) { 2004 String [] paths = new String [bootclasspathsSize]; 2005 bootclasspaths.toArray(paths); 2006 bootclasspaths.clear(); 2007 for (int i = 0; i < bootclasspathsSize; i++) { 2008 processPathEntries(DEFAULT_SIZE_CLASSPATH, bootclasspaths, 2009 paths[i], customEncoding, false, true); 2010 } 2011 } else { 2012 bootclasspaths = new ArrayList (DEFAULT_SIZE_CLASSPATH); 2013 2017 String javaversion = System.getProperty("java.version"); if (javaversion != null && javaversion.equalsIgnoreCase("1.1.8")) { this.logger.logWrongJDK(); 2020 this.proceed = false; 2021 return null; 2022 } 2023 2024 2027 String bootclasspathProperty = System.getProperty("sun.boot.class.path"); if ((bootclasspathProperty == null) || (bootclasspathProperty.length() == 0)) { 2030 bootclasspathProperty = System.getProperty("vm.boot.class.path"); if ((bootclasspathProperty == null) || (bootclasspathProperty.length() == 0)) { 2033 bootclasspathProperty = System.getProperty("org.apache.harmony.boot.class.path"); } 2036 } 2037 if ((bootclasspathProperty != null) && (bootclasspathProperty.length() != 0)) { 2038 StringTokenizer tokenizer = new StringTokenizer (bootclasspathProperty, File.pathSeparator); 2039 String token; 2040 while (tokenizer.hasMoreTokens()) { 2041 token = tokenizer.nextToken(); 2042 FileSystem.Classpath currentClasspath = FileSystem 2043 .getClasspath(token, customEncoding, null); 2044 if (currentClasspath != null) { 2045 bootclasspaths.add(currentClasspath); 2046 } 2047 } 2048 } else { 2049 final File javaHome = getJavaHome(); 2051 if (javaHome != null) { 2052 File [] directoriesToCheck = null; 2053 if (System.getProperty("os.name").startsWith("Mac")) { directoriesToCheck = new File [] { 2055 new File (javaHome, "../Classes"), }; 2057 } else { 2058 directoriesToCheck = new File [] { 2060 new File (javaHome, "lib") }; 2062 } 2063 File [][] systemLibrariesJars = getLibrariesFiles(directoriesToCheck); 2064 if (systemLibrariesJars != null) { 2065 for (int i = 0, max = systemLibrariesJars.length; i < max; i++) { 2066 File [] current = systemLibrariesJars[i]; 2067 if (current != null) { 2068 for (int j = 0, max2 = current.length; j < max2; j++) { 2069 FileSystem.Classpath classpath = 2070 FileSystem.getClasspath(current[j].getAbsolutePath(), 2071 null, false, null, null); 2072 if (classpath != null) { 2073 bootclasspaths.add(classpath); 2074 } 2075 } 2076 } 2077 } 2078 } 2079 } 2080 } 2081 } 2082 return bootclasspaths; 2083} 2084 2087protected ArrayList handleClasspath(ArrayList classpaths, String customEncoding) throws InvalidInputException { 2088 final int classpathsSize = classpaths == null ? 0 : classpaths.size(); 2089 if (classpathsSize != 0) { 2090 String [] paths = new String [classpathsSize]; 2091 classpaths.toArray(paths); 2092 classpaths.clear(); 2093 for (int i = 0; i < classpathsSize; i++) { 2094 processPathEntries(DEFAULT_SIZE_CLASSPATH, classpaths, paths[i], 2095 customEncoding, false, true); 2096 } 2097 } else { 2098 classpaths = new ArrayList (DEFAULT_SIZE_CLASSPATH); 2100 String classProp = System.getProperty("java.class.path"); if ((classProp == null) || (classProp.length() == 0)) { 2102 this.logger.logNoClasspath(); 2103 classpaths.add(FileSystem.getClasspath(System.getProperty("user.dir"), customEncoding, null)); } else { 2105 StringTokenizer tokenizer = new StringTokenizer (classProp, File.pathSeparator); 2106 String token; 2107 while (tokenizer.hasMoreTokens()) { 2108 token = tokenizer.nextToken(); 2109 FileSystem.Classpath currentClasspath = FileSystem 2110 .getClasspath(token, customEncoding, null); 2111 if (currentClasspath != null) { 2112 classpaths.add(currentClasspath); 2113 } else if (token.length() != 0) { 2114 this.logger.logIncorrectClasspath(token); 2115 } 2116 } 2117 } 2118 } 2119 return classpaths; 2120} 2121 2125protected ArrayList handleExtdirs(ArrayList extdirsClasspaths) { 2126 final File javaHome = getJavaHome(); 2127 2128 2134 if (extdirsClasspaths == null) { 2135 extdirsClasspaths = new ArrayList (DEFAULT_SIZE_CLASSPATH); 2136 String extdirsStr = System.getProperty("java.ext.dirs"); if (extdirsStr == null) { 2138 extdirsClasspaths.add(javaHome.getAbsolutePath() + "/lib/ext"); } else { 2140 StringTokenizer tokenizer = new StringTokenizer (extdirsStr, File.pathSeparator); 2141 while (tokenizer.hasMoreTokens()) 2142 extdirsClasspaths.add(tokenizer.nextToken()); 2143 } 2144 } 2145 2146 2150 if (extdirsClasspaths.size() != 0) { 2151 File [] directoriesToCheck = new File [extdirsClasspaths.size()]; 2152 for (int i = 0; i < directoriesToCheck.length; i++) 2153 directoriesToCheck[i] = new File ((String ) extdirsClasspaths.get(i)); 2154 extdirsClasspaths.clear(); 2155 File [][] extdirsJars = getLibrariesFiles(directoriesToCheck); 2156 if (extdirsJars != null) { 2157 for (int i = 0, max = extdirsJars.length; i < max; i++) { 2158 File [] current = extdirsJars[i]; 2159 if (current != null) { 2160 for (int j = 0, max2 = current.length; j < max2; j++) { 2161 FileSystem.Classpath classpath = 2162 FileSystem.getClasspath( 2163 current[j].getAbsolutePath(), 2164 null, null); 2165 if (classpath != null) { 2166 extdirsClasspaths.add(classpath); 2167 } 2168 } 2169 } else if (directoriesToCheck[i].isFile()) { 2170 this.logger.logIncorrectExtDirsEntry(directoriesToCheck[i].getAbsolutePath()); 2171 } 2172 } 2173 } 2174 } 2175 2176 return extdirsClasspaths; 2177} 2178 2181protected ArrayList handleEndorseddirs(ArrayList endorsedDirClasspaths) { 2182 final File javaHome = getJavaHome(); 2183 2189 if (endorsedDirClasspaths == null) { 2190 endorsedDirClasspaths = new ArrayList (DEFAULT_SIZE_CLASSPATH); 2191 String endorsedDirsStr = System.getProperty("java.endorsed.dirs"); if (endorsedDirsStr == null) { 2193 if (javaHome != null) { 2194 endorsedDirClasspaths.add(javaHome.getAbsolutePath() + "/lib/endorsed"); } 2196 } else { 2197 StringTokenizer tokenizer = new StringTokenizer (endorsedDirsStr, File.pathSeparator); 2198 while (tokenizer.hasMoreTokens()) { 2199 endorsedDirClasspaths.add(tokenizer.nextToken()); 2200 } 2201 } 2202 } 2203 2204 2208 if (endorsedDirClasspaths.size() != 0) { 2209 File [] directoriesToCheck = new File [endorsedDirClasspaths.size()]; 2210 for (int i = 0; i < directoriesToCheck.length; i++) 2211 directoriesToCheck[i] = new File ((String ) endorsedDirClasspaths.get(i)); 2212 endorsedDirClasspaths.clear(); 2213 File [][] endorsedDirsJars = getLibrariesFiles(directoriesToCheck); 2214 if (endorsedDirsJars != null) { 2215 for (int i = 0, max = endorsedDirsJars.length; i < max; i++) { 2216 File [] current = endorsedDirsJars[i]; 2217 if (current != null) { 2218 for (int j = 0, max2 = current.length; j < max2; j++) { 2219 FileSystem.Classpath classpath = 2220 FileSystem.getClasspath( 2221 current[j].getAbsolutePath(), 2222 null, null); 2223 if (classpath != null) { 2224 endorsedDirClasspaths.add(classpath); 2225 } 2226 } 2227 } else if (directoriesToCheck[i].isFile()) { 2228 this.logger.logIncorrectEndorsedDirsEntry(directoriesToCheck[i].getAbsolutePath()); 2229 } 2230 } 2231 } 2232 } 2233 return endorsedDirClasspaths; 2234} 2235 2236 2239public void configure(String [] argv) throws InvalidInputException { 2240 2241 if ((argv == null) || (argv.length == 0)) { 2242 printUsage(); 2243 return; 2244 } 2245 2246 final int INSIDE_CLASSPATH_start = 1; 2247 final int INSIDE_DESTINATION_PATH = 3; 2248 final int INSIDE_TARGET = 4; 2249 final int INSIDE_LOG = 5; 2250 final int INSIDE_REPETITION = 6; 2251 final int INSIDE_SOURCE = 7; 2252 final int INSIDE_DEFAULT_ENCODING = 8; 2253 final int INSIDE_BOOTCLASSPATH_start = 9; 2254 final int INSIDE_MAX_PROBLEMS = 11; 2255 final int INSIDE_EXT_DIRS = 12; 2256 final int INSIDE_SOURCE_PATH_start = 13; 2257 final int INSIDE_ENDORSED_DIRS = 15; 2258 final int INSIDE_SOURCE_DIRECTORY_DESTINATION_PATH = 16; 2259 final int INSIDE_PROCESSOR_PATH_start = 17; 2260 final int INSIDE_PROCESSOR_start = 18; 2261 final int INSIDE_S_start = 19; 2262 final int INSIDE_CLASS_NAMES = 20; 2263 2264 final int DEFAULT = 0; 2265 ArrayList bootclasspaths = new ArrayList (DEFAULT_SIZE_CLASSPATH); 2266 String sourcepathClasspathArg = null; 2267 ArrayList sourcepathClasspaths = new ArrayList (DEFAULT_SIZE_CLASSPATH); 2268 ArrayList classpaths = new ArrayList (DEFAULT_SIZE_CLASSPATH); 2269 ArrayList extdirsClasspaths = null; 2270 ArrayList endorsedDirClasspaths = null; 2271 2272 int index = -1; 2273 int filesCount = 0; 2274 int classCount = 0; 2275 int argCount = argv.length; 2276 int mode = DEFAULT; 2277 this.repetitions = 0; 2278 boolean printUsageRequired = false; 2279 String usageSection = null; 2280 boolean printVersionRequired = false; 2281 2282 boolean didSpecifyDefaultEncoding = false; 2283 boolean didSpecifyDeprecation = false; 2284 boolean didSpecifyWarnings = false; 2285 boolean useEnableJavadoc = false; 2286 boolean didSpecifyCompliance = false; 2287 boolean didSpecifyDisabledAnnotationProcessing = false; 2288 2289 String customEncoding = null; 2290 String customDestinationPath = null; 2291 String currentSourceDirectory = null; 2292 String currentArg = Util.EMPTY_STRING; 2293 2294 boolean needExpansion = false; 2296 loop: for (int i = 0; i < argCount; i++) { 2297 if (argv[i].startsWith("@")) { needExpansion = true; 2299 break loop; 2300 } 2301 } 2302 2303 String [] newCommandLineArgs = null; 2304 if (needExpansion) { 2305 newCommandLineArgs = new String [argCount]; 2306 index = 0; 2307 for (int i = 0; i < argCount; i++) { 2308 String [] newArgs = null; 2309 String arg = argv[i].trim(); 2310 if (arg.startsWith("@")) { try { 2312 LineNumberReader reader = new LineNumberReader (new StringReader (new String (Util.getFileCharContent(new File (arg.substring(1)), null)))); 2313 StringBuffer buffer = new StringBuffer (); 2314 String line; 2315 while((line = reader.readLine()) != null) { 2316 line = line.trim(); 2317 if (!line.startsWith("#")) { buffer.append(line).append(" "); } 2320 } 2321 newArgs = tokenize(buffer.toString()); 2322 } catch(IOException e) { 2323 throw new InvalidInputException( 2324 this.bind("configure.invalidexpansionargumentname", arg)); } 2326 } 2327 if (newArgs != null) { 2328 int newCommandLineArgsLength = newCommandLineArgs.length; 2329 int newArgsLength = newArgs.length; 2330 System.arraycopy(newCommandLineArgs, 0, (newCommandLineArgs = new String [newCommandLineArgsLength + newArgsLength - 1]), 0, index); 2331 System.arraycopy(newArgs, 0, newCommandLineArgs, index, newArgsLength); 2332 index += newArgsLength; 2333 } else { 2334 newCommandLineArgs[index++] = arg; 2335 } 2336 } 2337 index = -1; 2338 } else { 2339 newCommandLineArgs = argv; 2340 for (int i = 0; i < argCount; i++) { 2341 newCommandLineArgs[i] = newCommandLineArgs[i].trim(); 2342 } 2343 } 2344 argCount = newCommandLineArgs.length; 2345 this.expandedCommandLine = newCommandLineArgs; 2346 while (++index < argCount) { 2347 2348 if (customEncoding != null) { 2349 throw new InvalidInputException( 2350 this.bind("configure.unexpectedCustomEncoding", currentArg, customEncoding)); } 2352 2353 currentArg = newCommandLineArgs[index]; 2354 2355 switch(mode) { 2356 case DEFAULT : 2357 if (currentArg.startsWith("[")) { throw new InvalidInputException( 2359 this.bind("configure.unexpectedBracket", currentArg)); 2361 } 2362 2363 if (currentArg.endsWith("]")) { int encodingStart = currentArg.indexOf('[') + 1; 2366 if (encodingStart <= 1) { 2367 throw new InvalidInputException( 2368 this.bind("configure.unexpectedBracket", currentArg)); } 2370 int encodingEnd = currentArg.length() - 1; 2371 if (encodingStart >= 1) { 2372 if (encodingStart < encodingEnd) { 2373 customEncoding = currentArg.substring(encodingStart, encodingEnd); 2374 try { new InputStreamReader (new ByteArrayInputStream (new byte[0]), customEncoding); 2376 } catch (UnsupportedEncodingException e) { 2377 throw new InvalidInputException( 2378 this.bind("configure.unsupportedEncoding", customEncoding)); } 2380 } 2381 currentArg = currentArg.substring(0, encodingStart - 1); 2382 } 2383 } 2384 2385 if (currentArg.endsWith(SuffixConstants.SUFFIX_STRING_java)) { 2386 if (this.filenames == null) { 2387 this.filenames = new String [argCount - index]; 2388 this.encodings = new String [argCount - index]; 2389 this.destinationPaths = new String [argCount - index]; 2390 } else if (filesCount == this.filenames.length) { 2391 int length = this.filenames.length; 2392 System.arraycopy( 2393 this.filenames, 2394 0, 2395 (this.filenames = new String [length + argCount - index]), 2396 0, 2397 length); 2398 System.arraycopy( 2399 this.encodings, 2400 0, 2401 (this.encodings = new String [length + argCount - index]), 2402 0, 2403 length); 2404 System.arraycopy( 2405 this.destinationPaths, 2406 0, 2407 (this.destinationPaths = new String [length + argCount - index]), 2408 0, 2409 length); 2410 } 2411 this.filenames[filesCount] = currentArg; 2412 this.encodings[filesCount++] = customEncoding; 2413 customEncoding = null; 2415 mode = DEFAULT; 2416 continue; 2417 } 2418 if (currentArg.equals("-log")) { if (this.log != null) 2420 throw new InvalidInputException( 2421 this.bind("configure.duplicateLog", currentArg)); mode = INSIDE_LOG; 2423 continue; 2424 } 2425 if (currentArg.equals("-repeat")) { if (this.repetitions > 0) 2427 throw new InvalidInputException( 2428 this.bind("configure.duplicateRepeat", currentArg)); mode = INSIDE_REPETITION; 2430 continue; 2431 } 2432 if (currentArg.equals("-maxProblems")) { if (this.maxProblems > 0) 2434 throw new InvalidInputException( 2435 this.bind("configure.duplicateMaxProblems", currentArg)); mode = INSIDE_MAX_PROBLEMS; 2437 continue; 2438 } 2439 if (currentArg.equals("-source")) { mode = INSIDE_SOURCE; 2441 continue; 2442 } 2443 if (currentArg.equals("-encoding")) { mode = INSIDE_DEFAULT_ENCODING; 2445 continue; 2446 } 2447 if (currentArg.equals("-1.3")) { if (didSpecifyCompliance) { 2449 throw new InvalidInputException( 2450 this.bind("configure.duplicateCompliance", currentArg)); } 2452 didSpecifyCompliance = true; 2453 this.options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_3); 2454 mode = DEFAULT; 2455 continue; 2456 } 2457 if (currentArg.equals("-1.4")) { if (didSpecifyCompliance) { 2459 throw new InvalidInputException( 2460 this.bind("configure.duplicateCompliance", currentArg)); } 2462 didSpecifyCompliance = true; 2463 this.options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_4); 2464 mode = DEFAULT; 2465 continue; 2466 } 2467 if (currentArg.equals("-1.5") || currentArg.equals("-5") || currentArg.equals("-5.0")) { if (didSpecifyCompliance) { 2469 throw new InvalidInputException( 2470 this.bind("configure.duplicateCompliance", currentArg)); } 2472 didSpecifyCompliance = true; 2473 this.options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_5); 2474 mode = DEFAULT; 2475 continue; 2476 } 2477 if (currentArg.equals("-1.6") || currentArg.equals("-6") || currentArg.equals("-6.0")) { if (didSpecifyCompliance) { 2479 throw new InvalidInputException( 2480 this.bind("configure.duplicateCompliance", currentArg)); } 2482 didSpecifyCompliance = true; 2483 this.options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_6); 2484 mode = DEFAULT; 2485 continue; 2486 } 2487 if (currentArg.equals("-1.7") || currentArg.equals("-7") || currentArg.equals("-7.0")) { if (didSpecifyCompliance) { 2489 throw new InvalidInputException( 2490 this.bind("configure.duplicateCompliance", currentArg)); } 2492 didSpecifyCompliance = true; 2493 this.options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_7); 2494 mode = DEFAULT; 2495 continue; 2496 } 2497 if (currentArg.equals("-d")) { if (this.destinationPath != null) { 2499 StringBuffer errorMessage = new StringBuffer (); 2500 errorMessage.append(currentArg); 2501 if ((index + 1) < argCount) { 2502 errorMessage.append(' '); 2503 errorMessage.append(newCommandLineArgs[index + 1]); 2504 } 2505 throw new InvalidInputException( 2506 this.bind("configure.duplicateOutputPath", errorMessage.toString())); } 2508 mode = INSIDE_DESTINATION_PATH; 2509 continue; 2510 } 2511 if (currentArg.equals("-classpath") || currentArg.equals("-cp")) { mode = INSIDE_CLASSPATH_start; 2514 continue; 2515 } 2516 if (currentArg.equals("-bootclasspath")) { if (bootclasspaths.size() > 0) { 2518 StringBuffer errorMessage = new StringBuffer (); 2519 errorMessage.append(currentArg); 2520 if ((index + 1) < argCount) { 2521 errorMessage.append(' '); 2522 errorMessage.append(newCommandLineArgs[index + 1]); 2523 } 2524 throw new InvalidInputException( 2525 this.bind("configure.duplicateBootClasspath", errorMessage.toString())); } 2527 mode = INSIDE_BOOTCLASSPATH_start; 2528 continue; 2529 } 2530 if (currentArg.equals("-sourcepath")) { if (sourcepathClasspathArg != null) { 2532 StringBuffer errorMessage = new StringBuffer (); 2533 errorMessage.append(currentArg); 2534 if ((index + 1) < argCount) { 2535 errorMessage.append(' '); 2536 errorMessage.append(newCommandLineArgs[index + 1]); 2537 } 2538 throw new InvalidInputException( 2539 this.bind("configure.duplicateSourcepath", errorMessage.toString())); } 2541 mode = INSIDE_SOURCE_PATH_start; 2542 continue; 2543 } 2544 if (currentArg.equals("-extdirs")) { if (extdirsClasspaths != null) { 2546 StringBuffer errorMessage = new StringBuffer (); 2547 errorMessage.append(currentArg); 2548 if ((index + 1) < argCount) { 2549 errorMessage.append(' '); 2550 errorMessage.append(newCommandLineArgs[index + 1]); 2551 } 2552 throw new InvalidInputException( 2553 this.bind("configure.duplicateExtDirs", errorMessage.toString())); } 2555 mode = INSIDE_EXT_DIRS; 2556 continue; 2557 } 2558 if (currentArg.equals("-endorseddirs")) { if (endorsedDirClasspaths != null) { 2560 StringBuffer errorMessage = new StringBuffer (); 2561 errorMessage.append(currentArg); 2562 if ((index + 1) < argCount) { 2563 errorMessage.append(' '); 2564 errorMessage.append(newCommandLineArgs[index + 1]); 2565 } 2566 throw new InvalidInputException( 2567 this.bind("configure.duplicateEndorsedDirs", errorMessage.toString())); } 2569 mode = INSIDE_ENDORSED_DIRS; 2570 continue; 2571 } 2572 if (currentArg.equals("-progress")) { mode = DEFAULT; 2574 this.showProgress = true; 2575 continue; 2576 } 2577 if (currentArg.equals("-proceedOnError")) { mode = DEFAULT; 2579 this.proceedOnError = true; 2580 continue; 2581 } 2582 if (currentArg.equals("-time")) { mode = DEFAULT; 2584 this.timing = true; 2585 continue; 2586 } 2587 if (currentArg.equals("-version") || currentArg.equals("-v")) { this.logger.logVersion(true); 2590 this.proceed = false; 2591 return; 2592 } 2593 if (currentArg.equals("-showversion")) { printVersionRequired = true; 2595 mode = DEFAULT; 2596 continue; 2597 } 2598 if ("-deprecation".equals(currentArg)) { didSpecifyDeprecation = true; 2600 this.options.put(CompilerOptions.OPTION_ReportDeprecation, CompilerOptions.WARNING); 2601 mode = DEFAULT; 2602 continue; 2603 } 2604 if (currentArg.equals("-help") || currentArg.equals("-?")) { printUsageRequired = true; 2606 mode = DEFAULT; 2607 continue; 2608 } 2609 if (currentArg.equals("-help:warn") || currentArg.equals("-?:warn")) { printUsageRequired = true; 2612 usageSection = "misc.usage.warn"; continue; 2614 } 2615 if (currentArg.equals("-noExit")) { this.systemExitWhenFinished = false; 2617 mode = DEFAULT; 2618 continue; 2619 } 2620 if (currentArg.equals("-verbose")) { this.verbose = true; 2622 mode = DEFAULT; 2623 continue; 2624 } 2625 if (currentArg.equals("-referenceInfo")) { this.produceRefInfo = true; 2627 mode = DEFAULT; 2628 continue; 2629 } 2630 if (currentArg.equals("-inlineJSR")) { mode = DEFAULT; 2632 this.options.put( 2633 CompilerOptions.OPTION_InlineJsr, 2634 CompilerOptions.ENABLED); 2635 continue; 2636 } 2637 if (currentArg.startsWith("-g")) { mode = DEFAULT; 2639 String debugOption = currentArg; 2640 int length = currentArg.length(); 2641 if (length == 2) { 2642 this.options.put( 2643 CompilerOptions.OPTION_LocalVariableAttribute, 2644 CompilerOptions.GENERATE); 2645 this.options.put( 2646 CompilerOptions.OPTION_LineNumberAttribute, 2647 CompilerOptions.GENERATE); 2648 this.options.put( 2649 CompilerOptions.OPTION_SourceFileAttribute, 2650 CompilerOptions.GENERATE); 2651 continue; 2652 } 2653 if (length > 3) { 2654 this.options.put( 2655 CompilerOptions.OPTION_LocalVariableAttribute, 2656 CompilerOptions.DO_NOT_GENERATE); 2657 this.options.put( 2658 CompilerOptions.OPTION_LineNumberAttribute, 2659 CompilerOptions.DO_NOT_GENERATE); 2660 this.options.put( 2661 CompilerOptions.OPTION_SourceFileAttribute, 2662 CompilerOptions.DO_NOT_GENERATE); 2663 if (length == 7 && debugOption.equals("-g:" + NONE)) continue; 2665 StringTokenizer tokenizer = 2666 new StringTokenizer (debugOption.substring(3, debugOption.length()), ","); while (tokenizer.hasMoreTokens()) { 2668 String token = tokenizer.nextToken(); 2669 if (token.equals("vars")) { this.options.put( 2671 CompilerOptions.OPTION_LocalVariableAttribute, 2672 CompilerOptions.GENERATE); 2673 } else if (token.equals("lines")) { this.options.put( 2675 CompilerOptions.OPTION_LineNumberAttribute, 2676 CompilerOptions.GENERATE); 2677 } else if (token.equals("source")) { this.options.put( 2679 CompilerOptions.OPTION_SourceFileAttribute, 2680 CompilerOptions.GENERATE); 2681 } else { 2682 throw new InvalidInputException( 2683 this.bind("configure.invalidDebugOption", debugOption)); } 2685 } 2686 continue; 2687 } 2688 throw new InvalidInputException( 2689 this.bind("configure.invalidDebugOption", debugOption)); } 2691 if (currentArg.startsWith("-nowarn")) { disableWarnings(); 2693 mode = DEFAULT; 2694 continue; 2695 } 2696 if (currentArg.startsWith("-warn")) { mode = DEFAULT; 2698 String warningOption = currentArg; 2699 int length = currentArg.length(); 2700 if (length == 10 && warningOption.equals("-warn:" + NONE)) { disableWarnings(); 2702 continue; 2703 } 2704 if (length <= 6) { 2705 throw new InvalidInputException( 2706 this.bind("configure.invalidWarningConfiguration", warningOption)); } 2708 int warnTokenStart; 2709 boolean isEnabling; 2710 switch (warningOption.charAt(6)) { 2711 case '+' : 2712 warnTokenStart = 7; 2713 isEnabling = true; 2714 break; 2715 case '-' : 2716 warnTokenStart = 7; 2717 isEnabling = false; break; 2719 default: 2720 warnTokenStart = 6; 2721 if (!didSpecifyWarnings) disableWarnings(); 2724 isEnabling = true; 2725 } 2726 2727 StringTokenizer tokenizer = 2728 new StringTokenizer (warningOption.substring(warnTokenStart, warningOption.length()), ","); int tokenCounter = 0; 2730 2731 if (didSpecifyDeprecation) { this.options.put(CompilerOptions.OPTION_ReportDeprecation, CompilerOptions.WARNING); 2733 } 2734 2735 while (tokenizer.hasMoreTokens()) { 2736 String token = tokenizer.nextToken(); 2737 tokenCounter++; 2738 handleWarningToken(token, isEnabling, useEnableJavadoc); 2739 } 2740 if (tokenCounter == 0) 2741 throw new InvalidInputException( 2742 this.bind("configure.invalidWarningOption", currentArg)); didSpecifyWarnings = true; 2744 continue; 2745 } 2746 if (currentArg.equals("-target")) { mode = INSIDE_TARGET; 2748 continue; 2749 } 2750 if (currentArg.equals("-preserveAllLocals")) { this.options.put( 2752 CompilerOptions.OPTION_PreserveUnusedLocal, 2753 CompilerOptions.PRESERVE); 2754 mode = DEFAULT; 2755 continue; 2756 } 2757 if (currentArg.equals("-enableJavadoc")) { mode = DEFAULT; 2759 this.options.put( 2760 CompilerOptions.OPTION_DocCommentSupport, 2761 CompilerOptions.ENABLED); 2762 useEnableJavadoc = true; 2763 continue; 2764 } 2765 if (currentArg.equals("-Xemacs")) { mode = DEFAULT; 2767 this.logger.setEmacs(); 2768 continue; 2769 } 2770 if (currentArg.startsWith("-A")) { mode = DEFAULT; 2773 continue; 2774 } 2775 if (currentArg.equals("-processorpath")) { mode = INSIDE_PROCESSOR_PATH_start; 2777 continue; 2778 } 2779 if (currentArg.equals("-processor")) { mode = INSIDE_PROCESSOR_start; 2781 continue; 2782 } 2783 if (currentArg.equals("-proc:only")) { this.options.put( 2785 CompilerOptions.OPTION_GenerateClassFiles, 2786 CompilerOptions.DISABLED); 2787 mode = DEFAULT; 2788 continue; 2789 } 2790 if (currentArg.equals("-proc:none")) { didSpecifyDisabledAnnotationProcessing = true; 2792 this.options.put( 2793 CompilerOptions.OPTION_Process_Annotations, 2794 CompilerOptions.DISABLED); 2795 mode = DEFAULT; 2796 continue; 2797 } 2798 if (currentArg.equals("-s")) { mode = INSIDE_S_start; 2800 continue; 2801 } 2802 if (currentArg.equals("-XprintProcessorInfo") || currentArg.equals("-XprintRounds")) { mode = DEFAULT; 2805 continue; 2806 } 2807 if (currentArg.startsWith("-X")) { mode = DEFAULT; 2810 continue; 2811 } 2812 if (currentArg.startsWith("-J")) { mode = DEFAULT; 2814 continue; 2815 } 2816 if (currentArg.equals("-O")) { mode = DEFAULT; 2818 continue; 2819 } 2820 if (currentArg.equals("-classNames")) { mode = INSIDE_CLASS_NAMES; 2822 continue; 2823 } 2824 break; 2825 case INSIDE_TARGET : 2826 if (this.didSpecifyTarget) { 2827 throw new InvalidInputException( 2828 this.bind("configure.duplicateTarget", currentArg)); } 2830 this.didSpecifyTarget = true; 2831 if (currentArg.equals("1.1")) { this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_1); 2833 } else if (currentArg.equals("1.2")) { this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_2); 2835 } else if (currentArg.equals("1.3")) { this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_3); 2837 } else if (currentArg.equals("1.4")) { this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_4); 2839 } else if (currentArg.equals("1.5") || currentArg.equals("5") || currentArg.equals("5.0")) { this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_5); 2841 } else if (currentArg.equals("1.6") || currentArg.equals("6") || currentArg.equals("6.0")) { this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_6); 2843 } else if (currentArg.equals("1.7") || currentArg.equals("7") || currentArg.equals("7.0")) { this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_7); 2845 } else if (currentArg.equals("jsr14")) { this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_JSR14); 2847 } else { 2848 throw new InvalidInputException(this.bind("configure.targetJDK", currentArg)); } 2850 mode = DEFAULT; 2851 continue; 2852 case INSIDE_LOG : 2853 this.log = currentArg; 2854 mode = DEFAULT; 2855 continue; 2856 case INSIDE_REPETITION : 2857 try { 2858 this.repetitions = Integer.parseInt(currentArg); 2859 if (this.repetitions <= 0) { 2860 throw new InvalidInputException(this.bind("configure.repetition", currentArg)); } 2862 } catch (NumberFormatException e) { 2863 throw new InvalidInputException(this.bind("configure.repetition", currentArg)); } 2865 mode = DEFAULT; 2866 continue; 2867 case INSIDE_MAX_PROBLEMS : 2868 try { 2869 this.maxProblems = Integer.parseInt(currentArg); 2870 if (this.maxProblems <= 0) { 2871 throw new InvalidInputException(this.bind("configure.maxProblems", currentArg)); } 2873 this.options.put(CompilerOptions.OPTION_MaxProblemPerUnit, currentArg); 2874 } catch (NumberFormatException e) { 2875 throw new InvalidInputException(this.bind("configure.maxProblems", currentArg)); } 2877 mode = DEFAULT; 2878 continue; 2879 case INSIDE_SOURCE : 2880 if (this.didSpecifySource) { 2881 throw new InvalidInputException( 2882 this.bind("configure.duplicateSource", currentArg)); } 2884 this.didSpecifySource = true; 2885 if (currentArg.equals("1.3")) { this.options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_3); 2887 } else if (currentArg.equals("1.4")) { this.options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_4); 2889 } else if (currentArg.equals("1.5") || currentArg.equals("5") || currentArg.equals("5.0")) { this.options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_5); 2891 } else if (currentArg.equals("1.6") || currentArg.equals("6") || currentArg.equals("6.0")) { this.options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_6); 2893 } else if (currentArg.equals("1.7") || currentArg.equals("7") || currentArg.equals("7.0")) { this.options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_7); 2895 } else { 2896 throw new InvalidInputException(this.bind("configure.source", currentArg)); } 2898 mode = DEFAULT; 2899 continue; 2900 case INSIDE_DEFAULT_ENCODING : 2901 if (didSpecifyDefaultEncoding) { 2902 throw new InvalidInputException( 2903 this.bind("configure.duplicateDefaultEncoding", currentArg)); } 2905 try { new InputStreamReader (new ByteArrayInputStream (new byte[0]), currentArg); 2907 } catch (UnsupportedEncodingException e) { 2908 throw new InvalidInputException( 2909 this.bind("configure.unsupportedEncoding", currentArg)); } 2911 this.options.put(CompilerOptions.OPTION_Encoding, currentArg); 2912 didSpecifyDefaultEncoding = true; 2913 mode = DEFAULT; 2914 continue; 2915 case INSIDE_DESTINATION_PATH : 2916 this.setDestinationPath(currentArg.equals(NONE) ? NONE : currentArg); 2917 mode = DEFAULT; 2918 continue; 2919 case INSIDE_CLASSPATH_start: 2920 mode = DEFAULT; 2921 index += processPaths(newCommandLineArgs, index, currentArg, classpaths); 2922 continue; 2923 case INSIDE_BOOTCLASSPATH_start: 2924 mode = DEFAULT; 2925 index += processPaths(newCommandLineArgs, index, currentArg, bootclasspaths); 2926 continue; 2927 case INSIDE_SOURCE_PATH_start: 2928 mode = DEFAULT; 2929 String [] sourcePaths = new String [1]; 2930 index += processPaths(newCommandLineArgs, index, currentArg, sourcePaths); 2931 sourcepathClasspathArg = sourcePaths[0]; 2932 continue; 2933 case INSIDE_EXT_DIRS: 2934 if (currentArg.indexOf("[-d") != -1) { throw new InvalidInputException( 2936 this.bind("configure.unexpectedDestinationPathEntry", "-extdir")); } 2939 StringTokenizer tokenizer = new StringTokenizer (currentArg, File.pathSeparator, false); 2940 extdirsClasspaths = new ArrayList (DEFAULT_SIZE_CLASSPATH); 2941 while (tokenizer.hasMoreTokens()) 2942 extdirsClasspaths.add(tokenizer.nextToken()); 2943 mode = DEFAULT; 2944 continue; 2945 case INSIDE_ENDORSED_DIRS: 2946 if (currentArg.indexOf("[-d") != -1) { throw new InvalidInputException( 2948 this.bind("configure.unexpectedDestinationPathEntry", "-endorseddirs")); } tokenizer = new StringTokenizer (currentArg, File.pathSeparator, false); 2951 endorsedDirClasspaths = new ArrayList (DEFAULT_SIZE_CLASSPATH); 2952 while (tokenizer.hasMoreTokens()) 2953 endorsedDirClasspaths.add(tokenizer.nextToken()); 2954 mode = DEFAULT; 2955 continue; 2956 case INSIDE_SOURCE_DIRECTORY_DESTINATION_PATH: 2957 if (currentArg.endsWith("]")) { customDestinationPath = currentArg.substring(0, 2959 currentArg.length() - 1); 2960 } else { 2961 throw new InvalidInputException( 2962 this.bind("configure.incorrectDestinationPathEntry", "[-d " + currentArg)); } 2965 break; 2966 case INSIDE_PROCESSOR_PATH_start : 2967 mode = DEFAULT; 2969 continue; 2970 case INSIDE_PROCESSOR_start : 2971 mode = DEFAULT; 2973 continue; 2974 case INSIDE_S_start : 2975 mode = DEFAULT; 2977 continue; 2978 case INSIDE_CLASS_NAMES : 2979 tokenizer = new StringTokenizer (currentArg, ","); if (this.classNames == null) { 2981 this.classNames = new String [DEFAULT_SIZE_CLASSPATH]; 2982 } 2983 while (tokenizer.hasMoreTokens()) { 2984 if (this.classNames.length == classCount) { 2985 System.arraycopy( 2987 this.classNames, 2988 0, 2989 (this.classNames = new String [classCount * 2]), 2990 0, 2991 classCount); 2992 } 2993 this.classNames[classCount++] = tokenizer.nextToken(); 2994 } 2995 mode = DEFAULT; 2996 continue; 2997 } 2998 2999 if (customDestinationPath == null) { 3001 if (File.separatorChar != '/') { 3002 currentArg = currentArg.replace('/', File.separatorChar); 3003 } 3004 if (currentArg.endsWith("[-d")) { currentSourceDirectory = currentArg.substring(0, 3006 currentArg.length() - 3); 3007 mode = INSIDE_SOURCE_DIRECTORY_DESTINATION_PATH; 3008 continue; 3009 } else { 3010 currentSourceDirectory = currentArg; 3011 } 3012 } 3013 File dir = new File (currentSourceDirectory); 3014 if (!dir.isDirectory()) { 3015 throw new InvalidInputException( 3016 this.bind("configure.unrecognizedOption", currentSourceDirectory)); } 3018 String [] result = FileFinder.find(dir, SuffixConstants.SUFFIX_STRING_JAVA); 3019 if (NONE.equals(customDestinationPath)) { 3020 customDestinationPath = NONE; } 3022 if (this.filenames != null) { 3023 int length = result.length; 3025 System.arraycopy( 3026 this.filenames, 3027 0, 3028 (this.filenames = new String [length + filesCount]), 3029 0, 3030 filesCount); 3031 System.arraycopy( 3032 this.encodings, 3033 0, 3034 (this.encodings = new String [length + filesCount]), 3035 0, 3036 filesCount); 3037 System.arraycopy( 3038 this.destinationPaths, 3039 0, 3040 (this.destinationPaths = new String [length + filesCount]), 3041 0, 3042 filesCount); 3043 System.arraycopy(result, 0, this.filenames, filesCount, length); 3044 for (int i = 0; i < length; i++) { 3045 this.encodings[filesCount + i] = customEncoding; 3046 this.destinationPaths[filesCount + i] = customDestinationPath; 3047 } 3048 filesCount += length; 3049 customEncoding = null; 3050 customDestinationPath = null; 3051 currentSourceDirectory = null; 3052 } else { 3053 this.filenames = result; 3054 filesCount = this.filenames.length; 3055 this.encodings = new String [filesCount]; 3056 this.destinationPaths = new String [filesCount]; 3057 for (int i = 0; i < filesCount; i++) { 3058 this.encodings[i] = customEncoding; 3059 this.destinationPaths[i] = customDestinationPath; 3060 } 3061 customEncoding = null; 3062 customDestinationPath = null; 3063 currentSourceDirectory = null; 3064 } 3065 mode = DEFAULT; 3066 continue; 3067 } 3068 3069 if (printUsageRequired || (filesCount == 0 && classCount == 0)) { 3070 if (usageSection == null) { 3071 printUsage(); } else { 3073 printUsage(usageSection); 3074 } 3075 this.proceed = false; 3076 return; 3077 } 3078 3079 if (this.log != null) { 3080 this.logger.setLog(this.log); 3081 } else { 3082 this.showProgress = false; 3083 } 3084 this.logger.logVersion(printVersionRequired); 3085 3086 validateOptions(didSpecifyCompliance); 3087 3088 if (!didSpecifyDisabledAnnotationProcessing 3091 && CompilerOptions.versionToJdkLevel(this.options.get(CompilerOptions.OPTION_Compliance)) >= ClassFileConstants.JDK1_6) { 3092 this.options.put(CompilerOptions.OPTION_Process_Annotations, CompilerOptions.ENABLED); 3093 } 3094 3095 this.logger.logCommandLineArguments(newCommandLineArgs); 3096 this.logger.logOptions(this.options); 3097 if (this.repetitions == 0) { 3098 this.repetitions = 1; 3099 } 3100 if (this.repetitions >= 3 && this.timing) { 3101 this.times = new long[this.repetitions]; 3102 this.timesCounter = 0; 3103 } 3104 3105 if (filesCount != 0) { 3106 System.arraycopy( 3107 this.filenames, 3108 0, 3109 (this.filenames = new String [filesCount]), 3110 0, 3111 filesCount); 3112 } 3113 3114 if (classCount != 0) { 3115 System.arraycopy( 3116 this.classNames, 3117 0, 3118 (this.classNames = new String [classCount]), 3119 0, 3120 classCount); 3121 } 3122 3123 setPaths(bootclasspaths, 3124 sourcepathClasspathArg, 3125 sourcepathClasspaths, 3126 classpaths, 3127 extdirsClasspaths, 3128 endorsedDirClasspaths, 3129 customEncoding); 3130} 3131 3132protected void disableWarnings() { 3133 Object [] entries = this.options.entrySet().toArray(); 3134 for (int i = 0, max = entries.length; i < max; i++) { 3135 Map.Entry entry = (Map.Entry ) entries[i]; 3136 if (!(entry.getKey() instanceof String )) 3137 continue; 3138 if (!(entry.getValue() instanceof String )) 3139 continue; 3140 if (((String ) entry.getValue()).equals(CompilerOptions.WARNING)) { 3141 this.options.put(entry.getKey(), CompilerOptions.IGNORE); 3142 } 3143 } 3144 this.options.put(CompilerOptions.OPTION_TaskTags, Util.EMPTY_STRING); 3145} 3146 3147public String extractDestinationPathFromSourceFile(CompilationResult result) { 3148 ICompilationUnit compilationUnit = result.compilationUnit; 3149 if (compilationUnit != null) { 3150 char[] fileName = compilationUnit.getFileName(); 3151 int lastIndex = CharOperation.lastIndexOf(java.io.File.separatorChar, fileName); 3152 if (lastIndex != -1) { 3153 final String outputPathName = new String (fileName, 0, lastIndex); 3154 final File output = new File (outputPathName); 3155 if (output.exists() && output.isDirectory()) { 3156 return outputPathName; 3157 } 3158 } 3159 } 3160 return System.getProperty("user.dir"); } 3162 3163 3166public ICompilerRequestor getBatchRequestor() { 3167 return new ICompilerRequestor() { 3168 int lineDelta = 0; 3169 public void acceptResult(CompilationResult compilationResult) { 3170 if (compilationResult.lineSeparatorPositions != null) { 3171 int unitLineCount = compilationResult.lineSeparatorPositions.length; 3172 Main.this.lineCount += unitLineCount; 3173 this.lineDelta += unitLineCount; 3174 if (Main.this.showProgress && this.lineDelta > 2000) { 3175 Main.this.logger.logProgress(); 3177 this.lineDelta = 0; 3178 } 3179 } 3180 Main.this.logger.startLoggingSource(compilationResult); 3181 if (compilationResult.hasProblems() || compilationResult.hasTasks()) { 3182 int localErrorCount = Main.this.logger.logProblems(compilationResult.getAllProblems(), compilationResult.compilationUnit.getContents(), Main.this); 3183 if (Main.this.systemExitWhenFinished && !Main.this.proceedOnError && (localErrorCount > 0)) { 3185 CompilationUnitDeclaration[] queuedUnits = Main.this.batchCompiler.unitsToProcess; 3187 for (int i = 0, length = Main.this.batchCompiler.totalUnits; i < length; i++) { 3188 CompilationUnitDeclaration queuedUnit = queuedUnits[i]; 3189 if (queuedUnit == null) continue; 3190 CompilationResult result = queuedUnit.compilationResult; 3191 if (result.hasProblems() && !result.hasBeenAccepted) { 3192 Main.this.logger.logProblems(result.getAllProblems(), result.compilationUnit.getContents(), Main.this); 3193 } 3194 } 3195 Main.this.logger.endLoggingSource(); 3196 Main.this.logger.endLoggingSources(); 3197 Main.this.logger.printStats(); 3198 Main.this.logger.flush(); 3199 Main.this.logger.close(); 3200 System.exit(-1); 3201 } 3202 } 3203 outputClassFiles(compilationResult); 3204 Main.this.logger.endLoggingSource(); 3205 } 3206 }; 3207} 3208 3209 3212public CompilationUnit[] getCompilationUnits() 3213 throws InvalidInputException { 3214 int fileCount = this.filenames.length; 3215 CompilationUnit[] units = new CompilationUnit[fileCount]; 3216 HashtableOfObject knownFileNames = new HashtableOfObject(fileCount); 3217 3218 String defaultEncoding = (String ) this.options.get(CompilerOptions.OPTION_Encoding); 3219 if (Util.EMPTY_STRING.equals(defaultEncoding)) 3220 defaultEncoding = null; 3221 3222 for (int i = 0; i < fileCount; i++) { 3223 char[] charName = this.filenames[i].toCharArray(); 3224 if (knownFileNames.get(charName) != null) 3225 throw new InvalidInputException(this.bind("unit.more", this.filenames[i])); knownFileNames.put(charName, charName); 3227 File file = new File (this.filenames[i]); 3228 if (!file.exists()) 3229 throw new InvalidInputException(this.bind("unit.missing", this.filenames[i])); String encoding = this.encodings[i]; 3231 if (encoding == null) 3232 encoding = defaultEncoding; 3233 units[i] = new CompilationUnit(null, this.filenames[i], encoding, 3234 this.destinationPaths[i]); 3235 } 3236 return units; 3237} 3238 3239 3242public IErrorHandlingPolicy getHandlingPolicy() { 3243 3244 return new IErrorHandlingPolicy() { 3246 public boolean proceedOnErrors() { 3247 return Main.this.proceedOnError; } 3249 public boolean stopOnFirstError() { 3250 return false; 3251 } 3252 }; 3253} 3254 3257public File getJavaHome() { 3258 if (!javaHomeChecked) { 3259 javaHomeChecked = true; 3260 String javaHome = System.getProperty("java.home"); if (javaHome != null) { 3262 this.javaHomeCache = new File (javaHome); 3263 if (!this.javaHomeCache.exists()) 3264 this.javaHomeCache = null; 3265 } 3266 } 3267 return this.javaHomeCache; 3268} 3269 3270public FileSystem getLibraryAccess() { 3271 return new FileSystem(this.checkedClasspaths, this.filenames); 3272} 3273 3274 3277public IProblemFactory getProblemFactory() { 3278 return new DefaultProblemFactory(this.compilerLocale); 3279} 3280 3283protected void initialize(PrintWriter outWriter, 3284 PrintWriter errWriter, 3285 boolean systemExit) { 3286 this.initialize(outWriter, errWriter, systemExit, null); 3287} 3288protected void initialize(PrintWriter outWriter, 3289 PrintWriter errWriter, 3290 boolean systemExit, 3291 Map customDefaultOptions) { 3292 this.logger = new Logger(this, outWriter, errWriter); 3293 this.proceed = true; 3294 this.out = outWriter; 3295 this.err = errWriter; 3296 this.systemExitWhenFinished = systemExit; 3297 this.options = new CompilerOptions().getMap(); 3298 if (customDefaultOptions != null) { 3299 this.didSpecifySource = customDefaultOptions.get(CompilerOptions.OPTION_Source) != null; 3300 this.didSpecifyTarget = customDefaultOptions.get(CompilerOptions.OPTION_TargetPlatform) != null; 3301 for (Iterator iter = customDefaultOptions.entrySet().iterator(); iter.hasNext();) { 3302 Map.Entry entry = (Map.Entry ) iter.next(); 3303 this.options.put(entry.getKey(), entry.getValue()); 3304 } 3305 } else { 3306 this.didSpecifySource = false; 3307 this.didSpecifyTarget = false; 3308 } 3309 this.classNames = null; 3310} 3311public void outputClassFiles(CompilationResult unitResult) { 3314 if (!((unitResult == null) || (unitResult.hasErrors() && !this.proceedOnError))) { 3315 ClassFile[] classFiles = unitResult.getClassFiles(); 3316 String currentDestinationPath = null; 3317 boolean generateClasspathStructure = false; 3318 CompilationUnit compilationUnit = 3319 (CompilationUnit) unitResult.compilationUnit; 3320 if (compilationUnit.destinationPath == null) { 3321 if (this.destinationPath == null) { 3322 currentDestinationPath = 3323 extractDestinationPathFromSourceFile(unitResult); 3324 } else if (this.destinationPath != NONE) { 3325 currentDestinationPath = this.destinationPath; 3326 generateClasspathStructure = true; 3327 } } else if (compilationUnit.destinationPath != NONE) { 3329 currentDestinationPath = compilationUnit.destinationPath; 3330 generateClasspathStructure = true; 3331 } if (currentDestinationPath != null) { 3333 for (int i = 0, fileCount = classFiles.length; i < fileCount; i++) { 3334 ClassFile classFile = classFiles[i]; 3336 char[] filename = classFile.fileName(); 3337 int length = filename.length; 3338 char[] relativeName = new char[length + 6]; 3339 System.arraycopy(filename, 0, relativeName, 0, length); 3340 System.arraycopy(SuffixConstants.SUFFIX_class, 0, relativeName, length, 6); 3341 CharOperation.replace(relativeName, '/', File.separatorChar); 3342 String relativeStringName = new String (relativeName); 3343 try { 3344 if (this.compilerOptions.verbose) 3345 this.out.println( 3346 Messages.bind( 3347 Messages.compilation_write, 3348 new String [] { 3349 String.valueOf(this.exportedClassFilesCounter+1), 3350 relativeStringName 3351 })); 3352 ClassFile.writeToDisk( 3353 generateClasspathStructure, 3354 currentDestinationPath, 3355 relativeStringName, 3356 classFile); 3357 LookupEnvironment env = this.batchCompiler.lookupEnvironment; 3358 if (classFile.isShared) env.classFilePool.release(classFile); 3359 this.logger.logClassFile( 3360 generateClasspathStructure, 3361 currentDestinationPath, 3362 relativeStringName); 3363 this.exportedClassFilesCounter++; 3364 } catch (IOException e) { 3365 this.logger.logNoClassFileCreated(currentDestinationPath, relativeStringName, e); 3366 } 3367 } 3368 } 3369 } 3370} 3371 3372 3375public void performCompilation() throws InvalidInputException { 3376 3377 this.startTime = System.currentTimeMillis(); 3378 3379 FileSystem environment = getLibraryAccess(); 3380 this.compilerOptions = new CompilerOptions(this.options); 3381 this.compilerOptions.performMethodsFullRecovery = false; 3382 this.compilerOptions.performStatementsRecovery = false; 3383 this.batchCompiler = 3384 new Compiler ( 3385 environment, 3386 getHandlingPolicy(), 3387 this.compilerOptions, 3388 getBatchRequestor(), 3389 getProblemFactory(), 3390 this.out); 3391 3392 if (this.compilerOptions.complianceLevel >= ClassFileConstants.JDK1_6 3393 && this.compilerOptions.processAnnotations) { 3394 if (checkVMVersion(ClassFileConstants.JDK1_6)) { 3395 initializeAnnotationProcessorManager(); 3396 if (this.classNames != null) { 3397 this.batchCompiler.setBinaryTypes(processClassNames(this.batchCompiler.lookupEnvironment)); 3398 } 3399 } else { 3400 this.logger.logIncorrectVMVersionForAnnotationProcessing(); 3402 } 3403 } 3404 3405 this.compilerOptions.verbose = this.verbose; 3407 this.compilerOptions.produceReferenceInfo = this.produceRefInfo; 3408 try { 3409 this.logger.startLoggingSources(); 3410 this.batchCompiler.compile(getCompilationUnits()); 3411 } finally { 3412 this.logger.endLoggingSources(); 3413 } 3414 3415 if (this.extraProblems != null) { 3416 this.logger.loggingExtraProblems(this); 3417 this.extraProblems = null; 3418 } 3419 this.logger.printStats(); 3420 3421 environment.cleanup(); 3423} 3424private ReferenceBinding[] processClassNames(LookupEnvironment environment) throws InvalidInputException { 3425 int length = this.classNames.length; 3427 ReferenceBinding[] referenceBindings = new ReferenceBinding[length]; 3428 for (int i = 0; i < length; i++) { 3429 String currentName = this.classNames[i]; 3430 char[][] compoundName = null; 3431 if (currentName.indexOf('.') != -1) { 3432 char[] typeName = currentName.toCharArray(); 3434 compoundName = CharOperation.splitOn('.', typeName); 3435 } else { 3436 compoundName = new char[][] { currentName.toCharArray() }; 3437 } 3438 ReferenceBinding type = environment.getType(compoundName); 3439 if (type != null && type.isValidBinding()) { 3440 if (type.isBinaryBinding()) { 3441 referenceBindings[i] = type; 3442 } 3443 } else { 3444 throw new InvalidInputException( 3445 this.bind("configure.invalidClassName", currentName)); } 3447 } 3448 return referenceBindings; 3449} 3450protected void initializeAnnotationProcessorManager() { 3451 try { 3452 Class c = Class.forName("org.eclipse.jdt.internal.compiler.apt.dispatch.BatchAnnotationProcessorManager"); AbstractAnnotationProcessorManager annotationManager = (AbstractAnnotationProcessorManager) c.newInstance(); 3454 annotationManager.configure(this, this.expandedCommandLine); 3455 annotationManager.setErr(this.err); 3456 annotationManager.setOut(this.out); 3457 this.batchCompiler.annotationProcessorManager = annotationManager; 3458 } catch (ClassNotFoundException e) { 3459 } catch (InstantiationException e) { 3461 throw new org.eclipse.jdt.internal.compiler.problem.AbortCompilation(); 3463 } catch (IllegalAccessException e) { 3464 throw new org.eclipse.jdt.internal.compiler.problem.AbortCompilation(); 3466 } catch(UnsupportedClassVersionError e) { 3467 this.logger.logIncorrectVMVersionForAnnotationProcessing(); 3469 } 3470} 3471public void printUsage() { 3472 printUsage("misc.usage"); } 3474private void printUsage(String sectionID) { 3475 this.logger.logUsage( 3476 this.bind( 3477 sectionID, 3478 new String [] { 3479 System.getProperty("path.separator"), this.bind("compiler.name"), this.bind("compiler.version"), this.bind("compiler.copyright") })); 3484 this.logger.flush(); 3485} 3486 3489public void processPathEntries(final int defaultSize, final ArrayList paths, 3490 final String currentPath, String customEncoding, boolean isSourceOnly, 3491 boolean rejectDestinationPathOnJars) 3492 throws InvalidInputException { 3493 String currentClasspathName = null; 3494 String currentDestinationPath = null; 3495 ArrayList currentRuleSpecs = new ArrayList (defaultSize); 3496 StringTokenizer tokenizer = new StringTokenizer (currentPath, 3497 File.pathSeparator + "[]", true); ArrayList tokens = new ArrayList (); 3499 while (tokenizer.hasMoreTokens()) { 3500 tokens.add(tokenizer.nextToken()); 3501 } 3502 final int start = 0; 3504 final int readyToClose = 1; 3505 final int readyToCloseEndingWithRules = 2; 3507 final int readyToCloseOrOtherEntry = 3; 3509 final int rulesNeedAnotherRule = 4; 3511 final int rulesStart = 5; 3513 final int rulesReadyToClose = 6; 3515 final int destinationPathReadyToClose = 7; 3517 final int readyToCloseEndingWithDestinationPath = 8; 3519 final int destinationPathStart = 9; 3521 final int bracketOpened = 10; 3523 final int bracketClosed = 11; 3525 3527 final int error = 99; 3528 int state = start; 3529 String token = null; 3530 int cursor = 0, tokensNb = tokens.size(), bracket = -1; 3531 while (cursor < tokensNb && state != error) { 3532 token = (String ) tokens.get(cursor++); 3533 if (token.equals(File.pathSeparator)) { 3534 switch (state) { 3535 case start: 3536 case readyToCloseOrOtherEntry: 3537 case bracketOpened: 3538 break; 3539 case readyToClose: 3540 case readyToCloseEndingWithRules: 3541 case readyToCloseEndingWithDestinationPath: 3542 state = readyToCloseOrOtherEntry; 3543 addNewEntry(paths, currentClasspathName, currentRuleSpecs, 3544 customEncoding, currentDestinationPath, isSourceOnly, 3545 rejectDestinationPathOnJars); 3546 currentRuleSpecs.clear(); 3547 break; 3548 case rulesReadyToClose: 3549 state = rulesNeedAnotherRule; 3550 break; 3551 case destinationPathReadyToClose: 3552 throw new InvalidInputException( 3553 this.bind("configure.incorrectDestinationPathEntry", currentPath)); 3555 case bracketClosed: 3556 cursor = bracket + 1; 3557 state = rulesStart; 3558 break; 3559 default: 3560 state = error; 3561 } 3562 } else if (token.equals("[")) { switch (state) { 3564 case start: 3565 currentClasspathName = ""; case readyToClose: 3567 bracket = cursor - 1; 3568 case bracketClosed: 3569 state = bracketOpened; 3570 break; 3571 case readyToCloseEndingWithRules: 3572 state = destinationPathStart; 3573 break; 3574 case readyToCloseEndingWithDestinationPath: 3575 state = rulesStart; 3576 break; 3577 case bracketOpened: 3578 default: 3579 state = error; 3580 } 3581 } else if (token.equals("]")) { switch (state) { 3583 case rulesReadyToClose: 3584 state = readyToCloseEndingWithRules; 3585 break; 3586 case destinationPathReadyToClose: 3587 state = readyToCloseEndingWithDestinationPath; 3588 break; 3589 case bracketOpened: 3590 state = bracketClosed; 3591 break; 3592 case bracketClosed: 3593 default: 3594 state = error; 3595 } 3596 } else { 3597 switch (state) { 3599 case start: 3600 case readyToCloseOrOtherEntry: 3601 state = readyToClose; 3602 currentClasspathName = token; 3603 break; 3604 case rulesStart: 3605 if (token.startsWith("-d ")) { if (currentDestinationPath != null) { 3607 throw new InvalidInputException( 3608 this.bind("configure.duplicateDestinationPathEntry", currentPath)); 3610 } 3611 currentDestinationPath = token.substring(3).trim(); 3612 state = destinationPathReadyToClose; 3613 break; 3614 } case rulesNeedAnotherRule: 3616 if (currentDestinationPath != null) { 3617 throw new InvalidInputException( 3618 this.bind("configure.accessRuleAfterDestinationPath", currentPath)); 3620 } 3621 state = rulesReadyToClose; 3622 currentRuleSpecs.add(token); 3623 break; 3624 case destinationPathStart: 3625 if (!token.startsWith("-d ")) { state = error; 3627 } else { 3628 currentDestinationPath = token.substring(3).trim(); 3629 state = destinationPathReadyToClose; 3630 } 3631 break; 3632 case bracketClosed: 3633 for (int i = bracket; i < cursor ; i++) { 3634 currentClasspathName += (String ) tokens.get(i); 3635 } 3636 state = readyToClose; 3637 break; 3638 case bracketOpened: 3639 break; 3640 default: 3641 state = error; 3642 } 3643 } 3644 if (state == bracketClosed && cursor == tokensNb) { 3645 cursor = bracket + 1; 3646 state = rulesStart; 3647 } 3648 } 3649 switch(state) { 3650 case readyToCloseOrOtherEntry: 3651 break; 3652 case readyToClose: 3653 case readyToCloseEndingWithRules: 3654 case readyToCloseEndingWithDestinationPath: 3655 addNewEntry(paths, currentClasspathName, currentRuleSpecs, 3656 customEncoding, currentDestinationPath, isSourceOnly, 3657 rejectDestinationPathOnJars); 3658 break; 3659 case bracketOpened: 3660 case bracketClosed: 3661 default : 3662 if (currentPath.length() != 0) { 3664 this.logger.logIncorrectClasspath(currentPath); 3665 } 3666 } 3667} 3668 3669private int processPaths(String [] args, int index, String currentArg, ArrayList paths) throws InvalidInputException { 3670 int localIndex = index; 3671 int count = 0; 3672 for (int i = 0, max = currentArg.length(); i < max; i++) { 3673 switch(currentArg.charAt(i)) { 3674 case '[' : 3675 count++; 3676 break; 3677 case ']' : 3678 count--; 3679 break; 3680 } 3681 } 3682 if (count == 0) { 3683 paths.add(currentArg); 3684 } else if (count > 1) { 3685 throw new InvalidInputException( 3686 this.bind("configure.unexpectedBracket", currentArg)); 3688 } else { 3689 StringBuffer currentPath = new StringBuffer (currentArg); 3690 while (true) { 3691 if (localIndex >= args.length) { 3692 throw new InvalidInputException( 3693 this.bind("configure.unexpectedBracket", currentArg)); 3695 } 3696 localIndex++; 3697 String nextArg = args[localIndex]; 3698 for (int i = 0, max = nextArg.length(); i < max; i++) { 3699 switch(nextArg.charAt(i)) { 3700 case '[' : 3701 if (count > 1) { 3702 throw new InvalidInputException( 3703 this.bind("configure.unexpectedBracket", nextArg)); 3705 } 3706 count++; 3707 break; 3708 case ']' : 3709 count--; 3710 break; 3711 } 3712 } 3713 if (count == 0) { 3714 currentPath.append(' '); 3715 currentPath.append(nextArg); 3716 paths.add(currentPath.toString()); 3717 return localIndex - index; 3718 } else if (count < 0) { 3719 throw new InvalidInputException( 3720 this.bind("configure.unexpectedBracket", nextArg)); 3722 } else { 3723 currentPath.append(' '); 3724 currentPath.append(nextArg); 3725 } 3726 } 3727 3728 } 3729 return localIndex - index; 3730} 3731private int processPaths(String [] args, int index, String currentArg, String [] paths) throws InvalidInputException { 3732 int localIndex = index; 3733 int count = 0; 3734 for (int i = 0, max = currentArg.length(); i < max; i++) { 3735 switch(currentArg.charAt(i)) { 3736 case '[' : 3737 count++; 3738 break; 3739 case ']' : 3740 count--; 3741 break; 3742 } 3743 } 3744 if (count == 0) { 3745 paths[0] = currentArg; 3746 } else { 3747 StringBuffer currentPath = new StringBuffer (currentArg); 3748 while (true) { 3749 localIndex++; 3750 if (localIndex >= args.length) { 3751 throw new InvalidInputException( 3752 this.bind("configure.unexpectedBracket", currentArg)); 3754 } 3755 String nextArg = args[localIndex]; 3756 for (int i = 0, max = nextArg.length(); i < max; i++) { 3757 switch(nextArg.charAt(i)) { 3758 case '[' : 3759 if (count > 1) { 3760 throw new InvalidInputException( 3761 this.bind("configure.unexpectedBracket", currentArg)); 3763 } 3764 count++; 3765 break; 3766 case ']' : 3767 count--; 3768 break; 3769 } 3770 } 3771 if (count == 0) { 3772 currentPath.append(' '); 3773 currentPath.append(nextArg); 3774 paths[0] = currentPath.toString(); 3775 return localIndex - index; 3776 } else if (count < 0) { 3777 throw new InvalidInputException( 3778 this.bind("configure.unexpectedBracket", currentArg)); 3780 } else { 3781 currentPath.append(' '); 3782 currentPath.append(nextArg); 3783 } 3784 } 3785 3786 } 3787 return localIndex - index; 3788} 3789 3792public void relocalize() { 3793 relocalize(Locale.getDefault()); 3794} 3795 3796private void relocalize(Locale locale) { 3797 this.compilerLocale = locale; 3798 try { 3799 this.bundle = ResourceBundleFactory.getBundle(locale); 3800 } catch(MissingResourceException e) { 3801 System.out.println("Missing resource : " + Main.bundleName.replace('.', '/') + ".properties for locale " + locale); throw e; 3803 } 3804} 3805 3808public void setLocale(Locale locale) { 3809 relocalize(locale); 3810} 3811 3814public void setDestinationPath(String dest) { 3815 this.destinationPath = dest; 3816} 3817 3820protected void setPaths(ArrayList bootclasspaths, 3821 String sourcepathClasspathArg, 3822 ArrayList sourcepathClasspaths, 3823 ArrayList classpaths, 3824 ArrayList extdirsClasspaths, 3825 ArrayList endorsedDirClasspaths, 3826 String customEncoding) throws InvalidInputException { 3827 3828 bootclasspaths = handleBootclasspath(bootclasspaths, customEncoding); 3830 3831 classpaths = handleClasspath(classpaths, customEncoding); 3832 3833 if (sourcepathClasspathArg != null) { 3834 processPathEntries(DEFAULT_SIZE_CLASSPATH, sourcepathClasspaths, 3835 sourcepathClasspathArg, customEncoding, true, false); 3836 } 3837 3838 3844 extdirsClasspaths = handleExtdirs(extdirsClasspaths); 3845 3846 endorsedDirClasspaths = handleEndorseddirs(endorsedDirClasspaths); 3847 3848 3856 bootclasspaths.addAll(endorsedDirClasspaths); 3857 bootclasspaths.addAll(extdirsClasspaths); 3858 bootclasspaths.addAll(sourcepathClasspaths); 3859 bootclasspaths.addAll(classpaths); 3860 classpaths = bootclasspaths; 3861 classpaths = FileSystem.ClasspathNormalizer.normalize(classpaths); 3862 this.checkedClasspaths = new FileSystem.Classpath[classpaths.size()]; 3863 classpaths.toArray(this.checkedClasspaths); 3864 this.logger.logClasspath(this.checkedClasspaths); 3865} 3866protected void validateOptions(boolean didSpecifyCompliance) throws InvalidInputException { 3867 if (didSpecifyCompliance) { 3868 Object version = this.options.get(CompilerOptions.OPTION_Compliance); 3869 if (CompilerOptions.VERSION_1_3.equals(version)) { 3870 if (!this.didSpecifySource) this.options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_3); 3871 if (!this.didSpecifyTarget) this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_1); 3872 } else if (CompilerOptions.VERSION_1_4.equals(version)) { 3873 if (this.didSpecifySource) { 3874 Object source = this.options.get(CompilerOptions.OPTION_Source); 3875 if (CompilerOptions.VERSION_1_3.equals(source)) { 3876 if (!this.didSpecifyTarget) this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_2); 3877 } else if (CompilerOptions.VERSION_1_4.equals(source)) { 3878 if (!this.didSpecifyTarget) this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_4); 3879 } 3880 } else { 3881 this.options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_3); 3882 if (!this.didSpecifyTarget) this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_2); 3883 } 3884 } else if (CompilerOptions.VERSION_1_5.equals(version)) { 3885 if (this.didSpecifySource) { 3886 Object source = this.options.get(CompilerOptions.OPTION_Source); 3887 if (CompilerOptions.VERSION_1_3.equals(source) 3888 || CompilerOptions.VERSION_1_4.equals(source)) { 3889 if (!this.didSpecifyTarget) this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_4); 3890 } else if (CompilerOptions.VERSION_1_5.equals(source)) { 3891 if (!this.didSpecifyTarget) this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_5); 3892 } 3893 } else { 3894 this.options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_5); 3895 if (!this.didSpecifyTarget) this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_5); 3896 } 3897 } else if (CompilerOptions.VERSION_1_6.equals(version)) { 3898 if (this.didSpecifySource) { 3899 Object source = this.options.get(CompilerOptions.OPTION_Source); 3900 if (CompilerOptions.VERSION_1_3.equals(source) 3901 || CompilerOptions.VERSION_1_4.equals(source)) { 3902 if (!this.didSpecifyTarget) this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_4); 3903 } else if (CompilerOptions.VERSION_1_5.equals(source) 3904 || CompilerOptions.VERSION_1_6.equals(source)) { 3905 if (!this.didSpecifyTarget) this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_6); 3906 } 3907 } else { 3908 this.options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_6); 3909 if (!this.didSpecifyTarget) this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_6); 3910 } 3911 } else if (CompilerOptions.VERSION_1_7.equals(version)) { 3912 if (this.didSpecifySource) { 3913 Object source = this.options.get(CompilerOptions.OPTION_Source); 3914 if (CompilerOptions.VERSION_1_3.equals(source) 3915 || CompilerOptions.VERSION_1_4.equals(source)) { 3916 if (!this.didSpecifyTarget) this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_4); 3917 } else if (CompilerOptions.VERSION_1_5.equals(source) 3918 || CompilerOptions.VERSION_1_6.equals(source)) { 3919 if (!this.didSpecifyTarget) this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_6); 3920 } else if (CompilerOptions.VERSION_1_7.equals(source)) { 3921 if (!this.didSpecifyTarget) this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_7); 3922 } 3923 } else { 3924 this.options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_7); 3925 if (!this.didSpecifyTarget) this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_7); 3926 } 3927 } 3928 } else if (this.didSpecifySource) { 3929 Object version = this.options.get(CompilerOptions.OPTION_Source); 3930 if (CompilerOptions.VERSION_1_4.equals(version)) { 3932 if (!didSpecifyCompliance) this.options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_4); 3933 if (!this.didSpecifyTarget) this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_4); 3934 } else if (CompilerOptions.VERSION_1_5.equals(version)) { 3935 if (!didSpecifyCompliance) this.options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_5); 3936 if (!this.didSpecifyTarget) this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_5); 3937 } else if (CompilerOptions.VERSION_1_6.equals(version)) { 3938 if (!didSpecifyCompliance) this.options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_6); 3939 if (!this.didSpecifyTarget) this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_6); 3940 } else if (CompilerOptions.VERSION_1_7.equals(version)) { 3941 if (!didSpecifyCompliance) this.options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_7); 3942 if (!this.didSpecifyTarget) this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_7); 3943 } 3944 } 3945 3946 final Object sourceVersion = this.options.get(CompilerOptions.OPTION_Source); 3947 final Object compliance = this.options.get(CompilerOptions.OPTION_Compliance); 3948 if (sourceVersion.equals(CompilerOptions.VERSION_1_7) 3949 && CompilerOptions.versionToJdkLevel(compliance) < ClassFileConstants.JDK1_7) { 3950 throw new InvalidInputException(this.bind("configure.incompatibleComplianceForSource", (String )this.options.get(CompilerOptions.OPTION_Compliance), CompilerOptions.VERSION_1_7)); } else if (sourceVersion.equals(CompilerOptions.VERSION_1_6) 3953 && CompilerOptions.versionToJdkLevel(compliance) < ClassFileConstants.JDK1_6) { 3954 throw new InvalidInputException(this.bind("configure.incompatibleComplianceForSource", (String )this.options.get(CompilerOptions.OPTION_Compliance), CompilerOptions.VERSION_1_6)); } else if (sourceVersion.equals(CompilerOptions.VERSION_1_5) 3957 && CompilerOptions.versionToJdkLevel(compliance) < ClassFileConstants.JDK1_5) { 3958 throw new InvalidInputException(this.bind("configure.incompatibleComplianceForSource", (String )this.options.get(CompilerOptions.OPTION_Compliance), CompilerOptions.VERSION_1_5)); } else if (sourceVersion.equals(CompilerOptions.VERSION_1_4) 3961 && CompilerOptions.versionToJdkLevel(compliance) < ClassFileConstants.JDK1_4) { 3962 throw new InvalidInputException(this.bind("configure.incompatibleComplianceForSource", (String )this.options.get(CompilerOptions.OPTION_Compliance), CompilerOptions.VERSION_1_4)); } 3965 3966 if (this.didSpecifyTarget) { 3968 final Object targetVersion = this.options.get(CompilerOptions.OPTION_TargetPlatform); 3969 if (CompilerOptions.VERSION_JSR14.equals(targetVersion)) { 3971 if (CompilerOptions.versionToJdkLevel(sourceVersion) < ClassFileConstants.JDK1_5) { 3973 throw new InvalidInputException(this.bind("configure.incompatibleTargetForGenericSource", (String ) targetVersion, (String ) sourceVersion)); } 3975 } else { 3976 if (CompilerOptions.versionToJdkLevel(sourceVersion) >= ClassFileConstants.JDK1_7 3978 && CompilerOptions.versionToJdkLevel(targetVersion) < ClassFileConstants.JDK1_7){ 3979 throw new InvalidInputException(this.bind("configure.incompatibleTargetForSource", (String ) targetVersion, CompilerOptions.VERSION_1_7)); } 3981 if (CompilerOptions.versionToJdkLevel(sourceVersion) >= ClassFileConstants.JDK1_6 3983 && CompilerOptions.versionToJdkLevel(targetVersion) < ClassFileConstants.JDK1_6){ 3984 throw new InvalidInputException(this.bind("configure.incompatibleTargetForSource", (String ) targetVersion, CompilerOptions.VERSION_1_6)); } 3986 if (CompilerOptions.versionToJdkLevel(sourceVersion) >= ClassFileConstants.JDK1_5 3988 && CompilerOptions.versionToJdkLevel(targetVersion) < ClassFileConstants.JDK1_5){ 3989 throw new InvalidInputException(this.bind("configure.incompatibleTargetForSource", (String ) targetVersion, CompilerOptions.VERSION_1_5)); } 3991 if (CompilerOptions.versionToJdkLevel(sourceVersion) >= ClassFileConstants.JDK1_4 3993 && CompilerOptions.versionToJdkLevel(targetVersion) < ClassFileConstants.JDK1_4){ 3994 throw new InvalidInputException(this.bind("configure.incompatibleTargetForSource", (String ) targetVersion, CompilerOptions.VERSION_1_4)); } 3996 if (CompilerOptions.versionToJdkLevel(compliance) < CompilerOptions.versionToJdkLevel(targetVersion)){ 3998 throw new InvalidInputException(this.bind("configure.incompatibleComplianceForTarget", (String )this.options.get(CompilerOptions.OPTION_Compliance), (String ) targetVersion)); } 4000 } 4001 } 4002} 4003} 4004 | Popular Tags |