View | Details | Raw Unified | Return to bug 74394 | Differences between
and this patch

Collapse All | Expand All

(-)batch/org/eclipse/jdt/internal/compiler/batch/Main.java (-144 / +534 lines)
Lines 12-17 Link Here
12
12
13
import java.io.ByteArrayInputStream;
13
import java.io.ByteArrayInputStream;
14
import java.io.File;
14
import java.io.File;
15
import java.io.FileNotFoundException;
15
import java.io.FileOutputStream;
16
import java.io.FileOutputStream;
16
import java.io.FilenameFilter;
17
import java.io.FilenameFilter;
17
import java.io.IOException;
18
import java.io.IOException;
Lines 20-26 Link Here
20
import java.io.PrintWriter;
21
import java.io.PrintWriter;
21
import java.io.StringReader;
22
import java.io.StringReader;
22
import java.io.UnsupportedEncodingException;
23
import java.io.UnsupportedEncodingException;
24
import java.lang.reflect.Field;
25
import java.util.Collections;
23
import java.util.Enumeration;
26
import java.util.Enumeration;
27
import java.util.HashMap;
24
import java.util.Iterator;
28
import java.util.Iterator;
25
import java.util.Locale;
29
import java.util.Locale;
26
import java.util.Map;
30
import java.util.Map;
Lines 51-76 Link Here
51
public class Main implements ProblemSeverities, SuffixConstants {
55
public class Main implements ProblemSeverities, SuffixConstants {
52
56
53
	public static class Logger {
57
	public static class Logger {
54
		
58
		private static final String COMMAND_LINE_ARGUMENT = "argument"; //$NON-NLS-1$
55
		PrintWriter out;
59
		private static final String COMMAND_LINE_ARGUMENT_VALUE = "value"; //$NON-NLS-1$
56
		PrintWriter err;
60
		private static final String COMMAND_LINE_ARGUMENTS = "command_line"; //$NON-NLS-1$
57
		PrintWriter log;
61
		private static final String COMPILER = "compiler"; //$NON-NLS-1$
58
		
62
		private static final String ERROR = "ERROR"; //$NON-NLS-1$
63
		private static final String ERROR_TAG = "error"; //$NON-NLS-1$
64
		private static final String MESSAGE = "message"; //$NON-NLS-1$
65
		private static final String NUMBER_OF_CLASSFILES = "number_of_classfiles"; //$NON-NLS-1$
66
		private static final String NUMBER_OF_ERRORS = "errors"; //$NON-NLS-1$
67
		private static final String NUMBER_OF_PROBLEMS = "problems"; //$NON-NLS-1$
68
		private static final String NUMBER_OF_WARNINGS = "warnings"; //$NON-NLS-1$
69
		private static final String PROBLEM_ARGUMENT = "argument"; //$NON-NLS-1$
70
		private static final String PROBLEM_ARGUMENT_VALUE = "value"; //$NON-NLS-1$
71
		private static final String PROBLEM_ARGUMENTS = "arguments"; //$NON-NLS-1$
72
		private static final String PROBLEM_ID = "id"; //$NON-NLS-1$
73
		private static final String PROBLEM_FILE = "source"; //$NON-NLS-1$
74
		private static final String PROBLEM_LINE = "line"; //$NON-NLS-1$
75
		private static final String PROBLEM_MESSAGE = "message"; //$NON-NLS-1$
76
		private static final String PROBLEM_MESSAGE_VALUE = "value"; //$NON-NLS-1$
77
		private static final String PROBLEM_SEVERITY = "severity"; //$NON-NLS-1$
78
		private static final String PROBLEM_SOURCE_START = "start"; //$NON-NLS-1$
79
		private static final String PROBLEM_SOURCE_END = "end"; //$NON-NLS-1$
80
		private static final String PROBLEM_SUMMARY = "problem_summary"; //$NON-NLS-1$
81
		private static final String PROBLEM_TAG = "problem"; //$NON-NLS-1$
82
		private static final String PROBLEMS ="problems"; //$NON-NLS-1$
83
		private static final String WARNING = "WARNING"; //$NON-NLS-1$
84
		private static final String XML_VERSION= "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; //$NON-NLS-1$
85
86
		private static final HashMap FIELD_TABLE = new HashMap();
87
		static {
88
			try {
89
				Class c = IProblem.class;
90
				Field[] fields = c.getFields();
91
				for (int i = 0, max = fields.length; i < max; i++) {
92
					Field field = fields[i];
93
					FIELD_TABLE.put(field.get(null), field.getName());
94
				}
95
			} catch (SecurityException e) {
96
				e.printStackTrace();
97
			} catch (IllegalArgumentException e) {
98
				e.printStackTrace();
99
			} catch (IllegalAccessException e) {
100
				e.printStackTrace();
101
			}
102
		}
103
		private static void appendEscapedChar(StringBuffer buffer, char c) {
104
			String replacement= getReplacement(c);
105
			if (replacement != null) {
106
				buffer.append('&');
107
				buffer.append(replacement);
108
				buffer.append(';');
109
			} else {
110
				buffer.append(c);
111
			}
112
		}
113
		private static String getEscaped(String s) {
114
			StringBuffer result= new StringBuffer(s.length() + 10);
115
			for (int i= 0; i < s.length(); ++i)
116
				appendEscapedChar(result, s.charAt(i));
117
			return result.toString();
118
		}
119
		private static String getReplacement(char c) {
120
			// Encode special XML characters into the equivalent character references.
121
			// These five are defined by default for all XML documents.
122
			switch (c) {
123
				case '<' :
124
					return "lt"; //$NON-NLS-1$
125
				case '>' :
126
					return "gt"; //$NON-NLS-1$
127
				case '"' :
128
					return "quot"; //$NON-NLS-1$
129
				case '\'' :
130
					return "apos"; //$NON-NLS-1$
131
				case '&' :
132
					return "amp"; //$NON-NLS-1$
133
			}
134
			return null;
135
		}
136
		private PrintWriter err;
137
		boolean isXml;
138
		private PrintWriter log;
139
		private PrintWriter out;
140
		private int tab;
141
		private String[] commandLineArguments;
142
		private HashMap parameters;
143
59
		public Logger(PrintWriter out, PrintWriter err) {
144
		public Logger(PrintWriter out, PrintWriter err) {
60
			this.out = out;
145
			this.out = out;
61
			this.err = err;
146
			this.err = err;
147
			this.isXml = false;
148
			this.parameters = new HashMap();
62
		}
149
		}
63
		
150
64
		public void setLog(PrintWriter log) {
65
			this.log = log;
66
		}
67
		
68
		public void close() {
151
		public void close() {
69
			if (this.log != null) {
152
			if (this.log != null) {
153
				if (this.isXml) {
154
					this.endTag(COMPILER);
155
					this.flush();
156
				}
70
				this.log.close();
157
				this.log.close();
71
			}
158
			}
72
		}
159
		}
160
161
		/**
162
		 * 
163
		 */
164
		public void compiling() {
165
			this.printlnOut(Main.bind("progress.compiling")); //$NON-NLS-1$
166
		}
167
		
168
		/**
169
		 * Used to stop logging problems
170
		 */
171
		private void endLoggingProblems() {
172
			if (this.isXml) {
173
				this.endTag(PROBLEMS);
174
			}
175
		}
176
177
		public void endTag(String name) {
178
			tab--;
179
			this.printTag('/' + name, null, true, false);
180
			this.tab--;
181
		}
73
		
182
		
183
		private String getFieldName(int id) {
184
			return (String) FIELD_TABLE.get(new Integer(id));
185
		}
186
74
		public void flush() {
187
		public void flush() {
75
			this.out.flush();
188
			this.out.flush();
76
			this.err.flush();
189
			this.err.flush();
Lines 78-109 Link Here
78
				this.log.flush();
191
				this.log.flush();
79
			}
192
			}
80
		}
193
		}
81
		
194
82
		public void printErr(String s) {
195
		public void logCommandLineArguments() {
196
			final int length = this.commandLineArguments != null ? this.commandLineArguments.length : 0;
197
			if (length != 0) {
198
				if (this.isXml) {
199
					// generate xml output
200
					this.printTag(COMMAND_LINE_ARGUMENTS, null, true, false);
201
					parameters.clear();
202
					for (int i = 0; i < length; i++) {
203
						parameters.put(COMMAND_LINE_ARGUMENT_VALUE, this.commandLineArguments[i]);
204
						this.printTag(COMMAND_LINE_ARGUMENT, parameters, true, true);
205
					}
206
					this.endTag(COMMAND_LINE_ARGUMENTS);
207
				}
208
			}
209
		}
210
211
		/**
212
		 * @param message
213
		 */
214
		public void logExceptionMessage(String message) {
215
			if (isXml) {
216
				parameters.clear();
217
				parameters.put(MESSAGE, message);
218
				this.printTag(ERROR_TAG, parameters, true, true);
219
			}
220
			this.printlnErr(message);
221
		}
222
223
		/**
224
		 * @param wrongClasspath
225
		 *            the given wrong classpath entry
226
		 */
227
		public void logIncorrectClasspath(String wrongClasspath) {
228
			if (isXml) {
229
				parameters.clear();
230
				parameters.put(MESSAGE, wrongClasspath);
231
				this.printTag(ERROR_TAG, parameters, true, true);
232
			}
233
			this.printlnErr(Main.bind(
234
				"configure.incorrectClasspath", wrongClasspath)); //$NON-NLS-1$
235
		}
236
237
		/**
238
		 * 
239
		 */
240
		public void logNoClassFileCreated(String fileName) {
241
			if (isXml) {
242
				parameters.clear();
243
				parameters.put(MESSAGE, Main.bind("output.noClassFileCreated", fileName)); //$NON-NLS-1$
244
				this.printTag(ERROR_TAG, null, true, true);
245
			}
246
			this.printlnErr(Main.bind("output.noClassFileCreated", fileName)); //$NON-NLS-1$
247
		}
248
249
		public void logNoClasspath() {
250
			if (isXml) {
251
				parameters.clear();
252
				parameters.put(MESSAGE, Main.bind("configure.noClasspath")); //$NON-NLS-1$//$NON-NLS-2$
253
				this.printTag(ERROR_TAG, parameters, true, true);
254
			}
255
			this.printlnErr(Main.bind("configure.noClasspath")); //$NON-NLS-1$
256
		}
257
258
		/**
259
		 * @param exportedClassFilesCounter
260
		 */
261
		public void logNumberOfClassFilesGenerated(int exportedClassFilesCounter) {
262
			if (isXml) {
263
				parameters.clear();
264
				if (exportedClassFilesCounter == 1) {
265
					parameters.put(MESSAGE, Main.bind("compile.oneClassFileGenerated")); //$NON-NLS-1$
266
				} else {
267
					parameters.put(MESSAGE, Main.bind("compile.severalClassFilesGenerated", //$NON-NLS-1$
268
						String.valueOf(exportedClassFilesCounter)));
269
				}
270
				this.printTag(NUMBER_OF_CLASSFILES, parameters, true, true);
271
			}
272
			if (exportedClassFilesCounter == 1) {
273
				this.printlnOut(Main.bind("compile.oneClassFileGenerated")); //$NON-NLS-1$
274
			} else {
275
				this.printlnOut(Main.bind("compile.severalClassFilesGenerated", //$NON-NLS-1$
276
					String.valueOf(exportedClassFilesCounter)));
277
			}
278
		}
279
280
		public int logProblems(IProblem[] problems, char[] unitSource, Main currentMain) {
281
			final int count = problems.length;
282
			int localErrorCount = 0;
283
			if (count != 0) {
284
				this.startLoggingProblems();
285
				for (int i = 0; i < count; i++) {
286
					if (problems[i] != null) {
287
						currentMain.globalProblemsCount++;
288
						this.logProblem(problems[i], localErrorCount, currentMain.globalProblemsCount, unitSource);
289
						if (problems[i].isError()) {
290
							currentMain.globalErrorsCount++;
291
							localErrorCount++;
292
						} else {
293
							currentMain.globalWarningsCount++;
294
						}
295
					}
296
				}
297
				this.endLoggingProblems();
298
			}
299
			return localErrorCount;
300
		}
301
		/**
302
		 * @param problem
303
		 *            the given problem to log
304
		 * @param localErrorCount
305
		 *            the given local error count
306
		 * @param globalErrorCount
307
		 *            the given global error count
308
		 * @param unitSource
309
		 *            the given unit source
310
		 */
311
		private void logProblem(IProblem problem, int localErrorCount,
312
			int globalErrorCount, char[] unitSource) {
313
			if (this.isXml) {
314
				// generate the xml output
315
				parameters.clear();
316
				parameters.put(PROBLEM_ID, getFieldName(problem.getID()));
317
				parameters.put(PROBLEM_FILE, new String(problem.getOriginatingFileName()));
318
				parameters.put(PROBLEM_SEVERITY, problem.isError() ? ERROR : WARNING);
319
				parameters.put(PROBLEM_LINE, new Integer(problem.getSourceLineNumber()));
320
				parameters.put(PROBLEM_SOURCE_START, new Integer(problem.getSourceStart()));
321
				parameters.put(PROBLEM_SOURCE_END, new Integer(problem.getSourceEnd()));
322
				this.printTag(PROBLEM_TAG, parameters, true, false);
323
				parameters.clear();
324
				parameters.put(PROBLEM_MESSAGE_VALUE, problem.getMessage());
325
				this.printTag(PROBLEM_MESSAGE, parameters, true, true);
326
				String[] arguments = problem.getArguments();
327
				final int length = arguments.length;
328
				if (length != 0) {
329
					this.printTag(PROBLEM_ARGUMENTS, null, true, false);
330
					parameters.clear();
331
					for (int i = 0; i < length; i++) {
332
						parameters.put(PROBLEM_ARGUMENT_VALUE, arguments[i]);
333
						this.printTag(PROBLEM_ARGUMENT, parameters, true, true);
334
					}
335
					this.endTag(PROBLEM_ARGUMENTS);
336
				}
337
				this.endTag(PROBLEM_TAG);
338
			}
339
			if (localErrorCount == 0) {
340
				this.printlnErr("----------"); //$NON-NLS-1$
341
			}
342
			this.printlnErr(problem.isError() ?
343
				Main.bind(
344
					"requestor.error", //$NON-NLS-1$
345
					Integer.toString(globalErrorCount),
346
					new String(problem.getOriginatingFileName()))
347
				: Main.bind(
348
					"requestor.warning", //$NON-NLS-1$
349
					Integer.toString(globalErrorCount),
350
					new String(problem.getOriginatingFileName())));
351
			try {
352
				this.printlnErr(((DefaultProblem) problem).errorReportSource(unitSource));
353
				this.printlnErr(problem.getMessage());
354
			} catch (Exception e) {
355
				this.printlnErr(Main.bind(
356
					"requestor.notRetrieveErrorMessage", problem.toString())); //$NON-NLS-1$
357
			}
358
			this.printlnErr("----------"); //$NON-NLS-1$
359
		}
360
361
		/**
362
		 * @param globalProblemsCount
363
		 * @param globalErrorsCount
364
		 * @param globalWarningsCount
365
		 */
366
		public void logProblemsSummary(int globalProblemsCount,
367
			int globalErrorsCount, int globalWarningsCount) {
368
			if (this.isXml) {
369
				// generate xml
370
				parameters.clear();
371
				parameters.put(NUMBER_OF_PROBLEMS, new Integer(globalProblemsCount));
372
				parameters.put(NUMBER_OF_ERRORS, new Integer(globalErrorsCount));
373
				parameters.put(NUMBER_OF_WARNINGS, new Integer(globalWarningsCount));
374
				this.printTag(PROBLEM_SUMMARY, parameters, true, true);
375
			}
376
			if (globalProblemsCount == 1) {
377
				this.printErr(Main.bind("compile.oneProblem")); //$NON-NLS-1$
378
			} else {
379
				String errorMessage = null;
380
				String warningMessage = null;
381
				if (globalErrorsCount > 0) {
382
					if (globalErrorsCount == 1) {
383
						errorMessage = Main.bind("compile.oneError"); //$NON-NLS-1$
384
					} else {
385
						errorMessage = Main.bind("compile.severalErrors", String.valueOf(globalErrorsCount)); //$NON-NLS-1$
386
					}
387
				}
388
				if (globalWarningsCount > 0) {
389
					if (globalWarningsCount == 1) {
390
						warningMessage = Main.bind("compile.oneWarning"); //$NON-NLS-1$
391
					} else {
392
						warningMessage = Main.bind("compile.severalWarnings", String.valueOf(globalWarningsCount)); //$NON-NLS-1$
393
					}
394
				}
395
				if (errorMessage == null || warningMessage == null) {
396
					if (errorMessage == null) {
397
						this.printErr(Main.bind(
398
							"compile.severalProblemsErrorsOrWarnings", //$NON-NLS-1$
399
							String.valueOf(globalProblemsCount),
400
							warningMessage));
401
					} else {
402
						this.printErr(Main.bind(
403
							"compile.severalProblemsErrorsOrWarnings", //$NON-NLS-1$
404
							String.valueOf(globalProblemsCount),
405
							errorMessage));
406
					}
407
				} else {
408
					this.printErr(Main.bind(
409
						"compile.severalProblemsErrorsOrWarnings", //$NON-NLS-1$
410
						new String[] {
411
							String.valueOf(globalProblemsCount),
412
							errorMessage,
413
							warningMessage
414
						}));
415
				}
416
			}
417
		}
418
419
		/**
420
		 * 
421
		 */
422
		public void logProgress() {
423
			this.printOut('.');
424
		}
425
426
		/**
427
		 * @param i
428
		 *            the current repetition number
429
		 * @param repetitions
430
		 *            the given number of repetitions
431
		 */
432
		public void logRepetition(int i, int repetitions) {
433
			this.printlnOut(Main.bind("compile.repetition", //$NON-NLS-1$
434
				String.valueOf(i + 1), String.valueOf(repetitions)));
435
		}
436
437
		/**
438
		 * @param time
439
		 * @param lineCount
440
		 */
441
		public void logTiming(long time, long lineCount) {
442
			if (lineCount != 0) {
443
				this.printlnOut(Main.bind(
444
					"compile.instantTime", //$NON-NLS-1$
445
					new String[] {
446
						String.valueOf(lineCount),
447
						String.valueOf(time),
448
						String.valueOf(((int) (lineCount * 10000.0 / time)) / 10.0) }));
449
			} else {
450
				this.printlnOut(Main.bind("compile.totalTime", String.valueOf(time))); //$NON-NLS-1$
451
			}
452
		}
453
454
		/**
455
		 * @param usage
456
		 */
457
		public void logUsage(String usage) {
458
			this.printlnOut(usage); //$NON-NLS-1$//$NON-NLS-2$
459
		}
460
461
		/**
462
		 * 
463
		 */
464
		public void logVersion() {
465
			this.printlnOut(Main.bind("misc.version")); //$NON-NLS-1$
466
		}
467
468
		/**
469
		 * 
470
		 */
471
		public void logWrongJDK() {
472
			if (isXml) {
473
				parameters.clear();
474
				parameters.put(MESSAGE, Main.bind("configure.requiresJDK1.2orAbove")); //$NON-NLS-1$//$NON-NLS-2$
475
				this.printTag(ERROR, parameters, true, true);				
476
			}
477
			this.printlnErr(Main.bind("configure.requiresJDK1.2orAbove")); //$NON-NLS-1$
478
		}
479
480
		private void printErr(String s) {
83
			this.err.print(s);
481
			this.err.print(s);
84
			if (this.log != null) {
482
			if (!this.isXml) {
85
				this.log.print(s);
483
				if (this.log != null) {
484
					this.log.print(s);
485
				}
86
			}
486
			}
87
		}
487
		}
88
		
488
89
		public void printlnErr(String s) {
489
		private void printlnErr(String s) {
90
			this.err.println(s);
490
			this.err.println(s);
91
			if (this.log != null) {
491
			if (!this.isXml) {
92
				this.log.println(s);
492
				if (this.log != null) {
493
					this.log.println(s);
494
				}
93
			}
495
			}
94
		}
496
		}
95
		
497
96
		public void printlnOut(String s) {
498
		private void printlnOut(String s) {
97
			this.out.println(s);
499
			this.out.println(s);
98
		}
500
		}
99
		
501
100
		public void printlnOut() {
502
		/**
503
		 * 
504
		 */
505
		public void printNewLine() {
101
			this.out.println();
506
			this.out.println();
102
		}
507
		}
103
		
508
104
		public void printOut(char c) {
509
		private void printOut(char c) {
105
			this.out.print(c);
510
			this.out.print(c);
106
		}
511
		}
512
		public void printTag(String name, HashMap params, boolean insertNewLine, boolean closeTag) {
513
			for (int i= this.tab; i > 0; i--) this.log.print('\t');
514
			StringBuffer buffer= new StringBuffer();
515
			buffer.append("<"); //$NON-NLS-1$
516
			buffer.append(name);
517
			if (params != null) {
518
				for (Enumeration enumeration = Collections.enumeration(params.keySet()); enumeration.hasMoreElements();) {
519
					buffer.append(" "); //$NON-NLS-1$
520
					String key= (String) enumeration.nextElement();
521
					buffer.append(key);
522
					buffer.append("=\""); //$NON-NLS-1$
523
					buffer.append(getEscaped(String.valueOf(params.get(key))));
524
					buffer.append("\""); //$NON-NLS-1$
525
				}
526
			}
527
			if (closeTag) {
528
				buffer.append("/>"); //$NON-NLS-1$
529
			} else {
530
				buffer.append(">"); //$NON-NLS-1$
531
				this.tab++;
532
			}
533
			if (insertNewLine) {
534
				this.log.println(String.valueOf(buffer));
535
			} else {
536
				this.log.print(String.valueOf(buffer));
537
			}
538
		}
539
540
		public void setCommandLine(String[] args) {
541
			this.commandLineArguments = args;
542
		}
543
544
		public void setLog(String logFileName) throws InvalidInputException {
545
			try {
546
				this.log = new PrintWriter(new FileOutputStream(logFileName, false));
547
				int index = logFileName.lastIndexOf('.');
548
				if (index != 0) {
549
					if (logFileName.substring(index).toLowerCase().equals(".xml")) { //$NON-NLS-1$
550
						this.isXml = true;
551
						this.log.println(XML_VERSION);
552
						this.tab = 0;
553
						parameters.clear();
554
						parameters.put("name", Main.bind("compiler.name")); //$NON-NLS-1$//$NON-NLS-2$
555
						parameters.put("version", Main.bind("compiler.version")); //$NON-NLS-1$//$NON-NLS-2$
556
						this.printTag(COMPILER, parameters, true, false);
557
					}
558
				}
559
			} catch (FileNotFoundException e) {
560
				throw new InvalidInputException(Main.bind("configure.cannotOpenLog")); //$NON-NLS-1$
561
			}
562
		}
563
564
		/**
565
		 * Used to start logging problems
566
		 */
567
		private void startLoggingProblems() {
568
			if (this.isXml) {
569
				this.printTag(PROBLEMS, null, true, false);
570
			}
571
		}
107
	}
572
	}
