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 / +779 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_FILE = "classfile"; //$NON-NLS-1$
55
		PrintWriter out;
61
		private static final String CLASSPATH = "classpath"; //$NON-NLS-1$
56
		PrintWriter err;
62
		private static final String CLASSPATH_FILE = "file"; //$NON-NLS-1$
57
		PrintWriter log;
63
		private static final String CLASSPATH_FOLDER = "folder"; //$NON-NLS-1$
58
		
64
		private static final String CLASSPATH_JAR = "jar"; //$NON-NLS-1$
65
		private static final String CLASSPATHS = "classpaths"; //$NON-NLS-1$
66
		private static final String COMMAND_LINE_ARGUMENT = "argument"; //$NON-NLS-1$
67
		private static final String COMMAND_LINE_ARGUMENTS = "command_line"; //$NON-NLS-1$
68
		private static final String COMPILER = "compiler"; //$NON-NLS-1$
69
		private static final String COMPILER_COPYRIGHT = "copyright"; //$NON-NLS-1$
70
		private static final String COMPILER_VERSION = "version"; //$NON-NLS-1$
71
		private static final String COMPILER_NAME = "name"; //$NON-NLS-1$
72
		private static final String DETAILED_PROBLEM_MESSAGE = "detailed_message"; //$NON-NLS-1$
73
		private static final String ERROR = "ERROR"; //$NON-NLS-1$
74
		private static final String ERROR_TAG = "error"; //$NON-NLS-1$
75
		private static final String KEY = "key"; //$NON-NLS-1$
76
		private static final String MESSAGE = "message"; //$NON-NLS-1$
77
		private static final String NUMBER_OF_CLASSFILES = "number_of_classfiles"; //$NON-NLS-1$
78
		private static final String NUMBER_OF_ERRORS = "errors"; //$NON-NLS-1$
79
		private static final String NUMBER_OF_LINES = "number_of_lines"; //$NON-NLS-1$
80
		private static final String NUMBER_OF_PROBLEMS = "problems"; //$NON-NLS-1$
81
		private static final String NUMBER_OF_TASKS = "tasks"; //$NON-NLS-1$
82
		private static final String NUMBER_OF_WARNINGS = "warnings"; //$NON-NLS-1$
83
		private static final String OPTION = "option"; //$NON-NLS-1$
84
		private static final String OPTIONS = "options"; //$NON-NLS-1$
85
		private static final String PATH = "path"; //$NON-NLS-1$
86
		private static final String PROBLEM_ARGUMENT = "argument"; //$NON-NLS-1$
87
		private static final String PROBLEM_ARGUMENT_VALUE = "value"; //$NON-NLS-1$
88
		private static final String PROBLEM_ARGUMENTS = "arguments"; //$NON-NLS-1$
89
		private static final String PROBLEM_ID = "id"; //$NON-NLS-1$
90
		private static final String PROBLEM_FILE = "source"; //$NON-NLS-1$
91
		private static final String PROBLEM_LINE = "line"; //$NON-NLS-1$
92
		private static final String PROBLEM_MESSAGE = "message"; //$NON-NLS-1$
93
		private static final String PROBLEM_SEVERITY = "severity"; //$NON-NLS-1$
94
		private static final String PROBLEM_SOURCE_START = "start"; //$NON-NLS-1$
95
		private static final String PROBLEM_SOURCE_END = "end"; //$NON-NLS-1$
96
		private static final String PROBLEM_SUMMARY = "problem_summary"; //$NON-NLS-1$
97
		private static final String PROBLEM_TAG = "problem"; //$NON-NLS-1$
98
		private static final String PROBLEMS = "problems"; //$NON-NLS-1$
99
		private static final String SOURCE = "source"; //$NON-NLS-1$
100
		private static final String SOURCES = "sources"; //$NON-NLS-1$
101
		private static final String STATS = "stats"; //$NON-NLS-1$
102
		private static final String TASK = "task"; //$NON-NLS-1$
103
		private static final String TASKS = "tasks"; //$NON-NLS-1$
104
		private static final String TIME = "time"; //$NON-NLS-1$
105
		private static final String VALUE = "value"; //$NON-NLS-1$
106
		private static final String WARNING = "WARNING"; //$NON-NLS-1$
107
		private static final String XML_VERSION= "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; //$NON-NLS-1$
108
109
		private static final HashMap FIELD_TABLE = new HashMap();
110
		static {
111
			try {
112
				Class c = IProblem.class;
113
				Field[] fields = c.getFields();
114
				for (int i = 0, max = fields.length; i < max; i++) {
115
					Field field = fields[i];
116
					FIELD_TABLE.put(field.get(null), field.getName());
117
				}
118
			} catch (SecurityException e) {
119
				e.printStackTrace();
120
			} catch (IllegalArgumentException e) {
121
				e.printStackTrace();
122
			} catch (IllegalAccessException e) {
123
				e.printStackTrace();
124
			}
125
		}
126
		private static void appendEscapedChar(StringBuffer buffer, char c) {
127
			String replacement= getReplacement(c);
128
			if (replacement != null) {
129
				buffer.append('&');
130
				buffer.append(replacement);
131
				buffer.append(';');
132
			} else {
133
				buffer.append(c);
134
			}
135
		}
136
		private static String getEscaped(String s) {
137
			StringBuffer result= new StringBuffer(s.length() + 10);
138
			for (int i= 0; i < s.length(); ++i)
139
				appendEscapedChar(result, s.charAt(i));
140
			return result.toString();
141
		}
142
		private static String getReplacement(char c) {
143
			// Encode special XML characters into the equivalent character references.
144
			// These five are defined by default for all XML documents.
145
			switch (c) {
146
				case '<' :
147
					return "lt"; //$NON-NLS-1$
148
				case '>' :
149
					return "gt"; //$NON-NLS-1$
150
				case '"' :
151
					return "quot"; //$NON-NLS-1$
152
				case '\'' :
153
					return "apos"; //$NON-NLS-1$
154
				case '&' :
155
					return "amp"; //$NON-NLS-1$
156
			}
157
			return null;
158
		}
159
		private PrintWriter err;
160
		boolean isXml;
161
		private PrintWriter log;
162
		private PrintWriter out;
163
		private int tab;
164
		private HashMap parameters;
