use of java.lang.module.ModuleReference in project Bytecoder by mirkosertic.
the class DefaultRoots method compute.
/**
* Returns the default set of root modules for the unnamed module computed from
* the system modules observable with the given module finder.
*/
static Set<String> compute(ModuleFinder systemModuleFinder, ModuleFinder finder) {
Set<String> roots = new HashSet<>();
boolean hasJava = false;
if (systemModuleFinder.find(JAVA_SE).isPresent()) {
if (finder == systemModuleFinder || finder.find(JAVA_SE).isPresent()) {
// java.se is a system module
hasJava = true;
roots.add(JAVA_SE);
}
}
for (ModuleReference mref : systemModuleFinder.findAll()) {
String mn = mref.descriptor().name();
if (hasJava && mn.startsWith("java.")) {
// not a root
continue;
}
if (ModuleResolution.doNotResolveByDefault(mref)) {
// not a root
continue;
}
if ((finder == systemModuleFinder || finder.find(mn).isPresent())) {
// add as root if exports at least one package to all modules
ModuleDescriptor descriptor = mref.descriptor();
for (ModuleDescriptor.Exports e : descriptor.exports()) {
if (!e.isQualified()) {
roots.add(mn);
break;
}
}
}
}
return roots;
}
use of java.lang.module.ModuleReference in project Bytecoder by mirkosertic.
the class IllegalAccessMaps method generate.
/**
* Generate the maps of module to concealed and exported packages for
* the system modules that are observable with the given module finder.
*/
public static IllegalAccessMaps generate(ModuleFinder finder) {
Map<String, ModuleDescriptor> map = new HashMap<>();
finder.findAll().stream().map(ModuleReference::descriptor).forEach(md -> md.packages().forEach(pn -> map.putIfAbsent(pn, md)));
Map<String, Set<String>> concealedPackagesToOpen = new HashMap<>();
Map<String, Set<String>> exportedPackagesToOpen = new HashMap<>();
String rn = "jdk8_packages.dat";
InputStream in = IllegalAccessMaps.class.getResourceAsStream(rn);
if (in == null) {
throw new InternalError(rn + " not found");
}
try (BufferedReader br = new BufferedReader(new InputStreamReader(in, UTF_8))) {
br.lines().filter(line -> !line.isEmpty() && !line.startsWith("#")).forEach(pn -> {
ModuleDescriptor descriptor = map.get(pn);
if (descriptor != null && !isOpen(descriptor, pn)) {
String name = descriptor.name();
if (isExported(descriptor, pn)) {
exportedPackagesToOpen.computeIfAbsent(name, k -> new HashSet<>()).add(pn);
} else {
concealedPackagesToOpen.computeIfAbsent(name, k -> new HashSet<>()).add(pn);
}
}
});
} catch (IOException ioe) {
throw new UncheckedIOException(ioe);
}
return new IllegalAccessMaps(concealedPackagesToOpen, exportedPackagesToOpen);
}
use of java.lang.module.ModuleReference in project Bytecoder by mirkosertic.
the class ModuleBootstrap method loadModules.
/**
* Load/register the modules to the built-in class loaders.
*/
private static void loadModules(Configuration cf, Function<String, ClassLoader> clf) {
for (ResolvedModule resolvedModule : cf.modules()) {
ModuleReference mref = resolvedModule.reference();
String name = resolvedModule.name();
ClassLoader loader = clf.apply(name);
if (loader == null) {
// skip java.base as it is already loaded
if (!name.equals(JAVA_BASE)) {
BootLoader.loadModule(mref);
}
} else if (loader instanceof BuiltinClassLoader) {
((BuiltinClassLoader) loader).loadModule(mref);
}
}
}
Aggregations