108
	static {
573
	static {
109
		relocalize();
574
		relocalize();
Lines 354-361 Link Here
354
//				if (this.verbose) {
819
//				if (this.verbose) {
355
//					System.out.println(new CompilerOptions(this.options));
820
//					System.out.println(new CompilerOptions(this.options));
356
//				}
821
//				}
357
				if (this.showProgress)
822
				if (this.showProgress) this.logger.compiling(); //$NON-NLS-1$
358
					this.logger.printlnOut(Main.bind("progress.compiling")); //$NON-NLS-1$
359
				for (int i = 0; i < this.repetitions; i++) {
823
				for (int i = 0; i < this.repetitions; i++) {
360
					this.globalProblemsCount = 0;
824
					this.globalProblemsCount = 0;
361
					this.globalErrorsCount = 0;
825
					this.globalErrorsCount = 0;
Lines 365-389 Link Here
365
829
366
					if (this.repetitions > 1) {
830
					if (this.repetitions > 1) {
367
						this.logger.flush();
831
						this.logger.flush();
368
						this.logger.printlnOut(
832
						this.logger.logRepetition(i, this.repetitions);
369
							Main.bind(
370
								"compile.repetition", //$NON-NLS-1$
371
								String.valueOf(i + 1),
372
								String.valueOf(this.repetitions)));
373
					} 
833
					} 
374
					// request compilation
834
					// request compilation
375
					performCompilation();
835
					performCompilation();
376
				}
836
				}
377
				if (this.showProgress)
837
				if (this.showProgress) this.logger.printNewLine();
378
					this.logger.printlnOut();
379
			}
838
			}