165
59
		public Logger(PrintWriter out, PrintWriter err) {
166
		public Logger(PrintWriter out, PrintWriter err) {
60
			this.out = out;
167
			this.out = out;
61
			this.err = err;
168
			this.err = err;
169
			this.isXml = false;
170
			this.parameters = new HashMap();
62
		}
171
		}
63
		
172
64
		public void setLog(PrintWriter log) {
173
		public String buildFileName(
65
			this.log = log;
174
			String outputPath,
175
			String relativeFileName) {
176
			char fileSeparatorChar = File.separatorChar;
177
			String fileSeparator = File.separator;
178
			
179
			outputPath = outputPath.replace('/', fileSeparatorChar);
180
			// To be able to pass the mkdirs() method we need to remove the extra file separator at the end of the outDir name
181
			StringBuffer outDir = new StringBuffer(outputPath);
182
			if (!outputPath.endsWith(fileSeparator)) {
183
				outDir.append(fileSeparator);
184
			}
185
			StringTokenizer tokenizer =
186
				new StringTokenizer(relativeFileName, fileSeparator);
187
			String token = tokenizer.nextToken();
188
			while (tokenizer.hasMoreTokens()) {
189
				outDir.append(token).append(fileSeparator);
190
				token = tokenizer.nextToken();
191
			}
192
			// token contains the last one
193
			return outDir.append(token).toString();
66
		}
194
		}
67
		
195
		
68
		public void close() {
196
		public void close() {
69
			if (this.log != null) {
197
			if (this.log != null) {
198
				if (this.isXml) {
199
					this.endTag(COMPILER);
200
					this.flush();
201
				}
70
				this.log.close();
202
				this.log.close();
71
			}
203
			}
72
		}
204
		}
205
206
		/**
207
		 * 
208
		 */
209
		public void compiling() {
210
			this.printlnOut(Main.bind("progress.compiling")); //$NON-NLS-1$
211
		}
73
		
212
		
213
		/**
214
		 * Used to stop logging problems.
215
		 * Only use in xml mode.
216
		 */
217
		private void endLoggingProblems() {
218
			this.endTag(PROBLEMS);
219
		}
220
		public void endLoggingSource() {
221
			if (this.isXml) {
222
				this.endTag(SOURCE);
223
			}
224
		}
225
		public void endLoggingSources() {
226
			if (this.isXml) {
227
				this.endTag(SOURCES);
228
			}
229
		}
230
		public void endLoggingTasks() {
231
			if (this.isXml) {
232
				this.endTag(TASKS);
233
			}
234
		}
235
		public void endTag(String name) {
236
			tab--;
237
			this.printTag('/' + name, null, true, false);
238
			this.tab--;
239
		}
240
		
241
		private String getFieldName(int id) {
242
			return (String) FIELD_TABLE.get(new Integer(id));
243
		}
244
74
		public void flush() {
245
		public void flush() {
75
			this.out.flush();
246
			this.out.flush();
76
			this.err.flush();
247
			this.err.flush();
Lines 78-109 Link Here
78
				this.log.flush();
249
				this.log.flush();
79
			}
250
			}
80
		}
251
		}
252
		public void logClasspath(String[] classpaths) {
253
			if (classpaths == null) return;
254
			if (this.isXml) {
255
				final int length = classpaths.length;
256
				if (length != 0) {
257
					// generate xml output
258
					this.printTag(CLASSPATHS, null, true, false);
259
					for (int i = 0; i < length; i++) {
260
						this.parameters.clear();
261
						String classpath = classpaths[i];
262
						File f = new File(classpath);
263
						if (f.isFile()) {
264
							if (Util.isArchiveFileName(classpath)) {
265
								parameters.put(CLASSPATH_JAR, classpaths[i]);
266
							} else {
267
								parameters.put(CLASSPATH_FILE, classpaths[i]);
268
							}
269
						} else if (f.isDirectory()) {
270
							parameters.put(CLASSPATH_FOLDER, classpaths[i]);
271
						}
272
						this.printTag(CLASSPATH, parameters, true, true);
273
					}
274
					this.endTag(CLASSPATHS);
275
				}
276
			}
277
			
278
		}
279
280
		public void logCommandLineArguments(String[] commandLineArguments) {
281
			if (commandLineArguments == null) return;
282
			if (this.isXml) {
283
				final int length = commandLineArguments.length;
284
				if (length != 0) {
285
					// generate xml output
286
					this.printTag(COMMAND_LINE_ARGUMENTS, null, true, false);
287
					parameters.clear();
288
					for (int i = 0; i < length; i++) {
289
						parameters.put(VALUE, commandLineArguments[i]);
290
						this.printTag(COMMAND_LINE_ARGUMENT, parameters, true, true);
291
					}
292
					this.endTag(COMMAND_LINE_ARGUMENTS);
293
				}
294
			}
295
		}
296
297
		/**
298
		 * @param message
299
		 */
300
		public void logExceptionMessage(String message) {
301
			if (isXml) {
302
				parameters.clear();
303
				parameters.put(MESSAGE, message);
304
				this.printTag(ERROR_TAG, parameters, true, true);
305
			}
306
			this.printlnErr(message);
307
		}
308
309
		/**
310
		 * @param wrongClasspath
311
		 *            the given wrong classpath entry
312
		 */
313
		public void logIncorrectClasspath(String wrongClasspath) {
314
			if (isXml) {
315
				parameters.clear();
316
				parameters.put(MESSAGE, wrongClasspath);
317
				this.printTag(ERROR_TAG, parameters, true, true);
318
			}
319
			this.printlnErr(Main.bind(
320
				"configure.incorrectClasspath", wrongClasspath)); //$NON-NLS-1$
321
		}
322
323
		/**
324
		 * 
325
		 */
326
		public void logNoClassFileCreated(String fileName) {
327
			if (isXml) {
328
				parameters.clear();
329
				parameters.put(MESSAGE, Main.bind("output.noClassFileCreated", fileName)); //$NON-NLS-1$
330
				this.printTag(ERROR_TAG, null, true, true);
331
			}
332
			this.printlnErr(Main.bind("output.noClassFileCreated", fileName)); //$NON-NLS-1$
333
		}
334
335
		public void logNoClasspath() {
336
			if (isXml) {
337
				parameters.clear();
338
				parameters.put(MESSAGE, Main.bind("configure.noClasspath")); //$NON-NLS-1$//$NON-NLS-2$
339
				this.printTag(ERROR_TAG, parameters, true, true);
340
			}
341
			this.printlnErr(Main.bind("configure.noClasspath")); //$NON-NLS-1$
342
		}
