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 (-183 / +801 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-31 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.Arrays;
26
import java.util.Collections;
23
import java.util.Enumeration;
27
import java.util.Enumeration;
28
import java.util.HashMap;
24
import java.util.Iterator;
29
import java.util.Iterator;
25
import java.util.Locale;
30
import java.util.Locale;
26
import java.util.Map;
31
import java.util.Map;
27
import java.util.MissingResourceException;
32
import java.util.MissingResourceException;
28
import java.util.ResourceBundle;
33
import java.util.ResourceBundle;
34
import java.util.Set;
29
import java.util.StringTokenizer;
35
import java.util.StringTokenizer;
30
36
31
import org.eclipse.jdt.core.compiler.CharOperation;
37
import org.eclipse.jdt.core.compiler.CharOperation;
Lines 51-76 Link Here
51
public class Main implements ProblemSeverities, SuffixConstants {
57
public class Main implements ProblemSeverities, SuffixConstants {
52
58
53
	public static class Logger {
59
	public static class Logger {
54
		
60
		private static final String CLASS = "class"; //$NON-NLS-1$
55
		PrintWriter out;
61
		private static final String CLASS_FILE = "classfile"; //$NON-NLS-1$
56
		PrintWriter err;
62
		private static final String CLASSPATH = "classpath"; //$NON-NLS-1$
57
		PrintWriter log;
63
		private static final String CLASSPATH_ID = "id"; //$NON-NLS-1$
58
		
64
		private static final String CLASSPATH_FILE = "FILE"; //$NON-NLS-1$
65
		private static final String CLASSPATH_FOLDER = "FOLDER"; //$NON-NLS-1$
66
		private static final String CLASSPATH_JAR = "JAR"; //$NON-NLS-1$
67
		private static final String CLASSPATHS = "classpaths"; //$NON-NLS-1$
68
		private static final String COMMAND_LINE_ARGUMENT = "argument"; //$NON-NLS-1$
69
		private static final String COMMAND_LINE_ARGUMENTS = "command_line"; //$NON-NLS-1$
70
		private static final String COMPILER = "compiler"; //$NON-NLS-1$
71
		private static final String COMPILER_COPYRIGHT = "copyright"; //$NON-NLS-1$
72
		private static final String COMPILER_VERSION = "version"; //$NON-NLS-1$
73
		private static final String COMPILER_NAME = "name"; //$NON-NLS-1$
74
		private static final String EXCEPTION = "exception"; //$NON-NLS-1$
75
		private static final String ERROR = "ERROR"; //$NON-NLS-1$
76
		private static final String ERROR_TAG = "error"; //$NON-NLS-1$
77
		private static final String KEY = "key"; //$NON-NLS-1$
78
		private static final String MESSAGE = "message"; //$NON-NLS-1$
79
		private static final String NUMBER_OF_CLASSFILES = "number_of_classfiles"; //$NON-NLS-1$
80
		private static final String NUMBER_OF_ERRORS = "errors"; //$NON-NLS-1$
81
		private static final String NUMBER_OF_LINES = "number_of_lines"; //$NON-NLS-1$
82
		private static final String NUMBER_OF_PROBLEMS = "problems"; //$NON-NLS-1$
83
		private static final String NUMBER_OF_TASKS = "tasks"; //$NON-NLS-1$
84
		private static final String NUMBER_OF_WARNINGS = "warnings"; //$NON-NLS-1$
85
		private static final String OPTION = "option"; //$NON-NLS-1$
86
		private static final String OPTIONS = "options"; //$NON-NLS-1$
87
		private static final String PATH = "path"; //$NON-NLS-1$
88
		private static final String PROBLEM_ARGUMENT = "argument"; //$NON-NLS-1$
89
		private static final String PROBLEM_ARGUMENT_VALUE = "value"; //$NON-NLS-1$
90
		private static final String PROBLEM_ARGUMENTS = "arguments"; //$NON-NLS-1$
91
		private static final String PROBLEM_ID = "id"; //$NON-NLS-1$
92
		private static final String PROBLEM_LINE = "line"; //$NON-NLS-1$
93
		private static final String PROBLEM_MESSAGE = "message"; //$NON-NLS-1$
94
		private static final String PROBLEM_SEVERITY = "severity"; //$NON-NLS-1$
95
		private static final String PROBLEM_SOURCE = "problem_source"; //$NON-NLS-1$
96
		private static final String PROBLEM_SOURCE_START = "charStart"; //$NON-NLS-1$
97
		private static final String PROBLEM_SOURCE_END = "charEnd"; //$NON-NLS-1$
98
		private static final String PROBLEM_SUMMARY = "problem_summary"; //$NON-NLS-1$
99
		private static final String PROBLEM_TAG = "problem"; //$NON-NLS-1$
100
		private static final String PROBLEMS = "problems"; //$NON-NLS-1$
101
		private static final String SOURCE = "source"; //$NON-NLS-1$
102
		private static final String SOURCES = "sources"; //$NON-NLS-1$
103
		private static final String STATS = "stats"; //$NON-NLS-1$
104
		private static final String TASK = "task"; //$NON-NLS-1$
105
		private static final String TASKS = "tasks"; //$NON-NLS-1$
106
		private static final String TIME = "time"; //$NON-NLS-1$
107
		private static final String VALUE = "value"; //$NON-NLS-1$
108
		private static final String WARNING = "WARNING"; //$NON-NLS-1$
109
		private static final String XML_HEADER = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; //$NON-NLS-1$
110
		private static final String XML_DTD_DECLARATION = "<!DOCTYPE compiler SYSTEM \"compiler.dtd\">"; //$NON-NLS-1$
111
112
		private static final HashMap FIELD_TABLE = new HashMap();
113
		static {
114
			try {
115
				Class c = IProblem.class;
116
				Field[] fields = c.getFields();
117
				for (int i = 0, max = fields.length; i < max; i++) {
118
					Field field = fields[i];
119
					FIELD_TABLE.put(field.get(null), field.getName());
120
				}
121
			} catch (SecurityException e) {
122
				e.printStackTrace();
123
			} catch (IllegalArgumentException e) {
124
				e.printStackTrace();
125
			} catch (IllegalAccessException e) {
126
				e.printStackTrace();
127
			}
128
		}
129
		private static void appendEscapedChar(StringBuffer buffer, char c) {
130
			String replacement= getReplacement(c);
131
			if (replacement != null) {
132
				buffer.append('&');
133
				buffer.append(replacement);
134
				buffer.append(';');
135
			} else {
136
				buffer.append(c);
137
			}
138
		}
139
		private static String getEscaped(String s) {
140
			StringBuffer result= new StringBuffer(s.length() + 10);
141
			for (int i= 0; i < s.length(); ++i)
142
				appendEscapedChar(result, s.charAt(i));
143
			return result.toString();
144
		}
145
		private static String getReplacement(char c) {
146
			// Encode special XML characters into the equivalent character references.
147
			// These five are defined by default for all XML documents.
148
			switch (c) {
149
				case '<' :
150
					return "lt"; //$NON-NLS-1$
151
				case '>' :
152
					return "gt"; //$NON-NLS-1$
153
				case '"' :
154
					return "quot"; //$NON-NLS-1$
155
				case '\'' :
156
					return "apos"; //$NON-NLS-1$
157
				case '&' :
158
					return "amp"; //$NON-NLS-1$
159
			}
160
			return null;
161
		}
162
		private PrintWriter err;
163
		boolean isXml;
164
		private PrintWriter log;
165
		private PrintWriter out;
166
		private int tab;
167
		private HashMap parameters;
168
59
		public Logger(PrintWriter out, PrintWriter err) {
169
		public Logger(PrintWriter out, PrintWriter err) {
60
			this.out = out;
170
			this.out = out;
61
			this.err = err;
171
			this.err = err;
172
			this.isXml = false;
173
			this.parameters = new HashMap();
62
		}
174
		}
63
		
175
64
		public void setLog(PrintWriter log) {
176
		public String buildFileName(
65
			this.log = log;
177
			String outputPath,
178
			String relativeFileName) {
179
			char fileSeparatorChar = File.separatorChar;
180
			String fileSeparator = File.separator;
181
			
182
			outputPath = outputPath.replace('/', fileSeparatorChar);
183
			// To be able to pass the mkdirs() method we need to remove the extra file separator at the end of the outDir name
184
			StringBuffer outDir = new StringBuffer(outputPath);
185
			if (!outputPath.endsWith(fileSeparator)) {
186
				outDir.append(fileSeparator);
187
			}
188
			StringTokenizer tokenizer =
189
				new StringTokenizer(relativeFileName, fileSeparator);
190
			String token = tokenizer.nextToken();
191
			while (tokenizer.hasMoreTokens()) {
192
				outDir.append(token).append(fileSeparator);
193
				token = tokenizer.nextToken();
194
			}
195
			// token contains the last one
196
			return outDir.append(token).toString();
66
		}
197
		}
67
		
198
		
68
		public void close() {
199
		public void close() {
69
			if (this.log != null) {
200
			if (this.log != null) {
201
				if (this.isXml) {
202
					this.endTag(COMPILER);
203
					this.flush();
204
				}
70
				this.log.close();
205
				this.log.close();
71
			}
206
			}
72
		}
207
		}
208
209
		/**
210
		 * 
211
		 */
212
		public void compiling() {
213
			this.printlnOut(Main.bind("progress.compiling")); //$NON-NLS-1$
214
		}
73
		
215
		
216
		/**
217
		 * Used to stop logging problems.
218
		 * Only use in xml mode.
219
		 */
220
		private void endLoggingProblems() {
221
			this.endTag(PROBLEMS);
222
		}
223
		public void endLoggingSource() {
224
			if (this.isXml) {
225
				this.endTag(SOURCE);
226
			}
227
		}
228
		public void endLoggingSources() {
229
			if (this.isXml) {
230
				this.endTag(SOURCES);
231
			}
232
		}
233
		public void endLoggingTasks() {
234
			if (this.isXml) {
235
				this.endTag(TASKS);
236
			}
237
		}
238
		public void endTag(String name) {
239
			tab--;
240
			this.printTag('/' + name, null, true, false);
241
			this.tab--;
242
		}
243
		
244
		private String getFieldName(int id) {
245
			return (String) FIELD_TABLE.get(new Integer(id));
246
		}
247
74
		public void flush() {
248
		public void flush() {
75
			this.out.flush();
249
			this.out.flush();
76
			this.err.flush();
250
			this.err.flush();
Lines 78-109 Link Here
78
				this.log.flush();
252
				this.log.flush();
79
			}
253
			}
80
		}
254
		}
255
		public void logClasspath(String[] classpaths) {
256
			if (classpaths == null) return;
257
			if (this.isXml) {
258
				final int length = classpaths.length;
259
				if (length != 0) {
260
					// generate xml output
261
					this.printTag(CLASSPATHS, null, true, false);
262
					for (int i = 0; i < length; i++) {
263
						this.parameters.clear();
264
						String classpath = classpaths[i];
265
						parameters.put(PATH, classpath);
266
						File f = new File(classpath);
267
						String id = null;
268
						if (f.isFile()) {
269
							if (Util.isArchiveFileName(classpath)) {
270
								id = CLASSPATH_JAR;
271
							} else {
272
								id = CLASSPATH_FILE;
273
							}
274
						} else if (f.isDirectory()) {
275
							id = CLASSPATH_FOLDER;
276
						}
277
						parameters.put(CLASSPATH_ID, id);
278
						this.printTag(CLASSPATH, parameters, true, true);
279
					}
280
					this.endTag(CLASSPATHS);
281
				}
282
			}
283
			
284
		}
285
286
		public void logCommandLineArguments(String[] commandLineArguments) {
287
			if (commandLineArguments == null) return;
288
			if (this.isXml) {
289
				final int length = commandLineArguments.length;
290
				if (length != 0) {
291
					// generate xml output
292
					this.printTag(COMMAND_LINE_ARGUMENTS, null, true, false);
293
					parameters.clear();
294
					for (int i = 0; i < length; i++) {
295
						parameters.put(VALUE, commandLineArguments[i]);
296
						this.printTag(COMMAND_LINE_ARGUMENT, parameters, true, true);
297
					}
298
					this.endTag(COMMAND_LINE_ARGUMENTS);
299
				}
300
			}
301
		}
302
303
		/**
304
		 * @param e the given exception to log
305
		 */
306
		public void logException(Exception e) {
307
			final String message = e.getMessage();
308
			if (isXml) {
309
				parameters.clear();
310
				parameters.put(MESSAGE, message);
311
				parameters.put(CLASS, e.getClass());
312
				this.printTag(EXCEPTION, parameters, true, true);
313
			}
314
			this.printlnErr(message);
315
		}
316
317
		/**
318
		 * @param wrongClasspath
319
		 *            the given wrong classpath entry
320
		 */
321
		public void logIncorrectClasspath(String wrongClasspath) {
322
			if (isXml) {
323
				parameters.clear();
324
				parameters.put(MESSAGE, wrongClasspath);
325
				this.printTag(ERROR_TAG, parameters, true, true);
326
			}
327
			this.printlnErr(Main.bind(
328
				"configure.incorrectClasspath", wrongClasspath)); //$NON-NLS-1$
329
		}
330
331
		/**
332
		 * 
333
		 */
334
		public void logNoClassFileCreated(String fileName) {
335
			if (isXml) {
336
				parameters.clear();
337
				parameters.put(MESSAGE, Main.bind("output.noClassFileCreated", fileName)); //$NON-NLS-1$
338
				this.printTag(ERROR_TAG, null, true, true);
339
			}
340
			this.printlnErr(Main.bind("output.noClassFileCreated", fileName)); //$NON-NLS-1$
341
		}
342
343
		public void logNoClasspath() {
344
			if (isXml) {
345
				parameters.clear();
346
				parameters.put(MESSAGE, Main.bind("configure.noClasspath")); //$NON-NLS-1$//$NON-NLS-2$
347
				this.printTag(ERROR_TAG, parameters, true, true);
348
			}
349
			this.printlnErr(Main.bind("configure.noClasspath")); //$NON-NLS-1$
350
		}
351
352
		/**
353
		 * @param exportedClassFilesCounter
354
		 */
355
		public void logNumberOfClassFilesGenerated(int exportedClassFilesCounter) {
356
			if (isXml) {
357
				parameters.clear();
358
				parameters.put(VALUE, new Integer(exportedClassFilesCounter)); //$NON-NLS-1$
359
				this.printTag(NUMBER_OF_CLASSFILES, parameters, true, true);
360
			}
361
			if (exportedClassFilesCounter == 1) {
362
				this.printlnOut(Main.bind("compile.oneClassFileGenerated")); //$NON-NLS-1$
363
			} else {
364
				this.printlnOut(Main.bind("compile.severalClassFilesGenerated", //$NON-NLS-1$
365
					String.valueOf(exportedClassFilesCounter)));
366
			}
367
		}
368
369
		/**
370
		 * @param options the given compiler options
371
		 */
372
		public void logOptions(Map options) {
373
			if (this.isXml) {
374
				this.printTag(OPTIONS, null, true, false);
375
				final Set keySet = options.keySet();
376
				Object[] keys = keySet.toArray();
377
				Arrays.sort(keys);
378
				for (int i = 0, max = keys.length; i < max; i++) {
379
					this.parameters.clear();
380
					Object key = keys[i];
381
					this.parameters.put(KEY, key);
382
					this.parameters.put(VALUE, options.get(key));
383
					this.printTag(OPTION, this.parameters, true, true);
384
				}
385
				this.endTag(OPTIONS);
386
			}
387
		}
388
389
		private void logProblem(IProblem problem, int localErrorCount,
390
			int globalErrorCount, char[] unitSource) {
391
			if (localErrorCount == 0) {
392
				this.printlnErr("----------"); //$NON-NLS-1$
393
			}
394
			this.printlnErr(problem.isError() ?
395
				Main.bind(
396
					"requestor.error", //$NON-NLS-1$
397
					Integer.toString(globalErrorCount),
398
					new String(problem.getOriginatingFileName()))
399
				: Main.bind(
400
					"requestor.warning", //$NON-NLS-1$
401
					Integer.toString(globalErrorCount),
402
					new String(problem.getOriginatingFileName())));
403
			try {
404
				this.printlnErr(((DefaultProblem) problem).errorReportSource(unitSource));
405
				this.printlnErr(problem.getMessage());
406
			} catch (Exception e) {
407
				this.printlnErr(Main.bind(
408
					"requestor.notRetrieveErrorMessage", problem.toString())); //$NON-NLS-1$
409
			}
410
			this.printlnErr("----------"); //$NON-NLS-1$
411
		}
81
		
412
		
82
		public void printErr(String s) {
413
		/**
83
			this.err.print(s);
414
		 * @param globalProblemsCount
84
			if (this.log != null) {
415
		 * @param globalErrorsCount
85
				this.log.print(s);
416
		 * @param globalWarningsCount
417
		 */
418
		public void logProblemsSummary(int globalProblemsCount,
419
			int globalErrorsCount, int globalWarningsCount) {
420
			if (this.isXml) {
421
				// generate xml
422
				parameters.clear();
423
				parameters.put(NUMBER_OF_PROBLEMS, new Integer(globalProblemsCount));
424
				parameters.put(NUMBER_OF_ERRORS, new Integer(globalErrorsCount));
425
				parameters.put(NUMBER_OF_WARNINGS, new Integer(globalWarningsCount));
426
				this.printTag(PROBLEM_SUMMARY, parameters, true, true);
427
			}
428
			if (globalProblemsCount == 1) {
429
				this.printErr(Main.bind("compile.oneProblem")); //$NON-NLS-1$
430
			} else {
431
				String errorMessage = null;
432
				String warningMessage = null;
433
				if (globalErrorsCount > 0) {
434
					if (globalErrorsCount == 1) {
435
						errorMessage = Main.bind("compile.oneError"); //$NON-NLS-1$
436
					} else {
437
						errorMessage = Main.bind("compile.severalErrors", String.valueOf(globalErrorsCount)); //$NON-NLS-1$
438
					}
439
				}
440
				if (globalWarningsCount > 0) {
441
					if (globalWarningsCount == 1) {
442
						warningMessage = Main.bind("compile.oneWarning"); //$NON-NLS-1$
443
					} else {
444
						warningMessage = Main.bind("compile.severalWarnings", String.valueOf(globalWarningsCount)); //$NON-NLS-1$
445
					}
446
				}
447
				if (errorMessage == null || warningMessage == null) {
448
					if (errorMessage == null) {
449
						this.printErr(Main.bind(
450
							"compile.severalProblemsErrorsOrWarnings", //$NON-NLS-1$
451
							String.valueOf(globalProblemsCount),
452
							warningMessage));
453
					} else {
454
						this.printErr(Main.bind(
455
							"compile.severalProblemsErrorsOrWarnings", //$NON-NLS-1$
456
							String.valueOf(globalProblemsCount),
457
							errorMessage));
458
					}
459
				} else {
460
					this.printErr(Main.bind(
461
						"compile.severalProblemsErrorsOrWarnings", //$NON-NLS-1$
462
						new String[] {
463
							String.valueOf(globalProblemsCount),
464
							errorMessage,
465
							warningMessage
466
						}));
467
				}
86
			}
468
			}
87
		}
469
		}
470
471
		public int logProblems(IProblem[] problems, char[] unitSource, Main currentMain) {
472
			final int count = problems.length;
473
			int localErrorCount = 0;
474
			if (count != 0) {
475
				if (this.isXml) {
476
					int errors = 0;
477
					int warnings = 0;
478
					int tasks = 0;
479
					for (int i = 0; i < count; i++) {
480
						IProblem problem = problems[i];
481
						if (problem != null) {
482
							currentMain.globalProblemsCount++;
483
							this.logProblem(problem, localErrorCount, currentMain.globalProblemsCount, unitSource);
484
							if (problem.isError()) {
485
								errors++;
486
								currentMain.globalErrorsCount++;
487
								localErrorCount++;
488
							} else {
489
								if (problem.getID() == IProblem.Task) {
490
									tasks++;
491
								} else {
492
									warnings++;
493
								}
494
								currentMain.globalWarningsCount++;
495
							}
496
						}
497
					}
498
					if ((errors + warnings) != 0) {
499
						this.startLoggingProblems(errors, warnings);
500
						for (int i = 0; i < count; i++) {
501
							IProblem problem = problems[i];
502
							if (problem!= null) {
503
								if (problem.getID() != IProblem.Task) {
504
									this.logXmlProblem(problem, unitSource);
505
								}
506
							}
507
						}
508
						this.endLoggingProblems();
509
					}
510
					if (tasks != 0) {
511
						this.startLoggingTasks(tasks);
512
						for (int i = 0; i < count; i++) {
513
							IProblem problem = problems[i];
514
							if (problem!= null) {
515
								if (problem.getID() == IProblem.Task) {
516
									this.logXmlTask(problem, unitSource);
517
								}
518
							}
519
						}
520
						this.endLoggingTasks();
521
					}
522
				} else {
523
					for (int i = 0; i < count; i++) {
524
						if (problems[i] != null) {
525
							currentMain.globalProblemsCount++;
526
							this.logProblem(problems[i], localErrorCount, currentMain.globalProblemsCount, unitSource);
527
							if (problems[i].isError()) {
528
								currentMain.globalErrorsCount++;
529
								localErrorCount++;
530
							} else {
531
								currentMain.globalWarningsCount++;
532
							}
533
						}
534
					}
535
				}
536
			}
537
			return localErrorCount;
538
		}
88
		
539
		
89
		public void printlnErr(String s) {
540
		/**
541
		 * 
542
		 */
543
		public void logProgress() {
544
			this.printOut('.');
545
		}
546
547
		/**
548
		 * @param i
549
		 *            the current repetition number
550
		 * @param repetitions
551
		 *            the given number of repetitions
552
		 */
553
		public void logRepetition(int i, int repetitions) {
554
			this.printlnOut(Main.bind("compile.repetition", //$NON-NLS-1$
555
				String.valueOf(i + 1), String.valueOf(repetitions)));
556
		}
557
558
		public void printStats(Main main) {
559
			final boolean isTimed = main.timing;
560
			if (isXml) {
561
				this.printTag(STATS, null, true, false);
562
			}
563
			if (isTimed) {
564
				long time = System.currentTimeMillis() - main.startTime;
565
				this.logTiming(time, main.lineCount);
566
			}
567
			if (main.globalProblemsCount > 0) {
568
				this.logProblemsSummary(main.globalProblemsCount, main.globalErrorsCount, main.globalWarningsCount);
569
			}
570
			if (main.exportedClassFilesCounter != 0
571
					&& (main.showProgress || isTimed || main.verbose)) {
572
				this.logNumberOfClassFilesGenerated(main.exportedClassFilesCounter);
573
			}
574
			if (isXml) {
575
				this.endTag(STATS);
576
			}
577
		}
578
		/**
579
		 * @param time
580
		 * @param lineCount
581
		 */
582
		public void logTiming(long time, long lineCount) {
583
			if (isXml) {
584
				this.parameters.clear();
585
				this.parameters.put(VALUE, new Long(time));
586
				this.printTag(TIME, this.parameters, true, true);
587
				this.parameters.clear();
588
				this.parameters.put(VALUE, new Long(lineCount));
589
				this.printTag(NUMBER_OF_LINES, this.parameters, true, true);
590
			}
591
			if (lineCount != 0) {
592
				this.printlnOut(Main.bind(
593
					"compile.instantTime", //$NON-NLS-1$
594
					new String[] {
595
						String.valueOf(lineCount),
596
						String.valueOf(time),
597
						String.valueOf(((int) (lineCount * 10000.0 / time)) / 10.0) }));
598
			} else {
599
				this.printlnOut(Main.bind("compile.totalTime", String.valueOf(time))); //$NON-NLS-1$
600
			}
601
		}
602
603
		/**
604
		 * @param usage
605
		 */
606
		public void logUsage(String usage) {
607
			this.printlnOut(usage); //$NON-NLS-1$//$NON-NLS-2$
608
		}
609
610
		/**
611
		 * 
612
		 */
613
		public void logVersion() {
614
			this.printlnOut(Main.bind("misc.version")); //$NON-NLS-1$
615
		}
616
617
		/**
618
		 * 
619
		 */
620
		public void logWrongJDK() {
621
			if (isXml) {
622
				parameters.clear();
623
				parameters.put(MESSAGE, Main.bind("configure.requiresJDK1.2orAbove")); //$NON-NLS-1$//$NON-NLS-2$
624
				this.printTag(ERROR, parameters, true, true);				
625
			}
626
			this.printlnErr(Main.bind("configure.requiresJDK1.2orAbove")); //$NON-NLS-1$
627
		}
628
629
		/**
630
		 * @param problem
631
		 *            the given problem to log
632
		 * @param unitSource
633
		 *            the given unit source
634
		 */
635
		private void logXmlProblem(IProblem problem, char[] unitSource) {
636
			final int sourceStart = problem.getSourceStart();
637
			final int sourceEnd = problem.getSourceEnd();
638
			parameters.clear();
639
			parameters.put(PROBLEM_ID, getFieldName(problem.getID()));
640
			parameters.put(PROBLEM_SEVERITY, problem.isError() ? ERROR : WARNING);
641
			parameters.put(PROBLEM_LINE, new Integer(problem.getSourceLineNumber()));
642
			parameters.put(PROBLEM_SOURCE_START, new Integer(sourceStart));
643
			parameters.put(PROBLEM_SOURCE_END, new Integer(sourceEnd));
644
			this.printTag(PROBLEM_TAG, parameters, true, false);
645
			parameters.clear();
646
			parameters.put(VALUE, problem.getMessage());
647
			this.printTag(PROBLEM_MESSAGE, parameters, true, true);
648
			parameters.clear();
649
			StringBuffer buffer = new StringBuffer();
650
			if ((sourceStart > sourceEnd)
651
				|| ((sourceStart < 0) && (sourceEnd < 0))) {
652
				buffer.append(Util.bind("problem.noSourceInformation")); //$NON-NLS-1$
653
			} else {
654
				buffer.append(unitSource, sourceStart, sourceEnd - sourceStart + 1);
655
			}
656
			parameters.put(VALUE, String.valueOf(buffer));
657
			this.printTag(PROBLEM_SOURCE, parameters, true, true);
658
			String[] arguments = problem.getArguments();
659
			final int length = arguments.length;
660
			if (length != 0) {
661
				this.printTag(PROBLEM_ARGUMENTS, null, true, false);
662
				parameters.clear();
663
				for (int i = 0; i < length; i++) {
664
					parameters.put(PROBLEM_ARGUMENT_VALUE, arguments[i]);
665
					this.printTag(PROBLEM_ARGUMENT, parameters, true, true);
666
				}
667
				this.endTag(PROBLEM_ARGUMENTS);
668
			}
669
			this.endTag(PROBLEM_TAG);
670
		}
671
		/**
672
		 * @param problem
673
		 *            the given problem to log
674
		 * @param unitSource
675
		 *            the given unit source
676
		 */
677
		private void logXmlTask(IProblem problem, char[] unitSource) {
678
			parameters.clear();
679
			parameters.put(PROBLEM_LINE, new Integer(problem.getSourceLineNumber()));
680
			parameters.put(PROBLEM_SOURCE_START, new Integer(problem.getSourceStart()));
681
			parameters.put(PROBLEM_SOURCE_END, new Integer(problem.getSourceEnd()));
682
			this.printTag(TASK, parameters, true, false);
683
			parameters.clear();
684
			parameters.put(VALUE, problem.getMessage());
685
			this.printTag(PROBLEM_MESSAGE, parameters, true, true);
686
			this.endTag(TASK);
687
		}
688
		private void printErr(String s) {
689
			this.err.print(s);
690
			if (!this.isXml) {
691
				if (this.log != null) {
692
					this.log.print(s);
693
				}
694
			}
695
		}
696
697
		private void printlnErr(String s) {
90
			this.err.println(s);
698
			this.err.println(s);
91
			if (this.log != null) {
699
			if (!this.isXml) {
92
				this.log.println(s);
700
				if (this.log != null) {
701
					this.log.println(s);
702
				}
93
			}
703
			}
94
		}
704
		}
95
		
705
96
		public void printlnOut(String s) {
706
		private void printlnOut(String s) {
97
			this.out.println(s);
707
			this.out.println(s);
98
		}
708
		}
99
		
709
100
		public void printlnOut() {
710
		/**
711
		 * 
712
		 */
713
		public void printNewLine() {
101
			this.out.println();
714
			this.out.println();
102
		}
715
		}
103
		
716
104
		public void printOut(char c) {
717
		private void printOut(char c) {
105
			this.out.print(c);
718
			this.out.print(c);
106
		}
719
		}
720
		public void printTag(String name, HashMap params, boolean insertNewLine, boolean closeTag) {
721
			for (int i= this.tab; i > 0; i--) this.log.print('\t');
722
			StringBuffer buffer= new StringBuffer();
723
			buffer.append("<"); //$NON-NLS-1$
724
			buffer.append(name);
725
			if (params != null) {
726
				for (Enumeration enumeration = Collections.enumeration(params.keySet()); enumeration.hasMoreElements();) {
727
					buffer.append(" "); //$NON-NLS-1$
728
					String key= (String) enumeration.nextElement();
729
					buffer.append(key);
730
					buffer.append("=\""); //$NON-NLS-1$
731
					buffer.append(getEscaped(String.valueOf(params.get(key))));
732
					buffer.append("\""); //$NON-NLS-1$
733
				}
734
			}
735
			if (closeTag) {
736
				buffer.append("/>"); //$NON-NLS-1$
737
			} else {
738
				buffer.append(">"); //$NON-NLS-1$
739
				this.tab++;
740
			}
741
			if (insertNewLine) {
742
				this.log.println(String.valueOf(buffer));
743
			} else {
744
				this.log.print(String.valueOf(buffer));
745
			}
746
		}
747
748
		public void setLog(String logFileName) throws InvalidInputException {
749
			try {
750
				this.log = new PrintWriter(new FileOutputStream(logFileName, false));
751
				int index = logFileName.lastIndexOf('.');
752
				if (index != 0) {
753
					if (logFileName.substring(index).toLowerCase().equals(".xml")) { //$NON-NLS-1$
754
						this.isXml = true;
755
						this.log.println(XML_HEADER);
756
						this.log.println(XML_DTD_DECLARATION);
757
						this.tab = 0;
758
						parameters.clear();
759
						parameters.put(COMPILER_NAME, Main.bind("compiler.name")); //$NON-NLS-1$//$NON-NLS-2$
760
						parameters.put(COMPILER_VERSION, Main.bind("compiler.version")); //$NON-NLS-1$//$NON-NLS-2$
761
						parameters.put(COMPILER_COPYRIGHT, Main.bind("compiler.copyright")); //$NON-NLS-1$//$NON-NLS-2$
762
						this.printTag(COMPILER, parameters, true, false);
763
					}
764
				}
765
			} catch (FileNotFoundException e) {
766
				throw new InvalidInputException(Main.bind("configure.cannotOpenLog")); //$NON-NLS-1$
767
			}
768
		}
769
770
		/**
771
		 * Used to start logging problems.
772
		 * Only use in xml mode.
773
		 */
774
		private void startLoggingProblems(int errors, int warnings) {
775
			parameters.clear();
776
			parameters.put(NUMBER_OF_PROBLEMS, new Integer(errors + warnings));
777
			parameters.put(NUMBER_OF_ERRORS, new Integer(errors));
778
			parameters.put(NUMBER_OF_WARNINGS, new Integer(warnings));
779
			this.printTag(PROBLEMS, this.parameters, true, false);
780
		}
781
		public void startLoggingSource(CompilationResult compilationResult) {
782
			if (this.isXml) {
783
				ICompilationUnit compilationUnit = compilationResult.compilationUnit;
784
				char[] fileName = compilationUnit.getFileName();
785
				if (fileName != null) {
786
					this.parameters.clear();
787
					if (compilationUnit != null) {
788
						this.parameters.put(PATH, new String(fileName));
789
					}
790
				}
791
				this.printTag(SOURCE, this.parameters, true, false);
792
			}
793
		}
794
		public void startLoggingSources() {
795
			if (this.isXml) {
796
				this.printTag(SOURCES, null, true, false);
797
			}
798
		}
799
		public void startLoggingTasks(int tasks) {
800
			if (this.isXml) {
801
				parameters.clear();
802
				parameters.put(NUMBER_OF_TASKS, new Integer(tasks));
803
				this.printTag(TASKS, this.parameters, true, false);
804
			}
805
		}
806
		public void logClassFile(boolean generatePackagesStructure, String outputPath, String relativeFileName) {
807
			if (this.isXml) {
808
				String fileName = null;
809
				if (generatePackagesStructure) {
810
					fileName = buildFileName(outputPath, relativeFileName);
811
				} else {
812
					char fileSeparatorChar = File.separatorChar;
813
					String fileSeparator = File.separator;
814
					// First we ensure that the outputPath exists
815
					outputPath = outputPath.replace('/', fileSeparatorChar);
816
					// To be able to pass the mkdirs() method we need to remove the extra file separator at the end of the outDir name
817
					int indexOfPackageSeparator = relativeFileName.lastIndexOf(fileSeparatorChar);
818
					if (indexOfPackageSeparator == -1) {
819
						if (outputPath.endsWith(fileSeparator)) {
820
							fileName = outputPath + relativeFileName;
821
						} else {
822
							fileName = outputPath + fileSeparator + relativeFileName;
823
						}
824
					} else {
825
						int length = relativeFileName.length();
826
						if (outputPath.endsWith(fileSeparator)) {
827
							fileName = outputPath + relativeFileName.substring(indexOfPackageSeparator + 1, length);
828
						} else {
829
							fileName = outputPath + fileSeparator + relativeFileName.substring(indexOfPackageSeparator + 1, length);
830
						}
831
					}
832
				}
833
				this.parameters.clear();
834
				this.parameters.put(PATH, fileName);
835
				this.printTag(CLASS_FILE, this.parameters, true, true);
836
			}			
837
		}
107
	}
838
	}
