Java Code Examples for java.lang.module.ModuleFinder#compose()
The following examples show how to use
java.lang.module.ModuleFinder#compose() .
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: AutomaticModulesTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
/** * Basic test to ensure that no automatic modules are resolved when * an automatic module is not a root or required by other modules. */ public void testInConfiguration4() throws IOException { ModuleDescriptor descriptor1 = ModuleDescriptor.newModule("m1") .requires("java.base") .build(); // automatic modules Path dir = Files.createTempDirectory(USER_DIR, "mods"); createDummyJarFile(dir.resolve("auto1.jar"), "p1/C.class"); createDummyJarFile(dir.resolve("auto2.jar"), "p2/C.class"); createDummyJarFile(dir.resolve("auto3.jar"), "p3/C.class"); // module finder locates m1 and the modules in the directory ModuleFinder finder1 = ModuleUtils.finderOf(descriptor1); ModuleFinder finder2 = ModuleFinder.of(dir); ModuleFinder finder = ModuleFinder.compose(finder1, finder2); Configuration parent = ModuleLayer.boot().configuration(); Configuration cf = resolve(parent, finder, "m1"); // ensure that no automatic module is resolved assertTrue(cf.modules().size() == 1); assertTrue(cf.findModule("m1").isPresent()); }
Example 2
Source File: AutomaticModulesTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
/** * Basic test of a configuration created with automatic modules * a requires b* and c* * b* contains p * c* contains p */ @Test(expectedExceptions = { ResolutionException.class }) public void testDuplicateSuppliers1() throws IOException { ModuleDescriptor descriptor = ModuleDescriptor.newModule("a") .requires("b") .requires("c") .build(); // c and d are automatic modules with the same package Path dir = Files.createTempDirectory(USER_DIR, "mods"); createDummyJarFile(dir.resolve("b.jar"), "p/T.class"); createDummyJarFile(dir.resolve("c.jar"), "p/T.class"); // module finder locates 'a' and the modules in the directory ModuleFinder finder = ModuleFinder.compose(ModuleUtils.finderOf(descriptor), ModuleFinder.of(dir)); Configuration parent = ModuleLayer.boot().configuration(); resolve(parent, finder, "a"); }
Example 3
Source File: AutomaticModulesTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
/** * Basic test of a configuration created with automatic modules * a contains p, requires b* * b* contains p */ @Test(expectedExceptions = { ResolutionException.class }) public void testDuplicateSuppliers2() throws IOException { ModuleDescriptor descriptor = ModuleDescriptor.newModule("a") .packages(Set.of("p")) .requires("b") .build(); // c and d are automatic modules with the same package Path dir = Files.createTempDirectory(USER_DIR, "mods"); createDummyJarFile(dir.resolve("b.jar"), "p/T.class"); // module finder locates 'a' and the modules in the directory ModuleFinder finder = ModuleFinder.compose(ModuleUtils.finderOf(descriptor), ModuleFinder.of(dir)); Configuration parent = ModuleLayer.boot().configuration(); resolve(parent, finder, "a"); }
Example 4
Source File: ModuleFinderTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * Test ModuleFinder.compose with one module finder */ public void testComposeOfOne() throws Exception { Path dir = Files.createTempDirectory(USER_DIR, "mods"); createModularJar(dir.resolve("m1.jar"), "m1"); createModularJar(dir.resolve("m2.jar"), "m2"); ModuleFinder finder1 = ModuleFinder.of(dir); ModuleFinder finder = ModuleFinder.compose(finder1); assertTrue(finder.findAll().size() == 2); assertTrue(finder.find("m1").isPresent()); assertTrue(finder.find("m2").isPresent()); assertFalse(finder.find("java.rhubarb").isPresent()); }
Example 5
Source File: ModuleFinderTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * Test ModuleFinder.compose with two module finders */ public void testComposeOfTwo() throws Exception { Path dir1 = Files.createTempDirectory(USER_DIR, "mods1"); createModularJar(dir1.resolve("m1.jar"), "[email protected]"); createModularJar(dir1.resolve("m2.jar"), "[email protected]"); Path dir2 = Files.createTempDirectory(USER_DIR, "mods2"); createModularJar(dir2.resolve("m1.jar"), "[email protected]"); createModularJar(dir2.resolve("m2.jar"), "[email protected]"); createModularJar(dir2.resolve("m3.jar"), "m3"); createModularJar(dir2.resolve("m4.jar"), "m4"); ModuleFinder finder1 = ModuleFinder.of(dir1); ModuleFinder finder2 = ModuleFinder.of(dir2); ModuleFinder finder = ModuleFinder.compose(finder1, finder2); assertTrue(finder.findAll().size() == 4); assertTrue(finder.find("m1").isPresent()); assertTrue(finder.find("m2").isPresent()); assertTrue(finder.find("m3").isPresent()); assertTrue(finder.find("m4").isPresent()); assertFalse(finder.find("java.rhubarb").isPresent()); // check that [email protected] is found ModuleDescriptor m1 = finder.find("m1").get().descriptor(); assertEquals(m1.version().get().toString(), "1.0"); // check that [email protected] is found ModuleDescriptor m2 = finder.find("m2").get().descriptor(); assertEquals(m2.version().get().toString(), "1.0"); }
Example 6
Source File: AutomaticModulesTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * Basic test of layer containing automatic modules */ public void testInLayer() throws IOException { ModuleDescriptor descriptor = ModuleDescriptor.newModule("a") .requires("b") .requires("c") .build(); // b and c are simple JAR files Path dir = Files.createTempDirectory(USER_DIR, "mods"); createDummyJarFile(dir.resolve("b.jar"), "p/T.class"); createDummyJarFile(dir.resolve("c.jar"), "q/T2.class"); // module finder locates a and the modules in the directory ModuleFinder finder = ModuleFinder.compose(ModuleUtils.finderOf(descriptor), ModuleFinder.of(dir)); Configuration parent = ModuleLayer.boot().configuration(); Configuration cf = resolve(parent, finder, "a"); assertTrue(cf.modules().size() == 3); // each module gets its own loader ModuleLayer layer = ModuleLayer.boot().defineModules(cf, mn -> new ClassLoader() { }); // an unnamed module Module unnamed = (new ClassLoader() { }).getUnnamedModule(); Module b = layer.findModule("b").get(); assertTrue(b.isNamed()); assertTrue(b.canRead(unnamed)); testsReadsAll(b, layer); Module c = layer.findModule("c").get(); assertTrue(c.isNamed()); assertTrue(b.canRead(unnamed)); testsReadsAll(c, layer); }
Example 7
Source File: JdepsConfiguration.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
public JdepsConfiguration build() throws IOException { ModuleFinder finder = systemModulePath; if (upgradeModulePath != null) { finder = ModuleFinder.compose(upgradeModulePath, systemModulePath); } if (appModulePath != null) { finder = ModuleFinder.compose(finder, appModulePath); } if (!paths.isEmpty()) { ModuleFinder otherModulePath = ModuleFinder.of(paths.toArray(new Path[0])); finder = ModuleFinder.compose(finder, otherModulePath); // add modules specified on command-line (convenience) as root set otherModulePath.findAll().stream() .map(mref -> mref.descriptor().name()) .forEach(rootModules::add); } if ((addAllApplicationModules || allModules) && appModulePath != null) { appModulePath.findAll().stream() .map(mref -> mref.descriptor().name()) .forEach(rootModules::add); } // no archive is specified for analysis // add all system modules as root if --add-modules ALL-SYSTEM is specified if (addAllSystemModules && rootModules.isEmpty() && initialArchives.isEmpty() && classPaths.isEmpty()) { systemModulePath.findAll() .stream() .map(mref -> mref.descriptor().name()) .forEach(rootModules::add); } return new JdepsConfiguration(systemModulePath, finder, rootModules, classPaths, initialArchives, addAllDefaultModules, allModules, version); }
Example 8
Source File: ModuleFinderTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
/** * Test ModuleFinder.compose with three module finders */ public void testComposeOfThree() throws Exception { Path dir1 = Files.createTempDirectory(USER_DIR, "mods1"); createModularJar(dir1.resolve("m1.jar"), "[email protected]"); createModularJar(dir1.resolve("m2.jar"), "[email protected]"); Path dir2 = Files.createTempDirectory(USER_DIR, "mods2"); createModularJar(dir2.resolve("m1.jar"), "[email protected]"); createModularJar(dir2.resolve("m2.jar"), "[email protected]"); createModularJar(dir2.resolve("m3.jar"), "[email protected]"); createModularJar(dir2.resolve("m4.jar"), "[email protected]"); Path dir3 = Files.createTempDirectory(USER_DIR, "mods3"); createModularJar(dir3.resolve("m3.jar"), "[email protected]"); createModularJar(dir3.resolve("m4.jar"), "[email protected]"); createModularJar(dir3.resolve("m5.jar"), "m5"); createModularJar(dir3.resolve("m6.jar"), "m6"); ModuleFinder finder1 = ModuleFinder.of(dir1); ModuleFinder finder2 = ModuleFinder.of(dir2); ModuleFinder finder3 = ModuleFinder.of(dir3); ModuleFinder finder = ModuleFinder.compose(finder1, finder2, finder3); assertTrue(finder.findAll().size() == 6); assertTrue(finder.find("m1").isPresent()); assertTrue(finder.find("m2").isPresent()); assertTrue(finder.find("m3").isPresent()); assertTrue(finder.find("m4").isPresent()); assertTrue(finder.find("m5").isPresent()); assertTrue(finder.find("m6").isPresent()); assertFalse(finder.find("java.rhubarb").isPresent()); // check that [email protected] is found ModuleDescriptor m1 = finder.find("m1").get().descriptor(); assertEquals(m1.version().get().toString(), "1.0"); // check that [email protected] is found ModuleDescriptor m2 = finder.find("m2").get().descriptor(); assertEquals(m2.version().get().toString(), "1.0"); // check that [email protected] is found ModuleDescriptor m3 = finder.find("m3").get().descriptor(); assertEquals(m3.version().get().toString(), "2.0"); // check that [email protected] is found ModuleDescriptor m4 = finder.find("m4").get().descriptor(); assertEquals(m4.version().get().toString(), "2.0"); }
Example 9
Source File: AutomaticModulesTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
/** * Basic test of a configuration created with automatic modules. * a requires b* * a requires c* * b* * c* */ public void testConfiguration1() throws Exception { ModuleDescriptor descriptor1 = ModuleDescriptor.newModule("a") .requires("b") .requires("c") .requires("java.base") .build(); // b and c are automatic modules Path dir = Files.createTempDirectory(USER_DIR, "mods"); createDummyJarFile(dir.resolve("b.jar"), "p/T.class"); createDummyJarFile(dir.resolve("c.jar"), "q/T.class"); // module finder locates a and the modules in the directory ModuleFinder finder1 = ModuleUtils.finderOf(descriptor1); ModuleFinder finder2 = ModuleFinder.of(dir); ModuleFinder finder = ModuleFinder.compose(finder1, finder2); Configuration parent = ModuleLayer.boot().configuration(); Configuration cf = resolve(parent, finder, "a"); assertTrue(cf.modules().size() == 3); assertTrue(cf.findModule("a").isPresent()); assertTrue(cf.findModule("b").isPresent()); assertTrue(cf.findModule("c").isPresent()); ResolvedModule base = cf.findModule("java.base").get(); assertTrue(base.configuration() == ModuleLayer.boot().configuration()); ResolvedModule a = cf.findModule("a").get(); ResolvedModule b = cf.findModule("b").get(); ResolvedModule c = cf.findModule("c").get(); // b && c only require java.base assertTrue(b.reference().descriptor().requires().size() == 1); assertTrue(c.reference().descriptor().requires().size() == 1); // readability assertTrue(a.reads().size() == 3); assertTrue(a.reads().contains(base)); assertTrue(a.reads().contains(b)); assertTrue(a.reads().contains(c)); assertTrue(b.reads().contains(a)); assertTrue(b.reads().contains(c)); testReadAllBootModules(cf, "b"); // b reads all modules in boot layer assertTrue(c.reads().contains(a)); assertTrue(c.reads().contains(b)); testReadAllBootModules(cf, "c"); // c reads all modules in boot layer }
Example 10
Source File: AutomaticModulesTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
/** * Basic test of a configuration created with automatic modules * a requires b * b requires c* * c* * d* */ public void testInConfiguration2() throws IOException { ModuleDescriptor descriptor1 = ModuleDescriptor.newModule("a") .requires("b") .requires("java.base") .build(); ModuleDescriptor descriptor2 = ModuleDescriptor.newModule("b") .requires("c") .requires("java.base") .build(); // c and d are automatic modules Path dir = Files.createTempDirectory(USER_DIR, "mods"); createDummyJarFile(dir.resolve("c.jar"), "p/T.class"); createDummyJarFile(dir.resolve("d.jar"), "q/T.class"); // module finder locates a and the modules in the directory ModuleFinder finder1 = ModuleUtils.finderOf(descriptor1, descriptor2); ModuleFinder finder2 = ModuleFinder.of(dir); ModuleFinder finder = ModuleFinder.compose(finder1, finder2); Configuration parent = ModuleLayer.boot().configuration(); Configuration cf = resolve(parent, finder, "a", "d"); assertTrue(cf.modules().size() == 4); assertTrue(cf.findModule("a").isPresent()); assertTrue(cf.findModule("b").isPresent()); assertTrue(cf.findModule("c").isPresent()); assertTrue(cf.findModule("d").isPresent()); // c && d should only require java.base assertTrue(findDescriptor(cf, "c").requires().size() == 1); assertTrue(findDescriptor(cf, "d").requires().size() == 1); // readability ResolvedModule base = cf.findModule("java.base").get(); assertTrue(base.configuration() == ModuleLayer.boot().configuration()); ResolvedModule a = cf.findModule("a").get(); ResolvedModule b = cf.findModule("b").get(); ResolvedModule c = cf.findModule("c").get(); ResolvedModule d = cf.findModule("d").get(); assertTrue(a.reads().size() == 2); assertTrue(a.reads().contains(b)); assertTrue(a.reads().contains(base)); assertTrue(b.reads().size() == 3); assertTrue(b.reads().contains(c)); assertTrue(b.reads().contains(d)); assertTrue(b.reads().contains(base)); assertTrue(c.reads().contains(a)); assertTrue(c.reads().contains(b)); assertTrue(c.reads().contains(d)); testReadAllBootModules(cf, "c"); // c reads all modules in boot layer assertTrue(d.reads().contains(a)); assertTrue(d.reads().contains(b)); assertTrue(d.reads().contains(c)); testReadAllBootModules(cf, "d"); // d reads all modules in boot layer }
Example 11
Source File: AutomaticModulesTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
/** * Basic test of a configuration created with automatic modules * a requires b * b requires transitive c* * c* * d* */ public void testInConfiguration3() throws IOException { ModuleDescriptor descriptor1 = ModuleDescriptor.newModule("a") .requires("b") .requires("java.base") .build(); ModuleDescriptor descriptor2 = ModuleDescriptor.newModule("b") .requires(Set.of(Modifier.TRANSITIVE), "c") .requires("java.base") .build(); // c and d are automatic modules Path dir = Files.createTempDirectory(USER_DIR, "mods"); createDummyJarFile(dir.resolve("c.jar"), "p/T.class"); createDummyJarFile(dir.resolve("d.jar"), "q/T.class"); // module finder locates a and the modules in the directory ModuleFinder finder1 = ModuleUtils.finderOf(descriptor1, descriptor2); ModuleFinder finder2 = ModuleFinder.of(dir); ModuleFinder finder = ModuleFinder.compose(finder1, finder2); Configuration parent = ModuleLayer.boot().configuration(); Configuration cf = resolve(parent, finder, "a", "d"); assertTrue(cf.modules().size() == 4); assertTrue(cf.findModule("a").isPresent()); assertTrue(cf.findModule("b").isPresent()); assertTrue(cf.findModule("c").isPresent()); assertTrue(cf.findModule("d").isPresent()); ResolvedModule base = cf.findModule("java.base").get(); assertTrue(base.configuration() == ModuleLayer.boot().configuration()); ResolvedModule a = cf.findModule("a").get(); ResolvedModule b = cf.findModule("b").get(); ResolvedModule c = cf.findModule("c").get(); ResolvedModule d = cf.findModule("d").get(); // c && d should only require java.base assertTrue(findDescriptor(cf, "c").requires().size() == 1); assertTrue(findDescriptor(cf, "d").requires().size() == 1); // readability assertTrue(a.reads().size() == 4); assertTrue(a.reads().contains(b)); assertTrue(a.reads().contains(c)); assertTrue(a.reads().contains(d)); assertTrue(a.reads().contains(base)); assertTrue(b.reads().size() == 3); assertTrue(b.reads().contains(c)); assertTrue(b.reads().contains(d)); assertTrue(b.reads().contains(base)); assertTrue(reads(cf, "b", "c")); assertTrue(reads(cf, "b", "d")); assertTrue(reads(cf, "b", "java.base")); assertTrue(c.reads().contains(a)); assertTrue(c.reads().contains(b)); assertTrue(c.reads().contains(d)); testReadAllBootModules(cf, "c"); // c reads all modules in boot layer assertTrue(d.reads().contains(a)); assertTrue(d.reads().contains(b)); assertTrue(d.reads().contains(c)); testReadAllBootModules(cf, "d"); // d reads all modules in boot layer }
Example 12
Source File: AutomaticModulesTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
/** * Basic test to ensure that if an automatic module is resolved then * all observable automatic modules are resolved. */ public void testInConfiguration5() throws IOException { // m1 requires m2 ModuleDescriptor descriptor1 = ModuleDescriptor.newModule("m1") .requires("m2").build(); // m2 requires automatic module ModuleDescriptor descriptor2 = ModuleDescriptor.newModule("m2") .requires("auto1") .build(); // automatic modules Path dir = Files.createTempDirectory(USER_DIR, "mods"); createDummyJarFile(dir.resolve("auto1.jar"), "p1/C.class"); createDummyJarFile(dir.resolve("auto2.jar"), "p2/C.class"); createDummyJarFile(dir.resolve("auto3.jar"), "p3/C.class"); // module finder locates m1, m2, and the modules in the directory ModuleFinder finder1 = ModuleUtils.finderOf(descriptor1, descriptor2); ModuleFinder finder2 = ModuleFinder.of(dir); ModuleFinder finder = ModuleFinder.compose(finder1, finder2); Configuration parent = ModuleLayer.boot().configuration(); Configuration cf = resolve(parent, finder, "m1"); // all automatic modules should be resolved assertTrue(cf.modules().size() == 5); assertTrue(cf.findModule("m1").isPresent()); assertTrue(cf.findModule("m2").isPresent()); assertTrue(cf.findModule("auto1").isPresent()); assertTrue(cf.findModule("auto2").isPresent()); assertTrue(cf.findModule("auto3").isPresent()); ResolvedModule base = parent.findModule("java.base") .orElseThrow(() -> new RuntimeException()); ResolvedModule m1 = cf.findModule("m1").get(); ResolvedModule m2 = cf.findModule("m2").get(); ResolvedModule auto1 = cf.findModule("auto1").get(); ResolvedModule auto2 = cf.findModule("auto2").get(); ResolvedModule auto3 = cf.findModule("auto3").get(); // m1 does not read the automatic modules assertTrue(m1.reads().size() == 2); assertTrue(m1.reads().contains(m2)); assertTrue(m1.reads().contains(base)); // m2 should read all the automatic modules assertTrue(m2.reads().size() == 4); assertTrue(m2.reads().contains(auto1)); assertTrue(m2.reads().contains(auto2)); assertTrue(m2.reads().contains(auto3)); assertTrue(m2.reads().contains(base)); assertTrue(auto1.reads().contains(m1)); assertTrue(auto1.reads().contains(m2)); assertTrue(auto1.reads().contains(auto2)); assertTrue(auto1.reads().contains(auto3)); assertTrue(auto1.reads().contains(base)); assertTrue(auto2.reads().contains(m1)); assertTrue(auto2.reads().contains(m2)); assertTrue(auto2.reads().contains(auto1)); assertTrue(auto2.reads().contains(auto3)); assertTrue(auto2.reads().contains(base)); assertTrue(auto3.reads().contains(m1)); assertTrue(auto3.reads().contains(m2)); assertTrue(auto3.reads().contains(auto1)); assertTrue(auto3.reads().contains(auto2)); assertTrue(auto3.reads().contains(base)); }
Example 13
Source File: AutomaticModulesTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
/** * Basic test of automatic modules in a child configuration. All automatic * modules that are found with the before finder should be resolved. The * automatic modules that are found by the after finder and not shadowed * by the before finder, or parent configurations, should also be resolved. */ public void testInConfiguration6() throws IOException { // m1 requires auto1 ModuleDescriptor descriptor1 = ModuleDescriptor.newModule("m1") .requires("auto1") .build(); Path dir = Files.createTempDirectory(USER_DIR, "mods"); createDummyJarFile(dir.resolve("auto1.jar"), "p1/C.class"); // module finder locates m1 and auto1 ModuleFinder finder1 = ModuleUtils.finderOf(descriptor1); ModuleFinder finder2 = ModuleFinder.of(dir); ModuleFinder finder = ModuleFinder.compose(finder1, finder2); Configuration parent = ModuleLayer.boot().configuration(); Configuration cf1 = resolve(parent, finder, "m1"); assertTrue(cf1.modules().size() == 2); assertTrue(cf1.findModule("m1").isPresent()); assertTrue(cf1.findModule("auto1").isPresent()); ResolvedModule base = parent.findModule("java.base") .orElseThrow(() -> new RuntimeException()); ResolvedModule m1 = cf1.findModule("m1").get(); ResolvedModule auto1 = cf1.findModule("auto1").get(); assertTrue(m1.reads().size() == 2); assertTrue(m1.reads().contains(auto1)); assertTrue(m1.reads().contains(base)); assertTrue(auto1.reads().contains(m1)); assertTrue(auto1.reads().contains(base)); // create child configuration - the after finder locates auto1 dir = Files.createTempDirectory(USER_DIR, "mods"); createDummyJarFile(dir.resolve("auto2.jar"), "p2/C.class"); ModuleFinder beforeFinder = ModuleFinder.of(dir); dir = Files.createTempDirectory(USER_DIR, "mods"); createDummyJarFile(dir.resolve("auto1.jar"), "p1/C.class"); createDummyJarFile(dir.resolve("auto2.jar"), "p2/C.class"); createDummyJarFile(dir.resolve("auto3.jar"), "p3/C.class"); ModuleFinder afterFinder = ModuleFinder.of(dir); Configuration cf2 = cf1.resolve(beforeFinder, afterFinder, Set.of("auto2")); // auto1 should be found in parent and should not be in cf2 assertTrue(cf2.modules().size() == 2); assertTrue(cf2.findModule("auto2").isPresent()); assertTrue(cf2.findModule("auto3").isPresent()); ResolvedModule auto2 = cf2.findModule("auto2").get(); ResolvedModule auto3 = cf2.findModule("auto3").get(); assertTrue(auto2.reads().contains(m1)); assertTrue(auto2.reads().contains(auto1)); assertTrue(auto2.reads().contains(auto3)); assertTrue(auto2.reads().contains(base)); assertTrue(auto3.reads().contains(m1)); assertTrue(auto3.reads().contains(auto1)); assertTrue(auto3.reads().contains(auto2)); assertTrue(auto3.reads().contains(base)); }