author | jjg |
Fri, 17 Jun 2016 17:40:01 -0700 | |
changeset 39103 | 91a64ec5b970 |
parent 37854 | a76a06106d02 |
child 40308 | 274367a99f98 |
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 |
|
37758 | 31 |
* @build toolbox.ToolBox toolbox.JavacTask toolbox.ModuleBuilder 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; |
37758 | 42 |
import toolbox.ModuleBuilder; |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
43 |
import toolbox.Task; |
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
44 |
import toolbox.ToolBox; |
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
45 |
|
36526 | 46 |
public class UsesTest extends ModuleTestBase { |
47 |
public static void main(String... args) throws Exception { |
|
48 |
UsesTest t = new UsesTest(); |
|
49 |
t.runTests(); |
|
50 |
} |
|
51 |
||
52 |
@Test |
|
37758 | 53 |
public void testSimple(Path base) throws Exception { |
36526 | 54 |
Path src = base.resolve("src"); |
55 |
tb.writeJavaFiles(src, |
|
56 |
"module m { uses p.C; }", |
|
57 |
"package p; public class C { }"); |
|
58 |
Path classes = base.resolve("classes"); |
|
59 |
Files.createDirectories(classes); |
|
60 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
61 |
new JavacTask(tb) |
36526 | 62 |
.outdir(classes) |
63 |
.files(findJavaFiles(src)) |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
64 |
.run(Task.Expect.SUCCESS) |
36526 | 65 |
.writeAll(); |
66 |
} |
|
67 |
||
68 |
@Test |
|
37758 | 69 |
public void testSimpleInner(Path base) throws Exception { |
36526 | 70 |
Path src = base.resolve("src"); |
71 |
tb.writeJavaFiles(src, |
|
72 |
"module m { uses p.C.Inner; }", |
|
73 |
"package p; public class C { public class Inner { } }"); |
|
74 |
Path classes = base.resolve("classes"); |
|
75 |
Files.createDirectories(classes); |
|
76 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
77 |
new JavacTask(tb) |
36526 | 78 |
.outdir(classes) |
79 |
.files(findJavaFiles(src)) |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
80 |
.run(Task.Expect.SUCCESS) |
36526 | 81 |
.writeAll(); |
82 |
} |
|
83 |
||
84 |
@Test |
|
37854
a76a06106d02
8153268: javac accepts enums being referenced by 'uses' statement
vromero
parents:
37758
diff
changeset
|
85 |
public void testEnumAsAService(Path base) throws Exception { |
a76a06106d02
8153268: javac accepts enums being referenced by 'uses' statement
vromero
parents:
37758
diff
changeset
|
86 |
Path src = base.resolve("src"); |
a76a06106d02
8153268: javac accepts enums being referenced by 'uses' statement
vromero
parents:
37758
diff
changeset
|
87 |
tb.writeJavaFiles(src, |
a76a06106d02
8153268: javac accepts enums being referenced by 'uses' statement
vromero
parents:
37758
diff
changeset
|
88 |
"module m { uses pkg.EnumST; }", |
a76a06106d02
8153268: javac accepts enums being referenced by 'uses' statement
vromero
parents:
37758
diff
changeset
|
89 |
"package pkg; public enum EnumST {A, B}"); |
a76a06106d02
8153268: javac accepts enums being referenced by 'uses' statement
vromero
parents:
37758
diff
changeset
|
90 |
Path classes = base.resolve("classes"); |
a76a06106d02
8153268: javac accepts enums being referenced by 'uses' statement
vromero
parents:
37758
diff
changeset
|
91 |
Files.createDirectories(classes); |
a76a06106d02
8153268: javac accepts enums being referenced by 'uses' statement
vromero
parents:
37758
diff
changeset
|
92 |
|
a76a06106d02
8153268: javac accepts enums being referenced by 'uses' statement
vromero
parents:
37758
diff
changeset
|
93 |
List<String> output = new JavacTask(tb) |
a76a06106d02
8153268: javac accepts enums being referenced by 'uses' statement
vromero
parents:
37758
diff
changeset
|
94 |
.options("-XDrawDiagnostics") |
a76a06106d02
8153268: javac accepts enums being referenced by 'uses' statement
vromero
parents:
37758
diff
changeset
|
95 |
.outdir(classes) |
a76a06106d02
8153268: javac accepts enums being referenced by 'uses' statement
vromero
parents:
37758
diff
changeset
|
96 |
.files(tb.findJavaFiles(src)) |
a76a06106d02
8153268: javac accepts enums being referenced by 'uses' statement
vromero
parents:
37758
diff
changeset
|
97 |
.run(Task.Expect.FAIL) |
a76a06106d02
8153268: javac accepts enums being referenced by 'uses' statement
vromero
parents:
37758
diff
changeset
|
98 |
.writeAll() |
a76a06106d02
8153268: javac accepts enums being referenced by 'uses' statement
vromero
parents:
37758
diff
changeset
|
99 |
.getOutputLines(Task.OutputKind.DIRECT); |
a76a06106d02
8153268: javac accepts enums being referenced by 'uses' statement
vromero
parents:
37758
diff
changeset
|
100 |
List<String> expected = Arrays.asList("module-info.java:1:20: compiler.err.service.definition.is.enum: pkg.EnumST", |
a76a06106d02
8153268: javac accepts enums being referenced by 'uses' statement
vromero
parents:
37758
diff
changeset
|
101 |
"1 error"); |
a76a06106d02
8153268: javac accepts enums being referenced by 'uses' statement
vromero
parents:
37758
diff
changeset
|
102 |
if (!output.containsAll(expected)) { |
a76a06106d02
8153268: javac accepts enums being referenced by 'uses' statement
vromero
parents:
37758
diff
changeset
|
103 |
throw new Exception("Expected output not found"); |
a76a06106d02
8153268: javac accepts enums being referenced by 'uses' statement
vromero
parents:
37758
diff
changeset
|
104 |
} |
a76a06106d02
8153268: javac accepts enums being referenced by 'uses' statement
vromero
parents:
37758
diff
changeset
|
105 |
} |
a76a06106d02
8153268: javac accepts enums being referenced by 'uses' statement
vromero
parents:
37758
diff
changeset
|
106 |
|
a76a06106d02
8153268: javac accepts enums being referenced by 'uses' statement
vromero
parents:
37758
diff
changeset
|
107 |
@Test |
37758 | 108 |
public void testSimpleAnnotation(Path base) throws Exception { |
36526 | 109 |
Path src = base.resolve("src"); |
110 |
tb.writeJavaFiles(src, |
|
111 |
"module m { uses p.C; }", |
|
112 |
"package p; public @interface C { }"); |
|
113 |
Path classes = base.resolve("classes"); |
|
114 |
Files.createDirectories(classes); |
|
115 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
116 |
new JavacTask(tb) |
36526 | 117 |
.outdir(classes) |
118 |
.files(findJavaFiles(src)) |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
119 |
.run(Task.Expect.SUCCESS) |
36526 | 120 |
.writeAll(); |
121 |
} |
|
122 |
||
123 |
@Test |
|
37758 | 124 |
public void testPrivateService(Path base) throws Exception { |
36526 | 125 |
Path src = base.resolve("src"); |
126 |
tb.writeJavaFiles(src, |
|
127 |
"module m { uses p.C.A; uses p.C; }", |
|
128 |
"package p; public class C { protected class A { } }"); |
|
129 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
130 |
List<String> output = new JavacTask(tb) |
36526 | 131 |
.options("-XDrawDiagnostics") |
132 |
.outdir(Files.createDirectories(base.resolve("classes"))) |
|
133 |
.files(findJavaFiles(src)) |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
134 |
.run(Task.Expect.FAIL) |
36526 | 135 |
.writeAll() |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
136 |
.getOutputLines(Task.OutputKind.DIRECT); |
36526 | 137 |
|
138 |
List<String> expected = Arrays.asList("module-info.java:1:20: compiler.err.report.access: p.C.A, protected, p.C", |
|
139 |
"1 error"); |
|
140 |
if (!output.containsAll(expected)) { |
|
141 |
throw new Exception("Expected output not found"); |
|
142 |
} |
|
143 |
} |
|
144 |
||
145 |
@Test |
|
37758 | 146 |
public void testMulti(Path base) throws Exception { |
36526 | 147 |
Path src = base.resolve("src"); |
148 |
tb.writeJavaFiles(src.resolve("m1"), |
|
149 |
"module m1 { exports p; }", |
|
150 |
"package p; public class C { }"); |
|
151 |
tb.writeJavaFiles(src.resolve("m2"), |
|
152 |
"module m2 { requires m1; uses p.C; }"); |
|
153 |
Path modules = base.resolve("modules"); |
|
154 |
Files.createDirectories(modules); |
|
155 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
156 |
new JavacTask(tb) |
36526 | 157 |
.options("-modulesourcepath", src.toString()) |
158 |
.outdir(modules) |
|
159 |
.files(findJavaFiles(src)) |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
160 |
.run(Task.Expect.SUCCESS) |
36526 | 161 |
.writeAll(); |
162 |
} |
|
163 |
||
164 |
@Test |
|
37758 | 165 |
public void testMultiOnModulePath(Path base) throws Exception { |
39103
91a64ec5b970
8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents:
37854
diff
changeset
|
166 |
Path modSrc = base.resolve("modSrc"); |
36526 | 167 |
Path modules = base.resolve("modules"); |
37758 | 168 |
new ModuleBuilder(tb, "m1") |
36526 | 169 |
.exports("p") |
170 |
.classes("package p; public class C { }") |
|
171 |
.build(modules); |
|
37758 | 172 |
new ModuleBuilder(tb, "m2") |
36526 | 173 |
.requires("m1") |
174 |
.uses("p.C") |
|
39103
91a64ec5b970
8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents:
37854
diff
changeset
|
175 |
.write(modSrc); |
36526 | 176 |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
177 |
new JavacTask(tb) |
36526 | 178 |
.options("-mp", modules.toString()) |
179 |
.outdir(modules) |
|
39103
91a64ec5b970
8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents:
37854
diff
changeset
|
180 |
.files(findJavaFiles(modSrc.resolve("m2"))) |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
181 |
.run(Task.Expect.SUCCESS) |
36526 | 182 |
.writeAll(); |
183 |
} |
|
184 |
||
185 |
@Test |
|
37758 | 186 |
public void testMultiOnModulePathInner(Path base) throws Exception { |
39103
91a64ec5b970
8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents:
37854
diff
changeset
|
187 |
Path modSrc = base.resolve("modSrc"); |
36526 | 188 |
Path modules = base.resolve("modules"); |
37758 | 189 |
new ModuleBuilder(tb, "m1") |
36526 | 190 |
.exports("p") |
191 |
.classes("package p; public class C { public class Inner { } }") |
|
192 |
.build(modules); |
|
37758 | 193 |
new ModuleBuilder(tb, "m2") |
36526 | 194 |
.requires("m1") |
195 |
.uses("p.C.Inner") |
|
39103
91a64ec5b970
8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents:
37854
diff
changeset
|
196 |
.write(modSrc); |
36526 | 197 |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
198 |
new JavacTask(tb) |
36526 | 199 |
.options("-mp", modules.toString()) |
200 |
.outdir(modules) |
|
39103
91a64ec5b970
8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents:
37854
diff
changeset
|
201 |
.files(findJavaFiles(modSrc.resolve("m2"))) |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
202 |
.run(Task.Expect.SUCCESS) |
36526 | 203 |
.writeAll(); |
204 |
} |
|
205 |
||
206 |
@Test |
|
37758 | 207 |
public void testDuplicateUses(Path base) throws Exception { |
36526 | 208 |
Path src = base.resolve("src"); |
209 |
tb.writeJavaFiles(src.resolve("m"), |
|
210 |
"module m { uses p.C; uses p.C; }", |
|
211 |
"package p; public class C { }"); |
|
212 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
213 |
List<String> output = new JavacTask(tb) |
36526 | 214 |
.options("-XDrawDiagnostics") |
215 |
.outdir(Files.createDirectories(base.resolve("classes"))) |
|
216 |
.files(findJavaFiles(src)) |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
217 |
.run(Task.Expect.FAIL) |
36526 | 218 |
.writeAll() |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
219 |
.getOutputLines(Task.OutputKind.DIRECT); |
36526 | 220 |
|
221 |
if (!output.containsAll(Arrays.asList( |
|
222 |
"module-info.java:1:22: compiler.err.duplicate.uses: p.C"))) { |
|
223 |
throw new Exception("Expected output not found"); |
|
224 |
} |
|
225 |
} |
|
226 |
||
227 |
@Test |
|
37758 | 228 |
public void testServiceNotExist(Path base) throws Exception { |
36526 | 229 |
Path src = base.resolve("src"); |
230 |
tb.writeJavaFiles(src, |
|
231 |
"module m { uses p.NotExist; }", |
|
232 |
"package p; public class C { }"); |
|
233 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
234 |
List<String> output = new JavacTask(tb) |
36526 | 235 |
.outdir(Files.createDirectories(base.resolve("classes"))) |
236 |
.options("-XDrawDiagnostics") |
|
237 |
.files(findJavaFiles(src)) |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
238 |
.run(Task.Expect.FAIL) |
36526 | 239 |
.writeAll() |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
240 |
.getOutputLines(Task.OutputKind.DIRECT); |
36526 | 241 |
Collection<?> expected = Arrays.asList("module-info.java:1:18: compiler.err.cant.resolve.location: kindname.class, NotExist, , , (compiler.misc.location: kindname.package, p, null)", |
242 |
"1 error"); |
|
243 |
if (!output.containsAll(expected)) { |
|
244 |
throw new Exception("Expected output not found"); |
|
245 |
} |
|
246 |
} |
|
247 |
||
248 |
@Test |
|
37758 | 249 |
public void testUsesUnexportedService(Path base) throws Exception { |
36526 | 250 |
Path src = base.resolve("src"); |
251 |
tb.writeJavaFiles(src.resolve("m1"), |
|
252 |
"module m1 { }", |
|
253 |
"package p; public class C { }"); |
|
254 |
tb.writeJavaFiles(src.resolve("m2"), |
|
255 |
"module m2 { requires m1; uses p.C; }"); |
|
256 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
257 |
List<String> output = new JavacTask(tb) |
36526 | 258 |
.options("-XDrawDiagnostics", "-modulesourcepath", src.toString()) |
259 |
.outdir(Files.createDirectories(base.resolve("modules"))) |
|
260 |
.files(findJavaFiles(src)) |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
261 |
.run(Task.Expect.FAIL) |
36526 | 262 |
.writeAll() |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
263 |
.getOutputLines(Task.OutputKind.DIRECT); |
36526 | 264 |
|
265 |
List<String> expected = Arrays.asList("module-info.java:1:32: compiler.err.not.def.access.package.cant.access: p.C, p", |
|
266 |
"1 error"); |
|
267 |
if (!output.containsAll(expected)) { |
|
268 |
throw new Exception("Expected output not found"); |
|
269 |
} |
|
270 |
} |
|
271 |
||
272 |
@Test |
|
37758 | 273 |
public void testUsesUnexportedButProvidedService(Path base) throws Exception { |
36526 | 274 |
Path src = base.resolve("src"); |
275 |
tb.writeJavaFiles(src.resolve("m1"), |
|
276 |
"module m1 { provides p.C with p.C; }", |
|
277 |
"package p; public class C { }"); |
|
278 |
tb.writeJavaFiles(src.resolve("m2"), |
|
279 |
"module m2 { requires m1; uses p.C; }"); |
|
280 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
281 |
List<String> output = new JavacTask(tb) |
36526 | 282 |
.options("-XDrawDiagnostics", "-modulesourcepath", src.toString()) |
283 |
.outdir(Files.createDirectories(base.resolve("modules"))) |
|
284 |
.files(findJavaFiles(src)) |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
285 |
.run(Task.Expect.FAIL) |
36526 | 286 |
.writeAll() |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
287 |
.getOutputLines(Task.OutputKind.DIRECT); |
36526 | 288 |
|
289 |
List<String> expected = Arrays.asList("module-info.java:1:32: compiler.err.not.def.access.package.cant.access: p.C, p", |
|
290 |
"1 error"); |
|
291 |
if (!output.containsAll(expected)) { |
|
292 |
throw new Exception("Expected output not found"); |
|
293 |
} |
|
294 |
} |
|
295 |
} |