< prev index next >
src/jdk.compiler/share/classes/com/sun/tools/javac/file/Locations.java
Print this page
rev 3947 : imported patch xmodule-to-patch-module
@@ -430,11 +430,11 @@
}
/**
* @see JavaFileManager#getLocationForModule(Location, JavaFileObject, String)
*/
- Location getLocationForModule(Path dir) {
+ Location getLocationForModule(Path dir) throws IOException {
return null;
}
/**
* @see JavaFileManager#inferModuleName
@@ -543,11 +543,11 @@
if (l == null) {
Path out = outputDir.resolve(name);
l = new ModuleLocationHandler(location.getName() + "[" + name + "]",
name,
Collections.singleton(out),
- true, false);
+ true);
moduleLocations.put(name, l);
pathLocations.put(out.toAbsolutePath(), l);
}
return l;
}
@@ -862,33 +862,18 @@
*/
private class ModuleLocationHandler extends LocationHandler implements Location {
protected final String name;
protected final String moduleName;
protected final Collection<Path> searchPath;
- protected final Collection<Path> searchPathWithOverrides;
protected final boolean output;
ModuleLocationHandler(String name, String moduleName, Collection<Path> searchPath,
- boolean output, boolean allowOverrides) {
+ boolean output) {
this.name = name;
this.moduleName = moduleName;
this.searchPath = searchPath;
this.output = output;
-
- if (allowOverrides && patchMap != null) {
- SearchPath mPatch = patchMap.get(moduleName);
- if (mPatch != null) {
- SearchPath sp = new SearchPath();
- sp.addAll(mPatch);
- sp.addAll(searchPath);
- searchPathWithOverrides = sp;
- } else {
- searchPathWithOverrides = searchPath;
- }
- } else {
- searchPathWithOverrides = searchPath;
- }
}
@Override @DefinedBy(Api.COMPILER)
public String getName() {
return name;
@@ -907,11 +892,11 @@
@Override // defined by LocationHandler
Collection<Path> getPaths() {
// For now, we always return searchPathWithOverrides. This may differ from the
// JVM behavior if there is a module-info.class to be found in the overriding
// classes.
- return searchPathWithOverrides;
+ return searchPath;
}
@Override // defined by LocationHandler
void setPaths(Iterable<? extends Path> files) throws IOException {
throw new UnsupportedOperationException();
@@ -1061,11 +1046,11 @@
try {
String moduleName = readModuleName(moduleInfoClass);
String name = location.getName()
+ "[" + pathIndex + ":" + moduleName + "]";
ModuleLocationHandler l = new ModuleLocationHandler(name, moduleName,
- Collections.singleton(path), false, true);
+ Collections.singleton(path), false);
return Collections.singleton(l);
} catch (ModuleNameReader.BadClassFile e) {
log.error(Errors.LocnBadModuleInfo(path));
return Collections.emptySet();
} catch (IOException e) {
@@ -1086,11 +1071,11 @@
String moduleName = module.fst;
Path modulePath = module.snd;
String name = location.getName()
+ "[" + pathIndex + "." + (index++) + ":" + moduleName + "]";
ModuleLocationHandler l = new ModuleLocationHandler(name, moduleName,
- Collections.singleton(modulePath), false, true);
+ Collections.singleton(modulePath), false);
result.add(l);
}
return result;
}
@@ -1103,11 +1088,11 @@
String moduleName = module.fst;
Path modulePath = module.snd;
String name = location.getName()
+ "[" + pathIndex + ":" + moduleName + "]";
ModuleLocationHandler l = new ModuleLocationHandler(name, moduleName,
- Collections.singleton(modulePath), false, true);
+ Collections.singleton(modulePath), false);
return Collections.singleton(l);
}
private Pair<String,Path> inferModuleName(Path p) {
if (Files.isDirectory(p)) {
@@ -1270,11 +1255,11 @@
moduleLocations = new LinkedHashMap<>();
pathLocations = new LinkedHashMap<>();
map.forEach((k, v) -> {
String name = location.getName() + "[" + k + "]";
- ModuleLocationHandler h = new ModuleLocationHandler(name, k, v, false, false);
+ ModuleLocationHandler h = new ModuleLocationHandler(name, k, v, false);
moduleLocations.put(k, h);
v.forEach(p -> pathLocations.put(normalize(p), h));
});
}
@@ -1410,10 +1395,11 @@
private class SystemModulesLocationHandler extends BasicLocationHandler {
private Path systemJavaHome;
private Path modules;
private Map<String, ModuleLocationHandler> systemModules;
+ private Map<Path, Location> pathLocations;
SystemModulesLocationHandler() {
super(StandardLocation.SYSTEM_MODULES, Option.SYSTEM);
systemJavaHome = Locations.javaHome;
}
@@ -1484,10 +1470,16 @@
initSystemModules();
return systemModules.get(name);
}
@Override
+ Location getLocationForModule(Path dir) throws IOException {
+ initSystemModules();
+ return (pathLocations == null) ? null : pathLocations.get(dir);
+ }
+
+ @Override
Iterable<Set<Location>> listLocationsForModules() throws IOException {
initSystemModules();
Set<Location> locns = new LinkedHashSet<>();
for (Location l: systemModules.values())
locns.add(l);
@@ -1537,70 +1529,47 @@
throw new IOException("can't find system classes", e);
}
}
systemModules = new LinkedHashMap<>();
+ pathLocations = new LinkedHashMap<>();
try (DirectoryStream<Path> stream = Files.newDirectoryStream(modules, Files::isDirectory)) {
for (Path entry : stream) {
String moduleName = entry.getFileName().toString();
String name = location.getName() + "[" + moduleName + "]";
ModuleLocationHandler h = new ModuleLocationHandler(name, moduleName,
- Collections.singleton(entry), false, true);
+ Collections.singleton(entry), false);
systemModules.put(moduleName, h);
+ pathLocations.put(normalize(entry), h);
}
}
}
}
- Map<Location, LocationHandler> handlersForLocation;
- Map<Option, LocationHandler> handlersForOption;
+ private class PatchModulesLocationHandler extends BasicLocationHandler {
+ private final Map<String, ModuleLocationHandler> moduleLocations = new HashMap<>();
+ private final Map<Path, Location> pathLocations = new HashMap<>();
- void initHandlers() {
- handlersForLocation = new HashMap<>();
- handlersForOption = new EnumMap<>(Option.class);
-
- BasicLocationHandler[] handlers = {
- new BootClassPathLocationHandler(),
- new ClassPathLocationHandler(),
- new SimpleLocationHandler(StandardLocation.SOURCE_PATH, Option.SOURCE_PATH),
- new SimpleLocationHandler(StandardLocation.ANNOTATION_PROCESSOR_PATH, Option.PROCESSOR_PATH),
- new SimpleLocationHandler(StandardLocation.ANNOTATION_PROCESSOR_MODULE_PATH, Option.PROCESSOR_MODULE_PATH),
- new OutputLocationHandler(StandardLocation.CLASS_OUTPUT, Option.D),
- new OutputLocationHandler(StandardLocation.SOURCE_OUTPUT, Option.S),
- new OutputLocationHandler(StandardLocation.NATIVE_HEADER_OUTPUT, Option.H),
- new ModuleSourcePathLocationHandler(),
- // TODO: should UPGRADE_MODULE_PATH be merged with SYSTEM_MODULES?
- new ModulePathLocationHandler(StandardLocation.UPGRADE_MODULE_PATH, Option.UPGRADE_MODULE_PATH),
- new ModulePathLocationHandler(StandardLocation.MODULE_PATH, Option.MODULE_PATH),
- new SystemModulesLocationHandler(),
- };
-
- for (BasicLocationHandler h : handlers) {
- handlersForLocation.put(h.location, h);
- for (Option o : h.options) {
- handlersForOption.put(o, h);
- }
+ PatchModulesLocationHandler() {
+ super(StandardLocation.PATCH_MODULE_PATH, Option.PATCH_MODULE);
}
- }
-
- private Map<String, SearchPath> patchMap;
+ @Override
boolean handleOption(Option option, String value) {
- switch (option) {
- case PATCH_MODULE:
- if (value == null) {
- patchMap = null;
- } else {
+ if (!options.contains(option)) {
+ return false;
+ }
+
// Allow an extended syntax for --patch-module consisting of a series
// of values separated by NULL characters. This is to facilitate
// supporting deferred file manager options on the command line.
// See Option.PATCH_MODULE for the code that composes these multiple
// values.
for (String v : value.split("\0")) {
int eq = v.indexOf('=');
if (eq > 0) {
- String mName = v.substring(0, eq);
+ String moduleName = v.substring(0, eq);
SearchPath mPatchPath = new SearchPath()
.addFiles(v.substring(eq + 1));
boolean ok = true;
for (Path p : mPatchPath) {
Path mi = p.resolve("module-info.class");
@@ -1608,28 +1577,98 @@
log.error(Errors.LocnModuleInfoNotAllowedOnPatchPath(mi));
ok = false;
}
}
if (ok) {
- if (patchMap == null) {
- patchMap = new LinkedHashMap<>();
+ String name = location.getName() + "[" + moduleName + "]";
+ ModuleLocationHandler h = new ModuleLocationHandler(name, moduleName, mPatchPath, false);
+ moduleLocations.put(moduleName, h);
+ for (Path r : mPatchPath) {
+ pathLocations.put(normalize(r), h);
}
- patchMap.put(mName, mPatchPath);
}
} else {
// Should not be able to get here;
// this should be caught and handled in Option.PATCH_MODULE
log.error(Errors.LocnInvalidArgForXpatch(value));
}
}
- }
+
return true;
- default:
+ }
+
+ @Override
+ boolean isSet() {
+ return !moduleLocations.isEmpty();
+ }
+
+ @Override
+ Collection<Path> getPaths() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ void setPaths(Iterable<? extends Path> files) throws IOException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ Location getLocationForModule(String name) throws IOException {
+ return moduleLocations.get(name);
+ }
+
+ @Override
+ Location getLocationForModule(Path dir) throws IOException {
+ return (pathLocations == null) ? null : pathLocations.get(dir);
+ }
+
+ @Override
+ Iterable<Set<Location>> listLocationsForModules() throws IOException {
+ Set<Location> locns = new LinkedHashSet<>();
+ for (Location l: moduleLocations.values())
+ locns.add(l);
+ return Collections.singleton(locns);
+ }
+
+ }
+
+ Map<Location, LocationHandler> handlersForLocation;
+ Map<Option, LocationHandler> handlersForOption;
+
+ void initHandlers() {
+ handlersForLocation = new HashMap<>();
+ handlersForOption = new EnumMap<>(Option.class);
+
+ BasicLocationHandler[] handlers = {
+ new BootClassPathLocationHandler(),
+ new ClassPathLocationHandler(),
+ new SimpleLocationHandler(StandardLocation.SOURCE_PATH, Option.SOURCE_PATH),
+ new SimpleLocationHandler(StandardLocation.ANNOTATION_PROCESSOR_PATH, Option.PROCESSOR_PATH),
+ new SimpleLocationHandler(StandardLocation.ANNOTATION_PROCESSOR_MODULE_PATH, Option.PROCESSOR_MODULE_PATH),
+ new OutputLocationHandler(StandardLocation.CLASS_OUTPUT, Option.D),
+ new OutputLocationHandler(StandardLocation.SOURCE_OUTPUT, Option.S),
+ new OutputLocationHandler(StandardLocation.NATIVE_HEADER_OUTPUT, Option.H),
+ new ModuleSourcePathLocationHandler(),
+ new PatchModulesLocationHandler(),
+ // TODO: should UPGRADE_MODULE_PATH be merged with SYSTEM_MODULES?
+ new ModulePathLocationHandler(StandardLocation.UPGRADE_MODULE_PATH, Option.UPGRADE_MODULE_PATH),
+ new ModulePathLocationHandler(StandardLocation.MODULE_PATH, Option.MODULE_PATH),
+ new SystemModulesLocationHandler(),
+ };
+
+ for (BasicLocationHandler h : handlers) {
+ handlersForLocation.put(h.location, h);
+ for (Option o : h.options) {
+ handlersForOption.put(o, h);
+ }
+ }
+ }
+
+ boolean handleOption(Option option, String value) {
LocationHandler h = handlersForOption.get(option);
return (h == null ? false : h.handleOption(option, value));
}
- }
boolean hasLocation(Location location) {
LocationHandler h = getHandler(location);
return (h == null ? false : h.isSet());
}
@@ -1663,11 +1702,11 @@
Location getLocationForModule(Location location, String name) throws IOException {
LocationHandler h = getHandler(location);
return (h == null ? null : h.getLocationForModule(name));
}
- Location getLocationForModule(Location location, Path dir) {
+ Location getLocationForModule(Location location, Path dir) throws IOException {
LocationHandler h = getHandler(location);
return (h == null ? null : h.getLocationForModule(dir));
}
String inferModuleName(Location location) {
< prev index next >