108
	static {
839
	static {
109
		relocalize();
840
		relocalize();
Lines 354-361 Link Here
354
//				if (this.verbose) {
1085
//				if (this.verbose) {
355
//					System.out.println(new CompilerOptions(this.options));
1086
//					System.out.println(new CompilerOptions(this.options));
356
//				}
1087
//				}
357
				if (this.showProgress)
1088
				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++) {
1089
				for (int i = 0; i < this.repetitions; i++) {
360
					this.globalProblemsCount = 0;
1090
					this.globalProblemsCount = 0;
361
					this.globalErrorsCount = 0;
1091
					this.globalErrorsCount = 0;
Lines 365-388 Link Here
365
1095
366
					if (this.repetitions > 1) {
1096
					if (this.repetitions > 1) {
367
						this.logger.flush();
1097
						this.logger.flush();
368
						this.logger.printlnOut(
1098
						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
					} 
1099
					} 
374
					// request compilation
1100
					// request compilation
375
					performCompilation();
1101
					performCompilation();
376
				}
1102
				}
377
				if (this.showProgress)
1103
				if (this.showProgress) this.logger.printNewLine();
378
					this.logger.printlnOut();
379
			}
1104
			}
380
			if (this.systemExitWhenFinished) {
1105
			if (this.systemExitWhenFinished) {
381
				this.logger.flush();
1106
				this.logger.flush();
1107
    			this.logger.close();
382
				System.exit(this.globalErrorsCount > 0 ? -1 : 0);
1108
				System.exit(this.globalErrorsCount > 0 ? -1 : 0);
383
			}
1109
			}
