45 import java.util.zip.ZipFile; |
45 import java.util.zip.ZipFile; |
46 import javax.tools.JavaFileManager.Location; |
46 import javax.tools.JavaFileManager.Location; |
47 import javax.tools.StandardLocation; |
47 import javax.tools.StandardLocation; |
48 |
48 |
49 import com.sun.tools.javac.code.Lint; |
49 import com.sun.tools.javac.code.Lint; |
50 import com.sun.tools.javac.main.OptionName; |
50 import com.sun.tools.javac.main.Option; |
51 import com.sun.tools.javac.util.ListBuffer; |
51 import com.sun.tools.javac.util.ListBuffer; |
52 import com.sun.tools.javac.util.Log; |
52 import com.sun.tools.javac.util.Log; |
53 import com.sun.tools.javac.util.Options; |
53 import com.sun.tools.javac.util.Options; |
54 |
54 |
55 import javax.tools.JavaFileManager; |
55 import javax.tools.JavaFileManager; |
56 import static javax.tools.StandardLocation.*; |
56 import static javax.tools.StandardLocation.*; |
57 import static com.sun.tools.javac.main.OptionName.*; |
57 import static com.sun.tools.javac.main.Option.*; |
58 |
58 |
59 /** This class converts command line arguments, environment variables |
59 /** This class converts command line arguments, environment variables |
60 * and system properties (in File.pathSeparator-separated String form) |
60 * and system properties (in File.pathSeparator-separated String form) |
61 * into a boot class path, user class path, and source path (in |
61 * into a boot class path, user class path, and source path (in |
62 * Collection<String> form). |
62 * Collection<String> form). |
316 * @see #initHandlers |
316 * @see #initHandlers |
317 * @see #getHandler |
317 * @see #getHandler |
318 */ |
318 */ |
319 protected abstract class LocationHandler { |
319 protected abstract class LocationHandler { |
320 final Location location; |
320 final Location location; |
321 final Set<OptionName> options; |
321 final Set<Option> options; |
322 |
322 |
323 /** |
323 /** |
324 * Create a handler. The location and options provide a way to map |
324 * Create a handler. The location and options provide a way to map |
325 * from a location or an option to the corresponding handler. |
325 * from a location or an option to the corresponding handler. |
326 * @see #initHandlers |
326 * @see #initHandlers |
327 */ |
327 */ |
328 protected LocationHandler(Location location, OptionName... options) { |
328 protected LocationHandler(Location location, Option... options) { |
329 this.location = location; |
329 this.location = location; |
330 this.options = options.length == 0 ? |
330 this.options = options.length == 0 ? |
331 EnumSet.noneOf(OptionName.class): |
331 EnumSet.noneOf(Option.class): |
332 EnumSet.copyOf(Arrays.asList(options)); |
332 EnumSet.copyOf(Arrays.asList(options)); |
333 } |
333 } |
334 |
334 |
335 // TODO: TEMPORARY, while Options still used for command line options |
335 // TODO: TEMPORARY, while Options still used for command line options |
336 void update(Options optionTable) { |
336 void update(Options optionTable) { |
337 for (OptionName o: options) { |
337 for (Option o: options) { |
338 String v = optionTable.get(o); |
338 String v = optionTable.get(o); |
339 if (v != null) { |
339 if (v != null) { |
340 handleOption(o, v); |
340 handleOption(o, v); |
341 } |
341 } |
342 } |
342 } |
343 } |
343 } |
344 |
344 |
345 /** @see JavaFileManager#handleOption. */ |
345 /** @see JavaFileManager#handleOption. */ |
346 abstract boolean handleOption(OptionName option, String value); |
346 abstract boolean handleOption(Option option, String value); |
347 /** @see JavaFileManager#getLocation. */ |
347 /** @see JavaFileManager#getLocation. */ |
348 abstract Collection<File> getLocation(); |
348 abstract Collection<File> getLocation(); |
349 /** @see JavaFileManager#setLocation. */ |
349 /** @see JavaFileManager#setLocation. */ |
350 abstract void setLocation(Iterable<? extends File> files) throws IOException; |
350 abstract void setLocation(Iterable<? extends File> files) throws IOException; |
351 } |
351 } |
357 * The value is a single file, possibly null. |
357 * The value is a single file, possibly null. |
358 */ |
358 */ |
359 private class OutputLocationHandler extends LocationHandler { |
359 private class OutputLocationHandler extends LocationHandler { |
360 private File outputDir; |
360 private File outputDir; |
361 |
361 |
362 OutputLocationHandler(Location location, OptionName... options) { |
362 OutputLocationHandler(Location location, Option... options) { |
363 super(location, options); |
363 super(location, options); |
364 } |
364 } |
365 |
365 |
366 @Override |
366 @Override |
367 boolean handleOption(OptionName option, String value) { |
367 boolean handleOption(Option option, String value) { |
368 if (!options.contains(option)) |
368 if (!options.contains(option)) |
369 return false; |
369 return false; |
370 |
370 |
371 // TODO: could/should validate outputDir exists and is a directory |
371 // TODO: could/should validate outputDir exists and is a directory |
372 // need to decide how best to report issue for benefit of |
372 // need to decide how best to report issue for benefit of |
408 * The value is an ordered set of files and/or directories. |
408 * The value is an ordered set of files and/or directories. |
409 */ |
409 */ |
410 private class SimpleLocationHandler extends LocationHandler { |
410 private class SimpleLocationHandler extends LocationHandler { |
411 protected Collection<File> searchPath; |
411 protected Collection<File> searchPath; |
412 |
412 |
413 SimpleLocationHandler(Location location, OptionName... options) { |
413 SimpleLocationHandler(Location location, Option... options) { |
414 super(location, options); |
414 super(location, options); |
415 } |
415 } |
416 |
416 |
417 @Override |
417 @Override |
418 boolean handleOption(OptionName option, String value) { |
418 boolean handleOption(Option option, String value) { |
419 if (!options.contains(option)) |
419 if (!options.contains(option)) |
420 return false; |
420 return false; |
421 searchPath = value == null ? null : |
421 searchPath = value == null ? null : |
422 Collections.unmodifiableCollection(computePath(value)); |
422 Collections.unmodifiableCollection(computePath(value)); |
423 return true; |
423 return true; |
498 * Setting -bootclasspath or -Xbootclasspath overrides any existing |
498 * Setting -bootclasspath or -Xbootclasspath overrides any existing |
499 * value for -Xbootclasspath/p: and -Xbootclasspath/a:. |
499 * value for -Xbootclasspath/p: and -Xbootclasspath/a:. |
500 */ |
500 */ |
501 private class BootClassPathLocationHandler extends LocationHandler { |
501 private class BootClassPathLocationHandler extends LocationHandler { |
502 private Collection<File> searchPath; |
502 private Collection<File> searchPath; |
503 final Map<OptionName, String> optionValues = new EnumMap<OptionName,String>(OptionName.class); |
503 final Map<Option, String> optionValues = new EnumMap<Option,String>(Option.class); |
504 |
504 |
505 /** |
505 /** |
506 * rt.jar as found on the default bootclasspath. |
506 * rt.jar as found on the default bootclasspath. |
507 * If the user specified a bootclasspath, null is used. |
507 * If the user specified a bootclasspath, null is used. |
508 */ |
508 */ |
513 */ |
513 */ |
514 private boolean isDefaultBootClassPath; |
514 private boolean isDefaultBootClassPath; |
515 |
515 |
516 BootClassPathLocationHandler() { |
516 BootClassPathLocationHandler() { |
517 super(StandardLocation.PLATFORM_CLASS_PATH, |
517 super(StandardLocation.PLATFORM_CLASS_PATH, |
518 OptionName.BOOTCLASSPATH, OptionName.XBOOTCLASSPATH, |
518 Option.BOOTCLASSPATH, Option.XBOOTCLASSPATH, |
519 OptionName.XBOOTCLASSPATH_PREPEND, |
519 Option.XBOOTCLASSPATH_PREPEND, |
520 OptionName.XBOOTCLASSPATH_APPEND, |
520 Option.XBOOTCLASSPATH_APPEND, |
521 OptionName.ENDORSEDDIRS, OptionName.DJAVA_ENDORSED_DIRS, |
521 Option.ENDORSEDDIRS, Option.DJAVA_ENDORSED_DIRS, |
522 OptionName.EXTDIRS, OptionName.DJAVA_EXT_DIRS); |
522 Option.EXTDIRS, Option.DJAVA_EXT_DIRS); |
523 } |
523 } |
524 |
524 |
525 boolean isDefault() { |
525 boolean isDefault() { |
526 lazy(); |
526 lazy(); |
527 return isDefaultBootClassPath; |
527 return isDefaultBootClassPath; |
634 searchPath = Collections.unmodifiableCollection(computePath()); |
634 searchPath = Collections.unmodifiableCollection(computePath()); |
635 } |
635 } |
636 } |
636 } |
637 |
637 |
638 Map<Location, LocationHandler> handlersForLocation; |
638 Map<Location, LocationHandler> handlersForLocation; |
639 Map<OptionName, LocationHandler> handlersForOption; |
639 Map<Option, LocationHandler> handlersForOption; |
640 |
640 |
641 void initHandlers() { |
641 void initHandlers() { |
642 handlersForLocation = new HashMap<Location, LocationHandler>(); |
642 handlersForLocation = new HashMap<Location, LocationHandler>(); |
643 handlersForOption = new EnumMap<OptionName, LocationHandler>(OptionName.class); |
643 handlersForOption = new EnumMap<Option, LocationHandler>(Option.class); |
644 |
644 |
645 LocationHandler[] handlers = { |
645 LocationHandler[] handlers = { |
646 new BootClassPathLocationHandler(), |
646 new BootClassPathLocationHandler(), |
647 new ClassPathLocationHandler(), |
647 new ClassPathLocationHandler(), |
648 new SimpleLocationHandler(StandardLocation.SOURCE_PATH, OptionName.SOURCEPATH), |
648 new SimpleLocationHandler(StandardLocation.SOURCE_PATH, Option.SOURCEPATH), |
649 new SimpleLocationHandler(StandardLocation.ANNOTATION_PROCESSOR_PATH, OptionName.PROCESSORPATH), |
649 new SimpleLocationHandler(StandardLocation.ANNOTATION_PROCESSOR_PATH, Option.PROCESSORPATH), |
650 new OutputLocationHandler((StandardLocation.CLASS_OUTPUT), OptionName.D), |
650 new OutputLocationHandler((StandardLocation.CLASS_OUTPUT), Option.D), |
651 new OutputLocationHandler((StandardLocation.SOURCE_OUTPUT), OptionName.S) |
651 new OutputLocationHandler((StandardLocation.SOURCE_OUTPUT), Option.S) |
652 }; |
652 }; |
653 |
653 |
654 for (LocationHandler h: handlers) { |
654 for (LocationHandler h: handlers) { |
655 handlersForLocation.put(h.location, h); |
655 handlersForLocation.put(h.location, h); |
656 for (OptionName o: h.options) |
656 for (Option o: h.options) |
657 handlersForOption.put(o, h); |
657 handlersForOption.put(o, h); |
658 } |
658 } |
659 } |
659 } |
660 |
660 |
661 boolean handleOption(OptionName option, String value) { |
661 boolean handleOption(Option option, String value) { |
662 LocationHandler h = handlersForOption.get(option); |
662 LocationHandler h = handlersForOption.get(option); |
663 return (h == null ? false : h.handleOption(option, value)); |
663 return (h == null ? false : h.handleOption(option, value)); |
664 } |
664 } |
665 |
665 |
666 Collection<File> getLocation(Location location) { |
666 Collection<File> getLocation(Location location) { |