343
344
		/**
345
		 * @param exportedClassFilesCounter
346
		 */
347
		public void logNumberOfClassFilesGenerated(int exportedClassFilesCounter) {
348
			if (isXml) {
349
				parameters.clear();
350
				parameters.put(VALUE, new Integer(exportedClassFilesCounter)); //$NON-NLS-1$
351
				this.printTag(NUMBER_OF_CLASSFILES, parameters, true, true);
352
			}
353
			if (exportedClassFilesCounter == 1) {
354
				this.printlnOut(Main.bind("compile.oneClassFileGenerated")); //$NON-NLS-1$
355
			} else {
356
				this.printlnOut(Main.bind("compile.severalClassFilesGenerated", //$NON-NLS-1$
357
					String.valueOf(exportedClassFilesCounter)));
358
			}
359
		}
360
361
		/**
362
		 * @param options the given compiler options
363
		 */
364
		public void logOptions(Map options) {
365
			if (this.isXml) {
366
				this.printTag(OPTIONS, null, true, false);
367
				final Set keySet = options.keySet();
368
				Object[] keys = keySet.toArray();
369
				Arrays.sort(keys);
370
				for (int i = 0, max = keys.length; i < max; i++) {
371
					this.parameters.clear();
372
					Object key = keys[i];
373
					this.parameters.put(KEY, key);
374
					this.parameters.put(VALUE, options.get(key));
375
					this.printTag(OPTION, this.parameters, true, true);
376
				}
377
				this.endTag(OPTIONS);
378
			}
379
		}
380
381
		private void logProblem(IProblem problem, int localErrorCount,
382
			int globalErrorCount, char[] unitSource) {
383
			if (localErrorCount == 0) {
384
				this.printlnErr("----------"); //$NON-NLS-1$
385
			}
386
			this.printlnErr(problem.isError() ?
387
				Main.bind(
388
					"requestor.error", //$NON-NLS-1$
389
					Integer.toString(globalErrorCount),
390
					new String(problem.getOriginatingFileName()))
391
				: Main.bind(
392
					"requestor.warning", //$NON-NLS-1$
393
					Integer.toString(globalErrorCount),
394
					new String(problem.getOriginatingFileName())));
395
			try {
396
				this.printlnErr(((DefaultProblem) problem).errorReportSource(unitSource));
397
				this.printlnErr(problem.getMessage());
398
			} catch (Exception e) {
399
				this.printlnErr(Main.bind(
400
					"requestor.notRetrieveErrorMessage", problem.toString())); //$NON-NLS-1$
401
			}
402
			this.printlnErr("----------"); //$NON-NLS-1$
403
		}
81
		
404
		
82
		public void printErr(String s) {
405
		/**
83
			this.err.print(s);
406
		 * @param globalProblemsCount
84
			if (this.log != null) {
407
		 * @param globalErrorsCount
85
				this.log.print(s);
408
		 * @param globalWarningsCount
409
		 */
410
		public void logProblemsSummary(int globalProblemsCount,
411
			int globalErrorsCount, int globalWarningsCount) {
412
			if (this.isXml) {
413
				// generate xml
414
				parameters.clear();
415
				parameters.put(NUMBER_OF_PROBLEMS, new Integer(globalProblemsCount));
416
				parameters.put(NUMBER_OF_ERRORS, new Integer(globalErrorsCount));
417
				parameters.put(NUMBER_OF_WARNINGS, new Integer(globalWarningsCount));
418
				this.printTag(PROBLEM_SUMMARY, parameters, true, true);
419
			}
420
			if (globalProblemsCount == 1) {
421
				this.printErr(Main.bind("compile.oneProblem")); //$NON-NLS-1$
422
			} else {
423
				String errorMessage = null;
424
				String warningMessage = null;
425
				if (globalErrorsCount > 0) {
426
					if (globalErrorsCount == 1) {
427
						errorMessage = Main.bind("compile.oneError"); //$NON-NLS-1$
428
					} else {
429
						errorMessage = Main.bind("compile.severalErrors", String.valueOf(globalErrorsCount)); //$NON-NLS-1$
430
					}
431
				}
432
				if (globalWarningsCount > 0) {
433
					if (globalWarningsCount == 1) {
434
						warningMessage = Main.bind("compile.oneWarning"); //$NON-NLS-1$
435
					} else {
436
						warningMessage = Main.bind("compile.severalWarnings", String.valueOf(globalWarningsCount)); //$NON-NLS-1$
437
					}
438
				}
439
				if (errorMessage == null || warningMessage == null) {
440
					if (errorMessage == null) {
441
						this.printErr(Main.bind(
442
							"compile.severalProblemsErrorsOrWarnings", //$NON-NLS-1$
443
							String.valueOf(globalProblemsCount),
444
							warningMessage));
445
					} else {
446
						this.printErr(Main.bind(
447
							"compile.severalProblemsErrorsOrWarnings", //$NON-NLS-1$
448
							String.valueOf(globalProblemsCount),
449
							errorMessage));
450
					}
451
				} else {
452
					this.printErr(Main.bind(
453
						"compile.severalProblemsErrorsOrWarnings", //$NON-NLS-1$
454
						new String[] {
455
							String.valueOf(globalProblemsCount),
456
							errorMessage,
457
							warningMessage
458
						}));
459
				}
460
			}
461
		}
462
463
		public int logProblems(IProblem[] problems, char[] unitSource, Main currentMain) {
464
			final int count = problems.length;
465
			int localErrorCount = 0;
466
			if (count != 0) {
467
				if (this.isXml) {
468
					int errors = 0;
469
					int warnings = 0;
470
					int tasks = 0;
471
					for (int i = 0; i < count; i++) {
472
						IProblem problem = problems[i];
473
						if (problem != null) {
474
							currentMain.globalProblemsCount++;
475
							this.logProblem(problem, localErrorCount, currentMain.globalProblemsCount, unitSource);
476
							if (problem.isError()) {
477
								errors++;
478
								currentMain.globalErrorsCount++;
479
								localErrorCount++;
480
							} else {
481
								if (problem.getID() == IProblem.Task) {
482
									tasks++;
483
								} else {
484
									warnings++;
485
								}
486
								currentMain.globalWarningsCount++;
487
							}
488
						}
489
					}
490
					this.startLoggingProblems(errors, warnings);
491
					for (int i = 0; i < count; i++) {
492
						IProblem problem = problems[i];
493
						if (problem!= null) {
494
							if (problem.getID() != IProblem.Task) {
495
								this.logXmlProblem(problem, unitSource);
496
							}
497
						}
498
					}
499
					this.endLoggingProblems();
500
					this.startLoggingTasks(tasks);
501
					for (int i = 0; i < count; i++) {
502
						IProblem problem = problems[i];
503
						if (problem!= null) {
504
							if (problem.getID() == IProblem.Task) {
505
								this.logXmlTask(problem, unitSource);
506
							}
507
						}
508
					}
509
					this.endLoggingTasks();
510
				} else {
511
					for (int i = 0; i < count; i++) {
512
						if (problems[i] != null) {
513
							currentMain.globalProblemsCount++;
514
							this.logProblem(problems[i], localErrorCount, currentMain.globalProblemsCount, unitSource);
515
							if (problems[i].isError()) {
516
								currentMain.globalErrorsCount++;
517
								localErrorCount++;
518
							} else {
519
								currentMain.globalWarningsCount++;
520
							}
521
						}
522
					}
523
				}
86
			}
524
			}
525
			return localErrorCount;
87
		}
