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 = |
110 |
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + //$NON-NLS-1$ |
111 |
"<!DOCTYPE compiler [\n" + //$NON-NLS-1$ |
112 |
" <!ELEMENT command_line (argument*)>\n" + //$NON-NLS-1$ |
113 |
" <!ELEMENT options (option*)>\n" + //$NON-NLS-1$ |
114 |
" <!ELEMENT classpaths (classpath+)>\n" + //$NON-NLS-1$ |
115 |
" <!ELEMENT error (#PCDATA)>\n" + //$NON-NLS-1$ |
116 |
" <!ELEMENT sources (source+)>\n" + //$NON-NLS-1$ |
117 |
" <!ELEMENT source (problems*,tasks*,exception*,classfile*,error*)>\n" + //$NON-NLS-1$ |
118 |
" <!ELEMENT problems (problem+)>\n" + //$NON-NLS-1$ |
119 |
" <!ELEMENT problem (message,problem_source,arguments)>\n" + //$NON-NLS-1$ |
120 |
" <!ELEMENT arguments (argument+)>\n" + //$NON-NLS-1$ |
121 |
" <!ELEMENT tasks (task+)>\n" + //$NON-NLS-1$ |
122 |
" <!ELEMENT task (message)>\n" + //$NON-NLS-1$ |
123 |
" <!ELEMENT stats (time?,number_of_lines?,problem_summary?,number_of_classfiles?)>\n" + //$NON-NLS-1$ |
124 |
" <!ELEMENT argument (#PCDATA)>\n" + //$NON-NLS-1$ |
125 |
" <!ELEMENT option (#PCDATA)>\n" + //$NON-NLS-1$ |
126 |
" <!ELEMENT classpath (#PCDATA)>\n" + //$NON-NLS-1$ |
127 |
" <!ELEMENT message (#PCDATA)>\n" + //$NON-NLS-1$ |
128 |
" <!ELEMENT number_of_lines (#PCDATA)>\n" + //$NON-NLS-1$ |
129 |
" <!ELEMENT time (#PCDATA)>\n" + //$NON-NLS-1$ |
130 |
" <!ELEMENT number_of_classfiles (#PCDATA)>\n" + //$NON-NLS-1$ |
131 |
" <!ELEMENT classfile (#PCDATA)>\n" + //$NON-NLS-1$ |
132 |
" <!ELEMENT problem_source (#PCDATA)>\n" + //$NON-NLS-1$ |
133 |
" <!ELEMENT problem_summary (#PCDATA)>\n" + //$NON-NLS-1$ |
134 |
" <!ATTLIST argument value CDATA #REQUIRED>\n" + //$NON-NLS-1$ |
135 |
" <!ATTLIST option key CDATA #REQUIRED\n" + //$NON-NLS-1$ |
136 |
" value CDATA #REQUIRED\n" + //$NON-NLS-1$ |
137 |
" >\n" + //$NON-NLS-1$ |
138 |
" <!ATTLIST classpath path CDATA #REQUIRED\n" + //$NON-NLS-1$ |
139 |
" id CDATA #REQUIRED\n" + //$NON-NLS-1$ |
140 |
" >\n" + //$NON-NLS-1$ |
141 |
" <!ATTLIST source path CDATA #REQUIRED>\n" + //$NON-NLS-1$ |
142 |
" <!ATTLIST problems problems CDATA #REQUIRED\n" + //$NON-NLS-1$ |
143 |
" errors CDATA #REQUIRED\n" + //$NON-NLS-1$ |
144 |
" warnings CDATA #REQUIRED\n" + //$NON-NLS-1$ |
145 |
" >\n" + //$NON-NLS-1$ |
146 |
" <!ATTLIST tasks tasks CDATA #REQUIRED>\n" + //$NON-NLS-1$ |
147 |
" <!ATTLIST problem charEnd CDATA #REQUIRED\n" + //$NON-NLS-1$ |
148 |
" charStart CDATA #REQUIRED\n" + //$NON-NLS-1$ |
149 |
" severity CDATA #REQUIRED\n" + //$NON-NLS-1$ |
150 |
" line CDATA #REQUIRED\n" + //$NON-NLS-1$ |
151 |
" id CDATA #REQUIRED\n" + //$NON-NLS-1$ |
152 |
" >\n" + //$NON-NLS-1$ |
153 |
" <!ATTLIST message value CDATA #REQUIRED>\n" + //$NON-NLS-1$ |
154 |
" <!ATTLIST problem_source value CDATA #REQUIRED>\n" + //$NON-NLS-1$ |
155 |
" <!ATTLIST task charEnd CDATA #REQUIRED\n" + //$NON-NLS-1$ |
156 |
" charStart CDATA #REQUIRED\n" + //$NON-NLS-1$ |
157 |
" line CDATA #REQUIRED\n" + //$NON-NLS-1$ |
158 |
" >\n" + //$NON-NLS-1$ |
159 |
" <!ATTLIST classfile path CDATA #REQUIRED>\n" + //$NON-NLS-1$ |
160 |
" <!ATTLIST error message CDATA #REQUIRED>\n" + //$NON-NLS-1$ |
161 |
" <!ATTLIST problem_summary problems CDATA #REQUIRED\n" + //$NON-NLS-1$ |
162 |
" errors CDATA #REQUIRED\n" + //$NON-NLS-1$ |
163 |
" warnings CDATA #REQUIRED\n" + //$NON-NLS-1$ |
164 |
" >\n" + //$NON-NLS-1$ |
165 |
" <!ATTLIST number_of_classfiles value CDATA #REQUIRED>\n" + //$NON-NLS-1$ |
166 |
" <!ATTLIST time value CDATA #REQUIRED>\n" + //$NON-NLS-1$ |
167 |
" <!ATTLIST number_of_lines value CDATA #REQUIRED>\n" + //$NON-NLS-1$ |
168 |
" <!ATTLIST compiler name CDATA #REQUIRED\n" + //$NON-NLS-1$ |
169 |
" copyright CDATA #REQUIRED\n" + //$NON-NLS-1$ |
170 |
" version CDATA #REQUIRED\n" + //$NON-NLS-1$ |
171 |
" > \n" + //$NON-NLS-1$ |
172 |
" <!ELEMENT compiler (command_line,options,classpaths,error*,sources,stats?)>\n" + //$NON-NLS-1$ |
173 |
"]>"; //$NON-NLS-1$ |
174 |
|
175 |
private static final HashMap FIELD_TABLE = new HashMap(); |
176 |
static { |
177 |
try { |
178 |
Class c = IProblem.class; |
179 |
Field[] fields = c.getFields(); |
180 |
for (int i = 0, max = fields.length; i < max; i++) { |
181 |
Field field = fields[i]; |
182 |
FIELD_TABLE.put(field.get(null), field.getName()); |
183 |
} |
184 |
} catch (SecurityException e) { |
185 |
e.printStackTrace(); |
186 |
} catch (IllegalArgumentException e) { |
187 |
e.printStackTrace(); |
188 |
} catch (IllegalAccessException e) { |
189 |
e.printStackTrace(); |
190 |
} |
191 |
} |
192 |
private static void appendEscapedChar(StringBuffer buffer, char c) { |
193 |
String replacement= getReplacement(c); |
194 |
if (replacement != null) { |
195 |
buffer.append('&'); |
196 |
buffer.append(replacement); |
197 |
buffer.append(';'); |
198 |
} else { |
199 |
buffer.append(c); |
200 |
} |
201 |
} |
202 |
private static String getEscaped(String s) { |
203 |
StringBuffer result= new StringBuffer(s.length() + 10); |
204 |
for (int i= 0; i < s.length(); ++i) |
205 |
appendEscapedChar(result, s.charAt(i)); |
206 |
return result.toString(); |
207 |
} |
208 |
private static String getReplacement(char c) { |
209 |
// Encode special XML characters into the equivalent character references. |
210 |
// These five are defined by default for all XML documents. |
211 |
switch (c) { |
212 |
case '<' : |
213 |
return "lt"; //$NON-NLS-1$ |
214 |
case '>' : |
215 |
return "gt"; //$NON-NLS-1$ |
216 |
case '"' : |
217 |
return "quot"; //$NON-NLS-1$ |
218 |
case '\'' : |
219 |
return "apos"; //$NON-NLS-1$ |
220 |
case '&' : |
221 |
return "amp"; //$NON-NLS-1$ |
222 |
} |
223 |
return null; |
224 |
} |
225 |
private PrintWriter err; |
226 |
boolean isXml; |
227 |
private PrintWriter log; |
228 |
private PrintWriter out; |
229 |
private int tab; |
230 |
private HashMap parameters; |
231 |
|
59 |
public Logger(PrintWriter out, PrintWriter err) { |
232 |
public Logger(PrintWriter out, PrintWriter err) { |
60 |
this.out = out; |
233 |
this.out = out; |
61 |
this.err = err; |
234 |
this.err = err; |
|
|
235 |
this.isXml = false; |
236 |
this.parameters = new HashMap(); |
62 |
} |
237 |
} |
63 |
|
238 |
|
64 |
public void setLog(PrintWriter log) { |
239 |
public String buildFileName( |
65 |
this.log = log; |
240 |
String outputPath, |
|
|
241 |
String relativeFileName) { |
242 |
char fileSeparatorChar = File.separatorChar; |
243 |
String fileSeparator = File.separator; |
244 |
|
245 |
outputPath = outputPath.replace('/', fileSeparatorChar); |
246 |
// To be able to pass the mkdirs() method we need to remove the extra file separator at the end of the outDir name |
247 |
StringBuffer outDir = new StringBuffer(outputPath); |
248 |
if (!outputPath.endsWith(fileSeparator)) { |
249 |
outDir.append(fileSeparator); |
250 |
} |
251 |
StringTokenizer tokenizer = |
252 |
new StringTokenizer(relativeFileName, fileSeparator); |
253 |
String token = tokenizer.nextToken(); |
254 |
while (tokenizer.hasMoreTokens()) { |
255 |
outDir.append(token).append(fileSeparator); |
256 |
token = tokenizer.nextToken(); |
257 |
} |
258 |
// token contains the last one |
259 |
return outDir.append(token).toString(); |
66 |
} |
260 |
} |
67 |
|
261 |
|
68 |
public void close() { |
262 |
public void close() { |
69 |
if (this.log != null) { |
263 |
if (this.log != null) { |
|
|
264 |
if (this.isXml) { |
265 |
this.endTag(COMPILER); |
266 |
this.flush(); |
267 |
} |
70 |
this.log.close(); |
268 |
this.log.close(); |
71 |
} |
269 |
} |
72 |
} |
270 |
} |
|
|
271 |
|
272 |
/** |
273 |
* |
274 |
*/ |
275 |
public void compiling() { |
276 |
this.printlnOut(Main.bind("progress.compiling")); //$NON-NLS-1$ |
277 |
} |
73 |
|
278 |
|
|
|
279 |
/** |
280 |
* Used to stop logging problems. |
281 |
* Only use in xml mode. |
282 |
*/ |
283 |
private void endLoggingProblems() { |
284 |
this.endTag(PROBLEMS); |
285 |
} |
286 |
public void endLoggingSource() { |
287 |
if (this.isXml) { |
288 |
this.endTag(SOURCE); |
289 |
} |
290 |
} |
291 |
public void endLoggingSources() { |
292 |
if (this.isXml) { |
293 |
this.endTag(SOURCES); |
294 |
} |
295 |
} |
296 |
public void endLoggingTasks() { |
297 |
if (this.isXml) { |
298 |
this.endTag(TASKS); |
299 |
} |
300 |
} |
301 |
public void endTag(String name) { |
302 |
tab--; |
303 |
this.printTag('/' + name, null, true, false); |
304 |
this.tab--; |
305 |
} |
306 |
|
307 |
private String getFieldName(int id) { |
308 |
return (String) FIELD_TABLE.get(new Integer(id)); |
309 |
} |
310 |
|
74 |
public void flush() { |
311 |
public void flush() { |
75 |
this.out.flush(); |
312 |
this.out.flush(); |
76 |
this.err.flush(); |
313 |
this.err.flush(); |
Lines 78-109
Link Here
|
78 |
this.log.flush(); |
315 |
this.log.flush(); |
79 |
} |
316 |
} |
80 |
} |
317 |
} |
|
|
318 |
public void logClasspath(String[] classpaths) { |
319 |
if (classpaths == null) return; |
320 |
if (this.isXml) { |
321 |
final int length = classpaths.length; |
322 |
if (length != 0) { |
323 |
// generate xml output |
324 |
this.printTag(CLASSPATHS, null, true, false); |
325 |
for (int i = 0; i < length; i++) { |
326 |
this.parameters.clear(); |
327 |
String classpath = classpaths[i]; |
328 |
parameters.put(PATH, classpath); |
329 |
File f = new File(classpath); |
330 |
String id = null; |
331 |
if (f.isFile()) { |
332 |
if (Util.isArchiveFileName(classpath)) { |
333 |
id = CLASSPATH_JAR; |
334 |
} else { |
335 |
id = CLASSPATH_FILE; |
336 |
} |
337 |
} else if (f.isDirectory()) { |
338 |
id = CLASSPATH_FOLDER; |
339 |
} |
340 |
parameters.put(CLASSPATH_ID, id); |
341 |
this.printTag(CLASSPATH, parameters, true, true); |
342 |
} |
343 |
this.endTag(CLASSPATHS); |
344 |
} |
345 |
} |
346 |
|
347 |
} |
348 |
|
349 |
public void logCommandLineArguments(String[] commandLineArguments) { |
350 |
if (commandLineArguments == null) return; |
351 |
if (this.isXml) { |
352 |
final int length = commandLineArguments.length; |
353 |
if (length != 0) { |
354 |
// generate xml output |
355 |
this.printTag(COMMAND_LINE_ARGUMENTS, null, true, false); |
356 |
parameters.clear(); |
357 |
for (int i = 0; i < length; i++) { |
358 |
parameters.put(VALUE, commandLineArguments[i]); |
359 |
this.printTag(COMMAND_LINE_ARGUMENT, parameters, true, true); |
360 |
} |
361 |
this.endTag(COMMAND_LINE_ARGUMENTS); |
362 |
} |
363 |
} |
364 |
} |
365 |
|
366 |
/** |
367 |
* @param e the given exception to log |
368 |
*/ |
369 |
public void logException(Exception e) { |
370 |
final String message = e.getMessage(); |
371 |
if (isXml) { |
372 |
parameters.clear(); |
373 |
parameters.put(MESSAGE, message); |
374 |
parameters.put(CLASS, e.getClass()); |
375 |
this.printTag(EXCEPTION, parameters, true, true); |
376 |
} |
377 |
this.printlnErr(message); |
378 |
} |
379 |
|
380 |
/** |
381 |
* @param wrongClasspath |
382 |
* the given wrong classpath entry |
383 |
*/ |
384 |
public void logIncorrectClasspath(String wrongClasspath) { |
385 |
if (isXml) { |
386 |
parameters.clear(); |
387 |
parameters.put(MESSAGE, wrongClasspath); |
388 |
this.printTag(ERROR_TAG, parameters, true, true); |
389 |
} |
390 |
this.printlnErr(Main.bind( |
391 |
"configure.incorrectClasspath", wrongClasspath)); //$NON-NLS-1$ |
392 |
} |
393 |
|
394 |
/** |
395 |
* |
396 |
*/ |
397 |
public void logNoClassFileCreated(String fileName) { |
398 |
if (isXml) { |
399 |
parameters.clear(); |
400 |
parameters.put(MESSAGE, Main.bind("output.noClassFileCreated", fileName)); //$NON-NLS-1$ |
401 |
this.printTag(ERROR_TAG, null, true, true); |
402 |
} |
403 |
this.printlnErr(Main.bind("output.noClassFileCreated", fileName)); //$NON-NLS-1$ |
404 |
} |
405 |
|
406 |
public void logNoClasspath() { |
407 |
if (isXml) { |
408 |
parameters.clear(); |
409 |
parameters.put(MESSAGE, Main.bind("configure.noClasspath")); //$NON-NLS-1$//$NON-NLS-2$ |
410 |
this.printTag(ERROR_TAG, parameters, true, true); |
411 |
} |
412 |
this.printlnErr(Main.bind("configure.noClasspath")); //$NON-NLS-1$ |
413 |
} |
414 |
|
415 |
/** |
416 |
* @param exportedClassFilesCounter |
417 |
*/ |
418 |
public void logNumberOfClassFilesGenerated(int exportedClassFilesCounter) { |
419 |
if (isXml) { |
420 |
parameters.clear(); |
421 |
parameters.put(VALUE, new Integer(exportedClassFilesCounter)); //$NON-NLS-1$ |
422 |
this.printTag(NUMBER_OF_CLASSFILES, parameters, true, true); |
423 |
} |
424 |
if (exportedClassFilesCounter == 1) { |
425 |
this.printlnOut(Main.bind("compile.oneClassFileGenerated")); //$NON-NLS-1$ |
426 |
} else { |
427 |
this.printlnOut(Main.bind("compile.severalClassFilesGenerated", //$NON-NLS-1$ |
428 |
String.valueOf(exportedClassFilesCounter))); |
429 |
} |
430 |
} |
431 |
|
432 |
/** |
433 |
* @param options the given compiler options |
434 |
*/ |
435 |
public void logOptions(Map options) { |
436 |
if (this.isXml) { |
437 |
this.printTag(OPTIONS, null, true, false); |
438 |
final Set keySet = options.keySet(); |
439 |
Object[] keys = keySet.toArray(); |
440 |
Arrays.sort(keys); |
441 |
for (int i = 0, max = keys.length; i < max; i++) { |
442 |
this.parameters.clear(); |
443 |
Object key = keys[i]; |
444 |
this.parameters.put(KEY, key); |
445 |
this.parameters.put(VALUE, options.get(key)); |
446 |
this.printTag(OPTION, this.parameters, true, true); |
447 |
} |
448 |
this.endTag(OPTIONS); |
449 |
} |
450 |
} |
451 |
|
452 |
private void logProblem(IProblem problem, int localErrorCount, |
453 |
int globalErrorCount, char[] unitSource) { |
454 |
if (localErrorCount == 0) { |
455 |
this.printlnErr("----------"); //$NON-NLS-1$ |
456 |
} |
457 |
this.printlnErr(problem.isError() ? |
458 |
Main.bind( |
459 |
"requestor.error", //$NON-NLS-1$ |
460 |
Integer.toString(globalErrorCount), |
461 |
new String(problem.getOriginatingFileName())) |
462 |
: Main.bind( |
463 |
"requestor.warning", //$NON-NLS-1$ |
464 |
Integer.toString(globalErrorCount), |
465 |
new String(problem.getOriginatingFileName()))); |
466 |
try { |
467 |
this.printlnErr(((DefaultProblem) problem).errorReportSource(unitSource)); |
468 |
this.printlnErr(problem.getMessage()); |
469 |
} catch (Exception e) { |
470 |
this.printlnErr(Main.bind( |
471 |
"requestor.notRetrieveErrorMessage", problem.toString())); //$NON-NLS-1$ |
472 |
} |
473 |
this.printlnErr("----------"); //$NON-NLS-1$ |
474 |
} |
81 |
|
475 |
|
82 |
public void printErr(String s) { |
476 |
/** |
83 |
this.err.print(s); |
477 |
* @param globalProblemsCount |
84 |
if (this.log != null) { |
478 |
* @param globalErrorsCount |
85 |
this.log.print(s); |
479 |
* @param globalWarningsCount |
|
|
480 |
*/ |
481 |
public void logProblemsSummary(int globalProblemsCount, |
482 |
int globalErrorsCount, int globalWarningsCount) { |
483 |
if (this.isXml) { |
484 |
// generate xml |
485 |
parameters.clear(); |
486 |
parameters.put(NUMBER_OF_PROBLEMS, new Integer(globalProblemsCount)); |
487 |
parameters.put(NUMBER_OF_ERRORS, new Integer(globalErrorsCount)); |
488 |
parameters.put(NUMBER_OF_WARNINGS, new Integer(globalWarningsCount)); |
489 |
this.printTag(PROBLEM_SUMMARY, parameters, true, true); |
490 |
} |
491 |
if (globalProblemsCount == 1) { |
492 |
this.printErr(Main.bind("compile.oneProblem")); //$NON-NLS-1$ |
493 |
} else { |
494 |
String errorMessage = null; |
495 |
String warningMessage = null; |
496 |
if (globalErrorsCount > 0) { |
497 |
if (globalErrorsCount == 1) { |
498 |
errorMessage = Main.bind("compile.oneError"); //$NON-NLS-1$ |
499 |
} else { |
500 |
errorMessage = Main.bind("compile.severalErrors", String.valueOf(globalErrorsCount)); //$NON-NLS-1$ |
501 |
} |
502 |
} |
503 |
if (globalWarningsCount > 0) { |
504 |
if (globalWarningsCount == 1) { |
505 |
warningMessage = Main.bind("compile.oneWarning"); //$NON-NLS-1$ |
506 |
} else { |
507 |
warningMessage = Main.bind("compile.severalWarnings", String.valueOf(globalWarningsCount)); //$NON-NLS-1$ |
508 |
} |
509 |
} |
510 |
if (errorMessage == null || warningMessage == null) { |
511 |
if (errorMessage == null) { |
512 |
this.printErr(Main.bind( |
513 |
"compile.severalProblemsErrorsOrWarnings", //$NON-NLS-1$ |
514 |
String.valueOf(globalProblemsCount), |
515 |
warningMessage)); |
516 |
} else { |
517 |
this.printErr(Main.bind( |
518 |
"compile.severalProblemsErrorsOrWarnings", //$NON-NLS-1$ |
519 |
String.valueOf(globalProblemsCount), |
520 |
errorMessage)); |
521 |
} |
522 |
} else { |
523 |
this.printErr(Main.bind( |
524 |
"compile.severalProblemsErrorsOrWarnings", //$NON-NLS-1$ |
525 |
new String[] { |
526 |
String.valueOf(globalProblemsCount), |
527 |
errorMessage, |
528 |
warningMessage |
529 |
})); |
530 |
} |
86 |
} |
531 |
} |
87 |
} |
532 |
} |
|
|
533 |
|
534 |
public int logProblems(IProblem[] problems, char[] unitSource, Main currentMain) { |
535 |
final int count = problems.length; |
536 |
int localErrorCount = 0; |
537 |
if (count != 0) { |
538 |
if (this.isXml) { |
539 |
int errors = 0; |
540 |
int warnings = 0; |
541 |
int tasks = 0; |
542 |
for (int i = 0; i < count; i++) { |
543 |
IProblem problem = problems[i]; |
544 |
if (problem != null) { |
545 |
currentMain.globalProblemsCount++; |
546 |
this.logProblem(problem, localErrorCount, currentMain.globalProblemsCount, unitSource); |
547 |
if (problem.isError()) { |
548 |
errors++; |
549 |
currentMain.globalErrorsCount++; |
550 |
localErrorCount++; |
551 |
} else { |
552 |
if (problem.getID() == IProblem.Task) { |
553 |
tasks++; |
554 |
} else { |
555 |
warnings++; |
556 |
} |
557 |
currentMain.globalWarningsCount++; |
558 |
} |
559 |
} |
560 |
} |
561 |
if ((errors + warnings) != 0) { |
562 |
this.startLoggingProblems(errors, warnings); |
563 |
for (int i = 0; i < count; i++) { |
564 |
IProblem problem = problems[i]; |
565 |
if (problem!= null) { |
566 |
if (problem.getID() != IProblem.Task) { |
567 |
this.logXmlProblem(problem, unitSource); |
568 |
} |
569 |
} |
570 |
} |
571 |
this.endLoggingProblems(); |
572 |
} |
573 |
if (tasks != 0) { |
574 |
this.startLoggingTasks(tasks); |
575 |
for (int i = 0; i < count; i++) { |
576 |
IProblem problem = problems[i]; |
577 |
if (problem!= null) { |
578 |
if (problem.getID() == IProblem.Task) { |
579 |
this.logXmlTask(problem, unitSource); |
580 |
} |
581 |
} |
582 |
} |
583 |
this.endLoggingTasks(); |
584 |
} |
585 |
} else { |
586 |
for (int i = 0; i < count; i++) { |
587 |
if (problems[i] != null) { |
588 |
currentMain.globalProblemsCount++; |
589 |
this.logProblem(problems[i], localErrorCount, currentMain.globalProblemsCount, unitSource); |
590 |
if (problems[i].isError()) { |
591 |
currentMain.globalErrorsCount++; |
592 |
localErrorCount++; |
593 |
} else { |
594 |
currentMain.globalWarningsCount++; |
595 |
} |
596 |
} |
597 |
} |
598 |
} |
599 |
} |
600 |
return localErrorCount; |
601 |
} |
88 |
|
602 |
|
89 |
public void printlnErr(String s) { |
603 |
/** |
|
|
604 |
* |
605 |
*/ |
606 |
public void logProgress() { |
607 |
this.printOut('.'); |
608 |
} |
609 |
|
610 |
/** |
611 |
* @param i |
612 |
* the current repetition number |
613 |
* @param repetitions |
614 |
* the given number of repetitions |
615 |
*/ |
616 |
public void logRepetition(int i, int repetitions) { |
617 |
this.printlnOut(Main.bind("compile.repetition", //$NON-NLS-1$ |
618 |
String.valueOf(i + 1), String.valueOf(repetitions))); |
619 |
} |
620 |
|
621 |
public void printStats(Main main) { |
622 |
final boolean isTimed = main.timing; |
623 |
if (isXml) { |
624 |
this.printTag(STATS, null, true, false); |
625 |
} |
626 |
if (isTimed) { |
627 |
long time = System.currentTimeMillis() - main.startTime; |
628 |
this.logTiming(time, main.lineCount); |
629 |
} |
630 |
if (main.globalProblemsCount > 0) { |
631 |
this.logProblemsSummary(main.globalProblemsCount, main.globalErrorsCount, main.globalWarningsCount); |
632 |
} |
633 |
if (main.exportedClassFilesCounter != 0 |
634 |
&& (main.showProgress || isTimed || main.verbose)) { |
635 |
this.logNumberOfClassFilesGenerated(main.exportedClassFilesCounter); |
636 |
} |
637 |
if (isXml) { |
638 |
this.endTag(STATS); |
639 |
} |
640 |
} |
641 |
/** |
642 |
* @param time |
643 |
* @param lineCount |
644 |
*/ |
645 |
public void logTiming(long time, long lineCount) { |
646 |
if (isXml) { |
647 |
this.parameters.clear(); |
648 |
this.parameters.put(VALUE, new Long(time)); |
649 |
this.printTag(TIME, this.parameters, true, true); |
650 |
this.parameters.clear(); |
651 |
this.parameters.put(VALUE, new Long(lineCount)); |
652 |
this.printTag(NUMBER_OF_LINES, this.parameters, true, true); |
653 |
} |
654 |
if (lineCount != 0) { |
655 |
this.printlnOut(Main.bind( |
656 |
"compile.instantTime", //$NON-NLS-1$ |
657 |
new String[] { |
658 |
String.valueOf(lineCount), |
659 |
String.valueOf(time), |
660 |
String.valueOf(((int) (lineCount * 10000.0 / time)) / 10.0) })); |
661 |
} else { |
662 |
this.printlnOut(Main.bind("compile.totalTime", String.valueOf(time))); //$NON-NLS-1$ |
663 |
} |
664 |
} |
665 |
|
666 |
/** |
667 |
* @param usage |
668 |
*/ |
669 |
public void logUsage(String usage) { |
670 |
this.printlnOut(usage); //$NON-NLS-1$//$NON-NLS-2$ |
671 |
} |
672 |
|
673 |
/** |
674 |
* |
675 |
*/ |
676 |
public void logVersion() { |
677 |
this.printlnOut(Main.bind("misc.version")); //$NON-NLS-1$ |
678 |
} |
679 |
|
680 |
/** |
681 |
* |
682 |
*/ |
683 |
public void logWrongJDK() { |
684 |
if (isXml) { |
685 |
parameters.clear(); |
686 |
parameters.put(MESSAGE, Main.bind("configure.requiresJDK1.2orAbove")); //$NON-NLS-1$//$NON-NLS-2$ |
687 |
this.printTag(ERROR, parameters, true, true); |
688 |
} |
689 |
this.printlnErr(Main.bind("configure.requiresJDK1.2orAbove")); //$NON-NLS-1$ |
690 |
} |
691 |
|
692 |
/** |
693 |
* @param problem |
694 |
* the given problem to log |
695 |
* @param unitSource |
696 |
* the given unit source |
697 |
*/ |
698 |
private void logXmlProblem(IProblem problem, char[] unitSource) { |
699 |
final int sourceStart = problem.getSourceStart(); |
700 |
final int sourceEnd = problem.getSourceEnd(); |
701 |
parameters.clear(); |
702 |
parameters.put(PROBLEM_ID, getFieldName(problem.getID())); |
703 |
parameters.put(PROBLEM_SEVERITY, problem.isError() ? ERROR : WARNING); |
704 |
parameters.put(PROBLEM_LINE, new Integer(problem.getSourceLineNumber())); |
705 |
parameters.put(PROBLEM_SOURCE_START, new Integer(sourceStart)); |
706 |
parameters.put(PROBLEM_SOURCE_END, new Integer(sourceEnd)); |
707 |
this.printTag(PROBLEM_TAG, parameters, true, false); |
708 |
parameters.clear(); |
709 |
parameters.put(VALUE, problem.getMessage()); |
710 |
this.printTag(PROBLEM_MESSAGE, parameters, true, true); |
711 |
parameters.clear(); |
712 |
StringBuffer buffer = new StringBuffer(); |
713 |
if ((sourceStart > sourceEnd) |
714 |
|| ((sourceStart < 0) && (sourceEnd < 0))) { |
715 |
buffer.append(Util.bind("problem.noSourceInformation")); //$NON-NLS-1$ |
716 |
} else { |
717 |
buffer.append(unitSource, sourceStart, sourceEnd - sourceStart + 1); |
718 |
} |
719 |
parameters.put(VALUE, String.valueOf(buffer)); |
720 |
this.printTag(PROBLEM_SOURCE, parameters, true, true); |
721 |
String[] arguments = problem.getArguments(); |
722 |
final int length = arguments.length; |
723 |
if (length != 0) { |
724 |
this.printTag(PROBLEM_ARGUMENTS, null, true, false); |
725 |
parameters.clear(); |
726 |
for (int i = 0; i < length; i++) { |
727 |
parameters.put(PROBLEM_ARGUMENT_VALUE, arguments[i]); |
728 |
this.printTag(PROBLEM_ARGUMENT, parameters, true, true); |
729 |
} |
730 |
this.endTag(PROBLEM_ARGUMENTS); |
731 |
} |
732 |
this.endTag(PROBLEM_TAG); |
733 |
} |
734 |
/** |
735 |
* @param problem |
736 |
* the given problem to log |
737 |
* @param unitSource |
738 |
* the given unit source |
739 |
*/ |
740 |
private void logXmlTask(IProblem problem, char[] unitSource) { |
741 |
parameters.clear(); |
742 |
parameters.put(PROBLEM_LINE, new Integer(problem.getSourceLineNumber())); |
743 |
parameters.put(PROBLEM_SOURCE_START, new Integer(problem.getSourceStart())); |
744 |
parameters.put(PROBLEM_SOURCE_END, new Integer(problem.getSourceEnd())); |
745 |
this.printTag(TASK, parameters, true, false); |
746 |
parameters.clear(); |
747 |
parameters.put(VALUE, problem.getMessage()); |
748 |
this.printTag(PROBLEM_MESSAGE, parameters, true, true); |
749 |
this.endTag(TASK); |
750 |
} |
751 |
private void printErr(String s) { |
752 |
this.err.print(s); |
753 |
if (!this.isXml) { |
754 |
if (this.log != null) { |
755 |
this.log.print(s); |
756 |
} |
757 |
} |
758 |
} |
759 |
|
760 |
private void printlnErr(String s) { |
90 |
this.err.println(s); |
761 |
this.err.println(s); |
91 |
if (this.log != null) { |
762 |
if (!this.isXml) { |
92 |
this.log.println(s); |
763 |
if (this.log != null) { |
|
|
764 |
this.log.println(s); |
765 |
} |
93 |
} |
766 |
} |
94 |
} |
767 |
} |
95 |
|
768 |
|
96 |
public void printlnOut(String s) { |
769 |
private void printlnOut(String s) { |
97 |
this.out.println(s); |
770 |
this.out.println(s); |
98 |
} |
771 |
} |
99 |
|
772 |
|
100 |
public void printlnOut() { |
773 |
/** |
|
|
774 |
* |
775 |
*/ |
776 |
public void printNewLine() { |
101 |
this.out.println(); |
777 |
this.out.println(); |
102 |
} |
778 |
} |
103 |
|
779 |
|
104 |
public void printOut(char c) { |
780 |
private void printOut(char c) { |
105 |
this.out.print(c); |
781 |
this.out.print(c); |
106 |
} |
782 |
} |
|
|
783 |
public void printTag(String name, HashMap params, boolean insertNewLine, boolean closeTag) { |
784 |
for (int i= this.tab; i > 0; i--) this.log.print('\t'); |
785 |
StringBuffer buffer= new StringBuffer(); |
786 |
buffer.append("<"); //$NON-NLS-1$ |
787 |
buffer.append(name); |
788 |
if (params != null) { |
789 |
for (Enumeration enumeration = Collections.enumeration(params.keySet()); enumeration.hasMoreElements();) { |
790 |
buffer.append(" "); //$NON-NLS-1$ |
791 |
String key= (String) enumeration.nextElement(); |
792 |
buffer.append(key); |
793 |
buffer.append("=\""); //$NON-NLS-1$ |
794 |
buffer.append(getEscaped(String.valueOf(params.get(key)))); |
795 |
buffer.append("\""); //$NON-NLS-1$ |
796 |
} |
797 |
} |
798 |
if (closeTag) { |
799 |
buffer.append("/>"); //$NON-NLS-1$ |
800 |
} else { |
801 |
buffer.append(">"); //$NON-NLS-1$ |
802 |
this.tab++; |
803 |
} |
804 |
if (insertNewLine) { |
805 |
this.log.println(String.valueOf(buffer)); |
806 |
} else { |
807 |
this.log.print(String.valueOf(buffer)); |
808 |
} |
809 |
} |
810 |
|
811 |
public void setLog(String logFileName) throws InvalidInputException { |
812 |
try { |
813 |
this.log = new PrintWriter(new FileOutputStream(logFileName, false)); |
814 |
int index = logFileName.lastIndexOf('.'); |
815 |
if (index != 0) { |
816 |
if (logFileName.substring(index).toLowerCase().equals(".xml")) { //$NON-NLS-1$ |
817 |
this.isXml = true; |
818 |
this.log.println(XML_HEADER); |
819 |
this.tab = 0; |
820 |
parameters.clear(); |
821 |
parameters.put(COMPILER_NAME, Main.bind("compiler.name")); //$NON-NLS-1$//$NON-NLS-2$ |
822 |
parameters.put(COMPILER_VERSION, Main.bind("compiler.version")); //$NON-NLS-1$//$NON-NLS-2$ |
823 |
parameters.put(COMPILER_COPYRIGHT, Main.bind("compiler.copyright")); //$NON-NLS-1$//$NON-NLS-2$ |
824 |
this.printTag(COMPILER, parameters, true, false); |
825 |
} |
826 |
} |
827 |
} catch (FileNotFoundException e) { |
828 |
throw new InvalidInputException(Main.bind("configure.cannotOpenLog")); //$NON-NLS-1$ |
829 |
} |
830 |
} |
831 |
|
832 |
/** |
833 |
* Used to start logging problems. |
834 |
* Only use in xml mode. |
835 |
*/ |
836 |
private void startLoggingProblems(int errors, int warnings) { |
837 |
parameters.clear(); |
838 |
parameters.put(NUMBER_OF_PROBLEMS, new Integer(errors + warnings)); |
839 |
parameters.put(NUMBER_OF_ERRORS, new Integer(errors)); |
840 |
parameters.put(NUMBER_OF_WARNINGS, new Integer(warnings)); |
841 |
this.printTag(PROBLEMS, this.parameters, true, false); |
842 |
} |
843 |
public void startLoggingSource(CompilationResult compilationResult) { |
844 |
if (this.isXml) { |
845 |
ICompilationUnit compilationUnit = compilationResult.compilationUnit; |
846 |
char[] fileName = compilationUnit.getFileName(); |
847 |
if (fileName != null) { |
848 |
this.parameters.clear(); |
849 |
if (compilationUnit != null) { |
850 |
this.parameters.put(PATH, new String(fileName)); |
851 |
} |
852 |
} |
853 |
this.printTag(SOURCE, this.parameters, true, false); |
854 |
} |
855 |
} |
856 |
public void startLoggingSources() { |
857 |
if (this.isXml) { |
858 |
this.printTag(SOURCES, null, true, false); |
859 |
} |
860 |
} |
861 |
public void startLoggingTasks(int tasks) { |
862 |
if (this.isXml) { |
863 |
parameters.clear(); |
864 |
parameters.put(NUMBER_OF_TASKS, new Integer(tasks)); |
865 |
this.printTag(TASKS, this.parameters, true, false); |
866 |
} |
867 |
} |
868 |
public void logClassFile(boolean generatePackagesStructure, String outputPath, String relativeFileName) { |
869 |
if (this.isXml) { |
870 |
String fileName = null; |
871 |
if (generatePackagesStructure) { |
872 |
fileName = buildFileName(outputPath, relativeFileName); |
873 |
} else { |
874 |
char fileSeparatorChar = File.separatorChar; |
875 |
String fileSeparator = File.separator; |
876 |
// First we ensure that the outputPath exists |
877 |
outputPath = outputPath.replace('/', fileSeparatorChar); |
878 |
// To be able to pass the mkdirs() method we need to remove the extra file separator at the end of the outDir name |
879 |
int indexOfPackageSeparator = relativeFileName.lastIndexOf(fileSeparatorChar); |
880 |
if (indexOfPackageSeparator == -1) { |
881 |
if (outputPath.endsWith(fileSeparator)) { |
882 |
fileName = outputPath + relativeFileName; |
883 |
} else { |
884 |
fileName = outputPath + fileSeparator + relativeFileName; |
885 |
} |
886 |
} else { |
887 |
int length = relativeFileName.length(); |
888 |
if (outputPath.endsWith(fileSeparator)) { |
889 |
fileName = outputPath + relativeFileName.substring(indexOfPackageSeparator + 1, length); |
890 |
} else { |
891 |
fileName = outputPath + fileSeparator + relativeFileName.substring(indexOfPackageSeparator + 1, length); |
892 |
} |
893 |
} |
894 |
} |
895 |
this.parameters.clear(); |
896 |
this.parameters.put(PATH, fileName); |
897 |
this.printTag(CLASS_FILE, this.parameters, true, true); |
898 |
} |
899 |
} |
107 |
} |
900 |
} |
108 |
static { |
901 |
static { |
109 |
relocalize(); |
902 |
relocalize(); |
Lines 354-361
Link Here
|
354 |
// if (this.verbose) { |
1147 |
// if (this.verbose) { |
355 |
// System.out.println(new CompilerOptions(this.options)); |
1148 |
// System.out.println(new CompilerOptions(this.options)); |
356 |
// } |
1149 |
// } |
357 |
if (this.showProgress) |
1150 |
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++) { |
1151 |
for (int i = 0; i < this.repetitions; i++) { |
360 |
this.globalProblemsCount = 0; |
1152 |
this.globalProblemsCount = 0; |
361 |
this.globalErrorsCount = 0; |
1153 |
this.globalErrorsCount = 0; |
Lines 365-388
Link Here
|
365 |
|
1157 |
|
366 |
if (this.repetitions > 1) { |
1158 |
if (this.repetitions > 1) { |
367 |
this.logger.flush(); |
1159 |
this.logger.flush(); |
368 |
this.logger.printlnOut( |
1160 |
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 |
} |
1161 |
} |
374 |
// request compilation |
1162 |
// request compilation |
375 |
performCompilation(); |
1163 |
performCompilation(); |
376 |
} |
1164 |
} |
377 |
if (this.showProgress) |
1165 |
if (this.showProgress) this.logger.printNewLine(); |
378 |
this.logger.printlnOut(); |
|
|
379 |
} |
1166 |
} |
380 |
if (this.systemExitWhenFinished) { |
1167 |
if (this.systemExitWhenFinished) { |
381 |
this.logger.flush(); |
1168 |
this.logger.flush(); |
|
|
1169 |
this.logger.close(); |
382 |
System.exit(this.globalErrorsCount > 0 ? -1 : 0); |
1170 |
System.exit(this.globalErrorsCount > 0 ? -1 : 0); |
383 |
} |
1171 |
} |
384 |
} catch (InvalidInputException e) { |
1172 |
} catch (InvalidInputException e) { |
385 |
this.logger.printlnErr(e.getMessage()); |
1173 |
this.logger.logException(e); |
386 |
if (this.systemExitWhenFinished) { |
1174 |
if (this.systemExitWhenFinished) { |
387 |
this.logger.flush(); |
1175 |
this.logger.flush(); |
388 |
this.logger.close(); |
1176 |
this.logger.close(); |
Lines 396-402
Link Here
|
396 |
System.exit(-1); |
1184 |
System.exit(-1); |
397 |
} |
1185 |
} |
398 |
return false; |
1186 |
return false; |
399 |
//e.printStackTrace(); |
|
|
400 |
} finally { |
1187 |
} finally { |
401 |
this.logger.flush(); |
1188 |
this.logger.flush(); |
402 |
this.logger.close(); |
1189 |
this.logger.close(); |
Lines 1236-1242
Link Here
|
1236 |
// no user classpath specified. |
2023 |
// no user classpath specified. |
1237 |
String classProp = System.getProperty("java.class.path"); //$NON-NLS-1$ |
2024 |
String classProp = System.getProperty("java.class.path"); //$NON-NLS-1$ |
1238 |
if ((classProp == null) || (classProp.length() == 0)) { |
2025 |
if ((classProp == null) || (classProp.length() == 0)) { |
1239 |
this.logger.printlnErr(Main.bind("configure.noClasspath")); //$NON-NLS-1$ |
2026 |
this.logger.logNoClasspath(); //$NON-NLS-1$ |
1240 |
classProp = System.getProperty("user.dir"); //$NON-NLS-1$ |
2027 |
classProp = System.getProperty("user.dir"); //$NON-NLS-1$ |
1241 |
} |
2028 |
} |
1242 |
StringTokenizer tokenizer = new StringTokenizer(classProp, File.pathSeparator); |
2029 |
StringTokenizer tokenizer = new StringTokenizer(classProp, File.pathSeparator); |
Lines 1254-1260
Link Here
|
1254 |
*/ |
2041 |
*/ |
1255 |
String javaversion = System.getProperty("java.version");//$NON-NLS-1$ |
2042 |
String javaversion = System.getProperty("java.version");//$NON-NLS-1$ |
1256 |
if (javaversion != null && javaversion.equalsIgnoreCase("1.1.8")) { //$NON-NLS-1$ |
2043 |
if (javaversion != null && javaversion.equalsIgnoreCase("1.1.8")) { //$NON-NLS-1$ |
1257 |
this.logger.printlnErr(Main.bind("configure.requiresJDK1.2orAbove")); //$NON-NLS-1$ |
2044 |
this.logger.logWrongJDK(); //$NON-NLS-1$ |
1258 |
this.proceed = false; |
2045 |
this.proceed = false; |
1259 |
return; |
2046 |
return; |
1260 |
} |
2047 |
} |
Lines 1291-1301
Link Here
|
1291 |
} |
2078 |
} |
1292 |
|
2079 |
|
1293 |
if (this.log != null) { |
2080 |
if (this.log != null) { |
1294 |
try { |
2081 |
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 { |
2082 |
} else { |
1300 |
this.showProgress = false; |
2083 |
this.showProgress = false; |
1301 |
} |
2084 |
} |
Lines 1331-1337
Link Here
|
1331 |
for (int i = 0, max = this.classpaths.length; i < max; i++) { |
2114 |
for (int i = 0, max = this.classpaths.length; i < max; i++) { |
1332 |
File file = new File(this.classpaths[i]); |
2115 |
File file = new File(this.classpaths[i]); |
1333 |
if (!file.exists()) { // signal missing classpath entry file |
2116 |
if (!file.exists()) { // signal missing classpath entry file |
1334 |
this.logger.printlnErr(Main.bind("configure.incorrectClasspath", this.classpaths[i])); //$NON-NLS-1$ |
2117 |
this.logger.logIncorrectClasspath(this.classpaths[i]); //$NON-NLS-1$ |
1335 |
} |
2118 |
} |
1336 |
} |
2119 |
} |
1337 |
if (this.destinationPath == null) { |
2120 |
if (this.destinationPath == null) { |
Lines 1343-1366
Link Here
|
1343 |
if (didSpecifyCompliance) { |
2126 |
if (didSpecifyCompliance) { |
1344 |
Object version = this.options.get(CompilerOptions.OPTION_Compliance); |
2127 |
Object version = this.options.get(CompilerOptions.OPTION_Compliance); |
1345 |
if (CompilerOptions.VERSION_1_3.equals(version)) { |
2128 |
if (CompilerOptions.VERSION_1_3.equals(version)) { |
1346 |
if (!didSpecifySource) this.options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_3); |
2129 |
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); |
2130 |
if (!didSpecifyTarget) this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_1); |
1348 |
} else if (CompilerOptions.VERSION_1_4.equals(version)) { |
2131 |
} else if (CompilerOptions.VERSION_1_4.equals(version)) { |
1349 |
if (!didSpecifySource) this.options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_3); |
2132 |
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); |
2133 |
if (!didSpecifyTarget) this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_2); |
1351 |
} else if (CompilerOptions.VERSION_1_5.equals(version)) { |
2134 |
} else if (CompilerOptions.VERSION_1_5.equals(version)) { |
1352 |
if (!didSpecifySource) this.options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_5); |
2135 |
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); |
2136 |
if (!didSpecifyTarget) this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_5); |
1354 |
} |
2137 |
} |
1355 |
} |
2138 |
} |
1356 |
if (didSpecifySource) { |
2139 |
if (didSpecifySource) { |
1357 |
Object version = this.options.get(CompilerOptions.OPTION_Source); |
2140 |
Object version = this.options.get(CompilerOptions.OPTION_Source); |
1358 |
if (CompilerOptions.VERSION_1_4.equals(version)) { |
2141 |
if (CompilerOptions.VERSION_1_4.equals(version)) { |
1359 |
if (!didSpecifyCompliance) this.options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_4); |
2142 |
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); |
2143 |
if (!didSpecifyTarget) this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_4); |
1361 |
} else if (CompilerOptions.VERSION_1_5.equals(version)) { |
2144 |
} else if (CompilerOptions.VERSION_1_5.equals(version)) { |
1362 |
if (!didSpecifyCompliance) this.options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_5); |
2145 |
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); |
2146 |
if (!didSpecifyTarget) this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_5); |
1364 |
} |
2147 |
} |
1365 |
} |
2148 |
} |
1366 |
|
2149 |
|
Lines 1378-1384
Link Here
|
1378 |
} |
2161 |
} |
1379 |
// target cannot be greater than compliance level |
2162 |
// 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))){ |
2163 |
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$ |
2164 |
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 |
} |
2165 |
} |
1383 |
} |
2166 |
} |
1384 |
|
2167 |
|
Lines 1412-1418
Link Here
|
1412 |
} |
2195 |
} |
1413 |
} |
2196 |
} |
1414 |
} |
2197 |
} |
1415 |
|
2198 |
this.logger.logCommandLineArguments(newCommandLineArgs); |
|
|
2199 |
this.logger.logOptions(this.options); |
2200 |
this.logger.logClasspath(this.classpaths); |
1416 |
if (this.repetitions == 0) { |
2201 |
if (this.repetitions == 0) { |
1417 |
this.repetitions = 1; |
2202 |
this.repetitions = 1; |
1418 |
} |
2203 |
} |
Lines 1456-1512
Link Here
|
1456 |
int unitLineCount = compilationResult.lineSeparatorPositions.length; |
2241 |
int unitLineCount = compilationResult.lineSeparatorPositions.length; |
1457 |
Main.this.lineCount += unitLineCount; |
2242 |
Main.this.lineCount += unitLineCount; |
1458 |
this.lineDelta += unitLineCount; |
2243 |
this.lineDelta += unitLineCount; |
1459 |
if (Main.this.showProgress |
2244 |
if (Main.this.showProgress && this.lineDelta > 2000) { |
1460 |
&& this.lineDelta > 2000) { // in -log mode, dump a dot every 2000 lines compiled |
2245 |
// in -log mode, dump a dot every 2000 lines compiled |
1461 |
Main.this.logger.printOut('.'); |
2246 |
Main.this.logger.logProgress(); |
1462 |
this.lineDelta = 0; |
2247 |
this.lineDelta = 0; |
1463 |
} |
2248 |
} |
1464 |
} |
2249 |
} |
|
|
2250 |
Main.this.logger.startLoggingSource(compilationResult); |
1465 |
if (compilationResult.hasProblems() || compilationResult.hasTasks()) { |
2251 |
if (compilationResult.hasProblems() || compilationResult.hasTasks()) { |
1466 |
IProblem[] problems = compilationResult.getAllProblems(); |
2252 |
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? |
2253 |
// exit? |
1503 |
if (Main.this.systemExitWhenFinished && !Main.this.proceedOnError && (localErrorCount > 0)) { |
2254 |
if (Main.this.systemExitWhenFinished && !Main.this.proceedOnError && (localErrorCount > 0)) { |
1504 |
Main.this.printStats(); |
2255 |
Main.this.logger.endLoggingSource(); |
|
|
2256 |
Main.this.logger.printStats(Main.this); |
1505 |
Main.this.logger.flush(); |
2257 |
Main.this.logger.flush(); |
|
|
2258 |
Main.this.logger.close(); |
1506 |
System.exit(-1); |
2259 |
System.exit(-1); |
1507 |
} |
2260 |
} |
1508 |
} |
2261 |
} |
1509 |
outputClassFiles(compilationResult); |
2262 |
outputClassFiles(compilationResult); |
|
|
2263 |
Main.this.logger.endLoggingSource(); |
1510 |
} |
2264 |
} |
1511 |
}; |
2265 |
}; |
1512 |
} |
2266 |
} |
Lines 1603-1614
Link Here
|
1603 |
// Dump classfiles onto disk for all compilation units that where successfull. |
2357 |
// Dump classfiles onto disk for all compilation units that where successfull. |
1604 |
|
2358 |
|
1605 |
public void outputClassFiles(CompilationResult unitResult) { |
2359 |
public void outputClassFiles(CompilationResult unitResult) { |
1606 |
|
|
|
1607 |
if (!((unitResult == null) || (unitResult.hasErrors() && !this.proceedOnError))) { |
2360 |
if (!((unitResult == null) || (unitResult.hasErrors() && !this.proceedOnError))) { |
1608 |
Enumeration classFiles = unitResult.compiledTypes.elements(); |
2361 |
Enumeration classFiles = unitResult.compiledTypes.elements(); |
1609 |
if (!this.generatePackagesStructure) { |
2362 |
if (!this.generatePackagesStructure) { |
|
|
2363 |
this.destinationPath = extractDestinationPathFromSourceFile(unitResult); |
2364 |
} |
2365 |
if (this.destinationPath != null) { |
1610 |
while (classFiles.hasMoreElements()) { |
2366 |
while (classFiles.hasMoreElements()) { |
1611 |
this.destinationPath = extractDestinationPathFromSourceFile(unitResult); |
|
|
1612 |
// retrieve the key and the corresponding classfile |
2367 |
// retrieve the key and the corresponding classfile |
1613 |
ClassFile classFile = (ClassFile) classFiles.nextElement(); |
2368 |
ClassFile classFile = (ClassFile) classFiles.nextElement(); |
1614 |
char[] filename = classFile.fileName(); |
2369 |
char[] filename = classFile.fileName(); |
Lines 1622-1656
Link Here
|
1622 |
System.out.println(Util.bind("compilation.write", //$NON-NLS-1$ |
2377 |
System.out.println(Util.bind("compilation.write", //$NON-NLS-1$ |
1623 |
new String[] { |
2378 |
new String[] { |
1624 |
String.valueOf(this.exportedClassFilesCounter+1), |
2379 |
String.valueOf(this.exportedClassFilesCounter+1), |
1625 |
new String(relativeName) })); |
2380 |
new String(relativeName) |
1626 |
ClassFile.writeToDisk( |
2381 |
})); |
|
|
2382 |
this.logger.logClassFile( |
1627 |
this.generatePackagesStructure, |
2383 |
this.generatePackagesStructure, |
1628 |
this.destinationPath, |
2384 |
this.destinationPath, |
1629 |
new String(relativeName), |
2385 |
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( |
2386 |
ClassFile.writeToDisk( |
1655 |
this.generatePackagesStructure, |
2387 |
this.generatePackagesStructure, |
1656 |
this.destinationPath, |
2388 |
this.destinationPath, |
Lines 1659-1665
Link Here
|
1659 |
} catch (IOException e) { |
2391 |
} catch (IOException e) { |
1660 |
String fileName = this.destinationPath + new String(relativeName); |
2392 |
String fileName = this.destinationPath + new String(relativeName); |
1661 |
e.printStackTrace(); |
2393 |
e.printStackTrace(); |
1662 |
this.logger.printlnErr(Main.bind("output.noClassFileCreated", fileName)); //$NON-NLS-1$ |
2394 |
this.logger.logNoClassFileCreated(fileName); //$NON-NLS-1$ |
1663 |
} |
2395 |
} |
1664 |
this.exportedClassFilesCounter++; |
2396 |
this.exportedClassFilesCounter++; |
1665 |
} |
2397 |
} |
Lines 1686-1762
Link Here
|
1686 |
// set the non-externally configurable options. |
2418 |
// set the non-externally configurable options. |
1687 |
this.compilerOptions.verbose = this.verbose; |
2419 |
this.compilerOptions.verbose = this.verbose; |
1688 |
this.compilerOptions.produceReferenceInfo = this.produceRefInfo; |
2420 |
this.compilerOptions.produceReferenceInfo = this.produceRefInfo; |
1689 |
batchCompiler.compile(getCompilationUnits()); |
2421 |
try { |
|
|
2422 |
this.logger.startLoggingSources(); |
2423 |
batchCompiler.compile(getCompilationUnits()); |
2424 |
} finally { |
2425 |
this.logger.endLoggingSources(); |
2426 |
} |
1690 |
|
2427 |
|
1691 |
printStats(); |
2428 |
this.logger.printStats(this); |
1692 |
|
2429 |
|
1693 |
// cleanup |
2430 |
// cleanup |
1694 |
environment.cleanup(); |
2431 |
environment.cleanup(); |
1695 |
} |
2432 |
} |
1696 |
|
2433 |
|
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() { |
2434 |
public void printUsage() { |
1755 |
this.logger.printlnOut(Main.bind("misc.usage", System.getProperty("path.separator"))); //$NON-NLS-1$//$NON-NLS-2$ |
2435 |
this.logger.logUsage(Main.bind("misc.usage", System.getProperty("path.separator"))); //$NON-NLS-1$//$NON-NLS-2$ |
1756 |
this.logger.flush(); |
2436 |
this.logger.flush(); |
1757 |
} |
2437 |
} |
1758 |
public void printVersion() { |
2438 |
public void printVersion() { |
1759 |
this.logger.printlnOut(Main.bind("misc.version")); //$NON-NLS-1$ |
2439 |
this.logger.logVersion(); //$NON-NLS-1$ |
1760 |
this.logger.flush(); |
2440 |
this.logger.flush(); |
1761 |
} |
2441 |
} |
1762 |
} |
2442 |
} |