380
			if (this.systemExitWhenFinished) {
839
			if (this.systemExitWhenFinished) {
840
				if (this.globalErrorsCount > 0) {
841
					this.logger.logCommandLineArguments();
842
				}
381
				this.logger.flush();
843
				this.logger.flush();
844
    			this.logger.close();
382
				System.exit(this.globalErrorsCount > 0 ? -1 : 0);
845
				System.exit(this.globalErrorsCount > 0 ? -1 : 0);
383
			}
846
			}
384
		} catch (InvalidInputException e) {
847
		} catch (InvalidInputException e) {
385
			this.logger.printlnErr(e.getMessage());
848
			this.logger.logExceptionMessage(e.getMessage());
386
			if (this.systemExitWhenFinished) {
849
			if (this.systemExitWhenFinished) {
850
				if (this.globalErrorsCount > 0) {
851
					this.logger.logCommandLineArguments();
852
				}
387
    			this.logger.flush();
853
    			this.logger.flush();
388
    			this.logger.close();
854
    			this.logger.close();
389
				System.exit(-1);
855
				System.exit(-1);
Lines 391-396 Link Here
391
			return false;
857
			return false;
392
		} catch (RuntimeException e) { // internal compiler failure
858
		} catch (RuntimeException e) { // internal compiler failure
393
			if (this.systemExitWhenFinished) {
859
			if (this.systemExitWhenFinished) {
860
				if (this.globalErrorsCount > 0) {
861
					this.logger.logCommandLineArguments();
862
				}
394
				this.logger.flush();
863
				this.logger.flush();
395
				this.logger.close();
864
				this.logger.close();
396
				System.exit(-1);
865
				System.exit(-1);
Lines 398-403 Link Here
398
			return false;
867
			return false;
399
			//e.printStackTrace();
868
			//e.printStackTrace();
400
		} finally {
869
		} finally {
870
			if (this.globalErrorsCount > 0) {
871
				this.logger.logCommandLineArguments();
872
			}
401
			this.logger.flush();
873
			this.logger.flush();
402
			this.logger.close();
874
			this.logger.close();
403
		}
875
		}
Lines 493-498 Link Here
493
				newCommandLineArgs[i] = newCommandLineArgs[i].trim();
965
				newCommandLineArgs[i] = newCommandLineArgs[i].trim();
494
			}
966
			}
495
		}
