use of java.lang.module.ModuleDescriptor in project Bytecoder by mirkosertic.
the class SystemModuleFinders method of.
/**
* Returns a ModuleFinder that is backed by the given SystemModules object.
*
* @apiNote The returned ModuleFinder is thread safe.
*/
static ModuleFinder of(SystemModules systemModules) {
ModuleDescriptor[] descriptors = systemModules.moduleDescriptors();
ModuleTarget[] targets = systemModules.moduleTargets();
ModuleHashes[] recordedHashes = systemModules.moduleHashes();
ModuleResolution[] moduleResolutions = systemModules.moduleResolutions();
int moduleCount = descriptors.length;
ModuleReference[] mrefs = new ModuleReference[moduleCount];
@SuppressWarnings(value = { "rawtypes", "unchecked" }) Map.Entry<String, ModuleReference>[] map = (Map.Entry<String, ModuleReference>[]) new Map.Entry[moduleCount];
Map<String, byte[]> nameToHash = generateNameToHash(recordedHashes);
for (int i = 0; i < moduleCount; i++) {
String name = descriptors[i].name();
HashSupplier hashSupplier = hashSupplier(nameToHash, name);
ModuleReference mref = toModuleReference(descriptors[i], targets[i], recordedHashes[i], hashSupplier, moduleResolutions[i]);
mrefs[i] = mref;
map[i] = Map.entry(name, mref);
}
return new SystemModuleFinder(mrefs, map);
}
use of java.lang.module.ModuleDescriptor 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.ModuleDescriptor 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.ModuleDescriptor in project Bytecoder by mirkosertic.
the class ModuleBootstrap method checkSplitPackages.
/**
* Checks for split packages between modules defined to the built-in class
* loaders.
*/
private static void checkSplitPackages(Configuration cf, Function<String, ClassLoader> clf) {
Map<String, String> packageToModule = new HashMap<>();
for (ResolvedModule resolvedModule : cf.modules()) {
ModuleDescriptor descriptor = resolvedModule.reference().descriptor();
String name = descriptor.name();
ClassLoader loader = clf.apply(name);
if (loader == null || loader instanceof BuiltinClassLoader) {
for (String p : descriptor.packages()) {
String other = packageToModule.putIfAbsent(p, name);
if (other != null) {
String msg = "Package " + p + " in both module " + name + " and module " + other;
throw new LayerInstantiationException(msg);
}
}
}
}
}
Aggregations