64 // Define module: first_mod |
64 // Define module: first_mod |
65 // Can read: java.base |
65 // Can read: java.base |
66 // Packages: p1, p4 |
66 // Packages: p1, p4 |
67 // Packages exported: none |
67 // Packages exported: none |
68 ModuleDescriptor descriptor_first_mod = |
68 ModuleDescriptor descriptor_first_mod = |
69 ModuleDescriptor.module("first_mod") |
69 ModuleDescriptor.newModule("first_mod") |
70 .requires("java.base") |
70 .requires("java.base") |
71 .contains(Set.of("p1", "p4")) |
71 .packages(Set.of("p1", "p4")) |
72 .build(); |
72 .build(); |
73 |
73 |
74 // Define module: second_mod |
74 // Define module: second_mod |
75 // Can read: java.base |
75 // Can read: java.base |
76 // Packages: p2 |
76 // Packages: p2 |
77 // Packages exported: p2 is exported to first_mod |
77 // Packages exported: p2 is exported to first_mod |
78 ModuleDescriptor descriptor_second_mod = |
78 ModuleDescriptor descriptor_second_mod = |
79 ModuleDescriptor.module("second_mod") |
79 ModuleDescriptor.newModule("second_mod") |
80 .requires("java.base") |
80 .requires("java.base") |
81 .exports("p2", Set.of("first_mod")) |
81 .exports("p2", Set.of("first_mod")) |
82 .build(); |
82 .build(); |
83 |
83 |
84 // Set up a ModuleFinder containing all modules for this layer |
84 // Set up a ModuleFinder containing all modules for this layer |
85 ModuleFinder finder = ModuleLibrary.of(descriptor_first_mod, descriptor_second_mod); |
85 ModuleFinder finder = ModuleLibrary.of(descriptor_first_mod, descriptor_second_mod); |
86 |
86 |
87 // Resolves "first_mod" and "second_mod" |
87 // Resolves "first_mod" and "second_mod" |
88 Configuration cf = Layer.boot() |
88 Configuration cf = Layer.boot() |
89 .configuration() |
89 .configuration() |
90 .resolveRequires(finder, ModuleFinder.of(), Set.of("first_mod", "second_mod")); |
90 .resolve(finder, ModuleFinder.of(), Set.of("first_mod", "second_mod")); |
91 |
91 |
92 // Map each module to this class loader |
92 // Map each module to this class loader |
93 Map<String, ClassLoader> map = new HashMap<>(); |
93 Map<String, ClassLoader> map = new HashMap<>(); |
94 ClassLoader loader = AccessReadTwice.class.getClassLoader(); |
94 ClassLoader loader = AccessReadTwice.class.getClassLoader(); |
95 map.put("first_mod", loader); |
95 map.put("first_mod", loader); |