Lines 49-54
Link Here
|
49 |
|
49 |
|
50 |
public class Main implements ProblemSeverities, SuffixConstants { |
50 |
public class Main implements ProblemSeverities, SuffixConstants { |
51 |
|
51 |
|
|
|
52 |
public static class Logger { |
53 |
|
54 |
PrintWriter out; |
55 |
PrintWriter err; |
56 |
PrintWriter log; |
57 |
|
58 |
public Logger(PrintWriter out, PrintWriter err) { |
59 |
this.out = out; |
60 |
this.err = err; |
61 |
} |
62 |
|
63 |
public void setLog(PrintWriter log) { |
64 |
this.log = log; |
65 |
} |
66 |
|
67 |
public void close() { |
68 |
if (log != null) { |
69 |
this.log.close(); |
70 |
} |
71 |
} |
72 |
|
73 |
public void flush() { |
74 |
this.out.flush(); |
75 |
this.err.flush(); |
76 |
if (this.log != null) { |
77 |
this.log.flush(); |
78 |
} |
79 |
} |
80 |
|
81 |
public void printErr(String s) { |
82 |
this.err.print(s); |
83 |
if (this.log != null) { |
84 |
this.log.print(s); |
85 |
} |
86 |
} |
87 |
|
88 |
public void printlnErr(String s) { |
89 |
this.err.println(s); |
90 |
if (this.log != null) { |
91 |
this.log.println(s); |
92 |
} |
93 |
} |
94 |
|
95 |
public void printlnOut(String s) { |
96 |
this.out.println(s); |
97 |
} |
98 |
|
99 |
public void printlnOut() { |
100 |
this.out.println(); |
101 |
} |
102 |
|
103 |
public void printOut(char c) { |
104 |
this.out.print(c); |
105 |
} |
106 |
} |
52 |
static { |
107 |
static { |
53 |
relocalize(); |
108 |
relocalize(); |
54 |
} |
109 |
} |
Lines 63-69
Link Here
|
63 |
public String[] classpaths; |
118 |
public String[] classpaths; |
64 |
public String destinationPath; |
119 |
public String destinationPath; |
65 |
public String[] encodings; |
120 |
public String[] encodings; |
66 |
public PrintWriter err; |
121 |
public Logger logger; |
67 |
public int exportedClassFilesCounter; |
122 |
public int exportedClassFilesCounter; |
68 |
public String[] filenames; |
123 |
public String[] filenames; |
69 |
public boolean generatePackagesStructure; |
124 |
public boolean generatePackagesStructure; |
Lines 78-85
Link Here
|
78 |
public Map options; |
133 |
public Map options; |
79 |
public CompilerOptions compilerOptions; // read-only |
134 |
public CompilerOptions compilerOptions; // read-only |
80 |
|
135 |
|
81 |
public PrintWriter out; |
|
|
82 |
|
83 |
public boolean proceed = true; |
136 |
public boolean proceed = true; |
84 |
public boolean proceedOnError = false; |
137 |
public boolean proceedOnError = false; |
85 |
public boolean produceRefInfo = false; |
138 |
public boolean produceRefInfo = false; |
Lines 93-100
Link Here
|
93 |
|
146 |
|
94 |
public Main(PrintWriter outWriter, PrintWriter errWriter, boolean systemExitWhenFinished) { |
147 |
public Main(PrintWriter outWriter, PrintWriter errWriter, boolean systemExitWhenFinished) { |
95 |
|
148 |
|
96 |
this.out = outWriter; |
149 |
this.logger = new Logger(outWriter, errWriter); |
97 |
this.err = errWriter; |
|
|
98 |
this.systemExitWhenFinished = systemExitWhenFinished; |
150 |
this.systemExitWhenFinished = systemExitWhenFinished; |
99 |
this.options = new CompilerOptions().getMap(); |
151 |
this.options = new CompilerOptions().getMap(); |
100 |
} |
152 |
} |
Lines 300-306
Link Here
|
300 |
// System.out.println(new CompilerOptions(this.options)); |
352 |
// System.out.println(new CompilerOptions(this.options)); |
301 |
// } |
353 |
// } |
302 |
if (this.showProgress) |
354 |
if (this.showProgress) |
303 |
this.out.println(Main.bind("progress.compiling")); //$NON-NLS-1$ |
355 |
this.logger.printlnOut(Main.bind("progress.compiling")); //$NON-NLS-1$ |
304 |
for (int i = 0; i < this.repetitions; i++) { |
356 |
for (int i = 0; i < this.repetitions; i++) { |
305 |
this.globalProblemsCount = 0; |
357 |
this.globalProblemsCount = 0; |
306 |
this.globalErrorsCount = 0; |
358 |
this.globalErrorsCount = 0; |
Lines 309-316
Link Here
|
309 |
this.exportedClassFilesCounter = 0; |
361 |
this.exportedClassFilesCounter = 0; |
310 |
|
362 |
|
311 |
if (this.repetitions > 1) { |
363 |
if (this.repetitions > 1) { |
312 |
this.out.flush(); |
364 |
this.logger.flush(); |
313 |
this.out.println( |
365 |
this.logger.printlnOut( |
314 |
Main.bind( |
366 |
Main.bind( |
315 |
"compile.repetition", //$NON-NLS-1$ |
367 |
"compile.repetition", //$NON-NLS-1$ |
316 |
String.valueOf(i + 1), |
368 |
String.valueOf(i + 1), |
Lines 320-359
Link Here
|
320 |
performCompilation(); |
372 |
performCompilation(); |
321 |
} |
373 |
} |
322 |
if (this.showProgress) |
374 |
if (this.showProgress) |
323 |
this.out.println(); |
375 |
this.logger.printlnOut(); |
324 |
} |
376 |
} |
325 |
if (this.systemExitWhenFinished) { |
377 |
if (this.systemExitWhenFinished) { |
326 |
this.out.flush(); |
378 |
this.logger.flush(); |
327 |
this.err.flush(); |
|
|
328 |
System.exit(this.globalErrorsCount > 0 ? -1 : 0); |
379 |
System.exit(this.globalErrorsCount > 0 ? -1 : 0); |
329 |
} |
380 |
} |
330 |
} catch (InvalidInputException e) { |
381 |
} catch (InvalidInputException e) { |
331 |
this.err.println(e.getMessage()); |
382 |
this.logger.printlnErr(e.getMessage()); |
332 |
if (this.systemExitWhenFinished) { |
383 |
if (this.systemExitWhenFinished) { |
333 |
this.out.flush(); |
384 |
this.logger.flush(); |
334 |
this.err.flush(); |
|
|
335 |
if (this.log != null) { |
385 |
if (this.log != null) { |
336 |
this.err.close(); |
386 |
this.logger.close(); |
337 |
} |
387 |
} |
338 |
System.exit(-1); |
388 |
System.exit(-1); |
339 |
} |
389 |
} |
340 |
return false; |
390 |
return false; |
341 |
} catch (RuntimeException e) { // internal compiler failure |
391 |
} catch (RuntimeException e) { // internal compiler failure |
342 |
if (this.systemExitWhenFinished) { |
392 |
if (this.systemExitWhenFinished) { |
343 |
this.out.flush(); |
393 |
this.logger.flush(); |
344 |
this.err.flush(); |
|
|
345 |
if (this.log != null) { |
394 |
if (this.log != null) { |
346 |
this.err.close(); |
395 |
this.logger.close(); |
347 |
} |
396 |
} |
348 |
System.exit(-1); |
397 |
System.exit(-1); |
349 |
} |
398 |
} |
350 |
return false; |
399 |
return false; |
351 |
//e.printStackTrace(); |
400 |
//e.printStackTrace(); |
352 |
} finally { |
401 |
} finally { |
353 |
this.out.flush(); |
402 |
this.logger.flush(); |
354 |
this.err.flush(); |
|
|
355 |
if (this.log != null) { |
403 |
if (this.log != null) { |
356 |
this.err.close(); |
404 |
this.logger.close(); |
357 |
} |
405 |
} |
358 |
} |
406 |
} |
359 |
if (this.globalErrorsCount == 0) |
407 |
if (this.globalErrorsCount == 0) |
Lines 1169-1175
Link Here
|
1169 |
// no user classpath specified. |
1217 |
// no user classpath specified. |
1170 |
String classProp = System.getProperty("java.class.path"); //$NON-NLS-1$ |
1218 |
String classProp = System.getProperty("java.class.path"); //$NON-NLS-1$ |
1171 |
if ((classProp == null) || (classProp.length() == 0)) { |
1219 |
if ((classProp == null) || (classProp.length() == 0)) { |
1172 |
this.err.println(Main.bind("configure.noClasspath")); //$NON-NLS-1$ |
1220 |
this.logger.printlnErr(Main.bind("configure.noClasspath")); //$NON-NLS-1$ |
1173 |
classProp = System.getProperty("user.dir"); //$NON-NLS-1$ |
1221 |
classProp = System.getProperty("user.dir"); //$NON-NLS-1$ |
1174 |
} |
1222 |
} |
1175 |
StringTokenizer tokenizer = new StringTokenizer(classProp, File.pathSeparator); |
1223 |
StringTokenizer tokenizer = new StringTokenizer(classProp, File.pathSeparator); |
Lines 1187-1193
Link Here
|
1187 |
*/ |
1235 |
*/ |
1188 |
String javaversion = System.getProperty("java.version");//$NON-NLS-1$ |
1236 |
String javaversion = System.getProperty("java.version");//$NON-NLS-1$ |
1189 |
if (javaversion != null && javaversion.equalsIgnoreCase("1.1.8")) { //$NON-NLS-1$ |
1237 |
if (javaversion != null && javaversion.equalsIgnoreCase("1.1.8")) { //$NON-NLS-1$ |
1190 |
this.err.println(Main.bind("configure.requiresJDK1.2orAbove")); //$NON-NLS-1$ |
1238 |
this.logger.printlnErr(Main.bind("configure.requiresJDK1.2orAbove")); //$NON-NLS-1$ |
1191 |
this.proceed = false; |
1239 |
this.proceed = false; |
1192 |
return; |
1240 |
return; |
1193 |
} |
1241 |
} |
Lines 1225-1231
Link Here
|
1225 |
|
1273 |
|
1226 |
if (this.log != null) { |
1274 |
if (this.log != null) { |
1227 |
try { |
1275 |
try { |
1228 |
this.err = new PrintWriter(new FileOutputStream(this.log, false)); |
1276 |
this.logger.setLog(new PrintWriter(new FileOutputStream(this.log, false))); |
1229 |
} catch (IOException e) { |
1277 |
} catch (IOException e) { |
1230 |
throw new InvalidInputException(Main.bind("configure.cannotOpenLog")); //$NON-NLS-1$ |
1278 |
throw new InvalidInputException(Main.bind("configure.cannotOpenLog")); //$NON-NLS-1$ |
1231 |
} |
1279 |
} |
Lines 1264-1270
Link Here
|
1264 |
for (int i = 0, max = this.classpaths.length; i < max; i++) { |
1312 |
for (int i = 0, max = this.classpaths.length; i < max; i++) { |
1265 |
File file = new File(this.classpaths[i]); |
1313 |
File file = new File(this.classpaths[i]); |
1266 |
if (!file.exists()) { // signal missing classpath entry file |
1314 |
if (!file.exists()) { // signal missing classpath entry file |
1267 |
this.err.println(Main.bind("configure.incorrectClasspath", this.classpaths[i])); //$NON-NLS-1$ |
1315 |
this.logger.printlnErr(Main.bind("configure.incorrectClasspath", this.classpaths[i])); //$NON-NLS-1$ |
1268 |
} |
1316 |
} |
1269 |
} |
1317 |
} |
1270 |
if (this.destinationPath == null) { |
1318 |
if (this.destinationPath == null) { |
Lines 1391-1397
Link Here
|
1391 |
this.lineDelta += unitLineCount; |
1439 |
this.lineDelta += unitLineCount; |
1392 |
if (Main.this.showProgress |
1440 |
if (Main.this.showProgress |
1393 |
&& this.lineDelta > 2000) { // in -log mode, dump a dot every 2000 lines compiled |
1441 |
&& this.lineDelta > 2000) { // in -log mode, dump a dot every 2000 lines compiled |
1394 |
Main.this.out.print('.'); |
1442 |
Main.this.logger.printOut('.'); |
1395 |
this.lineDelta = 0; |
1443 |
this.lineDelta = 0; |
1396 |
} |
1444 |
} |
1397 |
} |
1445 |
} |
Lines 1404-1411
Link Here
|
1404 |
if (problems[i] != null) { |
1452 |
if (problems[i] != null) { |
1405 |
Main.this.globalProblemsCount++; |
1453 |
Main.this.globalProblemsCount++; |
1406 |
if (localErrorCount == 0) |
1454 |
if (localErrorCount == 0) |
1407 |
Main.this.err.println("----------"); //$NON-NLS-1$ |
1455 |
Main.this.logger.printlnErr("----------"); //$NON-NLS-1$ |
1408 |
Main.this.err.print( |
1456 |
Main.this.logger.printErr( |
1409 |
Main.this.globalProblemsCount |
1457 |
Main.this.globalProblemsCount |
1410 |
+ ". " //$NON-NLS-1$ |
1458 |
+ ". " //$NON-NLS-1$ |
1411 |
+ (problems[i].isError() |
1459 |
+ (problems[i].isError() |
Lines 1416-1433
Link Here
|
1416 |
} else { |
1464 |
} else { |
1417 |
Main.this.globalWarningsCount++; |
1465 |
Main.this.globalWarningsCount++; |
1418 |
} |
1466 |
} |
1419 |
Main.this.err.print(" "); //$NON-NLS-1$ |
1467 |
Main.this.logger.printErr(" "); //$NON-NLS-1$ |
1420 |
Main.this.err.print( |
1468 |
Main.this.logger.printErr( |
1421 |
Main.bind("requestor.in", new String(problems[i].getOriginatingFileName()))); //$NON-NLS-1$ |
1469 |
Main.bind("requestor.in", new String(problems[i].getOriginatingFileName()))); //$NON-NLS-1$ |
1422 |
try { |
1470 |
try { |
1423 |
Main.this.err.println( |
1471 |
Main.this.logger.printlnErr( |
1424 |
((DefaultProblem) problems[i]).errorReportSource(unitSource)); |
1472 |
((DefaultProblem) problems[i]).errorReportSource(unitSource)); |
1425 |
Main.this.err.println(problems[i].getMessage()); |
1473 |
Main.this.logger.printlnErr(problems[i].getMessage()); |
1426 |
} catch (Exception e) { |
1474 |
} catch (Exception e) { |
1427 |
Main.this.err.println( |
1475 |
Main.this.logger.printlnErr( |
1428 |
Main.bind("requestor.notRetrieveErrorMessage", problems[i].toString())); //$NON-NLS-1$ |
1476 |
Main.bind("requestor.notRetrieveErrorMessage", problems[i].toString())); //$NON-NLS-1$ |
1429 |
} |
1477 |
} |
1430 |
Main.this.err.println("----------"); //$NON-NLS-1$ |
1478 |
Main.this.logger.printlnErr("----------"); //$NON-NLS-1$ |
1431 |
if (problems[i].isError()) |
1479 |
if (problems[i].isError()) |
1432 |
localErrorCount++; |
1480 |
localErrorCount++; |
1433 |
} |
1481 |
} |
Lines 1435-1442
Link Here
|
1435 |
// exit? |
1483 |
// exit? |
1436 |
if (Main.this.systemExitWhenFinished && !Main.this.proceedOnError && (localErrorCount > 0)) { |
1484 |
if (Main.this.systemExitWhenFinished && !Main.this.proceedOnError && (localErrorCount > 0)) { |
1437 |
Main.this.printStats(); |
1485 |
Main.this.printStats(); |
1438 |
Main.this.err.flush(); |
1486 |
Main.this.logger.flush(); |
1439 |
Main.this.out.flush(); |
|
|
1440 |
System.exit(-1); |
1487 |
System.exit(-1); |
1441 |
} |
1488 |
} |
1442 |
} |
1489 |
} |
Lines 1565-1571
Link Here
|
1565 |
} catch (IOException e) { |
1612 |
} catch (IOException e) { |
1566 |
String fileName = this.destinationPath + new String(relativeName); |
1613 |
String fileName = this.destinationPath + new String(relativeName); |
1567 |
e.printStackTrace(); |
1614 |
e.printStackTrace(); |
1568 |
this.err.println(Main.bind("output.noClassFileCreated", fileName)); //$NON-NLS-1$ |
1615 |
this.logger.printlnErr(Main.bind("output.noClassFileCreated", fileName)); //$NON-NLS-1$ |
1569 |
} |
1616 |
} |
1570 |
this.exportedClassFilesCounter++; |
1617 |
this.exportedClassFilesCounter++; |
1571 |
} |
1618 |
} |
Lines 1593-1599
Link Here
|
1593 |
} catch (IOException e) { |
1640 |
} catch (IOException e) { |
1594 |
String fileName = this.destinationPath + new String(relativeName); |
1641 |
String fileName = this.destinationPath + new String(relativeName); |
1595 |
e.printStackTrace(); |
1642 |
e.printStackTrace(); |
1596 |
this.err.println(Main.bind("output.noClassFileCreated", fileName)); //$NON-NLS-1$ |
1643 |
this.logger.printlnErr(Main.bind("output.noClassFileCreated", fileName)); //$NON-NLS-1$ |
1597 |
} |
1644 |
} |
1598 |
this.exportedClassFilesCounter++; |
1645 |
this.exportedClassFilesCounter++; |
1599 |
} |
1646 |
} |
Lines 1633-1639
Link Here
|
1633 |
|
1680 |
|
1634 |
long time = System.currentTimeMillis() - this.startTime; |
1681 |
long time = System.currentTimeMillis() - this.startTime; |
1635 |
if (this.lineCount != 0) { |
1682 |
if (this.lineCount != 0) { |
1636 |
this.out.println( |
1683 |
this.logger.printlnOut( |
1637 |
Main.bind( |
1684 |
Main.bind( |
1638 |
"compile.instantTime", //$NON-NLS-1$ |
1685 |
"compile.instantTime", //$NON-NLS-1$ |
1639 |
new String[] { |
1686 |
new String[] { |
Lines 1641-1684
Link Here
|
1641 |
String.valueOf(time), |
1688 |
String.valueOf(time), |
1642 |
String.valueOf(((int)(this.lineCount * 10000.0 / time)) / 10.0)})); |
1689 |
String.valueOf(((int)(this.lineCount * 10000.0 / time)) / 10.0)})); |
1643 |
} else { |
1690 |
} else { |
1644 |
this.out.println(Main.bind("compile.totalTime", String.valueOf(time))); //$NON-NLS-1$ |
1691 |
this.logger.printlnOut(Main.bind("compile.totalTime", String.valueOf(time))); //$NON-NLS-1$ |
1645 |
} |
1692 |
} |
1646 |
} |
1693 |
} |
1647 |
if (this.globalProblemsCount > 0) { |
1694 |
if (this.globalProblemsCount > 0) { |
1648 |
if (this.globalProblemsCount == 1) { |
1695 |
if (this.globalProblemsCount == 1) { |
1649 |
this.err.print(Main.bind("compile.oneProblem")); //$NON-NLS-1$ |
1696 |
this.logger.printErr(Main.bind("compile.oneProblem")); //$NON-NLS-1$ |
1650 |
} else { |
1697 |
} else { |
1651 |
this.err.print( |
1698 |
this.logger.printErr( |
1652 |
Main.bind("compile.severalProblems", String.valueOf(this.globalProblemsCount))); //$NON-NLS-1$ |
1699 |
Main.bind("compile.severalProblems", String.valueOf(this.globalProblemsCount))); //$NON-NLS-1$ |
1653 |
} |
1700 |
} |
1654 |
this.err.print(" ("); //$NON-NLS-1$ |
1701 |
this.logger.printErr(" ("); //$NON-NLS-1$ |
1655 |
if (this.globalErrorsCount > 0) { |
1702 |
if (this.globalErrorsCount > 0) { |
1656 |
if (this.globalErrorsCount == 1) { |
1703 |
if (this.globalErrorsCount == 1) { |
1657 |
this.err.print(Main.bind("compile.oneError")); //$NON-NLS-1$ |
1704 |
this.logger.printErr(Main.bind("compile.oneError")); //$NON-NLS-1$ |
1658 |
} else { |
1705 |
} else { |
1659 |
this.err.print( |
1706 |
this.logger.printErr( |
1660 |
Main.bind("compile.severalErrors", String.valueOf(this.globalErrorsCount))); //$NON-NLS-1$ |
1707 |
Main.bind("compile.severalErrors", String.valueOf(this.globalErrorsCount))); //$NON-NLS-1$ |
1661 |
} |
1708 |
} |
1662 |
} |
1709 |
} |
1663 |
if (this.globalWarningsCount > 0) { |
1710 |
if (this.globalWarningsCount > 0) { |
1664 |
if (this.globalErrorsCount > 0) { |
1711 |
if (this.globalErrorsCount > 0) { |
1665 |
this.err.print(", "); //$NON-NLS-1$ |
1712 |
this.logger.printErr(", "); //$NON-NLS-1$ |
1666 |
} |
1713 |
} |
1667 |
if (this.globalWarningsCount == 1) { |
1714 |
if (this.globalWarningsCount == 1) { |
1668 |
this.err.print(Main.bind("compile.oneWarning")); //$NON-NLS-1$ |
1715 |
this.logger.printErr(Main.bind("compile.oneWarning")); //$NON-NLS-1$ |
1669 |
} else { |
1716 |
} else { |
1670 |
this.err.print( |
1717 |
this.logger.printErr( |
1671 |
Main.bind("compile.severalWarnings", String.valueOf(this.globalWarningsCount))); //$NON-NLS-1$ |
1718 |
Main.bind("compile.severalWarnings", String.valueOf(this.globalWarningsCount))); //$NON-NLS-1$ |
1672 |
} |
1719 |
} |
1673 |
} |
1720 |
} |
1674 |
this.err.println(")"); //$NON-NLS-1$ |
1721 |
this.logger.printlnErr(")"); //$NON-NLS-1$ |
1675 |
} |
1722 |
} |
1676 |
if (this.exportedClassFilesCounter != 0 |
1723 |
if (this.exportedClassFilesCounter != 0 |
1677 |
&& (this.showProgress || this.timing || this.verbose)) { |
1724 |
&& (this.showProgress || this.timing || this.verbose)) { |
1678 |
if (this.exportedClassFilesCounter == 1) { |
1725 |
if (this.exportedClassFilesCounter == 1) { |
1679 |
this.out.println(Main.bind("compile.oneClassFileGenerated")); //$NON-NLS-1$ |
1726 |
this.logger.printlnOut(Main.bind("compile.oneClassFileGenerated")); //$NON-NLS-1$ |
1680 |
} else { |
1727 |
} else { |
1681 |
this.out.println( |
1728 |
this.logger.printlnOut( |
1682 |
Main.bind( |
1729 |
Main.bind( |
1683 |
"compile.severalClassFilesGenerated", //$NON-NLS-1$ |
1730 |
"compile.severalClassFilesGenerated", //$NON-NLS-1$ |
1684 |
String.valueOf(this.exportedClassFilesCounter))); |
1731 |
String.valueOf(this.exportedClassFilesCounter))); |
Lines 1686-1698
Link Here
|
1686 |
} |
1733 |
} |
1687 |
} |
1734 |
} |
1688 |
public void printUsage() { |
1735 |
public void printUsage() { |
1689 |
this.out.println(Main.bind("misc.usage", System.getProperty("path.separator"))); //$NON-NLS-1$//$NON-NLS-2$ |
1736 |
this.logger.printlnOut(Main.bind("misc.usage", System.getProperty("path.separator"))); //$NON-NLS-1$//$NON-NLS-2$ |
1690 |
this.out.flush(); |
1737 |
this.logger.flush(); |
1691 |
this.err.flush(); |
|
|
1692 |
} |
1738 |
} |
1693 |
public void printVersion() { |
1739 |
public void printVersion() { |
1694 |
this.out.println(Main.bind("misc.version")); //$NON-NLS-1$ |
1740 |
this.logger.printlnOut(Main.bind("misc.version")); //$NON-NLS-1$ |
1695 |
this.out.flush(); |
1741 |
this.logger.flush(); |
1696 |
this.err.flush(); |
|
|
1697 |
} |
1742 |
} |
1698 |
} |
1743 |
} |