384
		} catch (InvalidInputException e) {
1110
		} catch (InvalidInputException e) {
385
			this.logger.printlnErr(e.getMessage());
1111
			this.logger.logException(e);
386
			if (this.systemExitWhenFinished) {
1112
			if (this.systemExitWhenFinished) {
387
    			this.logger.flush();
1113
    			this.logger.flush();
388
    			this.logger.close();
1114
    			this.logger.close();
Lines 396-402 Link Here
396
				System.exit(-1);
1122
				System.exit(-1);
397
			}
1123
			}
398
			return false;
1124
			return false;
399
			//e.printStackTrace();
400
		} finally {
1125
		} finally {
401
			this.logger.flush();
1126
			this.logger.flush();
402
			this.logger.close();
1127
			this.logger.close();
Lines 1236-1242 Link Here
1236
			// no user classpath specified.
1961
			// no user classpath specified.
1237
			String classProp = System.getProperty("java.class.path"); //$NON-NLS-1$
1962
			String classProp = System.getProperty("java.class.path"); //$NON-NLS-1$
1238
			if ((classProp == null) || (classProp.length() == 0)) {
1963
			if ((classProp == null) || (classProp.length() == 0)) {
1239
				this.logger.printlnErr(Main.bind("configure.noClasspath")); //$NON-NLS-1$
1964
				this.logger.logNoClasspath(); //$NON-NLS-1$
1240
				classProp = System.getProperty("user.dir"); //$NON-NLS-1$
1965
				classProp = System.getProperty("user.dir"); //$NON-NLS-1$
1241
			}
1966
			}
1242
			StringTokenizer tokenizer = new StringTokenizer(classProp, File.pathSeparator);
1967
			StringTokenizer tokenizer = new StringTokenizer(classProp, File.pathSeparator);
Lines 1254-1260 Link Here
1254
			 */
1979
			 */
1255
			 String javaversion = System.getProperty("java.version");//$NON-NLS-1$
1980
			 String javaversion = System.getProperty("java.version");//$NON-NLS-1$
1256
			 if (javaversion != null && javaversion.equalsIgnoreCase("1.1.8")) { //$NON-NLS-1$
1981
			 if (javaversion != null && javaversion.equalsIgnoreCase("1.1.8")) { //$NON-NLS-1$
1257
				this.logger.printlnErr(Main.bind("configure.requiresJDK1.2orAbove")); //$NON-NLS-1$
1982
				this.logger.logWrongJDK(); //$NON-NLS-1$
1258
				this.proceed = false;
1983
				this.proceed = false;
1259
				return;
1984
				return;
1260
			 }
1985
			 }
Lines 1291-1301 Link Here
1291
		}
