java.lang.module.ResolvedModule Java Examples

The following examples show how to use java.lang.module.ResolvedModule. 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: ConfigurationTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Basic test of "requires static":
 *     m1 requires static m2
 *     m2
 *     resolve m1
 */
public void testRequiresStatic2() {
    ModuleDescriptor descriptor1 = newBuilder("m1")
            .requires(Set.of(Requires.Modifier.STATIC), "m2")
            .build();

    ModuleDescriptor descriptor2 = newBuilder("m2")
            .build();

    ModuleFinder finder = ModuleUtils.finderOf(descriptor1, descriptor2);

    Configuration cf = resolve(finder, "m1");

    assertTrue(cf.modules().size() == 1);

    ResolvedModule m1 = cf.findModule("m1").get();
    assertTrue(m1.reads().size() == 0);
}
 
Example #2
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 #3
Source File: ModuleLayer.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
/**
 * Checks a configuration and the module-to-loader mapping to ensure that
 * no two modules mapped to the same class loader have the same package.
 * It also checks that no two automatic modules have the same package.
 *
 * @throws LayerInstantiationException
 */
private static void checkForDuplicatePkgs(Configuration cf,
                                          Function<String, ClassLoader> clf)
{
    // HashMap allows null keys
    Map<ClassLoader, Set<String>> loaderToPackages = new HashMap<>();
    for (ResolvedModule resolvedModule : cf.modules()) {
        ModuleDescriptor descriptor = resolvedModule.reference().descriptor();
        ClassLoader loader = clf.apply(descriptor.name());

        Set<String> loaderPackages
            = loaderToPackages.computeIfAbsent(loader, k -> new HashSet<>());

        for (String pkg : descriptor.packages()) {
            boolean added = loaderPackages.add(pkg);
            if (!added) {
                throw fail("More than one module with package %s mapped" +
                           " to the same class loader", pkg);
            }
        }
    }
}
 
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: ModuleBootstrap.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
/**
 * 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);
                }
            }
        }
    }
}
 
Example #6
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 #7
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 #8
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 #9
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 #10
Source File: Module.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
/**
 * Find the runtime Module corresponding to the given ResolvedModule
 * in the given parent layer (or its parents).
 */
private static Module findModule(ModuleLayer parent,
                                 ResolvedModule resolvedModule) {
    Configuration cf = resolvedModule.configuration();
    String dn = resolvedModule.name();
    return parent.layers()
            .filter(l -> l.configuration() == cf)
            .findAny()
            .map(layer -> {
                Optional<Module> om = layer.findModule(dn);
                assert om.isPresent() : dn + " not found in layer";
                Module m = om.get();
                assert m.getLayer() == layer : m + " not in expected layer";
                return m;
            })
            .orElse(null);
}
 
Example #11
Source File: ModuleDotGraph.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private static Set<String> javaSE() {
    String root = "java.se.ee";
    ModuleFinder system = ModuleFinder.ofSystem();
    if (system.find(root).isPresent()) {
        return Stream.concat(Stream.of(root),
                             Configuration.empty().resolve(system,
                                                           ModuleFinder.of(),
                                                           Set.of(root))
                                          .findModule(root).get()
                                          .reads().stream()
                                          .map(ResolvedModule::name))
                     .collect(toSet());
    } else {
        // approximation
        return system.findAll().stream()
            .map(ModuleReference::descriptor)
            .map(ModuleDescriptor::name)
            .filter(name -> name.startsWith("java.") &&
                                !name.equals("java.smartcardio"))
            .collect(Collectors.toSet());
    }
}
 
