29 import java.io.IOException; |
29 import java.io.IOException; |
30 import java.io.PrintWriter; |
30 import java.io.PrintWriter; |
31 import java.net.URL; |
31 import java.net.URL; |
32 import java.security.DigestInputStream; |
32 import java.security.DigestInputStream; |
33 import java.security.MessageDigest; |
33 import java.security.MessageDigest; |
|
34 import java.util.Arrays; |
34 import java.util.Collection; |
35 import java.util.Collection; |
35 import java.util.LinkedHashSet; |
36 import java.util.LinkedHashSet; |
36 import java.util.Set; |
37 import java.util.Set; |
37 import javax.tools.JavaFileManager; |
38 import javax.tools.JavaFileManager; |
38 import javax.tools.JavaFileObject; |
39 import javax.tools.JavaFileObject; |
206 /** Process command line arguments: store all command line options |
207 /** Process command line arguments: store all command line options |
207 * in `options' table and return all source filenames. |
208 * in `options' table and return all source filenames. |
208 * @param flags The array of command line arguments. |
209 * @param flags The array of command line arguments. |
209 */ |
210 */ |
210 public Collection<File> processArgs(String[] flags) { // XXX sb protected |
211 public Collection<File> processArgs(String[] flags) { // XXX sb protected |
|
212 return processArgs(flags, null); |
|
213 } |
|
214 |
|
215 public Collection<File> processArgs(String[] flags, String[] classNames) { // XXX sb protected |
211 int ac = 0; |
216 int ac = 0; |
212 while (ac < flags.length) { |
217 while (ac < flags.length) { |
213 String flag = flags[ac]; |
218 String flag = flags[ac]; |
214 ac++; |
219 ac++; |
215 |
220 |
344 public Result compile(String[] args, |
353 public Result compile(String[] args, |
345 Context context, |
354 Context context, |
346 List<JavaFileObject> fileObjects, |
355 List<JavaFileObject> fileObjects, |
347 Iterable<? extends Processor> processors) |
356 Iterable<? extends Processor> processors) |
348 { |
357 { |
|
358 return compile(args, null, context, fileObjects, processors); |
|
359 } |
|
360 |
|
361 public Result compile(String[] args, |
|
362 String[] classNames, |
|
363 Context context, |
|
364 List<JavaFileObject> fileObjects, |
|
365 Iterable<? extends Processor> processors) |
|
366 { |
349 context.put(Log.outKey, out); |
367 context.put(Log.outKey, out); |
350 log = Log.instance(context); |
368 log = Log.instance(context); |
351 |
369 |
352 if (options == null) |
370 if (options == null) |
353 options = Options.instance(context); // creates a new one |
371 options = Options.instance(context); // creates a new one |
359 * TODO: Logic below about what is an acceptable command line |
377 * TODO: Logic below about what is an acceptable command line |
360 * should be updated to take annotation processing semantics |
378 * should be updated to take annotation processing semantics |
361 * into account. |
379 * into account. |
362 */ |
380 */ |
363 try { |
381 try { |
364 if (args.length == 0 && fileObjects.isEmpty()) { |
382 if (args.length == 0 |
|
383 && (classNames == null || classNames.length == 0) |
|
384 && fileObjects.isEmpty()) { |
365 Option.HELP.process(optionHelper, "-help"); |
385 Option.HELP.process(optionHelper, "-help"); |
366 return Result.CMDERR; |
386 return Result.CMDERR; |
367 } |
387 } |
368 |
388 |
369 Collection<File> files; |
389 Collection<File> files; |
370 try { |
390 try { |
371 files = processArgs(CommandLine.parse(args)); |
391 files = processArgs(CommandLine.parse(args), classNames); |
372 if (files == null) { |
392 if (files == null) { |
373 // null signals an error in options, abort |
393 // null signals an error in options, abort |
374 return Result.CMDERR; |
394 return Result.CMDERR; |
375 } else if (files.isEmpty() && fileObjects.isEmpty() && classnames.isEmpty()) { |
395 } else if (files.isEmpty() && fileObjects.isEmpty() && classnames.isEmpty()) { |
376 // it is allowed to compile nothing if just asking for help or version info |
396 // it is allowed to compile nothing if just asking for help or version info |