967
		}
968
		this.logger.setCommandLine(newCommandLineArgs);
496
		argCount = newCommandLineArgs.length;
969
		argCount = newCommandLineArgs.length;
497
		while (++index < argCount) {
970
		while (++index < argCount) {
498
971
Lines 1236-1242 Link Here
1236
			// no user classpath specified.
1709
			// no user classpath specified.
1237
			String classProp = System.getProperty("java.class.path"); //$NON-NLS-1$
1710
			String classProp = System.getProperty("java.class.path"); //$NON-NLS-1$
1238
			if ((classProp == null) || (classProp.length() == 0)) {
1711
			if ((classProp == null) || (classProp.length() == 0)) {
1239
				this.logger.printlnErr(Main.bind("configure.noClasspath")); //$NON-NLS-1$
1712
				this.logger.logNoClasspath(); //$NON-NLS-1$
1240
				classProp = System.getProperty("user.dir"); //$NON-NLS-1$
1713
				classProp = System.getProperty("user.dir"); //$NON-NLS-1$
1241
			}
1714
			}
1242
			StringTokenizer tokenizer = new StringTokenizer(classProp, File.pathSeparator);
1715
			StringTokenizer tokenizer = new StringTokenizer(classProp, File.pathSeparator);
Lines 1254-1260 Link Here
1254
			 */
1727
			 */
1255
			 String javaversion = System.getProperty("java.version");//$NON-NLS-1$
1728
			 String javaversion = System.getProperty("java.version");//$NON-NLS-1$
1256
			 if (javaversion != null && javaversion.equalsIgnoreCase("1.1.8")) { //$NON-NLS-1$
1729
			 if (javaversion != null && javaversion.equalsIgnoreCase("1.1.8")) { //$NON-NLS-1$
1257
				this.logger.printlnErr(Main.bind("configure.requiresJDK1.2orAbove")); //$NON-NLS-1$
1730
				this.logger.logWrongJDK(); //$NON-NLS-1$
1258
				this.proceed = false;
1731
				this.proceed = false;
1259
				return;
1732
				return;
1260
			 }
1733
			 }
Lines 1291-1301 Link Here
1291
		}
1764
		}
