< 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,440 ****
}
/**
* @see JavaFileManager#getLocationForModule(Location, JavaFileObject, String)
*/
! Location getLocationForModule(Path dir) {
return null;
}
/**
* @see JavaFileManager#inferModuleName
--- 430,440 ----
}
/**
* @see JavaFileManager#getLocationForModule(Location, JavaFileObject, String)
*/
! Location getLocationForModule(Path dir) throws IOException {
return null;
}
/**
* @see JavaFileManager#inferModuleName
*** 543,553 ****
if (l == null) {
Path out = outputDir.resolve(name);
l = new ModuleLocationHandler(location.getName() + "[" + name + "]",
name,
Collections.singleton(out),
! true, false);
moduleLocations.put(name, l);
pathLocations.put(out.toAbsolutePath(), l);
}
return l;
}
--- 543,553 ----
if (l == null) {
Path out = outputDir.resolve(name);
l = new ModuleLocationHandler(location.getName() + "[" + name + "]",
name,
Collections.singleton(out),
! true);
moduleLocations.put(name, l);
pathLocations.put(out.toAbsolutePath(), l);
}
return l;
}
*** 862,894 ****
*/
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) {
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;
--- 862,879 ----
*/
private class ModuleLocationHandler extends LocationHandler implements Location {
protected final String name;
protected final String moduleName;
protected final Collection<Path> searchPath;
protected final boolean output;
ModuleLocationHandler(String name, String moduleName, Collection<Path> searchPath,
! boolean output) {
this.name = name;
this.moduleName = moduleName;
this.searchPath = searchPath;
this.output = output;
}
@Override @DefinedBy(Api.COMPILER)
public String getName() {
return name;
*** 907,917 ****
@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;
}
@Override // defined by LocationHandler
void setPaths(Iterable<? extends Path> files) throws IOException {
throw new UnsupportedOperationException();
--- 892,902 ----
@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 searchPath;
}
@Override // defined by LocationHandler
void setPaths(Iterable<? extends Path> files) throws IOException {
throw new UnsupportedOperationException();
*** 1061,1071 ****
try {
String moduleName = readModuleName(moduleInfoClass);
String name = location.getName()
+ "[" + pathIndex + ":" + moduleName + "]";
ModuleLocationHandler l = new ModuleLocationHandler(name, moduleName,
! Collections.singleton(path), false, true);
return Collections.singleton(l);
} catch (ModuleNameReader.BadClassFile e) {
log.error(Errors.LocnBadModuleInfo(path));
return Collections.emptySet();
} catch (IOException e) {
--- 1046,1056 ----
try {
String moduleName = readModuleName(moduleInfoClass);
String name = location.getName()
+ "[" + pathIndex + ":" + moduleName + "]";
ModuleLocationHandler l = new ModuleLocationHandler(name, moduleName,
! Collections.singleton(path), false);
return Collections.singleton(l);
} catch (ModuleNameReader.BadClassFile e) {
log.error(Errors.LocnBadModuleInfo(path));
return Collections.emptySet();
} catch (IOException e) {
*** 1086,1096 ****
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);
result.add(l);
}
return result;
}
--- 1071,1081 ----
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);
result.add(l);
}
return result;
}
*** 1103,1113 ****
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);
return Collections.singleton(l);
}
private Pair<String,Path> inferModuleName(Path p) {
if (Files.isDirectory(p)) {
--- 1088,1098 ----
String moduleName = module.fst;
Path modulePath = module.snd;
String name = location.getName()
+ "[" + pathIndex + ":" + moduleName + "]";
ModuleLocationHandler l = new ModuleLocationHandler(name, moduleName,
! Collections.singleton(modulePath), false);
return Collections.singleton(l);
}
private Pair<String,Path> inferModuleName(Path p) {
if (Files.isDirectory(p)) {
*** 1270,1280 ****
moduleLocations = new LinkedHashMap<>();
pathLocations = new LinkedHashMap<>();
map.forEach((k, v) -> {
String name = location.getName() + "[" + k + "]";
! ModuleLocationHandler h = new ModuleLocationHandler(name, k, v, false, false);
moduleLocations.put(k, h);
v.forEach(p -> pathLocations.put(normalize(p), h));
});
}
--- 1255,1265 ----
moduleLocations = new LinkedHashMap<>();
pathLocations = new LinkedHashMap<>();
map.forEach((k, v) -> {
String name = location.getName() + "[" + k + "]";
! ModuleLocationHandler h = new ModuleLocationHandler(name, k, v, false);
moduleLocations.put(k, h);
v.forEach(p -> pathLocations.put(normalize(p), h));
});
}
*** 1410,1419 ****
--- 1395,1405 ----
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,1493 ****
--- 1470,1485 ----
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,1606 ****
throw new IOException("can't find system classes", e);
}
}
systemModules = 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);
systemModules.put(moduleName, h);
}
}
}
}
! 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(),
! // 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);
! }
}
- }
-
- 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");
--- 1529,1575 ----
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);
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));
boolean ok = true;
for (Path p : mPatchPath) {
Path mi = p.resolve("module-info.class");
*** 1608,1635 ****
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());
}
--- 1577,1674 ----
log.error(Errors.LocnModuleInfoNotAllowedOnPatchPath(mi));
ok = false;
}
}
if (ok) {
! 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;
!
! 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,1673 ****
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) {
LocationHandler h = getHandler(location);
return (h == null ? null : h.getLocationForModule(dir));
}
String inferModuleName(Location location) {
--- 1702,1712 ----
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) throws IOException {
LocationHandler h = getHandler(location);
return (h == null ? null : h.getLocationForModule(dir));
}
String inferModuleName(Location location) {
< prev index next >