2016
		}
1292
2017
1293
		if (this.log != null) {
2018
		if (this.log != null) {
1294
			try {
2019
			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 {
2020
		} else {
1300
			this.showProgress = false;
2021
			this.showProgress = false;
1301
		}
2022
		}
Lines 1331-1337 Link Here
1331
		for (int i = 0, max = this.classpaths.length; i < max; i++) {
2052
		for (int i = 0, max = this.classpaths.length; i < max; i++) {
1332
			File file = new File(this.classpaths[i]);
2053
			File file = new File(this.classpaths[i]);
1333
			if (!file.exists()) { // signal missing classpath entry file
2054
			if (!file.exists()) { // signal missing classpath entry file
1334
				this.logger.printlnErr(Main.bind("configure.incorrectClasspath", this.classpaths[i])); //$NON-NLS-1$
2055
				this.logger.logIncorrectClasspath(this.classpaths[i]); //$NON-NLS-1$
1335
			}
2056
			}
1336
		}
2057
		}
1337
		if (this.destinationPath == null) {
2058
		if (this.destinationPath == null) {
Lines 1343-1366 Link Here
1343
		if (didSpecifyCompliance) {
2064
		if (didSpecifyCompliance) {
1344
			Object version = this.options.get(CompilerOptions.OPTION_Compliance);
2065
			Object version = this.options.get(CompilerOptions.OPTION_Compliance);
1345
			if (CompilerOptions.VERSION_1_3.equals(version)) {
2066
			if (CompilerOptions.VERSION_1_3.equals(version)) {
1346
					if (!didSpecifySource) this.options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_3);
2067
				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);
2068
				if (!didSpecifyTarget) this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_1);
1348
			} else if (CompilerOptions.VERSION_1_4.equals(version)) {
2069
			} else if (CompilerOptions.VERSION_1_4.equals(version)) {
1349
					if (!didSpecifySource) this.options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_3);
2070
				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);
2071
				if (!didSpecifyTarget) this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_2);
1351
			} else if (CompilerOptions.VERSION_1_5.equals(version)) {
2072
			} else if (CompilerOptions.VERSION_1_5.equals(version)) {
1352
					if (!didSpecifySource) this.options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_5);
2073
				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);
