use of java.lang.module.ResolvedModule in project Bytecoder by mirkosertic.
the class ModuleLoaderMap method mappingFunction.
/**
* Returns the function to map modules in the given configuration to the
* built-in class loaders.
*/
static Function<String, ClassLoader> mappingFunction(Configuration cf) {
Set<String> bootModules = bootModules();
Set<String> platformModules = platformModules();
ClassLoader platformClassLoader = ClassLoaders.platformClassLoader();
ClassLoader appClassLoader = ClassLoaders.appClassLoader();
Map<String, ClassLoader> map = new HashMap<>();
for (ResolvedModule resolvedModule : cf.modules()) {
String mn = resolvedModule.name();
if (!bootModules.contains(mn)) {
if (platformModules.contains(mn)) {
map.put(mn, platformClassLoader);
} else {
map.put(mn, appClassLoader);
}
}
}
return new Mapper(map);
}
use of java.lang.module.ResolvedModule 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);
}
}
}
}
}
use of java.lang.module.ResolvedModule 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);
}
}
}
use of java.lang.module.ResolvedModule 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