526
		}
88
		
527
		
89
		public void printlnErr(String s) {
528
		/**
529
		 * 
530
		 */
531
		public void logProgress() {
532
			this.printOut('.');
533
		}
534
535
		/**
536
		 * @param i
537
		 *            the current repetition number
538
		 * @param repetitions
539
		 *            the given number of repetitions
540
		 */
541
		public void logRepetition(int i, int repetitions) {
542
			this.printlnOut(Main.bind("compile.repetition", //$NON-NLS-1$
543
				String.valueOf(i + 1), String.valueOf(repetitions)));
544
		}
545
546
		public void printStats(Main main) {
547
			final boolean isTimed = main.timing;
548
			if (isXml) {
549
				this.printTag(STATS, null, true, false);
550
			}
551
			if (isTimed) {
552
				long time = System.currentTimeMillis() - main.startTime;
553
				this.logTiming(time, main.lineCount);
554
			}
555
			if (main.globalProblemsCount > 0) {
556
				this.logProblemsSummary(main.globalProblemsCount, main.globalErrorsCount, main.globalWarningsCount);
557
			}
558
			if (main.exportedClassFilesCounter != 0
559
					&& (main.showProgress || isTimed || main.verbose)) {
560
				this.logNumberOfClassFilesGenerated(main.exportedClassFilesCounter);
561
			}
562
			if (isXml) {
563
				this.endTag(STATS);
564
			}
565
		}
566
		/**
567
		 * @param time
568
		 * @param lineCount
569
		 */
570
		public void logTiming(long time, long lineCount) {
571
			if (isXml) {
572
				this.parameters.clear();
573
				this.parameters.put(VALUE, new Long(time));
574
				this.printTag(TIME, this.parameters, true, true);
575
				this.parameters.clear();
576
				this.parameters.put(VALUE, new Long(lineCount));
577
				this.printTag(NUMBER_OF_LINES, this.parameters, true, true);
578
			}
579
			if (lineCount != 0) {
580
				this.printlnOut(Main.bind(
581
					"compile.instantTime", //$NON-NLS-1$
582
					new String[] {
583
						String.valueOf(lineCount),
584
						String.valueOf(time),
585
						String.valueOf(((int) (lineCount * 10000.0 / time)) / 10.0) }));
586
			} else {
587
				this.printlnOut(Main.bind("compile.totalTime", String.valueOf(time))); //$NON-NLS-1$
588
			}
589
		}
590
591
		/**
592
		 * @param usage
593
		 */
594
		public void logUsage(String usage) {
595
			this.printlnOut(usage); //$NON-NLS-1$//$NON-NLS-2$
596
		}
597
598
		/**
599
		 * 
600
		 */
601
		public void logVersion() {
602
			this.printlnOut(Main.bind("misc.version")); //$NON-NLS-1$
603
		}
604
605
		/**
606
		 * 
607
		 */
608
		public void logWrongJDK() {
609
			if (isXml) {
610
				parameters.clear();
611
				parameters.put(MESSAGE, Main.bind("configure.requiresJDK1.2orAbove")); //$NON-NLS-1$//$NON-NLS-2$
612
				this.printTag(ERROR, parameters, true, true);				
613
			}
614
			this.printlnErr(Main.bind("configure.requiresJDK1.2orAbove")); //$NON-NLS-1$
615
		}
616
617
		/**
618
		 * @param problem
619
		 *            the given problem to log
620
		 * @param unitSource
621
		 *            the given unit source
622
		 */
623
		private void logXmlProblem(IProblem problem, char[] unitSource) {
624
			parameters.clear();
625
			parameters.put(PROBLEM_ID, getFieldName(problem.getID()));
626
			parameters.put(PROBLEM_FILE, new String(problem.getOriginatingFileName()));
627
			parameters.put(PROBLEM_SEVERITY, problem.isError() ? ERROR : WARNING);
628
			parameters.put(PROBLEM_LINE, new Integer(problem.getSourceLineNumber()));
629
			parameters.put(PROBLEM_SOURCE_START, new Integer(problem.getSourceStart()));
630
			parameters.put(PROBLEM_SOURCE_END, new Integer(problem.getSourceEnd()));
631
			this.printTag(PROBLEM_TAG, parameters, true, false);
632
			parameters.clear();
633
			parameters.put(VALUE, problem.getMessage());
634
			this.printTag(PROBLEM_MESSAGE, parameters, true, true);
635
			parameters.clear();
636
			parameters.put(VALUE, ((DefaultProblem) problem).reportSource(unitSource));
637
			this.printTag(DETAILED_PROBLEM_MESSAGE, parameters, true, true);
638
			String[] arguments = problem.getArguments();
639
			final int length = arguments.length;
640
			if (length != 0) {
641
				this.printTag(PROBLEM_ARGUMENTS, null, true, false);
642
				parameters.clear();
643
				for (int i = 0; i < length; i++) {
644
					parameters.put(PROBLEM_ARGUMENT_VALUE, arguments[i]);
645
					this.printTag(PROBLEM_ARGUMENT, parameters, true, true);
646
				}
647
				this.endTag(PROBLEM_ARGUMENTS);
648
			}
649
			this.endTag(PROBLEM_TAG);
650
		}
651
		/**
652
		 * @param problem
653
		 *            the given problem to log
654
		 * @param unitSource
655
		 *            the given unit source
656
		 */
657
		private void logXmlTask(IProblem problem, char[] unitSource) {
658
			parameters.clear();
659
			parameters.put(PROBLEM_LINE, new Integer(problem.getSourceLineNumber()));
660
			parameters.put(PROBLEM_SOURCE_START, new Integer(problem.getSourceStart()));
661
			parameters.put(PROBLEM_SOURCE_END, new Integer(problem.getSourceEnd()));
662
			this.printTag(TASK, parameters, true, false);
663
			parameters.clear();
664
			parameters.put(VALUE, problem.getMessage());
665
			this.printTag(PROBLEM_MESSAGE, parameters, true, true);
666
			this.endTag(TASK);
667
		}
668
		private void printErr(String s) {
669
			this.err.print(s);
670
			if (!this.isXml) {
671
				if (this.log != null) {
672
					this.log.print(s);
673
				}
674
			}
675
		}
676
677
		private void printlnErr(String s) {
90
			this.err.println(s);
678
			this.err.println(s);
91
			if (this.log != null) {
679
			if (!this.isXml) {
92
				this.log.println(s);
680
				if (this.log != null) {
681
					this.log.println(s);
682
				}
93
			}
683
			}
94
		}
684
		}