1292
1765
1293
		if (this.log != null) {
1766
		if (this.log != null) {
1294
			try {
1767
			this.logger.setLog(this.log);
1295
				this.logger.setLog(new PrintWriter(new FileOutputStream(this.log, false)));
1296
			} catch (IOException e) {
1297
				throw new InvalidInputException(Main.bind("configure.cannotOpenLog")); //$NON-NLS-1$
1298
			}
1299
		} else {
1768
		} else {
1300
			this.showProgress = false;
1769
			this.showProgress = false;
1301
		}
1770
		}
Lines 1331-1337 Link Here
1331
		for (int i = 0, max = this.classpaths.length; i < max; i++) {
1800
		for (int i = 0, max = this.classpaths.length; i < max; i++) {
1332
			File file = new File(this.classpaths[i]);
1801
			File file = new File(this.classpaths[i]);
1333
			if (!file.exists()) { // signal missing classpath entry file
1802
			if (!file.exists()) { // signal missing classpath entry file
1334
				this.logger.printlnErr(Main.bind("configure.incorrectClasspath", this.classpaths[i])); //$NON-NLS-1$
1803
				this.logger.logIncorrectClasspath(this.classpaths[i]); //$NON-NLS-1$
1335
			}
1804
			}
1336
		}
1805
		}
