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

The following examples show how to use java.lang.module.ResolvedModule#reference() . 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: Loader.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a {@code Loader} that loads classes/resources from a collection
 * of modules.
 *
 * @throws IllegalArgumentException
 *         If two or more modules have the same package
 */
public Loader(Collection<ResolvedModule> modules, ClassLoader parent) {
    super(parent);

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

    Map<String, ModuleReference> nameToModule = new HashMap<>();
    Map<String, LoadedModule> localPackageToModule = new HashMap<>();
    for (ResolvedModule resolvedModule : modules) {
        ModuleReference mref = resolvedModule.reference();
        ModuleDescriptor descriptor = mref.descriptor();
        nameToModule.put(descriptor.name(), mref);
        descriptor.packages().forEach(pn -> {
            LoadedModule lm = new LoadedModule(mref);
            if (localPackageToModule.put(pn, lm) != null)
                throw new IllegalArgumentException("Package "
                    + pn + " in more than one module");
        });
    }
    this.nameToModule = nameToModule;
    this.localPackageToModule = localPackageToModule;

    this.acc = AccessController.getContext();
}
 
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: ModuleBootstrap.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
/**
 * Checks incubating status of modules in the configuration
 */
private static void checkIncubatingStatus(Configuration cf) {
    String incubating = null;
    for (ResolvedModule resolvedModule : cf.modules()) {
        ModuleReference mref = resolvedModule.reference();

        // emit warning if the WARN_INCUBATING module resolution bit set
        if (ModuleResolution.hasIncubatingWarning(mref)) {
            String mn = mref.descriptor().name();
            if (incubating == null) {
                incubating = mn;
            } else {
                incubating += ", " + mn;
            }
        }
    }
    if (incubating != null)
        warn("Using incubator modules: " + incubating);
}
 
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: Loader.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates a {@code Loader} that loads classes/resources from a collection
 * of modules.
 *
 * @throws IllegalArgumentException
 *         If two or more modules have the same package
 */
public Loader(Collection<ResolvedModule> modules, ClassLoader parent) {
    super(parent);

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

    Map<String, ModuleReference> nameToModule = new HashMap<>();
    Map<String, LoadedModule> localPackageToModule = new HashMap<>();
    for (ResolvedModule resolvedModule : modules) {
        ModuleReference mref = resolvedModule.reference();
        ModuleDescriptor descriptor = mref.descriptor();
        nameToModule.put(descriptor.name(), mref);
        descriptor.packages().forEach(pn -> {
            LoadedModule lm = new LoadedModule(mref);
            if (localPackageToModule.put(pn, lm) != null)
                throw new IllegalArgumentException("Package "
                    + pn + " in more than one module");
        });
    }
    this.nameToModule = nameToModule;
    this.localPackageToModule = localPackageToModule;

    this.acc = AccessController.getContext();
}
 
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: ModuleBootstrap.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Checks incubating status of modules in the configuration
 */
private static void checkIncubatingStatus(Configuration cf) {
    String incubating = null;
    for (ResolvedModule resolvedModule : cf.modules()) {
        ModuleReference mref = resolvedModule.reference();

        // emit warning if the WARN_INCUBATING module resolution bit set
        if (ModuleResolution.hasIncubatingWarning(mref)) {
            String mn = mref.descriptor().name();
            if (incubating == null) {
                incubating = mn;
            } else {
                incubating += ", " + mn;
            }
        }
    }
    if (incubating != null)
        warn("Using incubator modules: " + incubating);
}