22 */ |
22 */ |
23 |
23 |
24 import java.lang.module.Configuration; |
24 import java.lang.module.Configuration; |
25 import java.lang.module.ModuleFinder; |
25 import java.lang.module.ModuleFinder; |
26 import java.lang.reflect.InvocationHandler; |
26 import java.lang.reflect.InvocationHandler; |
27 import java.lang.reflect.Layer; |
|
28 import java.lang.reflect.Proxy; |
27 import java.lang.reflect.Proxy; |
29 import java.nio.file.Path; |
28 import java.nio.file.Path; |
30 import java.nio.file.Paths; |
29 import java.nio.file.Paths; |
31 import java.util.Arrays; |
30 import java.util.Arrays; |
32 |
31 |
68 assertTrue(CompilerUtils.compile(msrc, MODS_DIR, "--module-source-path", SRC_DIR.toString())); |
67 assertTrue(CompilerUtils.compile(msrc, MODS_DIR, "--module-source-path", SRC_DIR.toString())); |
69 } |
68 } |
70 } |
69 } |
71 |
70 |
72 /** |
71 /** |
73 * Test proxy implementing interfaces in a Layer defined in |
72 * Test proxy implementing interfaces in a layer defined in |
74 * an unnamed module |
73 * an unnamed module |
75 */ |
74 */ |
76 @Test |
75 @Test |
77 public void testProxyInUnnamed() throws Exception { |
76 public void testProxyInUnnamed() throws Exception { |
78 ModuleFinder finder = ModuleFinder.of(MODS_DIR); |
77 ModuleFinder finder = ModuleFinder.of(MODS_DIR); |
79 Layer bootLayer = Layer.boot(); |
78 ModuleLayer bootLayer = ModuleLayer.boot(); |
80 Configuration cf = bootLayer |
79 Configuration cf = bootLayer |
81 .configuration() |
80 .configuration() |
82 .resolveAndBind(ModuleFinder.of(), finder, Arrays.asList(modules)); |
81 .resolveAndBind(ModuleFinder.of(), finder, Arrays.asList(modules)); |
83 ClassLoader scl = ClassLoader.getSystemClassLoader(); |
82 ClassLoader scl = ClassLoader.getSystemClassLoader(); |
84 Layer layer = bootLayer.defineModulesWithOneLoader(cf, scl); |
83 ModuleLayer layer = bootLayer.defineModulesWithOneLoader(cf, scl); |
85 |
84 |
86 ClassLoader loader = layer.findLoader("m1"); |
85 ClassLoader loader = layer.findLoader("m1"); |
87 |
86 |
88 assertTrue(layer.findModule("m1").isPresent()); |
87 assertTrue(layer.findModule("m1").isPresent()); |
89 assertTrue(layer.findModule("m2").isPresent()); |
88 assertTrue(layer.findModule("m2").isPresent()); |
108 * dynamic module |
107 * dynamic module |
109 */ |
108 */ |
110 @Test |
109 @Test |
111 public void testProxyInDynamicModule() throws Exception { |
110 public void testProxyInDynamicModule() throws Exception { |
112 ModuleFinder finder = ModuleFinder.of(MODS_DIR); |
111 ModuleFinder finder = ModuleFinder.of(MODS_DIR); |
113 Layer bootLayer = Layer.boot(); |
112 ModuleLayer bootLayer = ModuleLayer.boot(); |
114 Configuration cf = bootLayer |
113 Configuration cf = bootLayer |
115 .configuration() |
114 .configuration() |
116 .resolveAndBind(ModuleFinder.of(), finder, Arrays.asList(modules)); |
115 .resolveAndBind(ModuleFinder.of(), finder, Arrays.asList(modules)); |
117 ClassLoader scl = ClassLoader.getSystemClassLoader(); |
116 ClassLoader scl = ClassLoader.getSystemClassLoader(); |
118 Layer layer = bootLayer.defineModulesWithOneLoader(cf, scl); |
117 ModuleLayer layer = bootLayer.defineModulesWithOneLoader(cf, scl); |
119 |
118 |
120 ClassLoader loader = layer.findLoader("m1"); |
119 ClassLoader loader = layer.findLoader("m1"); |
121 |
120 |
122 assertTrue(layer.findModule("m1").isPresent()); |
121 assertTrue(layer.findModule("m1").isPresent()); |
123 assertTrue(layer.findModule("m2").isPresent()); |
122 assertTrue(layer.findModule("m2").isPresent()); |
138 * Test proxy implementing interfaces that the target module has no access |
137 * Test proxy implementing interfaces that the target module has no access |
139 */ |
138 */ |
140 @Test |
139 @Test |
141 public void testNoReadAccess() throws Exception { |
140 public void testNoReadAccess() throws Exception { |
142 ModuleFinder finder = ModuleFinder.of(MODS_DIR); |
141 ModuleFinder finder = ModuleFinder.of(MODS_DIR); |
143 Layer bootLayer = Layer.boot(); |
142 ModuleLayer bootLayer = ModuleLayer.boot(); |
144 Configuration cf = bootLayer |
143 Configuration cf = bootLayer |
145 .configuration() |
144 .configuration() |
146 .resolveAndBind(ModuleFinder.of(), finder, Arrays.asList(modules)); |
145 .resolveAndBind(ModuleFinder.of(), finder, Arrays.asList(modules)); |
147 ClassLoader scl = ClassLoader.getSystemClassLoader(); |
146 ClassLoader scl = ClassLoader.getSystemClassLoader(); |
148 Layer layer = bootLayer.defineModulesWithOneLoader(cf, scl); |
147 ModuleLayer layer = bootLayer.defineModulesWithOneLoader(cf, scl); |
149 |
148 |
150 ClassLoader loader = layer.findLoader("m1"); |
149 ClassLoader loader = layer.findLoader("m1"); |
151 |
150 |
152 assertTrue(layer.findModule("m1").isPresent()); |
151 assertTrue(layer.findModule("m1").isPresent()); |
153 assertTrue(layer.findModule("m2").isPresent()); |
152 assertTrue(layer.findModule("m2").isPresent()); |