1337
		if (this.destinationPath == null) {
1806
		if (this.destinationPath == null) {
Lines 1343-1366 Link Here
1343
		if (didSpecifyCompliance) {
1812
		if (didSpecifyCompliance) {
1344
			Object version = this.options.get(CompilerOptions.OPTION_Compliance);
1813
			Object version = this.options.get(CompilerOptions.OPTION_Compliance);
1345
			if (CompilerOptions.VERSION_1_3.equals(version)) {
1814
			if (CompilerOptions.VERSION_1_3.equals(version)) {
1346
					if (!didSpecifySource) this.options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_3);
1815
				if (!didSpecifySource) this.options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_3);
1347
					if (!didSpecifyTarget) this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_1);
1816
				if (!didSpecifyTarget) this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_1);
1348
			} else if (CompilerOptions.VERSION_1_4.equals(version)) {
1817
			} else if (CompilerOptions.VERSION_1_4.equals(version)) {
1349
					if (!didSpecifySource) this.options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_3);
1818
				if (!didSpecifySource) this.options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_3);
1350
					if (!didSpecifyTarget) this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_2);
1819
				if (!didSpecifyTarget) this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_2);
1351
			} else if (CompilerOptions.VERSION_1_5.equals(version)) {
1820
			} else if (CompilerOptions.VERSION_1_5.equals(version)) {
1352
					if (!didSpecifySource) this.options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_5);
1821
				if (!didSpecifySource) this.options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_5);
1353
					if (!didSpecifyTarget) this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_5);
1822
				if (!didSpecifyTarget) this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_5);
1354
			}
1823
			}
1355
		}
1824
		}
1356
		if (didSpecifySource) {
1825
		if (didSpecifySource) {
1357
			Object version = this.options.get(CompilerOptions.OPTION_Source);
1826
			Object version = this.options.get(CompilerOptions.OPTION_Source);
1358
			 if (CompilerOptions.VERSION_1_4.equals(version)) {
1827
			 if (CompilerOptions.VERSION_1_4.equals(version)) {
1359
					if (!didSpecifyCompliance) this.options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_4);
1828
				if (!didSpecifyCompliance) this.options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_4);
1360
					if (!didSpecifyTarget) this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_4);
1829
				if (!didSpecifyTarget) this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_4);
1361
			} else if (CompilerOptions.VERSION_1_5.equals(version)) {
1830
			} else if (CompilerOptions.VERSION_1_5.equals(version)) {
1362
					if (!didSpecifyCompliance) this.options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_5);
1831
				if (!didSpecifyCompliance) this.options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_5);
1363
					if (!didSpecifyTarget) this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_5);
1832
				if (!didSpecifyTarget) this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_5);
1364
			}
1833
			}
1365
		}
1834
		}
1366
1835
Lines 1378-1384 Link Here
1378
	   		}
1847
	   		}
1379
			// target cannot be greater than compliance level
1848
			// target cannot be greater than compliance level
1380
			if (CompilerOptions.versionToJdkLevel(this.options.get(CompilerOptions.OPTION_Compliance)) < CompilerOptions.versionToJdkLevel(this.options.get(CompilerOptions.OPTION_TargetPlatform))){ 
1849
			if (CompilerOptions.versionToJdkLevel(this.options.get(CompilerOptions.OPTION_Compliance)) < CompilerOptions.versionToJdkLevel(this.options.get(CompilerOptions.OPTION_TargetPlatform))){ 
1381
					throw new InvalidInputException(Main.bind("configure.incompatibleComplianceForTarget", (String)this.options.get(CompilerOptions.OPTION_Compliance), (String)this.options.get(CompilerOptions.OPTION_TargetPlatform))); //$NON-NLS-1$
1850
				throw new InvalidInputException(Main.bind("configure.incompatibleComplianceForTarget", (String)this.options.get(CompilerOptions.OPTION_Compliance), (String)this.options.get(CompilerOptions.OPTION_TargetPlatform))); //$NON-NLS-1$
1382
			}
1851
			}