Example #12
Source File: ModuleSummary.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
ModuleTableRow(ModuleSummary ms) {
    this.ms = ms;
    Configuration cf = resolve(Set.of(ms.name()));
    this.deps = cf.modules().stream()
            .map(ResolvedModule::reference)
            .map(ModuleReference::descriptor)
            .collect(Collectors.toSet());
    int count = (ms.numClasses() > 0 ? 1 : 0) +
                (ms.numResources() > 0 ? 1 : 0) +
                (ms.numConfigs() > 0 ? 1 : 0) +
                (ms.numNativeLibraries() > 0 ? 1 : 0) +
                (ms.numNativeLibrariesDebug() > 0 ? 1 : 0) +
                (ms.numCommands() > 0 ? 1 : 0) +
                (ms.numCommandsDebug() > 0 ? 1 : 0);
    this.aggregator = ms.numClasses() == 1 && count == 1; // only module-info.class

    // 5 fixed rows (name + 2 transitive count/size + 2 blank rows)
    this.maxRows = 5 + count + (aggregator && !aggregatorNote ? 2 : 0);
}
 
Example #13
Source File: Module.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Find the runtime Module corresponding to the given ResolvedModule
 * in the given parent layer (or its parents).
 */
private static Module findModule(ModuleLayer parent,
                                 ResolvedModule resolvedModule) {
    Configuration cf = resolvedModule.configuration();
    String dn = resolvedModule.name();
    return parent.layers()
            .filter(l -> l.configuration() == cf)
            .findAny()
            .map(layer -> {
                Optional<Module> om = layer.findModule(dn);
                assert om.isPresent() : dn + " not found in layer";
                Module m = om.get();
                assert m.getLayer() == layer : m + " not in expected layer";
                return m;
            })
            .orElse(null);
}
 
Example #14
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 #15
Source File: ConfigurationTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Basic test of "requires static":
 *     m1 requires static m2
 *     m2
 *     resolve m1, m2
 */
public void testRequiresStatic3() {
    ModuleDescriptor descriptor1 = newBuilder("m1")
            .requires(Set.of(Requires.Modifier.STATIC), "m2")
            .build();

    ModuleDescriptor descriptor2 = newBuilder("m2")
            .build();

    ModuleFinder finder = ModuleUtils.finderOf(descriptor1, descriptor2);

    Configuration cf = resolve(finder, "m1", "m2");

    assertTrue(cf.modules().size() == 2);

    ResolvedModule m1 = cf.findModule("m1").get();
    ResolvedModule m2 = cf.findModule("m2").get();

    assertTrue(m1.reads().size() == 1);
    assertTrue(m1.reads().contains(m2));

    assertTrue(m2.reads().size() == 0);
}
 
Example #16
Source File: Main.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    String mn = args[0];

    ModuleReference mref = ModuleLayer.boot()
            .configuration()
            .findModule(mn)
            .map(ResolvedModule::reference)
            .orElseThrow(() -> new RuntimeException(mn + " not resolved!!"));

    try (ModuleReader reader = mref.open()) {
        reader.list().forEach(name -> {
            testFindUnchecked(name);

            // if the resource is a directory then find without trailing slash
            if (name.endsWith("/")) {
                testFindUnchecked(name.substring(0, name.length() - 1));
            }
        });
    }
}
 
Example #17
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);
}
 
Example #18
Source File: ConfigurationTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Test the scenario where a module contains a package p and reads
 * a module that also contains a package p.
 */
public void testContainsPackageInSelfAndOther() {
    ModuleDescriptor descriptor1 = newBuilder("m1")
            .requires("m2")
            .packages(Set.of("p"))
            .build();

    ModuleDescriptor descriptor2 = newBuilder("m2")
            .packages(Set.of("p"))
            .build();

    ModuleFinder finder = ModuleUtils.finderOf(descriptor1, descriptor2);

    Configuration cf = resolve(finder, "m1");

    assertTrue(cf.modules().size() == 2);
    assertTrue(cf.findModule("m1").isPresent());
    assertTrue(cf.findModule("m2").isPresent());

    // m1 reads m2, m2 reads nothing
    ResolvedModule m1 = cf.findModule("m1").get();
    ResolvedModule m2 = cf.findModule("m2").get();
    assertTrue(m1.reads().size() == 1);
    assertTrue(m1.reads().contains(m2));
    assertTrue(m2.reads().size() == 0);
}
 
Example #19
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);
}
 
Example #20
Source File: ModuleBootstrap.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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);
                }
            }
        }

    }
}
 
