author | jjg |
Thu, 31 Mar 2016 15:20:50 -0700 | |
changeset 36778 | e04318f39f92 |
parent 36526 | 3b41f1c69604 |
child 37758 | 3ecf9b414e05 |
permissions | -rw-r--r-- |
36526 | 1 |
/* |
2 |
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. |
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
22 |
*/ |
|
23 |
||
24 |
/** |
|
25 |
* @test |
|
26 |
* @summary simple tests of module uses |
|
27 |
* @library /tools/lib |
|
28 |
* @modules |
|
29 |
* jdk.compiler/com.sun.tools.javac.api |
|
30 |
* jdk.compiler/com.sun.tools.javac.main |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
31 |
* @build toolbox.ToolBox toolbox.JavacTask ModuleTestBase |
36526 | 32 |
* @run main UsesTest |
33 |
*/ |
|
34 |
||
35 |
import java.nio.file.Files; |
|
36 |
import java.nio.file.Path; |
|
37 |
import java.util.Arrays; |
|
38 |
import java.util.Collection; |
|
39 |
import java.util.List; |
|
40 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
41 |
import toolbox.JavacTask; |
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
42 |
import toolbox.Task; |
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
43 |
import toolbox.ToolBox; |
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
44 |
|
36526 | 45 |
public class UsesTest extends ModuleTestBase { |
46 |
public static void main(String... args) throws Exception { |
|
47 |
UsesTest t = new UsesTest(); |
|
48 |
t.runTests(); |
|
49 |
} |
|
50 |
||
51 |
@Test |
|
52 |
void testSimple(Path base) throws Exception { |
|
53 |
Path src = base.resolve("src"); |
|
54 |
tb.writeJavaFiles(src, |
|
55 |
"module m { uses p.C; }", |
|
56 |
"package p; public class C { }"); |
|
57 |
Path classes = base.resolve("classes"); |
|
58 |
Files.createDirectories(classes); |
|
59 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
60 |
new JavacTask(tb) |
36526 | 61 |
.outdir(classes) |
62 |
.files(findJavaFiles(src)) |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
63 |
.run(Task.Expect.SUCCESS) |
36526 | 64 |
.writeAll(); |
65 |
} |
|
66 |
||
67 |
@Test |
|
68 |
void testSimpleInner(Path base) throws Exception { |
|
69 |
Path src = base.resolve("src"); |
|
70 |
tb.writeJavaFiles(src, |
|
71 |
"module m { uses p.C.Inner; }", |
|
72 |
"package p; public class C { public class Inner { } }"); |
|
73 |
Path classes = base.resolve("classes"); |
|
74 |
Files.createDirectories(classes); |
|
75 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
76 |
new JavacTask(tb) |
36526 | 77 |
.outdir(classes) |
78 |
.files(findJavaFiles(src)) |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
79 |
.run(Task.Expect.SUCCESS) |
36526 | 80 |
.writeAll(); |
81 |
} |
|
82 |
||
83 |
@Test |
|
84 |
void testSimpleAnnotation(Path base) throws Exception { |
|
85 |
Path src = base.resolve("src"); |
|
86 |
tb.writeJavaFiles(src, |
|
87 |
"module m { uses p.C; }", |
|
88 |
"package p; public @interface C { }"); |
|
89 |
Path classes = base.resolve("classes"); |
|
90 |
Files.createDirectories(classes); |
|
91 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
92 |
new JavacTask(tb) |
36526 | 93 |
.outdir(classes) |
94 |
.files(findJavaFiles(src)) |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
95 |
.run(Task.Expect.SUCCESS) |
36526 | 96 |
.writeAll(); |
97 |
} |
|
98 |
||
99 |
@Test |
|
100 |
void testPrivateService(Path base) throws Exception { |
|
101 |
Path src = base.resolve("src"); |
|
102 |
tb.writeJavaFiles(src, |
|
103 |
"module m { uses p.C.A; uses p.C; }", |
|
104 |
"package p; public class C { protected class A { } }"); |
|
105 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
106 |
List<String> output = new JavacTask(tb) |
36526 | 107 |
.options("-XDrawDiagnostics") |
108 |
.outdir(Files.createDirectories(base.resolve("classes"))) |
|
109 |
.files(findJavaFiles(src)) |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
110 |
.run(Task.Expect.FAIL) |
36526 | 111 |
.writeAll() |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
112 |
.getOutputLines(Task.OutputKind.DIRECT); |
36526 | 113 |
|
114 |
List<String> expected = Arrays.asList("module-info.java:1:20: compiler.err.report.access: p.C.A, protected, p.C", |
|
115 |
"1 error"); |
|
116 |
if (!output.containsAll(expected)) { |
|
117 |
throw new Exception("Expected output not found"); |
|
118 |
} |
|
119 |
} |
|
120 |
||
121 |
@Test |
|
122 |
void testMulti(Path base) throws Exception { |
|
123 |
Path src = base.resolve("src"); |
|
124 |
tb.writeJavaFiles(src.resolve("m1"), |
|
125 |
"module m1 { exports p; }", |
|
126 |
"package p; public class C { }"); |
|
127 |
tb.writeJavaFiles(src.resolve("m2"), |
|
128 |
"module m2 { requires m1; uses p.C; }"); |
|
129 |
Path modules = base.resolve("modules"); |
|
130 |
Files.createDirectories(modules); |
|
131 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
132 |
new JavacTask(tb) |
36526 | 133 |
.options("-modulesourcepath", src.toString()) |
134 |
.outdir(modules) |
|
135 |
.files(findJavaFiles(src)) |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
136 |
.run(Task.Expect.SUCCESS) |
36526 | 137 |
.writeAll(); |
138 |
} |
|
139 |
||
140 |
@Test |
|
141 |
void testMultiOnModulePath(Path base) throws Exception { |
|
142 |
Path modules = base.resolve("modules"); |
|
143 |
new ModuleBuilder("m1") |
|
144 |
.exports("p") |
|
145 |
.classes("package p; public class C { }") |
|
146 |
.build(modules); |
|
147 |
new ModuleBuilder("m2") |
|
148 |
.requires("m1") |
|
149 |
.uses("p.C") |
|
150 |
.write(modules); |
|
151 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
152 |
new JavacTask(tb) |
36526 | 153 |
.options("-mp", modules.toString()) |
154 |
.outdir(modules) |
|
155 |
.files(findJavaFiles(modules.resolve("m2"))) |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
156 |
.run(Task.Expect.SUCCESS) |
36526 | 157 |
.writeAll(); |
158 |
} |
|
159 |
||
160 |
@Test |
|
161 |
void testMultiOnModulePathInner(Path base) throws Exception { |
|
162 |
Path modules = base.resolve("modules"); |
|
163 |
new ModuleBuilder("m1") |
|
164 |
.exports("p") |
|
165 |
.classes("package p; public class C { public class Inner { } }") |
|
166 |
.build(modules); |
|
167 |
new ModuleBuilder("m2") |
|
168 |
.requires("m1") |
|
169 |
.uses("p.C.Inner") |
|
170 |
.write(modules); |
|
171 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
172 |
new JavacTask(tb) |
36526 | 173 |
.options("-mp", modules.toString()) |
174 |
.outdir(modules) |
|
175 |
.files(findJavaFiles(modules.resolve("m2"))) |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
176 |
.run(Task.Expect.SUCCESS) |
36526 | 177 |
.writeAll(); |
178 |
} |
|
179 |
||
180 |
@Test |
|
181 |
void testDuplicateUses(Path base) throws Exception { |
|
182 |
Path src = base.resolve("src"); |
|
183 |
tb.writeJavaFiles(src.resolve("m"), |
|
184 |
"module m { uses p.C; uses p.C; }", |
|
185 |
"package p; public class C { }"); |
|
186 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
187 |
List<String> output = new JavacTask(tb) |
36526 | 188 |
.options("-XDrawDiagnostics") |
189 |
.outdir(Files.createDirectories(base.resolve("classes"))) |
|
190 |
.files(findJavaFiles(src)) |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
191 |
.run(Task.Expect.FAIL) |
36526 | 192 |
.writeAll() |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
193 |
.getOutputLines(Task.OutputKind.DIRECT); |
36526 | 194 |
|
195 |
if (!output.containsAll(Arrays.asList( |
|
196 |
"module-info.java:1:22: compiler.err.duplicate.uses: p.C"))) { |
|
197 |
throw new Exception("Expected output not found"); |
|
198 |
} |
|
199 |
} |
|
200 |
||
201 |
@Test |
|
202 |
void testServiceNotExist(Path base) throws Exception { |
|
203 |
Path src = base.resolve("src"); |
|
204 |
tb.writeJavaFiles(src, |
|
205 |
"module m { uses p.NotExist; }", |
|
206 |
"package p; public class C { }"); |
|
207 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
208 |
List<String> output = new JavacTask(tb) |
36526 | 209 |
.outdir(Files.createDirectories(base.resolve("classes"))) |
210 |
.options("-XDrawDiagnostics") |
|
211 |
.files(findJavaFiles(src)) |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
212 |
.run(Task.Expect.FAIL) |
36526 | 213 |
.writeAll() |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
214 |
.getOutputLines(Task.OutputKind.DIRECT); |
36526 | 215 |
Collection<?> expected = Arrays.asList("module-info.java:1:18: compiler.err.cant.resolve.location: kindname.class, NotExist, , , (compiler.misc.location: kindname.package, p, null)", |
216 |
"1 error"); |
|
217 |
if (!output.containsAll(expected)) { |
|
218 |
throw new Exception("Expected output not found"); |
|
219 |
} |
|
220 |
} |
|
221 |
||
222 |
@Test |
|
223 |
void testUsesUnexportedService(Path base) throws Exception { |
|
224 |
Path src = base.resolve("src"); |
|
225 |
tb.writeJavaFiles(src.resolve("m1"), |
|
226 |
"module m1 { }", |
|
227 |
"package p; public class C { }"); |
|
228 |
tb.writeJavaFiles(src.resolve("m2"), |
|
229 |
"module m2 { requires m1; uses p.C; }"); |
|
230 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
231 |
List<String> output = new JavacTask(tb) |
36526 | 232 |
.options("-XDrawDiagnostics", "-modulesourcepath", src.toString()) |
233 |
.outdir(Files.createDirectories(base.resolve("modules"))) |
|
234 |
.files(findJavaFiles(src)) |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
235 |
.run(Task.Expect.FAIL) |
36526 | 236 |
.writeAll() |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
237 |
.getOutputLines(Task.OutputKind.DIRECT); |
36526 | 238 |
|
239 |
List<String> expected = Arrays.asList("module-info.java:1:32: compiler.err.not.def.access.package.cant.access: p.C, p", |
|
240 |
"1 error"); |
|
241 |
if (!output.containsAll(expected)) { |
|
242 |
throw new Exception("Expected output not found"); |
|
243 |
} |
|
244 |
} |
|
245 |
||
246 |
@Test |
|
247 |
void testUsesUnexportedButProvidedService(Path base) throws Exception { |
|
248 |
Path src = base.resolve("src"); |
|
249 |
tb.writeJavaFiles(src.resolve("m1"), |
|
250 |
"module m1 { provides p.C with p.C; }", |
|
251 |
"package p; public class C { }"); |
|
252 |
tb.writeJavaFiles(src.resolve("m2"), |
|
253 |
"module m2 { requires m1; uses p.C; }"); |
|
254 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
255 |
List<String> output = new JavacTask(tb) |
36526 | 256 |
.options("-XDrawDiagnostics", "-modulesourcepath", src.toString()) |
257 |
.outdir(Files.createDirectories(base.resolve("modules"))) |
|
258 |
.files(findJavaFiles(src)) |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
259 |
.run(Task.Expect.FAIL) |
36526 | 260 |
.writeAll() |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
261 |
.getOutputLines(Task.OutputKind.DIRECT); |
36526 | 262 |
|
263 |
List<String> expected = Arrays.asList("module-info.java:1:32: compiler.err.not.def.access.package.cant.access: p.C, p", |
|
264 |
"1 error"); |
|
265 |
if (!output.containsAll(expected)) { |
|
266 |
throw new Exception("Expected output not found"); |
|
267 |
} |
|
268 |
} |
|
269 |
} |