95
		
685
96
		public void printlnOut(String s) {
686
		private void printlnOut(String s) {
97
			this.out.println(s);
687
			this.out.println(s);
98
		}
688
		}
99
		
689
100
		public void printlnOut() {
690
		/**
691
		 * 
692
		 */
693
		public void printNewLine() {
101
			this.out.println();
694
			this.out.println();
102
		}
695
		}
103
		
696
104
		public void printOut(char c) {
697
		private void printOut(char c) {
105
			this.out.print(c);
698
			this.out.print(c);
106
		}
699
		}
700
		public void printTag(String name, HashMap params, boolean insertNewLine, boolean closeTag) {
701
			for (int i= this.tab; i > 0; i--) this.log.print('\t');
702
			StringBuffer buffer= new StringBuffer();
703
			buffer.append("<"); //$NON-NLS-1$
704
			buffer.append(name);
705
			if (params != null) {
706
				for (Enumeration enumeration = Collections.enumeration(params.keySet()); enumeration.hasMoreElements();) {
707
					buffer.append(" "); //$NON-NLS-1$
708
					String key= (String) enumeration.nextElement();
709
					buffer.append(key);
710
					buffer.append("=\""); //$NON-NLS-1$
711
					buffer.append(getEscaped(String.valueOf(params.get(key))));
712
					buffer.append("\""); //$NON-NLS-1$
713
				}
714
			}
715
			if (closeTag) {
716
				buffer.append("/>"); //$NON-NLS-1$
717
			} else {
718
				buffer.append(">"); //$NON-NLS-1$
719
				this.tab++;
720
			}
721
			if (insertNewLine) {
722
				this.log.println(String.valueOf(buffer));
723
			} else {
724
				this.log.print(String.valueOf(buffer));
725
			}
726
		}
727
728
		public void setLog(String logFileName) throws InvalidInputException {
729
			try {
730
				this.log = new PrintWriter(new FileOutputStream(logFileName, false));
731
				int index = logFileName.lastIndexOf('.');
732
				if (index != 0) {
733
					if (logFileName.substring(index).toLowerCase().equals(".xml")) { //$NON-NLS-1$
734
						this.isXml = true;
735
						this.log.println(XML_VERSION);
736
						this.tab = 0;
737
						parameters.clear();
738
						parameters.put(COMPILER_NAME, Main.bind("compiler.name")); //$NON-NLS-1$//$NON-NLS-2$
739
						parameters.put(COMPILER_VERSION, Main.bind("compiler.version")); //$NON-NLS-1$//$NON-NLS-2$
740
						parameters.put(COMPILER_COPYRIGHT, Main.bind("compiler.copyright")); //$NON-NLS-1$//$NON-NLS-2$
741
						this.printTag(COMPILER, parameters, true, false);
742
					}
743
				}
744
			} catch (FileNotFoundException e) {
745
				throw new InvalidInputException(Main.bind("configure.cannotOpenLog")); //$NON-NLS-1$
746
			}
747
		}
748
749
		/**
750
		 * Used to start logging problems.
751
		 * Only use in xml mode.
752
		 */
753
		private void startLoggingProblems(int errors, int warnings) {
754
			parameters.clear();
755
			parameters.put(NUMBER_OF_PROBLEMS, new Integer(errors + warnings));
756
			parameters.put(NUMBER_OF_ERRORS, new Integer(errors));
757
			parameters.put(NUMBER_OF_WARNINGS, new Integer(warnings));
758
			this.printTag(PROBLEMS, this.parameters, true, false);
759
		}
760
		public void startLoggingSource(CompilationResult compilationResult) {
761
			if (this.isXml) {
762
				ICompilationUnit compilationUnit = compilationResult.compilationUnit;
763
				char[] fileName = compilationUnit.getFileName();
764
				if (fileName != null) {
765
					this.parameters.clear();
766
					if (compilationUnit != null) {
767
						this.parameters.put(PATH, new String(fileName));
768
					}
769
				}
770
				this.printTag(SOURCE, this.parameters, true, false);
771
			}
772
		}
773
		public void startLoggingSources() {
774
			if (this.isXml) {
775
				this.printTag(SOURCES, null, true, false);
776
			}
777
		}
778
		public void startLoggingTasks(int tasks) {
779
			if (this.isXml) {
780
				parameters.clear();
781
				parameters.put(NUMBER_OF_TASKS, new Integer(tasks));
782
				this.printTag(TASKS, this.parameters, true, false);
783
			}
784
		}