2074
				if (!didSpecifyTarget) this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_5);
1354
			}
2075
			}
1355
		}
2076
		}
1356
		if (didSpecifySource) {
2077
		if (didSpecifySource) {
1357
			Object version = this.options.get(CompilerOptions.OPTION_Source);
2078
			Object version = this.options.get(CompilerOptions.OPTION_Source);
1358
			 if (CompilerOptions.VERSION_1_4.equals(version)) {
2079
			 if (CompilerOptions.VERSION_1_4.equals(version)) {
1359
					if (!didSpecifyCompliance) this.options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_4);
2080
				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);
2081
				if (!didSpecifyTarget) this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_4);
1361
			} else if (CompilerOptions.VERSION_1_5.equals(version)) {
2082
			} else if (CompilerOptions.VERSION_1_5.equals(version)) {
1362
					if (!didSpecifyCompliance) this.options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_5);
2083
				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);
2084
				if (!didSpecifyTarget) this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_5);
1364
			}
2085
			}
1365
		}
2086
		}
1366
2087
Lines 1378-1384 Link Here
1378
	   		}
2099
	   		}
1379
			// target cannot be greater than compliance level
2100
			// 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))){ 
2101
			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$
2102
				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
			}
2103
			}
1383
		}
2104
		}
1384
2105
Lines 1412-1418 Link Here
1412
				}
