35 * @run main/othervm -Xbootclasspath/a:. DiffCL_ExpQualToM1 |
35 * @run main/othervm -Xbootclasspath/a:. DiffCL_ExpQualToM1 |
36 */ |
36 */ |
37 |
37 |
38 import static jdk.test.lib.Asserts.*; |
38 import static jdk.test.lib.Asserts.*; |
39 |
39 |
40 import java.lang.reflect.Layer; |
|
41 import java.lang.module.Configuration; |
40 import java.lang.module.Configuration; |
42 import java.lang.module.ModuleDescriptor; |
41 import java.lang.module.ModuleDescriptor; |
43 import java.lang.module.ModuleFinder; |
42 import java.lang.module.ModuleFinder; |
44 import java.util.HashMap; |
43 import java.util.HashMap; |
45 import java.util.Map; |
44 import java.util.Map; |
56 // class p1.c1 defined in m1x tries to access p2.c2 defined in m2x |
55 // class p1.c1 defined in m1x tries to access p2.c2 defined in m2x |
57 // Access allowed since m1x can read m2x and package p2 is exported to m1x. |
56 // Access allowed since m1x can read m2x and package p2 is exported to m1x. |
58 // |
57 // |
59 public class DiffCL_ExpQualToM1 { |
58 public class DiffCL_ExpQualToM1 { |
60 |
59 |
61 // Create a Layer over the boot layer. |
60 // Create a layer over the boot layer. |
62 // Define modules within this layer to test access between |
61 // Define modules within this layer to test access between |
63 // publically defined classes within packages of those modules. |
62 // publically defined classes within packages of those modules. |
64 public void createLayerOnBoot() throws Throwable { |
63 public void createLayerOnBoot() throws Throwable { |
65 |
64 |
66 // Define module: m1x |
65 // Define module: m1x |
86 |
85 |
87 // Set up a ModuleFinder containing all modules for this layer. |
86 // Set up a ModuleFinder containing all modules for this layer. |
88 ModuleFinder finder = ModuleLibrary.of(descriptor_m1x, descriptor_m2x); |
87 ModuleFinder finder = ModuleLibrary.of(descriptor_m1x, descriptor_m2x); |
89 |
88 |
90 // Resolves "m1x" |
89 // Resolves "m1x" |
91 Configuration cf = Layer.boot() |
90 Configuration cf = ModuleLayer.boot() |
92 .configuration() |
91 .configuration() |
93 .resolve(finder, ModuleFinder.of(), Set.of("m1x")); |
92 .resolve(finder, ModuleFinder.of(), Set.of("m1x")); |
94 |
93 |
95 // map each module to differing class loaders for this test |
94 // map each module to differing class loaders for this test |
96 Map<String, ClassLoader> map = new HashMap<>(); |
95 Map<String, ClassLoader> map = new HashMap<>(); |
97 map.put("m1x", MyDiffClassLoader.loader1); |
96 map.put("m1x", MyDiffClassLoader.loader1); |
98 map.put("m2x", MyDiffClassLoader.loader2); |
97 map.put("m2x", MyDiffClassLoader.loader2); |
99 |
98 |
100 // Create Layer that contains m1x & m2x |
99 // Create layer that contains m1x & m2x |
101 Layer layer = Layer.boot().defineModules(cf, map::get); |
100 ModuleLayer layer = ModuleLayer.boot().defineModules(cf, map::get); |
102 |
101 |
103 assertTrue(layer.findLoader("m1x") == MyDiffClassLoader.loader1); |
102 assertTrue(layer.findLoader("m1x") == MyDiffClassLoader.loader1); |
104 assertTrue(layer.findLoader("m2x") == MyDiffClassLoader.loader2); |
103 assertTrue(layer.findLoader("m2x") == MyDiffClassLoader.loader2); |
105 assertTrue(layer.findLoader("java.base") == null); |
104 assertTrue(layer.findLoader("java.base") == null); |
106 |
105 |