785
		public void logClassFile(boolean generatePackagesStructure, String outputPath, String relativeFileName) {
786
			if (this.isXml) {
787
				String fileName = null;
788
				if (generatePackagesStructure) {
789
					fileName = buildFileName(outputPath, relativeFileName);
790
				} else {
791
					char fileSeparatorChar = File.separatorChar;
792
					String fileSeparator = File.separator;
793
					// First we ensure that the outputPath exists
794
					outputPath = outputPath.replace('/', fileSeparatorChar);
795
					// To be able to pass the mkdirs() method we need to remove the extra file separator at the end of the outDir name
796
					int indexOfPackageSeparator = relativeFileName.lastIndexOf(fileSeparatorChar);
797
					if (indexOfPackageSeparator == -1) {
798
						if (outputPath.endsWith(fileSeparator)) {
799
							fileName = outputPath + relativeFileName;
800
						} else {
801
							fileName = outputPath + fileSeparator + relativeFileName;
802
						}
803
					} else {
804
						int length = relativeFileName.length();
805
						if (outputPath.endsWith(fileSeparator)) {
806
							fileName = outputPath + relativeFileName.substring(indexOfPackageSeparator + 1, length);
807
						} else {
808
							fileName = outputPath + fileSeparator + relativeFileName.substring(indexOfPackageSeparator + 1, length);
809
						}
810
					}
811
				}
812
				this.parameters.clear();
813
				this.parameters.put(PATH, fileName);
814
				this.printTag(CLASS_FILE, this.parameters, true, true);
815
			}			
816
		}
107
	}
817
	}
108
	static {
818
	static {
109
		relocalize();
819
		relocalize();
Lines 354-361 Link Here
354
//				if (this.verbose) {
1064
//				if (this.verbose) {
355
//					System.out.println(new CompilerOptions(this.options));
1065
//					System.out.println(new CompilerOptions(this.options));
356
//				}
1066
//				}
357
				if (this.showProgress)
1067
				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++) {
1068
				for (int i = 0; i < this.repetitions; i++) {
360
					this.globalProblemsCount = 0;
1069
					this.globalProblemsCount = 0;
361
					this.globalErrorsCount = 0;
1070
					this.globalErrorsCount = 0;
Lines 365-388 Link Here
365
1074
366
					if (this.repetitions > 1) {
1075
					if (this.repetitions > 1) {
367
						this.logger.flush();
1076
						this.logger.flush();
368
						this.logger.printlnOut(
1077
						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
					} 
1078
					} 
374
					// request compilation
1079
					// request compilation
375
					performCompilation();
1080
					performCompilation();
376
				}
1081
				}
377
				if (this.showProgress)
1082
				if (this.showProgress) this.logger.printNewLine();
378
					this.logger.printlnOut();
379
			}
1083
			}
380
			if (this.systemExitWhenFinished) {
1084
			if (this.systemExitWhenFinished) {
381
				this.logger.flush();
1085
				this.logger.flush();
1086
    			this.logger.close();
382
				System.exit(this.globalErrorsCount > 0 ? -1 : 0);
1087
				System.exit(this.globalErrorsCount > 0 ? -1 : 0);
383
			}
1088
			}
384
		} catch (InvalidInputException e) {
1089
		} catch (InvalidInputException e) {
385
			this.logger.printlnErr(e.getMessage());
1090
			this.logger.logExceptionMessage(e.getMessage());
386
			if (this.systemExitWhenFinished) {
1091
			if (this.systemExitWhenFinished) {
387
    			this.logger.flush();
1092
    			this.logger.flush();
388
    			this.logger.close();
1093
    			this.logger.close();
Lines 396-402 Link Here
396
				System.exit(-1);
1101
				System.exit(-1);
397
			}
1102
			}
398
			return false;
1103
			return false;
399
			//e.printStackTrace();
400
		} finally {
1104
		} finally {
401
			this.logger.flush();
1105
			this.logger.flush();
402
			this.logger.close();
1106
			this.logger.close();
Lines 1236-1242 Link Here
1236
			// no user classpath specified.
1940
			// no user classpath specified.
1237
			String classProp = System.getProperty("java.class.path"); //$NON-NLS-1$
1941
			String classProp = System.getProperty("java.class.path"); //$NON-NLS-1$
1238
			if ((classProp == null) || (classProp.length() == 0)) {
1942
			if ((classProp == null) || (classProp.length() == 0)) {
1239
				this.logger.printlnErr(Main.bind("configure.noClasspath")); //$NON-NLS-1$
1943
				this.logger.logNoClasspath(); //$NON-NLS-1$
1240
				classProp = System.getProperty("user.dir"); //$NON-NLS-1$
1944
				classProp = System.getProperty("user.dir"); //$NON-NLS-1$
1241
			}
1945
			}
1242
			StringTokenizer tokenizer = new StringTokenizer(classProp, File.pathSeparator);
1946
			StringTokenizer tokenizer = new StringTokenizer(classProp, File.pathSeparator);
Lines 1254-1260 Link Here
1254
			 */
1958
			 */
1255
			 String javaversion = System.getProperty("java.version");//$NON-NLS-1$
1959
			 String javaversion = System.getProperty("java.version");//$NON-NLS-1$
1256
			 if (javaversion != null && javaversion.equalsIgnoreCase("1.1.8")) { //$NON-NLS-1$
1960
			 if (javaversion != null && javaversion.equalsIgnoreCase("1.1.8")) { //$NON-NLS-1$
1257
				this.logger.printlnErr(Main.bind("configure.requiresJDK1.2orAbove")); //$NON-NLS-1$
1961
				this.logger.logWrongJDK(); //$NON-NLS-1$
1258
				this.proceed = false;
1962
				this.proceed = false;
1259
				return;
1963
				return;
1260
			 }
1964
			 }
Lines 1291-1301 Link Here
1291
		}
1995
		}