Example #21
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 #22
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 #23
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 #24
Source File: ModuleLayer.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Checks a configuration and the module-to-loader mapping to ensure that
 * no two modules mapped to the same class loader have the same package.
 * It also checks that no two automatic modules have the same package.
 *
 * @throws LayerInstantiationException
 */
private static void checkForDuplicatePkgs(Configuration cf,
                                          Function<String, ClassLoader> clf)
{
    // HashMap allows null keys
    Map<ClassLoader, Set<String>> loaderToPackages = new HashMap<>();
    for (ResolvedModule resolvedModule : cf.modules()) {
        ModuleDescriptor descriptor = resolvedModule.reference().descriptor();
        ClassLoader loader = clf.apply(descriptor.name());

        Set<String> loaderPackages
            = loaderToPackages.computeIfAbsent(loader, k -> new HashSet<>());

        for (String pkg : descriptor.packages()) {
            boolean added = loaderPackages.add(pkg);
            if (!added) {
                throw fail("More than one module with package %s mapped" +
                           " to the same class loader", pkg);
            }
        }
    }
}
 
Example #25
Source File: ConfigurationTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Basic test of "requires static":
 * The test consists of three configurations:
 * - Configuration cf1: m1, m2
 * - Configuration cf2: m3 requires m1, requires static m2
 */
public void testRequiresStatic5() {
    ModuleDescriptor descriptor1 = newBuilder("m1")
            .build();

    ModuleDescriptor descriptor2 = newBuilder("m2")
            .build();

    ModuleFinder finder1 = ModuleUtils.finderOf(descriptor1, descriptor2);

    Configuration cf1 = resolve(finder1, "m1", "m2");

    assertTrue(cf1.modules().size() == 2);
    assertTrue(cf1.findModule("m1").isPresent());
    assertTrue(cf1.findModule("m2").isPresent());

    ModuleDescriptor descriptor3 = newBuilder("m3")
            .requires("m1")
            .requires(Set.of(Requires.Modifier.STATIC), "m2")
            .build();

    ModuleFinder finder2 = ModuleUtils.finderOf(descriptor3);

    Configuration cf2 = resolve(cf1, finder2, "m3");

    assertTrue(cf2.modules().size() == 1);
    assertTrue(cf2.findModule("m3").isPresent());

    ResolvedModule m1 = cf1.findModule("m1").get();
    ResolvedModule m2 = cf1.findModule("m2").get();
    ResolvedModule m3 = cf2.findModule("m3").get();

    assertTrue(m3.reads().size() == 2);
    assertTrue(m3.reads().contains(m1));
    assertTrue(m3.reads().contains(m2));
}
 
Example #26
Source File: ConfigurationTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Basic test of binding services
 *     m1 uses p.S
 *     m2 provides p.S
 */
public void testServiceBinding1() {

    ModuleDescriptor descriptor1 = newBuilder("m1")
            .exports("p")
            .uses("p.S")
            .build();

    ModuleDescriptor descriptor2 = newBuilder("m2")
            .requires("m1")
            .provides("p.S", List.of("q.T"))
            .build();

    ModuleFinder finder = ModuleUtils.finderOf(descriptor1, descriptor2);

    Configuration cf = resolveAndBind(finder, "m1");

    assertTrue(cf.modules().size() == 2);
    assertTrue(cf.findModule("m1").isPresent());
    assertTrue(cf.findModule("m2").isPresent());
    assertTrue(cf.parents().size() == 1);
    assertTrue(cf.parents().get(0) == Configuration.empty());

    ResolvedModule m1 = cf.findModule("m1").get();
    ResolvedModule m2 = cf.findModule("m2").get();

    assertTrue(m1.configuration() == cf);
    assertTrue(m1.reads().size() == 0);

    assertTrue(m2.configuration() == cf);
    assertTrue(m2.reads().size() == 1);
    assertTrue(m2.reads().contains(m1));
}
 
Example #27
Source File: ConfigurationTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Basic test of "requires static":
 * - Configuration cf1: m2 requires transitive static m1
 * - Configuration cf2: m3 requires m2
 */
