use of java.lang.module.Configuration in project Bytecoder by mirkosertic.
the class Loader method initRemotePackageMap.
/**
* Completes initialization of this Loader. This method populates
* remotePackageToLoader with the packages of the remote modules, where
* "remote modules" are the modules read by modules defined to this loader.
*
* @param cf the Configuration containing at least modules to be defined to
* this class loader
*
* @param parentModuleLayers the parent ModuleLayers
*/
public Loader initRemotePackageMap(Configuration cf, List<ModuleLayer> parentModuleLayers) {
for (String name : nameToModule.keySet()) {
ResolvedModule resolvedModule = cf.findModule(name).get();
assert resolvedModule.configuration() == cf;
for (ResolvedModule other : resolvedModule.reads()) {
String mn = other.name();
ClassLoader loader;
if (other.configuration() == cf) {
// loader then the packages are local.
if (pool == null) {
assert nameToModule.containsKey(mn);
continue;
}
loader = pool.loaderFor(mn);
assert loader != null;
} else {
// find the layer for the target module
ModuleLayer layer = parentModuleLayers.stream().map(parent -> findModuleLayer(parent, other.configuration())).flatMap(Optional::stream).findAny().orElseThrow(() -> new InternalError("Unable to find parent layer"));
// boot loader
assert layer.findModule(mn).isPresent();
loader = layer.findLoader(mn);
if (loader == null)
loader = ClassLoaders.platformClassLoader();
}
// find the packages that are exported to the target module
String target = resolvedModule.name();
ModuleDescriptor descriptor = other.reference().descriptor();
for (ModuleDescriptor.Exports e : descriptor.exports()) {
boolean delegate;
if (e.isQualified()) {
// qualified export in same configuration
delegate = (other.configuration() == cf) && e.targets().contains(target);
} else {
// unqualified
delegate = true;
}
if (delegate) {
String pn = e.source();
ClassLoader l = remotePackageToLoader.putIfAbsent(pn, loader);
if (l != null && l != loader) {
throw new IllegalArgumentException("Package " + pn + " cannot be imported from multiple loaders");
}
}
}
}
}
return this;
}
use of java.lang.module.Configuration in project Bytecoder by mirkosertic.
the class NamedPackage method location.
/**
* Returns the location of the module if this named package is in
* a named module; otherwise, returns null.
*/
URI location() {
if (module.isNamed() && module.getLayer() != null) {
Configuration cf = module.getLayer().configuration();
ModuleReference mref = cf.findModule(module.getName()).get().reference();
return mref.location().orElse(null);
}
return null;
}
use of java.lang.module.Configuration in project Bytecoder by mirkosertic.
the class ModuleBootstrap method createBootLayerForValidation.
/**
* Create a boot module layer for validation that resolves all
* system modules.
*/
private static ModuleLayer createBootLayerForValidation() {
Set<String> allSystem = ModuleFinder.ofSystem().findAll().stream().map(ModuleReference::descriptor).map(ModuleDescriptor::name).collect(Collectors.toSet());
Configuration cf = SharedSecrets.getJavaLangModuleAccess().resolveAndBind(ModuleFinder.ofSystem(), allSystem, null);
Function<String, ClassLoader> clf = ModuleLoaderMap.mappingFunction(cf);
return ModuleLayer.empty().defineModules(cf, clf);
}
use of java.lang.module.Configuration in project junit5 by junit-team.
the class ModuleUtils method streamResolvedModules.
/**
* Stream resolved modules from the supplied layer.
*/
private static Stream<ResolvedModule> streamResolvedModules(Predicate<String> moduleNamePredicate, ModuleLayer layer) {
logger.debug(() -> "Streaming modules for layer @" + System.identityHashCode(layer) + ": " + layer);
Configuration configuration = layer.configuration();
logger.debug(() -> "Module layer configuration: " + configuration);
Stream<ResolvedModule> stream = configuration.modules().stream();
return stream.filter(module -> moduleNamePredicate.test(module.name()));
}
Aggregations