equal
deleted
inserted
replaced
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.HashSet; |
32 import java.util.HashSet; |
45 // class p1.c1 defined in m1x tries to access p2.c2 defined in m2x |
44 // class p1.c1 defined in m1x tries to access p2.c2 defined in m2x |
46 // Access allowed since m1x can read m2x and package p2 is exported to m1x. |
45 // Access allowed since m1x can read m2x and package p2 is exported to m1x. |
47 // |
46 // |
48 public class ModuleNonBuiltinCLMain { |
47 public class ModuleNonBuiltinCLMain { |
49 |
48 |
50 // Create a Layer over the boot layer. |
49 // Create a layer over the boot layer. |
51 // Define modules within this layer to test access between |
50 // Define modules within this layer to test access between |
52 // publically defined classes within packages of those modules. |
51 // publically defined classes within packages of those modules. |
53 public void createLayerOnBoot() throws Throwable { |
52 public void createLayerOnBoot() throws Throwable { |
54 |
53 |
55 // Define module: m1x |
54 // Define module: m1x |
88 |
87 |
89 // Set up a ModuleFinder containing all modules for this layer. |
88 // Set up a ModuleFinder containing all modules for this layer. |
90 ModuleFinder finder = ModuleLibrary.of(descriptor_m1x, descriptor_m2x, descriptor_m3x); |
89 ModuleFinder finder = ModuleLibrary.of(descriptor_m1x, descriptor_m2x, descriptor_m3x); |
91 |
90 |
92 // Resolves "m1x" |
91 // Resolves "m1x" |
93 Configuration cf = Layer.boot() |
92 Configuration cf = ModuleLayer.boot() |
94 .configuration() |
93 .configuration() |
95 .resolve(finder, ModuleFinder.of(), Set.of("m1x")); |
94 .resolve(finder, ModuleFinder.of(), Set.of("m1x")); |
96 |
95 |
97 // map each module to differing user defined class loaders for this test |
96 // map each module to differing user defined class loaders for this test |
98 Map<String, ClassLoader> map = new HashMap<>(); |
97 Map<String, ClassLoader> map = new HashMap<>(); |
101 ClassLoader cl3 = ClassLoader.getSystemClassLoader(); |
100 ClassLoader cl3 = ClassLoader.getSystemClassLoader(); |
102 map.put("m1x", cl1); |
101 map.put("m1x", cl1); |
103 map.put("m2x", cl2); |
102 map.put("m2x", cl2); |
104 map.put("m3x", cl3); |
103 map.put("m3x", cl3); |
105 |
104 |
106 // Create Layer that contains m1x & m2x |
105 // Create layer that contains m1x & m2x |
107 Layer layer = Layer.boot().defineModules(cf, map::get); |
106 ModuleLayer layer = ModuleLayer.boot().defineModules(cf, map::get); |
108 assertTrue(layer.findLoader("m1x") == cl1); |
107 assertTrue(layer.findLoader("m1x") == cl1); |
109 assertTrue(layer.findLoader("m2x") == cl2); |
108 assertTrue(layer.findLoader("m2x") == cl2); |
110 assertTrue(layer.findLoader("m3x") == cl3); |
109 assertTrue(layer.findLoader("m3x") == cl3); |
111 assertTrue(layer.findLoader("java.base") == null); |
110 assertTrue(layer.findLoader("java.base") == null); |
112 |
111 |