1292
1996
1293
		if (this.log != null) {
1997
		if (this.log != null) {
1294
			try {
1998
			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 {
1999
		} else {
1300
			this.showProgress = false;
2000
			this.showProgress = false;
1301
		}
2001
		}
Lines 1331-1337 Link Here
1331
		for (int i = 0, max = this.classpaths.length; i < max; i++) {
2031
		for (int i = 0, max = this.classpaths.length; i < max; i++) {
1332
			File file = new File(this.classpaths[i]);
2032
			File file = new File(this.classpaths[i]);
1333
			if (!file.exists()) { // signal missing classpath entry file
2033
			if (!file.exists()) { // signal missing classpath entry file
1334
				this.logger.printlnErr(Main.bind("configure.incorrectClasspath", this.classpaths[i])); //$NON-NLS-1$
2034
				this.logger.logIncorrectClasspath(this.classpaths[i]); //$NON-NLS-1$
1335
			}
2035
			}
1336
		}
2036
		}
1337
		if (this.destinationPath == null) {
2037
		if (this.destinationPath == null) {
Lines 1343-1366 Link Here
1343
		if (didSpecifyCompliance) {
2043
		if (didSpecifyCompliance) {
1344
			Object version = this.options.get(CompilerOptions.OPTION_Compliance);
2044
			Object version = this.options.get(CompilerOptions.OPTION_Compliance);
1345
			if (CompilerOptions.VERSION_1_3.equals(version)) {
2045
			if (CompilerOptions.VERSION_1_3.equals(version)) {
1346
					if (!didSpecifySource) this.options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_3);
2046
				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);
2047
				if (!didSpecifyTarget) this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_1);
1348
			} else if (CompilerOptions.VERSION_1_4.equals(version)) {
2048
			} else if (CompilerOptions.VERSION_1_4.equals(version)) {
1349
					if (!didSpecifySource) this.options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_3);
2049
				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);
2050
				if (!didSpecifyTarget) this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_2);
1351
			} else if (CompilerOptions.VERSION_1_5.equals(version)) {
2051
			} else if (CompilerOptions.VERSION_1_5.equals(version)) {
1352
					if (!didSpecifySource) this.options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_5);
2052
				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);
2053
				if (!didSpecifyTarget) this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_5);
1354
			}
2054
			}
1355
		}
2055
		}
1356
		if (didSpecifySource) {
2056
		if (didSpecifySource) {
1357
			Object version = this.options.get(CompilerOptions.OPTION_Source);
2057
			Object version = this.options.get(CompilerOptions.OPTION_Source);
1358
			 if (CompilerOptions.VERSION_1_4.equals(version)) {
2058
			 if (CompilerOptions.VERSION_1_4.equals(version)) {
1359
					if (!didSpecifyCompliance) this.options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_4);
2059
				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);
2060
				if (!didSpecifyTarget) this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_4);
1361
			} else if (CompilerOptions.VERSION_1_5.equals(version)) {
2061
			} else if (CompilerOptions.VERSION_1_5.equals(version)) {
1362
					if (!didSpecifyCompliance) this.options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_5);
2062
				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);
2063
				if (!didSpecifyTarget) this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_5);
1364
			}
2064
			}
1365
		}
2065
		}
1366
2066
Lines 1378-1384 Link Here
1378
	   		}
2078
	   		}
1379
			// target cannot be greater than compliance level
2079
			// 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))){ 
2080
			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$
2081
				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
			}
2082
			}
1383
		}
2083
		}
1384
2084
Lines 1412-1418 Link Here
1412
				}
2112
				}
1413
			}
2113
			}
1414
		}
2114
		}
1415
2115
		this.logger.logCommandLineArguments(newCommandLineArgs);
2116
		this.logger.logOptions(this.options);
2117
		this.logger.logClasspath(this.classpaths);
1416
		if (this.repetitions == 0) {
2118
		if (this.repetitions == 0) {
1417
			this.repetitions = 1;
2119
			this.repetitions = 1;
1418
		}
2120
		}
Lines 1456-1512 Link Here
1456
					int unitLineCount = compilationResult.lineSeparatorPositions.length;
2158
					int unitLineCount = compilationResult.lineSeparatorPositions.length;
1457
					Main.this.lineCount += unitLineCount;
2159
					Main.this.lineCount += unitLineCount;
1458
					this.lineDelta += unitLineCount;
2160
					this.lineDelta += unitLineCount;
1459
					if (Main.this.showProgress
2161
					if (Main.this.showProgress && this.lineDelta > 2000) {
1460
						&& this.lineDelta > 2000) { // in -log mode, dump a dot every 2000 lines compiled
2162
						// in -log mode, dump a dot every 2000 lines compiled
1461
						Main.this.logger.printOut('.');
2163
						Main.this.logger.logProgress();
1462
						this.lineDelta = 0;
2164
						this.lineDelta = 0;
1463
					}
2165
					}
1464
				}
2166
				}
2167
				Main.this.logger.startLoggingSource(compilationResult);
1465
				if (compilationResult.hasProblems() || compilationResult.hasTasks()) {
2168
				if (compilationResult.hasProblems() || compilationResult.hasTasks()) {
1466
					IProblem[] problems = compilationResult.getAllProblems();
2169
					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?
2170
					// exit?
1503
					if (Main.this.systemExitWhenFinished && !Main.this.proceedOnError && (localErrorCount > 0)) {
2171
					if (Main.this.systemExitWhenFinished && !Main.this.proceedOnError && (localErrorCount > 0)) {
1504
						Main.this.printStats();
2172
						Main.this.logger.endLoggingSource();
2173
						Main.this.logger.printStats(Main.this);
1505
						Main.this.logger.flush();
2174
						Main.this.logger.flush();
1506
						System.exit(-1);
2175
						System.exit(-1);
1507
					}
2176
					}
1508
				}
2177
				}
1509
				outputClassFiles(compilationResult);
2178
				outputClassFiles(compilationResult);
2179
				Main.this.logger.endLoggingSource();
1510
			}
2180
			}
1511
		};
2181
		};
1512
	}
2182
	}
Lines 1603-1614 Link Here
1603
	// Dump classfiles onto disk for all compilation units that where successfull.
2273
	// Dump classfiles onto disk for all compilation units that where successfull.