2133
				}
1413
			}
2134
			}
1414
		}
2135
		}
1415
2136
		this.logger.logCommandLineArguments(newCommandLineArgs);
2137
		this.logger.logOptions(this.options);
2138
		this.logger.logClasspath(this.classpaths);
1416
		if (this.repetitions == 0) {
2139
		if (this.repetitions == 0) {
1417
			this.repetitions = 1;
2140
			this.repetitions = 1;
1418
		}
2141
		}
Lines 1456-1512 Link Here
1456
					int unitLineCount = compilationResult.lineSeparatorPositions.length;
2179
					int unitLineCount = compilationResult.lineSeparatorPositions.length;
1457
					Main.this.lineCount += unitLineCount;
2180
					Main.this.lineCount += unitLineCount;
1458
					this.lineDelta += unitLineCount;
2181
					this.lineDelta += unitLineCount;
1459
					if (Main.this.showProgress
2182
					if (Main.this.showProgress && this.lineDelta > 2000) {
1460
						&& this.lineDelta > 2000) { // in -log mode, dump a dot every 2000 lines compiled
2183
						// in -log mode, dump a dot every 2000 lines compiled
1461
						Main.this.logger.printOut('.');
2184
						Main.this.logger.logProgress();
1462
						this.lineDelta = 0;
2185
						this.lineDelta = 0;
1463
					}
2186
					}
