82 import com.sun.tools.javac.util.Pair; |
82 import com.sun.tools.javac.util.Pair; |
83 import com.sun.tools.javac.util.StringUtils; |
83 import com.sun.tools.javac.util.StringUtils; |
84 |
84 |
85 import static javax.tools.StandardLocation.PLATFORM_CLASS_PATH; |
85 import static javax.tools.StandardLocation.PLATFORM_CLASS_PATH; |
86 |
86 |
87 import static com.sun.tools.javac.main.Option.BOOTCLASSPATH; |
87 import static com.sun.tools.javac.main.Option.BOOT_CLASS_PATH; |
88 import static com.sun.tools.javac.main.Option.DJAVA_ENDORSED_DIRS; |
88 import static com.sun.tools.javac.main.Option.DJAVA_ENDORSED_DIRS; |
89 import static com.sun.tools.javac.main.Option.DJAVA_EXT_DIRS; |
89 import static com.sun.tools.javac.main.Option.DJAVA_EXT_DIRS; |
90 import static com.sun.tools.javac.main.Option.ENDORSEDDIRS; |
90 import static com.sun.tools.javac.main.Option.ENDORSEDDIRS; |
91 import static com.sun.tools.javac.main.Option.EXTDIRS; |
91 import static com.sun.tools.javac.main.Option.EXTDIRS; |
92 import static com.sun.tools.javac.main.Option.XBOOTCLASSPATH; |
92 import static com.sun.tools.javac.main.Option.XBOOTCLASSPATH; |
578 * If no value is given, a default is provided, based on system properties and other values. |
578 * If no value is given, a default is provided, based on system properties and other values. |
579 */ |
579 */ |
580 private class ClassPathLocationHandler extends SimpleLocationHandler { |
580 private class ClassPathLocationHandler extends SimpleLocationHandler { |
581 |
581 |
582 ClassPathLocationHandler() { |
582 ClassPathLocationHandler() { |
583 super(StandardLocation.CLASS_PATH, |
583 super(StandardLocation.CLASS_PATH, Option.CLASS_PATH); |
584 Option.CLASSPATH, Option.CP); |
|
585 } |
584 } |
586 |
585 |
587 @Override |
586 @Override |
588 Collection<Path> getPaths() { |
587 Collection<Path> getPaths() { |
589 lazy(); |
588 lazy(); |
647 */ |
646 */ |
648 private boolean isDefault; |
647 private boolean isDefault; |
649 |
648 |
650 BootClassPathLocationHandler() { |
649 BootClassPathLocationHandler() { |
651 super(StandardLocation.PLATFORM_CLASS_PATH, |
650 super(StandardLocation.PLATFORM_CLASS_PATH, |
652 Option.BOOTCLASSPATH, Option.XBOOTCLASSPATH, |
651 Option.BOOT_CLASS_PATH, Option.XBOOTCLASSPATH, |
653 Option.XBOOTCLASSPATH_PREPEND, |
652 Option.XBOOTCLASSPATH_PREPEND, |
654 Option.XBOOTCLASSPATH_APPEND, |
653 Option.XBOOTCLASSPATH_APPEND, |
655 Option.ENDORSEDDIRS, Option.DJAVA_ENDORSED_DIRS, |
654 Option.ENDORSEDDIRS, Option.DJAVA_ENDORSED_DIRS, |
656 Option.EXTDIRS, Option.DJAVA_EXT_DIRS); |
655 Option.EXTDIRS, Option.DJAVA_EXT_DIRS); |
657 } |
656 } |
667 return false; |
666 return false; |
668 } |
667 } |
669 |
668 |
670 option = canonicalize(option); |
669 option = canonicalize(option); |
671 optionValues.put(option, value); |
670 optionValues.put(option, value); |
672 if (option == BOOTCLASSPATH) { |
671 if (option == BOOT_CLASS_PATH) { |
673 optionValues.remove(XBOOTCLASSPATH_PREPEND); |
672 optionValues.remove(XBOOTCLASSPATH_PREPEND); |
674 optionValues.remove(XBOOTCLASSPATH_APPEND); |
673 optionValues.remove(XBOOTCLASSPATH_APPEND); |
675 } |
674 } |
676 searchPath = null; // reset to "uninitialized" |
675 searchPath = null; // reset to "uninitialized" |
677 return true; |
676 return true; |
680 // TODO: would be better if option aliasing was handled at a higher |
679 // TODO: would be better if option aliasing was handled at a higher |
681 // level |
680 // level |
682 private Option canonicalize(Option option) { |
681 private Option canonicalize(Option option) { |
683 switch (option) { |
682 switch (option) { |
684 case XBOOTCLASSPATH: |
683 case XBOOTCLASSPATH: |
685 return Option.BOOTCLASSPATH; |
684 return Option.BOOT_CLASS_PATH; |
686 case DJAVA_ENDORSED_DIRS: |
685 case DJAVA_ENDORSED_DIRS: |
687 return Option.ENDORSEDDIRS; |
686 return Option.ENDORSEDDIRS; |
688 case DJAVA_EXT_DIRS: |
687 case DJAVA_EXT_DIRS: |
689 return Option.EXTDIRS; |
688 return Option.EXTDIRS; |
690 default: |
689 default: |
711 } |
710 } |
712 |
711 |
713 SearchPath computePath() throws IOException { |
712 SearchPath computePath() throws IOException { |
714 SearchPath path = new SearchPath(); |
713 SearchPath path = new SearchPath(); |
715 |
714 |
716 String bootclasspathOpt = optionValues.get(BOOTCLASSPATH); |
715 String bootclasspathOpt = optionValues.get(BOOT_CLASS_PATH); |
717 String endorseddirsOpt = optionValues.get(ENDORSEDDIRS); |
716 String endorseddirsOpt = optionValues.get(ENDORSEDDIRS); |
718 String extdirsOpt = optionValues.get(EXTDIRS); |
717 String extdirsOpt = optionValues.get(EXTDIRS); |
719 String xbootclasspathPrependOpt = optionValues.get(XBOOTCLASSPATH_PREPEND); |
718 String xbootclasspathPrependOpt = optionValues.get(XBOOTCLASSPATH_PREPEND); |
720 String xbootclasspathAppendOpt = optionValues.get(XBOOTCLASSPATH_APPEND); |
719 String xbootclasspathAppendOpt = optionValues.get(XBOOTCLASSPATH_APPEND); |
721 path.addFiles(xbootclasspathPrependOpt); |
720 path.addFiles(xbootclasspathPrependOpt); |
1139 private Map<Path, Location> pathLocations; |
1138 private Map<Path, Location> pathLocations; |
1140 |
1139 |
1141 |
1140 |
1142 ModuleSourcePathLocationHandler() { |
1141 ModuleSourcePathLocationHandler() { |
1143 super(StandardLocation.MODULE_SOURCE_PATH, |
1142 super(StandardLocation.MODULE_SOURCE_PATH, |
1144 Option.MODULESOURCEPATH); |
1143 Option.MODULE_SOURCE_PATH); |
1145 } |
1144 } |
1146 |
1145 |
1147 @Override |
1146 @Override |
1148 boolean handleOption(Option option, String value) { |
1147 boolean handleOption(Option option, String value) { |
1149 init(value); |
1148 init(value); |
1471 handlersForOption = new EnumMap<>(Option.class); |
1470 handlersForOption = new EnumMap<>(Option.class); |
1472 |
1471 |
1473 BasicLocationHandler[] handlers = { |
1472 BasicLocationHandler[] handlers = { |
1474 new BootClassPathLocationHandler(), |
1473 new BootClassPathLocationHandler(), |
1475 new ClassPathLocationHandler(), |
1474 new ClassPathLocationHandler(), |
1476 new SimpleLocationHandler(StandardLocation.SOURCE_PATH, Option.SOURCEPATH), |
1475 new SimpleLocationHandler(StandardLocation.SOURCE_PATH, Option.SOURCE_PATH), |
1477 new SimpleLocationHandler(StandardLocation.ANNOTATION_PROCESSOR_PATH, Option.PROCESSORPATH), |
1476 new SimpleLocationHandler(StandardLocation.ANNOTATION_PROCESSOR_PATH, Option.PROCESSOR_PATH), |
1478 new SimpleLocationHandler(StandardLocation.ANNOTATION_PROCESSOR_MODULE_PATH, Option.PROCESSORMODULEPATH), |
1477 new SimpleLocationHandler(StandardLocation.ANNOTATION_PROCESSOR_MODULE_PATH, Option.PROCESSOR_MODULE_PATH), |
1479 new OutputLocationHandler(StandardLocation.CLASS_OUTPUT, Option.D), |
1478 new OutputLocationHandler(StandardLocation.CLASS_OUTPUT, Option.D), |
1480 new OutputLocationHandler(StandardLocation.SOURCE_OUTPUT, Option.S), |
1479 new OutputLocationHandler(StandardLocation.SOURCE_OUTPUT, Option.S), |
1481 new OutputLocationHandler(StandardLocation.NATIVE_HEADER_OUTPUT, Option.H), |
1480 new OutputLocationHandler(StandardLocation.NATIVE_HEADER_OUTPUT, Option.H), |
1482 new ModuleSourcePathLocationHandler(), |
1481 new ModuleSourcePathLocationHandler(), |
1483 // TODO: should UPGRADE_MODULE_PATH be merged with SYSTEM_MODULES? |
1482 // TODO: should UPGRADE_MODULE_PATH be merged with SYSTEM_MODULES? |
1484 new ModulePathLocationHandler(StandardLocation.UPGRADE_MODULE_PATH, Option.UPGRADEMODULEPATH), |
1483 new ModulePathLocationHandler(StandardLocation.UPGRADE_MODULE_PATH, Option.UPGRADE_MODULE_PATH), |
1485 new ModulePathLocationHandler(StandardLocation.MODULE_PATH, Option.MODULEPATH, Option.MP), |
1484 new ModulePathLocationHandler(StandardLocation.MODULE_PATH, Option.MODULE_PATH), |
1486 new SystemModulesLocationHandler(), |
1485 new SystemModulesLocationHandler(), |
1487 }; |
1486 }; |
1488 |
1487 |
1489 for (BasicLocationHandler h : handlers) { |
1488 for (BasicLocationHandler h : handlers) { |
1490 handlersForLocation.put(h.location, h); |
1489 handlersForLocation.put(h.location, h); |
1496 |
1495 |
1497 private Map<String, SearchPath> patchMap; |
1496 private Map<String, SearchPath> patchMap; |
1498 |
1497 |
1499 boolean handleOption(Option option, String value) { |
1498 boolean handleOption(Option option, String value) { |
1500 switch (option) { |
1499 switch (option) { |
1501 case XPATCH: |
1500 case PATCH_MODULE: |
1502 Map<String, SearchPath> map = new LinkedHashMap<>(); |
1501 if (value == null) { |
1503 int eq = value.indexOf('='); |
1502 patchMap = null; |
1504 if (eq > 0) { |
1503 } else { |
1505 String mName = value.substring(0, eq); |
1504 // Allow an extended syntax for --patch-module consisting of a series |
1506 SearchPath mPatchPath = new SearchPath() |
1505 // of values separated by NULL characters. This is to facilitate |
1507 .addFiles(value.substring(eq + 1)); |
1506 // supporting deferred file manager options on the command line. |
1508 boolean ok = true; |
1507 // See Option.PATCH_MODULE for the code that composes these multiple |
1509 for (Path p: mPatchPath) { |
1508 // values. |
1510 Path mi = p.resolve("module-info.class"); |
1509 for (String v : value.split("\0")) { |
1511 if (Files.exists(mi)) { |
1510 int eq = v.indexOf('='); |
1512 log.error(Errors.LocnModuleInfoNotAllowedOnPatchPath(mi)); |
1511 if (eq > 0) { |
1513 ok = false; |
1512 String mName = v.substring(0, eq); |
|
1513 SearchPath mPatchPath = new SearchPath() |
|
1514 .addFiles(v.substring(eq + 1)); |
|
1515 boolean ok = true; |
|
1516 for (Path p : mPatchPath) { |
|
1517 Path mi = p.resolve("module-info.class"); |
|
1518 if (Files.exists(mi)) { |
|
1519 log.error(Errors.LocnModuleInfoNotAllowedOnPatchPath(mi)); |
|
1520 ok = false; |
|
1521 } |
|
1522 } |
|
1523 if (ok) { |
|
1524 if (patchMap == null) { |
|
1525 patchMap = new LinkedHashMap<>(); |
|
1526 } |
|
1527 patchMap.put(mName, mPatchPath); |
|
1528 } |
|
1529 } else { |
|
1530 // Should not be able to get here; |
|
1531 // this should be caught and handled in Option.PATCH_MODULE |
|
1532 log.error(Errors.LocnInvalidArgForXpatch(value)); |
1514 } |
1533 } |
1515 } |
1534 } |
1516 if (ok && !mPatchPath.isEmpty()) { |
1535 } |
1517 map.computeIfAbsent(mName, (_x) -> new SearchPath()) |
|
1518 .addAll(mPatchPath); |
|
1519 } |
|
1520 } else { |
|
1521 log.error(Errors.LocnInvalidArgForXpatch(value)); |
|
1522 } |
|
1523 patchMap = map; |
|
1524 return true; |
1536 return true; |
1525 default: |
1537 default: |
1526 LocationHandler h = handlersForOption.get(option); |
1538 LocationHandler h = handlersForOption.get(option); |
1527 return (h == null ? false : h.handleOption(option, value)); |
1539 return (h == null ? false : h.handleOption(option, value)); |
1528 } |
1540 } |