< prev index next >
src/jdk.compiler/share/classes/com/sun/tools/javac/file/Locations.java
Print this page
@@ -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,20 +1529,98 @@
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);
+ }
+ }
+ }
+ }
+
+ private class PatchModulesLocationHandler extends BasicLocationHandler {
+ private final Map<String, ModuleLocationHandler> moduleLocations = new HashMap<>();
+ private final Map<Path, Location> pathLocations = new HashMap<>();
+
+ PatchModulesLocationHandler() {
+ super(StandardLocation.PATCH_MODULE_PATH, Option.PATCH_MODULE);
+ }
+
+ @Override
+ boolean handleOption(Option option, String value) {
+ 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 moduleName = v.substring(0, eq);
+ SearchPath mPatchPath = new SearchPath()
+ .addFiles(v.substring(eq + 1));
+ 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);
+ }
+ } 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;
+ }
+
+ @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;
@@ -1566,10 +1636,11 @@
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(),
};
@@ -1580,56 +1651,14 @@
handlersForOption.put(o, h);
}
}
}
- private Map<String, SearchPath> patchMap;
-
boolean handleOption(Option option, String value) {
- switch (option) {
- case PATCH_MODULE:
- if (value == null) {
- patchMap = null;
- } else {
- // 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);
- SearchPath mPatchPath = new SearchPath()
- .addFiles(v.substring(eq + 1));
- boolean ok = true;
- for (Path p : mPatchPath) {
- Path mi = p.resolve("module-info.class");
- if (Files.exists(mi)) {
- log.error(Errors.LocnModuleInfoNotAllowedOnPatchPath(mi));
- ok = false;
- }
- }
- if (ok) {
- if (patchMap == null) {
- patchMap = new LinkedHashMap<>();
- }
- 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:
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 +1692,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 >