1464
				}
2187
				}
2188
				Main.this.logger.startLoggingSource(compilationResult);
1465
				if (compilationResult.hasProblems() || compilationResult.hasTasks()) {
2189
				if (compilationResult.hasProblems() || compilationResult.hasTasks()) {
1466
					IProblem[] problems = compilationResult.getAllProblems();
2190
					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?
2191
					// exit?
1503
					if (Main.this.systemExitWhenFinished && !Main.this.proceedOnError && (localErrorCount > 0)) {
2192
					if (Main.this.systemExitWhenFinished && !Main.this.proceedOnError && (localErrorCount > 0)) {
1504
						Main.this.printStats();
2193
						Main.this.logger.endLoggingSource();
2194
						Main.this.logger.printStats(Main.this);
1505
						Main.this.logger.flush();
2195
						Main.this.logger.flush();
2196
						Main.this.logger.close();
1506
						System.exit(-1);
2197
						System.exit(-1);
1507
					}
2198
					}
1508
				}
2199
				}
1509
				outputClassFiles(compilationResult);
2200
				outputClassFiles(compilationResult);
2201
				Main.this.logger.endLoggingSource();
1510
			}
2202
			}
1511
		};
2203
		};
1512
	}
2204
	}
Lines 1603-1614 Link Here
1603
	// Dump classfiles onto disk for all compilation units that where successfull.
2295
	// Dump classfiles onto disk for all compilation units that where successfull.