1383
		}
1852
		}
1384
1853
Lines 1456-1504 Link Here
1456
					int unitLineCount = compilationResult.lineSeparatorPositions.length;
1925
					int unitLineCount = compilationResult.lineSeparatorPositions.length;
1457
					Main.this.lineCount += unitLineCount;
1926
					Main.this.lineCount += unitLineCount;
1458
					this.lineDelta += unitLineCount;
1927
					this.lineDelta += unitLineCount;
1459
					if (Main.this.showProgress
1928
					if (Main.this.showProgress && this.lineDelta > 2000) {
1460
						&& this.lineDelta > 2000) { // in -log mode, dump a dot every 2000 lines compiled
1929
						// in -log mode, dump a dot every 2000 lines compiled
1461
						Main.this.logger.printOut('.');
1930
						Main.this.logger.logProgress();
1462
						this.lineDelta = 0;
1931
						this.lineDelta = 0;
1463
					}
1932
					}
1464
				}
1933
				}
1465
				if (compilationResult.hasProblems() || compilationResult.hasTasks()) {
1934
				if (compilationResult.hasProblems() || compilationResult.hasTasks()) {
1466
					IProblem[] problems = compilationResult.getAllProblems();
1935
					int localErrorCount = Main.this.logger.logProblems(compilationResult.getAllProblems(), compilationResult.compilationUnit.getContents(), Main.this);
1467
					int count = problems.length;
1468
					int localErrorCount = 0;
1469
					char[] unitSource = compilationResult.compilationUnit.getContents();
1470
					for (int i = 0; i < count; i++) {
1471
						if (problems[i] != null) {
1472
							Main.this.globalProblemsCount++;
1473
							if (localErrorCount == 0)
1474
								Main.this.logger.printlnErr("----------"); //$NON-NLS-1$
1475
							Main.this.logger.printErr(
1476
								Main.this.globalProblemsCount
1477
									+ ". "  //$NON-NLS-1$
1478
									+ (problems[i].isError()
1479
										? Main.bind("requestor.error")  //$NON-NLS-1$
1480
										: Main.bind("requestor.warning")));  //$NON-NLS-1$
1481
							if (problems[i].isError()) {
1482
								Main.this.globalErrorsCount++;
1483
							} else {
1484
								Main.this.globalWarningsCount++;
1485
							}
1486
							Main.this.logger.printErr(" "); //$NON-NLS-1$
1487
							Main.this.logger.printErr(
1488
								Main.bind("requestor.in", new String(problems[i].getOriginatingFileName()))); //$NON-NLS-1$
1489
							try {
1490
								Main.this.logger.printlnErr(
1491
									((DefaultProblem) problems[i]).errorReportSource(unitSource));
1492
								Main.this.logger.printlnErr(problems[i].getMessage());
1493
							} catch (Exception e) {
1494
								Main.this.logger.printlnErr(
1495
									Main.bind("requestor.notRetrieveErrorMessage", problems[i].toString())); //$NON-NLS-1$
1496
							}
1497
							Main.this.logger.printlnErr("----------"); //$NON-NLS-1$
1498
							if (problems[i].isError())
1499
								localErrorCount++;
1500
						}
1501
					}
1502
					// exit?
1936
					// exit?
1503
					if (Main.this.systemExitWhenFinished && !Main.this.proceedOnError && (localErrorCount > 0)) {
1937
					if (Main.this.systemExitWhenFinished && !Main.this.proceedOnError && (localErrorCount > 0)) {
1504
						Main.this.printStats();
1938
						Main.this.printStats();
Lines 1631-1637 Link Here
1631
					} catch (IOException e) {
2065
					} catch (IOException e) {
1632
						String fileName = this.destinationPath + new String(relativeName);
2066
						String fileName = this.destinationPath + new String(relativeName);
1633
						e.printStackTrace();
2067
						e.printStackTrace();
1634
						this.logger.printlnErr(Main.bind("output.noClassFileCreated", fileName));  //$NON-NLS-1$
2068
						this.logger.logNoClassFileCreated(fileName);  //$NON-NLS-1$
1635
					}
2069
					}
1636
					this.exportedClassFilesCounter++;
2070
					this.exportedClassFilesCounter++;
1637
				}
2071
				}
Lines 1659-1665 Link Here
1659
					} catch (IOException e) {
2093
					} catch (IOException e) {
1660
						String fileName = this.destinationPath + new String(relativeName);
2094
						String fileName = this.destinationPath + new String(relativeName);
1661
						e.printStackTrace();
2095
						e.printStackTrace();
1662
						this.logger.printlnErr(Main.bind("output.noClassFileCreated", fileName)); //$NON-NLS-1$
2096
						this.logger.logNoClassFileCreated(fileName); //$NON-NLS-1$
1663
					}
2097
					}
1664
					this.exportedClassFilesCounter++;
2098
					this.exportedClassFilesCounter++;
1665
				}
2099
				}
Lines 1696-1762 Link Here
1696
	
2130
	
