Java Code Examples for java.lang.module.ResolvedModule#name()

The following examples show how to use java.lang.module.ResolvedModule#name() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Loader.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a {@code Loader} in a loader pool that loads classes/resources
 * from one module.
 */
public Loader(ResolvedModule resolvedModule,
              LoaderPool pool,
              ClassLoader parent)
{
    super("Loader-" + resolvedModule.name(), parent);

    this.pool = pool;
    this.parent = parent;

    ModuleReference mref = resolvedModule.reference();
    ModuleDescriptor descriptor = mref.descriptor();
    String mn = descriptor.name();
    this.nameToModule = Map.of(mn, mref);

    Map<String, LoadedModule> localPackageToModule = new HashMap<>();
    LoadedModule lm = new LoadedModule(mref);
    descriptor.packages().forEach(pn -> localPackageToModule.put(pn, lm));
    this.localPackageToModule = localPackageToModule;

    this.acc = AccessController.getContext();
}
 
Example 2
Source File: LoaderPool.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a pool of class loaders. Each module in the given configuration
 * is mapped to its own class loader in the pool. The class loader is
 * created with the given parent class loader as its parent.
 */
public LoaderPool(Configuration cf,
                  List<ModuleLayer> parentLayers,
                  ClassLoader parentLoader)
{
    Map<String, Loader> loaders = new HashMap<>();
    for (ResolvedModule resolvedModule : cf.modules()) {
        Loader loader = new Loader(resolvedModule, this, parentLoader);
        String mn = resolvedModule.name();
        loaders.put(mn, loader);
    }
    this.loaders = loaders;

    // complete the initialization
    loaders.values().forEach(l -> l.initRemotePackageMap(cf, parentLayers));
}
 
Example 3
Source File: ModuleBootstrap.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
/**
 * 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);
        }
    }
}
 
Example 4
Source File: ModuleLoaderMap.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
/**
 * 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);
}
 
Example 5
Source File: Loader.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates a {@code Loader} in a loader pool that loads classes/resources
 * from one module.
 */
public Loader(ResolvedModule resolvedModule,
              LoaderPool pool,
              ClassLoader parent)
{
    super("Loader-" + resolvedModule.name(), parent);

    this.pool = pool;
    this.parent = parent;

    ModuleReference mref = resolvedModule.reference();
    ModuleDescriptor descriptor = mref.descriptor();
    String mn = descriptor.name();
    this.nameToModule = Map.of(mn, mref);

    Map<String, LoadedModule> localPackageToModule = new HashMap<>();
    LoadedModule lm = new LoadedModule(mref);
    descriptor.packages().forEach(pn -> localPackageToModule.put(pn, lm));
    this.localPackageToModule = localPackageToModule;

    this.acc = AccessController.getContext();
}
 
Example 6
Source File: LoaderPool.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates a pool of class loaders. Each module in the given configuration
 * will be loaded its own class loader in the pool. The class loader is
 * created with the given parent class loader as its parent.
 */
public LoaderPool(Configuration cf,
                  List<ModuleLayer> parentLayers,
                  ClassLoader parentLoader)
{
    Map<String, Loader> loaders = new HashMap<>();
    for (ResolvedModule resolvedModule : cf.modules()) {
        Loader loader = new Loader(resolvedModule, this, parentLoader);
        String mn = resolvedModule.name();
        loaders.put(mn, loader);
    }
    this.loaders = loaders;

    // complete the initialization
    loaders.values().forEach(l -> l.initRemotePackageMap(cf, parentLayers));
}
 
Example 7
Source File: ModuleBootstrap.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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);
        }
    }
}
 
Example 8
Source File: ModuleLoaderMap.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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);
}