1604
2274
1605
	public void outputClassFiles(CompilationResult unitResult) {
2275
	public void outputClassFiles(CompilationResult unitResult) {
1606
1607
		if (!((unitResult == null) || (unitResult.hasErrors() && !this.proceedOnError))) {
2276
		if (!((unitResult == null) || (unitResult.hasErrors() && !this.proceedOnError))) {
1608
			Enumeration classFiles = unitResult.compiledTypes.elements();
2277
			Enumeration classFiles = unitResult.compiledTypes.elements();
1609
			if (!this.generatePackagesStructure) {
2278
			if (!this.generatePackagesStructure) {
2279
				this.destinationPath = extractDestinationPathFromSourceFile(unitResult);
2280
			}
2281
			if (this.destinationPath != null) {
1610
				while (classFiles.hasMoreElements()) {
2282
				while (classFiles.hasMoreElements()) {
1611
					this.destinationPath = extractDestinationPathFromSourceFile(unitResult);
1612
					// retrieve the key and the corresponding classfile
2283
					// retrieve the key and the corresponding classfile
1613
					ClassFile classFile = (ClassFile) classFiles.nextElement();
2284
					ClassFile classFile = (ClassFile) classFiles.nextElement();
1614
					char[] filename = classFile.fileName();
2285
					char[] filename = classFile.fileName();
Lines 1622-1656 Link Here
1622
							System.out.println(Util.bind("compilation.write", //$NON-NLS-1$
2293
							System.out.println(Util.bind("compilation.write", //$NON-NLS-1$
1623
								new String[] {
2294
								new String[] {
1624
									String.valueOf(this.exportedClassFilesCounter+1),
2295
									String.valueOf(this.exportedClassFilesCounter+1),
1625
									new String(relativeName) }));					    
2296
									new String(relativeName)
1626
						ClassFile.writeToDisk(
2297
								}));
2298
						this.logger.logClassFile(
1627
							this.generatePackagesStructure,
2299
							this.generatePackagesStructure,
1628
							this.destinationPath,
2300
							this.destinationPath,
1629
							new String(relativeName),
2301
							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(
2302
						ClassFile.writeToDisk(
1655
							this.generatePackagesStructure,
2303
							this.generatePackagesStructure,
1656
							this.destinationPath,
2304
							this.destinationPath,
Lines 1659-1665 Link Here
1659
					} catch (IOException e) {
2307
					} catch (IOException e) {
1660
						String fileName = this.destinationPath + new String(relativeName);
2308
						String fileName = this.destinationPath + new String(relativeName);
1661
						e.printStackTrace();
2309
						e.printStackTrace();
1662
						this.logger.printlnErr(Main.bind("output.noClassFileCreated", fileName)); //$NON-NLS-1$
2310
						this.logger.logNoClassFileCreated(fileName); //$NON-NLS-1$
1663
					}
2311
					}
1664
					this.exportedClassFilesCounter++;
2312
					this.exportedClassFilesCounter++;
1665
				}
2313
				}
Lines 1686-1762 Link Here
1686
		// set the non-externally configurable options.
2334
		// set the non-externally configurable options.
1687
		this.compilerOptions.verbose = this.verbose;
2335
		this.compilerOptions.verbose = this.verbose;
1688
		this.compilerOptions.produceReferenceInfo = this.produceRefInfo;
2336
		this.compilerOptions.produceReferenceInfo = this.produceRefInfo;
1689
		batchCompiler.compile(getCompilationUnits());
2337
		try {
2338
			this.logger.startLoggingSources();
2339
			batchCompiler.compile(getCompilationUnits());
2340
		} finally {
2341
			this.logger.endLoggingSources();
2342
		}
1690
2343
1691
		printStats();
2344
		this.logger.printStats(this);
1692
		
2345
		
1693
		// cleanup
2346
		// cleanup
1694
		environment.cleanup();
2347
		environment.cleanup();
1695
	}
2348
	}
1696
	
2349
	
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() {
2350
	public void printUsage() {
1755
		this.logger.printlnOut(Main.bind("misc.usage", System.getProperty("path.separator"))); //$NON-NLS-1$//$NON-NLS-2$
2351
		this.logger.logUsage(Main.bind("misc.usage", System.getProperty("path.separator"))); //$NON-NLS-1$//$NON-NLS-2$
1756
		this.logger.flush();
2352
		this.logger.flush();
1757
	}
2353
	}
1758
	public void printVersion() {
2354
	public void printVersion() {
1759
		this.logger.printlnOut(Main.bind("misc.version"));  //$NON-NLS-1$
2355
		this.logger.logVersion();  //$NON-NLS-1$
1760
		this.logger.flush();
2356
		this.logger.flush();
1761
	}
2357
	}
1762
}
2358
}
(-)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
(-)compiler/org/eclipse/jdt/internal/compiler/problem/DefaultProblem.java (+49 lines)
Lines 177-182 Link Here
177
		return (this.severity & ProblemSeverities.Error) == 0;
177
		return (this.severity & ProblemSeverities.Error) == 0;
178
	}
178
	}
179
179
180
	public String reportSource(char[] unitSource) {
181
		//extra from the source the innacurate     token
182
		//and "highlight" it using some underneath ^^^^^
183
		//put some context around too.
184
185
		//this code assumes that the font used in the console is fixed size
186
187
		//sanity .....
188
		if ((this.startPosition > this.endPosition)
189
			|| ((this.startPosition < 0) && (this.endPosition < 0)))
190
			return Util.bind("problem.noSourceInformation"); //$NON-NLS-1$
191
192
		StringBuffer errorBuffer = new StringBuffer(); //$NON-NLS-1$
193
		char c;
194
		final char SPACE = '\u0020';
195
		final char MARK = '^';
196
		final char TAB = '\t';
197
		//the next code tries to underline the token.....
198
		//it assumes (for a good display) that token source does not
199
		//contain any \r \n. This is false on statements ! 
200
		//(the code still works but the display is not optimal !)
201
202
		// expand to line limits
203
		int length = unitSource.length, begin, end;
204
		for (begin = this.startPosition >= length ? length - 1 : this.startPosition; begin > 0; begin--) {
205
			if ((c = unitSource[begin - 1]) == '\n' || c == '\r') break;
206
		}
207
		for (end = this.endPosition >= length ? length - 1 : this.endPosition ; end+1 < length; end++) {
208
			if ((c = unitSource[end + 1]) == '\r' || c == '\n') break;
209
		}
210
		
211
		// trim left and right spaces/tabs
212
		while ((c = unitSource[begin]) == ' ' || c == '\t') begin++;
213
		while ((c = unitSource[end]) == ' ' || c == '\t') end--;
214
		
215
		// copy source
216
		errorBuffer.append(unitSource, begin, end-begin+1);
217
		errorBuffer.append(LINE_DELIMITER); //$NON-NLS-1$
218
219
		// compute underline
220
		for (int i = begin; i <this.startPosition; i++) {
221
			errorBuffer.append((unitSource[i] == TAB) ? TAB : SPACE);
222
		}
223
		for (int i = this.startPosition; i <= (this.endPosition >= length ? length - 1 : this.endPosition); i++) {
224
			errorBuffer.append(MARK);
225
		}
226
		return errorBuffer.toString();
227
	}
228
180
	public void setOriginatingFileName(char[] fileName) {
229
	public void setOriginatingFileName(char[] fileName) {
181
		this.fileName = fileName;
230
		this.fileName = fileName;
182
	}
231
	}

Return to bug 74394