1604
2296
1605
	public void outputClassFiles(CompilationResult unitResult) {
2297
	public void outputClassFiles(CompilationResult unitResult) {
1606
1607
		if (!((unitResult == null) || (unitResult.hasErrors() && !this.proceedOnError))) {
2298
		if (!((unitResult == null) || (unitResult.hasErrors() && !this.proceedOnError))) {
1608
			Enumeration classFiles = unitResult.compiledTypes.elements();
2299
			Enumeration classFiles = unitResult.compiledTypes.elements();
1609
			if (!this.generatePackagesStructure) {
2300
			if (!this.generatePackagesStructure) {
2301
				this.destinationPath = extractDestinationPathFromSourceFile(unitResult);
2302
			}
2303
			if (this.destinationPath != null) {
1610
				while (classFiles.hasMoreElements()) {
2304
				while (classFiles.hasMoreElements()) {
1611
					this.destinationPath = extractDestinationPathFromSourceFile(unitResult);
1612
					// retrieve the key and the corresponding classfile
2305
					// retrieve the key and the corresponding classfile
1613
					ClassFile classFile = (ClassFile) classFiles.nextElement();
2306
					ClassFile classFile = (ClassFile) classFiles.nextElement();
1614
					char[] filename = classFile.fileName();
2307
					char[] filename = classFile.fileName();
Lines 1622-1656 Link Here
1622
							System.out.println(Util.bind("compilation.write", //$NON-NLS-1$
2315
							System.out.println(Util.bind("compilation.write", //$NON-NLS-1$
1623
								new String[] {
2316
								new String[] {
1624
									String.valueOf(this.exportedClassFilesCounter+1),
2317
									String.valueOf(this.exportedClassFilesCounter+1),
1625
									new String(relativeName) }));					    
2318
									new String(relativeName)
1626
						ClassFile.writeToDisk(
2319
								}));
2320
						this.logger.logClassFile(
1627
							this.generatePackagesStructure,
2321
							this.generatePackagesStructure,
1628
							this.destinationPath,
2322
							this.destinationPath,
1629
							new String(relativeName),
2323
							new String(relativeName));
1630
							classFile.getBytes());
1631
					} catch (IOException e) {
1632
						String fileName = this.destinationPath + new String(relativeName);
1633
						e.printStackTrace();
1634
						this.logger.printlnErr(Main.bind("output.noClassFileCreated", fileName));  //$NON-NLS-1$
1635
					}
1636
					this.exportedClassFilesCounter++;
1637
				}
1638
			} else if (this.destinationPath != null) {
1639
				while (classFiles.hasMoreElements()) {
1640
					// retrieve the key and the corresponding classfile
1641
					ClassFile classFile = (ClassFile) classFiles.nextElement();
1642
					char[] filename = classFile.fileName();
1643
					int length = filename.length;
1644
					char[] relativeName = new char[length + 6];
1645
					System.arraycopy(filename, 0, relativeName, 0, length);
1646
					System.arraycopy(SUFFIX_class, 0, relativeName, length, 6);
1647
					CharOperation.replace(relativeName, '/', File.separatorChar);
1648
					try {
1649
						if (this.compilerOptions.verbose)
1650
							System.out.println(Util.bind("compilation.write", //$NON-NLS-1$
1651
								new String[] {
1652
									String.valueOf(this.exportedClassFilesCounter+1),
1653
									new String(relativeName) }));					    
1654
						ClassFile.writeToDisk(
2324
						ClassFile.writeToDisk(
1655
							this.generatePackagesStructure,
2325
							this.generatePackagesStructure,
1656
							this.destinationPath,
2326
							this.destinationPath,
Lines 1659-1665 Link Here
1659
					} catch (IOException e) {
2329
					} catch (IOException e) {
1660
						String fileName = this.destinationPath + new String(relativeName);
2330
						String fileName = this.destinationPath + new String(relativeName);
1661
						e.printStackTrace();
2331
						e.printStackTrace();
1662
						this.logger.printlnErr(Main.bind("output.noClassFileCreated", fileName)); //$NON-NLS-1$
2332
						this.logger.logNoClassFileCreated(fileName); //$NON-NLS-1$
1663
					}
2333
					}
1664
					this.exportedClassFilesCounter++;
2334
					this.exportedClassFilesCounter++;
1665
				}
2335
				}
Lines 1686-1762 Link Here
1686
		// set the non-externally configurable options.
2356
		// set the non-externally configurable options.
1687
		this.compilerOptions.verbose = this.verbose;
2357
		this.compilerOptions.verbose = this.verbose;
1688
		this.compilerOptions.produceReferenceInfo = this.produceRefInfo;
2358
		this.compilerOptions.produceReferenceInfo = this.produceRefInfo;
1689
		batchCompiler.compile(getCompilationUnits());
2359
		try {
2360
			this.logger.startLoggingSources();
2361
			batchCompiler.compile(getCompilationUnits());
2362
		} finally {
2363
			this.logger.endLoggingSources();
2364
		}
1690
2365
1691
		printStats();
2366
		this.logger.printStats(this);
1692
		
2367
		
1693
		// cleanup
2368
		// cleanup
1694
		environment.cleanup();
2369
		environment.cleanup();
1695
	}
2370
	}
1696
	
2371
	
1697
	public void printStats() {
1698
		if (this.timing) {
1699
1700
			long time = System.currentTimeMillis() - this.startTime;
1701
			if (this.lineCount != 0) {
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
		}
1713
		if (this.globalProblemsCount > 0) {
1714
			if (this.globalProblemsCount == 1) {
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
		}
1742
		if (this.exportedClassFilesCounter != 0
1743
			&& (this.showProgress || this.timing || this.verbose)) {
1744
			if (this.exportedClassFilesCounter == 1) {
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
		}
1753
	}
1754
	public void printUsage() {
2372
	public void printUsage() {
1755
		this.logger.printlnOut(Main.bind("misc.usage", System.getProperty("path.separator"))); //$NON-NLS-1$//$NON-NLS-2$
2373
		this.logger.logUsage(Main.bind("misc.usage", System.getProperty("path.separator"))); //$NON-NLS-1$//$NON-NLS-2$
1756
		this.logger.flush();
2374
		this.logger.flush();
1757
	}
2375
	}
1758
	public void printVersion() {
2376
	public void printVersion() {
1759
		this.logger.printlnOut(Main.bind("misc.version"));  //$NON-NLS-1$
2377
		this.logger.logVersion();  //$NON-NLS-1$
1760
		this.logger.flush();
2378
		this.logger.flush();
1761
	}
2379
	}
1762
}
2380
}
(-)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