public void testRequiresStatic8() {
    ModuleDescriptor descriptor1 = null;  // not observable

    ModuleDescriptor descriptor2 = newBuilder("m2")
            .requires(Set.of(Requires.Modifier.TRANSITIVE,
                            Requires.Modifier.STATIC),
                    "m1")
            .build();

    ModuleFinder finder1 = ModuleUtils.finderOf(descriptor2);

    Configuration cf1 = resolve(finder1, "m2");

    assertTrue(cf1.modules().size() == 1);
    assertTrue(cf1.findModule("m2").isPresent());
    ResolvedModule m2 = cf1.findModule("m2").get();
    assertTrue(m2.reads().isEmpty());

    ModuleDescriptor descriptor3 = newBuilder("m3")
            .requires("m2")
            .build();

    ModuleFinder finder2 = ModuleUtils.finderOf(descriptor3);

    Configuration cf2 = resolve(cf1, finder2, "m3");

    assertTrue(cf2.modules().size() == 1);
    assertTrue(cf2.findModule("m3").isPresent());
    ResolvedModule m3 = cf2.findModule("m3").get();
    assertTrue(m3.reads().size() == 1);
    assertTrue(m3.reads().contains(m2));
}
 
Example #28
Source File: ConfigurationTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Basic test of "requires static":
 *     (m1 not observable)
 *     m2 requires transitive static m1
 *     m3 requires m2
 */
public void testRequiresStatic7() {
    ModuleDescriptor descriptor1 = null;  // not observable

    ModuleDescriptor descriptor2 = newBuilder("m2")
            .requires(Set.of(Requires.Modifier.TRANSITIVE,
                            Requires.Modifier.STATIC),
                     "m1")
            .build();

    ModuleDescriptor descriptor3 = newBuilder("m3")
            .requires("m2")
            .build();

    ModuleFinder finder = ModuleUtils.finderOf(descriptor2, descriptor3);

    Configuration cf = resolve(finder, "m3");

    assertTrue(cf.modules().size() == 2);
    assertTrue(cf.findModule("m2").isPresent());
    assertTrue(cf.findModule("m3").isPresent());
    ResolvedModule m2 = cf.findModule("m2").get();
    ResolvedModule m3 = cf.findModule("m3").get();
    assertTrue(m2.reads().isEmpty());
    assertTrue(m3.reads().size() == 1);
    assertTrue(m3.reads().contains(m2));
}
 
Example #29
Source File: ConfigurationTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Basic test of "requires static":
 *     m1 requires m2, m3
 *     m2 requires static m2
 *     m3
 */
public void testRequiresStatic4() {
    ModuleDescriptor descriptor1 = newBuilder("m1")
            .requires("m2")
            .requires("m3")
            .build();

    ModuleDescriptor descriptor2 = newBuilder("m2")
            .requires(Set.of(Requires.Modifier.STATIC), "m3")
            .build();

    ModuleDescriptor descriptor3 = newBuilder("m3")
            .build();

    ModuleFinder finder
        = ModuleUtils.finderOf(descriptor1, descriptor2, descriptor3);

    Configuration cf = resolve(finder, "m1");

    assertTrue(cf.modules().size() == 3);

    ResolvedModule m1 = cf.findModule("m1").get();
    ResolvedModule m2 = cf.findModule("m2").get();
    ResolvedModule m3 = cf.findModule("m3").get();

    assertTrue(m1.reads().size() == 2);
    assertTrue(m1.reads().contains(m2));
    assertTrue(m1.reads().contains(m3));

    assertTrue(m2.reads().size() == 1);
    assertTrue(m2.reads().contains(m3));

    assertTrue(m3.reads().size() == 0);
}
 
Example #30
Source File: AutomaticModulesTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Test that the given Module reads all module in the given layer
 * and its parent layers.
 */
static void testsReadsAll(Module m, ModuleLayer layer) {
    // check that m reads all modules in the layer
    layer.configuration().modules().stream()
        .map(ResolvedModule::name)
        .map(layer::findModule)
        .map(Optional::get)
        .forEach(other -> assertTrue(m.canRead(other)));

    // also check parent layers
    layer.parents().forEach(l -> testsReadsAll(m, l));
}