26 * @summary simple tests of module uses |
26 * @summary simple tests of module uses |
27 * @library /tools/lib |
27 * @library /tools/lib |
28 * @modules |
28 * @modules |
29 * jdk.compiler/com.sun.tools.javac.api |
29 * jdk.compiler/com.sun.tools.javac.api |
30 * jdk.compiler/com.sun.tools.javac.main |
30 * jdk.compiler/com.sun.tools.javac.main |
31 * @build toolbox.ToolBox toolbox.JavacTask ModuleTestBase |
31 * @build toolbox.ToolBox toolbox.JavacTask toolbox.ModuleBuilder ModuleTestBase |
32 * @run main UsesTest |
32 * @run main UsesTest |
33 */ |
33 */ |
34 |
34 |
35 import java.nio.file.Files; |
35 import java.nio.file.Files; |
36 import java.nio.file.Path; |
36 import java.nio.file.Path; |
37 import java.util.Arrays; |
37 import java.util.Arrays; |
38 import java.util.Collection; |
38 import java.util.Collection; |
39 import java.util.List; |
39 import java.util.List; |
40 |
40 |
41 import toolbox.JavacTask; |
41 import toolbox.JavacTask; |
|
42 import toolbox.ModuleBuilder; |
42 import toolbox.Task; |
43 import toolbox.Task; |
43 import toolbox.ToolBox; |
44 import toolbox.ToolBox; |
44 |
45 |
45 public class UsesTest extends ModuleTestBase { |
46 public class UsesTest extends ModuleTestBase { |
46 public static void main(String... args) throws Exception { |
47 public static void main(String... args) throws Exception { |
47 UsesTest t = new UsesTest(); |
48 UsesTest t = new UsesTest(); |
48 t.runTests(); |
49 t.runTests(); |
49 } |
50 } |
50 |
51 |
51 @Test |
52 @Test |
52 void testSimple(Path base) throws Exception { |
53 public void testSimple(Path base) throws Exception { |
53 Path src = base.resolve("src"); |
54 Path src = base.resolve("src"); |
54 tb.writeJavaFiles(src, |
55 tb.writeJavaFiles(src, |
55 "module m { uses p.C; }", |
56 "module m { uses p.C; }", |
56 "package p; public class C { }"); |
57 "package p; public class C { }"); |
57 Path classes = base.resolve("classes"); |
58 Path classes = base.resolve("classes"); |
63 .run(Task.Expect.SUCCESS) |
64 .run(Task.Expect.SUCCESS) |
64 .writeAll(); |
65 .writeAll(); |
65 } |
66 } |
66 |
67 |
67 @Test |
68 @Test |
68 void testSimpleInner(Path base) throws Exception { |
69 public void testSimpleInner(Path base) throws Exception { |
69 Path src = base.resolve("src"); |
70 Path src = base.resolve("src"); |
70 tb.writeJavaFiles(src, |
71 tb.writeJavaFiles(src, |
71 "module m { uses p.C.Inner; }", |
72 "module m { uses p.C.Inner; }", |
72 "package p; public class C { public class Inner { } }"); |
73 "package p; public class C { public class Inner { } }"); |
73 Path classes = base.resolve("classes"); |
74 Path classes = base.resolve("classes"); |
79 .run(Task.Expect.SUCCESS) |
80 .run(Task.Expect.SUCCESS) |
80 .writeAll(); |
81 .writeAll(); |
81 } |
82 } |
82 |
83 |
83 @Test |
84 @Test |
84 void testSimpleAnnotation(Path base) throws Exception { |
85 public void testSimpleAnnotation(Path base) throws Exception { |
85 Path src = base.resolve("src"); |
86 Path src = base.resolve("src"); |
86 tb.writeJavaFiles(src, |
87 tb.writeJavaFiles(src, |
87 "module m { uses p.C; }", |
88 "module m { uses p.C; }", |
88 "package p; public @interface C { }"); |
89 "package p; public @interface C { }"); |
89 Path classes = base.resolve("classes"); |
90 Path classes = base.resolve("classes"); |
95 .run(Task.Expect.SUCCESS) |
96 .run(Task.Expect.SUCCESS) |
96 .writeAll(); |
97 .writeAll(); |
97 } |
98 } |
98 |
99 |
99 @Test |
100 @Test |
100 void testPrivateService(Path base) throws Exception { |
101 public void testPrivateService(Path base) throws Exception { |
101 Path src = base.resolve("src"); |
102 Path src = base.resolve("src"); |
102 tb.writeJavaFiles(src, |
103 tb.writeJavaFiles(src, |
103 "module m { uses p.C.A; uses p.C; }", |
104 "module m { uses p.C.A; uses p.C; }", |
104 "package p; public class C { protected class A { } }"); |
105 "package p; public class C { protected class A { } }"); |
105 |
106 |
117 throw new Exception("Expected output not found"); |
118 throw new Exception("Expected output not found"); |
118 } |
119 } |
119 } |
120 } |
120 |
121 |
121 @Test |
122 @Test |
122 void testMulti(Path base) throws Exception { |
123 public void testMulti(Path base) throws Exception { |
123 Path src = base.resolve("src"); |
124 Path src = base.resolve("src"); |
124 tb.writeJavaFiles(src.resolve("m1"), |
125 tb.writeJavaFiles(src.resolve("m1"), |
125 "module m1 { exports p; }", |
126 "module m1 { exports p; }", |
126 "package p; public class C { }"); |
127 "package p; public class C { }"); |
127 tb.writeJavaFiles(src.resolve("m2"), |
128 tb.writeJavaFiles(src.resolve("m2"), |
136 .run(Task.Expect.SUCCESS) |
137 .run(Task.Expect.SUCCESS) |
137 .writeAll(); |
138 .writeAll(); |
138 } |
139 } |
139 |
140 |
140 @Test |
141 @Test |
141 void testMultiOnModulePath(Path base) throws Exception { |
142 public void testMultiOnModulePath(Path base) throws Exception { |
142 Path modules = base.resolve("modules"); |
143 Path modules = base.resolve("modules"); |
143 new ModuleBuilder("m1") |
144 new ModuleBuilder(tb, "m1") |
144 .exports("p") |
145 .exports("p") |
145 .classes("package p; public class C { }") |
146 .classes("package p; public class C { }") |
146 .build(modules); |
147 .build(modules); |
147 new ModuleBuilder("m2") |
148 new ModuleBuilder(tb, "m2") |
148 .requires("m1") |
149 .requires("m1") |
149 .uses("p.C") |
150 .uses("p.C") |
150 .write(modules); |
151 .write(modules); |
151 |
152 |
152 new JavacTask(tb) |
153 new JavacTask(tb) |
156 .run(Task.Expect.SUCCESS) |
157 .run(Task.Expect.SUCCESS) |
157 .writeAll(); |
158 .writeAll(); |
158 } |
159 } |
159 |
160 |
160 @Test |
161 @Test |
161 void testMultiOnModulePathInner(Path base) throws Exception { |
162 public void testMultiOnModulePathInner(Path base) throws Exception { |
162 Path modules = base.resolve("modules"); |
163 Path modules = base.resolve("modules"); |
163 new ModuleBuilder("m1") |
164 new ModuleBuilder(tb, "m1") |
164 .exports("p") |
165 .exports("p") |
165 .classes("package p; public class C { public class Inner { } }") |
166 .classes("package p; public class C { public class Inner { } }") |
166 .build(modules); |
167 .build(modules); |
167 new ModuleBuilder("m2") |
168 new ModuleBuilder(tb, "m2") |
168 .requires("m1") |
169 .requires("m1") |
169 .uses("p.C.Inner") |
170 .uses("p.C.Inner") |
170 .write(modules); |
171 .write(modules); |
171 |
172 |
172 new JavacTask(tb) |
173 new JavacTask(tb) |
176 .run(Task.Expect.SUCCESS) |
177 .run(Task.Expect.SUCCESS) |
177 .writeAll(); |
178 .writeAll(); |
178 } |
179 } |
179 |
180 |
180 @Test |
181 @Test |
181 void testDuplicateUses(Path base) throws Exception { |
182 public void testDuplicateUses(Path base) throws Exception { |
182 Path src = base.resolve("src"); |
183 Path src = base.resolve("src"); |
183 tb.writeJavaFiles(src.resolve("m"), |
184 tb.writeJavaFiles(src.resolve("m"), |
184 "module m { uses p.C; uses p.C; }", |
185 "module m { uses p.C; uses p.C; }", |
185 "package p; public class C { }"); |
186 "package p; public class C { }"); |
186 |
187 |
197 throw new Exception("Expected output not found"); |
198 throw new Exception("Expected output not found"); |
198 } |
199 } |
199 } |
200 } |
200 |
201 |
201 @Test |
202 @Test |
202 void testServiceNotExist(Path base) throws Exception { |
203 public void testServiceNotExist(Path base) throws Exception { |
203 Path src = base.resolve("src"); |
204 Path src = base.resolve("src"); |
204 tb.writeJavaFiles(src, |
205 tb.writeJavaFiles(src, |
205 "module m { uses p.NotExist; }", |
206 "module m { uses p.NotExist; }", |
206 "package p; public class C { }"); |
207 "package p; public class C { }"); |
207 |
208 |
218 throw new Exception("Expected output not found"); |
219 throw new Exception("Expected output not found"); |
219 } |
220 } |
220 } |
221 } |
221 |
222 |
222 @Test |
223 @Test |
223 void testUsesUnexportedService(Path base) throws Exception { |
224 public void testUsesUnexportedService(Path base) throws Exception { |
224 Path src = base.resolve("src"); |
225 Path src = base.resolve("src"); |
225 tb.writeJavaFiles(src.resolve("m1"), |
226 tb.writeJavaFiles(src.resolve("m1"), |
226 "module m1 { }", |
227 "module m1 { }", |
227 "package p; public class C { }"); |
228 "package p; public class C { }"); |
228 tb.writeJavaFiles(src.resolve("m2"), |
229 tb.writeJavaFiles(src.resolve("m2"), |
242 throw new Exception("Expected output not found"); |
243 throw new Exception("Expected output not found"); |
243 } |
244 } |
244 } |
245 } |
245 |
246 |
246 @Test |
247 @Test |
247 void testUsesUnexportedButProvidedService(Path base) throws Exception { |
248 public void testUsesUnexportedButProvidedService(Path base) throws Exception { |
248 Path src = base.resolve("src"); |
249 Path src = base.resolve("src"); |
249 tb.writeJavaFiles(src.resolve("m1"), |
250 tb.writeJavaFiles(src.resolve("m1"), |
250 "module m1 { provides p.C with p.C; }", |
251 "module m1 { provides p.C with p.C; }", |
251 "package p; public class C { }"); |
252 "package p; public class C { }"); |
252 tb.writeJavaFiles(src.resolve("m2"), |
253 tb.writeJavaFiles(src.resolve("m2"), |