1697
	public void printStats() {
2131
	public void printStats() {
1698
		if (this.timing) {
2132
		if (this.timing) {
1699
1700
			long time = System.currentTimeMillis() - this.startTime;
2133
			long time = System.currentTimeMillis() - this.startTime;
1701
			if (this.lineCount != 0) {
2134
			this.logger.logTiming(time, this.lineCount);
1702
				this.logger.printlnOut(
1703
					Main.bind(
1704
						"compile.instantTime", 	//$NON-NLS-1$
1705
						new String[] {
1706
							String.valueOf(this.lineCount),
1707
							String.valueOf(time),
1708
							String.valueOf(((int)(this.lineCount * 10000.0 / time)) / 10.0)}));
1709
			} else {
1710
				this.logger.printlnOut(Main.bind("compile.totalTime", String.valueOf(time))); //$NON-NLS-1$
1711
			}
1712
		}
2135
		}
1713
		if (this.globalProblemsCount > 0) {
2136
		if (this.globalProblemsCount > 0) {
1714
			if (this.globalProblemsCount == 1) {
2137
			this.logger.logProblemsSummary(this.globalProblemsCount, this.globalErrorsCount, this.globalWarningsCount);
1715
				this.logger.printErr(Main.bind("compile.oneProblem")); //$NON-NLS-1$
1716
			} else {
1717
				this.logger.printErr(
1718
					Main.bind("compile.severalProblems", String.valueOf(this.globalProblemsCount))); 	//$NON-NLS-1$
1719
			}
1720
			this.logger.printErr(" ("); //$NON-NLS-1$
1721
			if (this.globalErrorsCount > 0) {
1722
				if (this.globalErrorsCount == 1) {
1723
					this.logger.printErr(Main.bind("compile.oneError")); //$NON-NLS-1$
1724
				} else {
1725
					this.logger.printErr(
1726
						Main.bind("compile.severalErrors", String.valueOf(this.globalErrorsCount))); 	//$NON-NLS-1$
1727
				}
1728
			}
1729
			if (this.globalWarningsCount > 0) {
1730
				if (this.globalErrorsCount > 0) {
1731
					this.logger.printErr(", "); //$NON-NLS-1$
1732
				}
1733
				if (this.globalWarningsCount == 1) {
1734
					this.logger.printErr(Main.bind("compile.oneWarning")); //$NON-NLS-1$
1735
				} else {
1736
					this.logger.printErr(
1737
						Main.bind("compile.severalWarnings", String.valueOf(this.globalWarningsCount))); 	//$NON-NLS-1$
1738
				}
1739
			}
1740
			this.logger.printlnErr(")"); //$NON-NLS-1$
1741
		}
2138
		}
1742
		if (this.exportedClassFilesCounter != 0
2139
		if (this.exportedClassFilesCounter != 0
1743
			&& (this.showProgress || this.timing || this.verbose)) {
2140
				&& (this.showProgress || this.timing || this.verbose)) {
1744
			if (this.exportedClassFilesCounter == 1) {
2141
			this.logger.logNumberOfClassFilesGenerated(this.exportedClassFilesCounter);
1745
				this.logger.printlnOut(Main.bind("compile.oneClassFileGenerated")); //$NON-NLS-1$
1746
			} else {
1747
				this.logger.printlnOut(
1748
					Main.bind(
1749
						"compile.severalClassFilesGenerated", //$NON-NLS-1$
1750
						String.valueOf(this.exportedClassFilesCounter)));
1751
			}
1752
		}
2142
		}
1753
	}
2143
	}
1754
	public void printUsage() {
2144
	public void printUsage() {
1755
		this.logger.printlnOut(Main.bind("misc.usage", System.getProperty("path.separator"))); //$NON-NLS-1$//$NON-NLS-2$
2145
		this.logger.logUsage(Main.bind("misc.usage", System.getProperty("path.separator"))); //$NON-NLS-1$//$NON-NLS-2$
1756
		this.logger.flush();
2146
		this.logger.flush();
1757
	}
2147
	}
1758
	public void printVersion() {
2148
	public void printVersion() {
1759
		this.logger.printlnOut(Main.bind("misc.version"));  //$NON-NLS-1$
2149
		this.logger.logVersion();  //$NON-NLS-1$
1760
		this.logger.flush();
2150
		this.logger.flush();
1761
	}
2151
	}
1762
}
2152
}
(-)batch/org/eclipse/jdt/internal/compiler/batch/messages.properties (-5 / +5 lines)
Lines 27-34 Link Here
27
compile.repetition = [repetition {0}/{1}]
27
compile.repetition = [repetition {0}/{1}]
28
compile.instantTime = [compiled {0} lines in {1} ms: {2} lines/s]
28
compile.instantTime = [compiled {0} lines in {1} ms: {2} lines/s]
29
compile.totalTime = [total compilation time: {0}]
29
compile.totalTime = [total compilation time: {0}]
30
compile.oneProblem = 1 problem
30
compile.oneProblem = 1 problem ({0})
31
compile.severalProblems = {0} problems
31
compile.severalProblemsErrorsOrWarnings = {0} problems ({1})
32
compile.severalProblemsErrorsAndWarnings = {0} problems ({1}, {2})
32
compile.oneError = 1 error
33
compile.oneError = 1 error
33
compile.severalErrors = {0} errors
34
compile.severalErrors = {0} errors
34
compile.oneWarning = 1 warning
35
compile.oneWarning = 1 warning
Lines 69-77 Link Here
69
configure.invalidTaskTag ={0} is an invalid task tag
70
configure.invalidTaskTag ={0} is an invalid task tag
70
71
71
### requestor
72
### requestor
72
requestor.error = ERROR
73
requestor.error = {0}. ERROR in {1}
73
requestor.warning = WARNING
74
requestor.warning = {0}. WARNING in {1}
74
requestor.in = in {0}
75
requestor.notRetrieveErrorMessage = Cannot retrieve the error message for {0}
75
requestor.notRetrieveErrorMessage = Cannot retrieve the error message for {0}
76
76
77
### unit
77
### unit

Return to bug 74394