29 import java.net.URL;
30 import java.net.URLClassLoader;
31 import java.nio.file.Path;
32 import java.nio.file.Paths;
33 import java.util.Set;
34
35 public class TestLayer {
36 private static final Path MODS_DIR = Paths.get("mods");
37 private static final Set<String> modules = Set.of("m1", "m2");
38
39 public static void main(String[] args) throws Exception {
40 // disable security manager until Class.forName is called.
41 SecurityManager sm = System.getSecurityManager();
42 if (sm != null) {
43 System.setSecurityManager(null);
44 }
45
46 ModuleFinder finder = ModuleFinder.of(MODS_DIR);
47
48 Configuration parent = Layer.boot().configuration();
49 Configuration cf = parent.resolveRequiresAndUses(ModuleFinder.of(),
50 finder,
51 modules);
52
53 ClassLoader scl = ClassLoader.getSystemClassLoader();
54 Layer layer = Layer.boot().defineModulesWithManyLoaders(cf, scl);
55
56 Module m1 = layer.findModule("m1").get();
57 Module m2 = layer.findModule("m2").get();
58
59 if (sm != null) {
60 System.setSecurityManager(sm);
61 }
62
63 // find exported and non-exported class from a named module
64 findClass(m1, "p1.A");
65 findClass(m1, "p1.internal.B");
66 findClass(m2, "p2.C");
67
68 // find class from unnamed module
69 ClassLoader ld = TestLayer.class.getClassLoader();
|
29 import java.net.URL;
30 import java.net.URLClassLoader;
31 import java.nio.file.Path;
32 import java.nio.file.Paths;
33 import java.util.Set;
34
35 public class TestLayer {
36 private static final Path MODS_DIR = Paths.get("mods");
37 private static final Set<String> modules = Set.of("m1", "m2");
38
39 public static void main(String[] args) throws Exception {
40 // disable security manager until Class.forName is called.
41 SecurityManager sm = System.getSecurityManager();
42 if (sm != null) {
43 System.setSecurityManager(null);
44 }
45
46 ModuleFinder finder = ModuleFinder.of(MODS_DIR);
47
48 Configuration parent = Layer.boot().configuration();
49 Configuration cf = parent.resolveAndBind(ModuleFinder.of(),
50 finder,
51 modules);
52
53 ClassLoader scl = ClassLoader.getSystemClassLoader();
54 Layer layer = Layer.boot().defineModulesWithManyLoaders(cf, scl);
55
56 Module m1 = layer.findModule("m1").get();
57 Module m2 = layer.findModule("m2").get();
58
59 if (sm != null) {
60 System.setSecurityManager(sm);
61 }
62
63 // find exported and non-exported class from a named module
64 findClass(m1, "p1.A");
65 findClass(m1, "p1.internal.B");
66 findClass(m2, "p2.C");
67
68 // find class from unnamed module
69 ClassLoader ld = TestLayer.class.getClassLoader();
|