23 * questions. |
23 * questions. |
24 */ |
24 */ |
25 |
25 |
26 import static jdk.test.lib.Asserts.*; |
26 import static jdk.test.lib.Asserts.*; |
27 |
27 |
28 import java.lang.reflect.Layer; |
|
29 import java.lang.module.Configuration; |
28 import java.lang.module.Configuration; |
30 import java.lang.module.ModuleDescriptor; |
29 import java.lang.module.ModuleDescriptor; |
31 import java.lang.module.ModuleFinder; |
30 import java.lang.module.ModuleFinder; |
32 import java.util.HashMap; |
31 import java.util.HashMap; |
33 import java.util.Map; |
32 import java.util.Map; |
43 // class p1.c1 defined in m1x tries to access p2.c2 defined in m2x |
42 // class p1.c1 defined in m1x tries to access p2.c2 defined in m2x |
44 // Access allowed since m1x can read m2x and package p2 is exported to m1x. |
43 // Access allowed since m1x can read m2x and package p2 is exported to m1x. |
45 // |
44 // |
46 public class ModuleSameCLMain { |
45 public class ModuleSameCLMain { |
47 |
46 |
48 // Create a Layer over the boot layer. |
47 // Create a layer over the boot layer. |
49 // Define modules within this layer to test access between |
48 // Define modules within this layer to test access between |
50 // publically defined classes within packages of those modules. |
49 // publically defined classes within packages of those modules. |
51 public void createLayerOnBoot() throws Throwable { |
50 public void createLayerOnBoot() throws Throwable { |
52 |
51 |
53 // Define module: m1x |
52 // Define module: m1x |
73 |
72 |
74 // Set up a ModuleFinder containing all modules for this layer. |
73 // Set up a ModuleFinder containing all modules for this layer. |
75 ModuleFinder finder = ModuleLibrary.of(descriptor_m1x, descriptor_m2x); |
74 ModuleFinder finder = ModuleLibrary.of(descriptor_m1x, descriptor_m2x); |
76 |
75 |
77 // Resolves "m1x" |
76 // Resolves "m1x" |
78 Configuration cf = Layer.boot() |
77 Configuration cf = ModuleLayer.boot() |
79 .configuration() |
78 .configuration() |
80 .resolve(finder, ModuleFinder.of(), Set.of("m1x")); |
79 .resolve(finder, ModuleFinder.of(), Set.of("m1x")); |
81 |
80 |
82 // map each module to the same class loader for this test |
81 // map each module to the same class loader for this test |
83 Map<String, ClassLoader> map = new HashMap<>(); |
82 Map<String, ClassLoader> map = new HashMap<>(); |
84 Loader1 cl1 = new Loader1(); |
83 Loader1 cl1 = new Loader1(); |
85 map.put("m1x", cl1); |
84 map.put("m1x", cl1); |
86 map.put("m2x", cl1); |
85 map.put("m2x", cl1); |
87 |
86 |
88 // Create Layer that contains m1x & m2x |
87 // Create layer that contains m1x & m2x |
89 Layer layer = Layer.boot().defineModules(cf, map::get); |
88 ModuleLayer layer = ModuleLayer.boot().defineModules(cf, map::get); |
90 assertTrue(layer.findLoader("m1x") == cl1); |
89 assertTrue(layer.findLoader("m1x") == cl1); |
91 assertTrue(layer.findLoader("m2x") == cl1); |
90 assertTrue(layer.findLoader("m2x") == cl1); |
92 assertTrue(layer.findLoader("java.base") == null); |
91 assertTrue(layer.findLoader("java.base") == null); |
93 |
92 |
94 // now use the same loader to load class p1.c1 |
93 // now use the same loader to load class p1.c1 |