author | jjg |
Wed, 10 Aug 2016 15:47:46 -0700 | |
changeset 40308 | 274367a99f98 |
parent 38916 | d118cb2cffab |
child 42407 | f3702cff2933 |
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 |
|
38916
d118cb2cffab
8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents:
37758
diff
changeset
|
26 |
* @bug 8158123 |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
27 |
* @summary tests for module declarations |
36526 | 28 |
* @library /tools/lib |
29 |
* @modules |
|
30 |
* jdk.compiler/com.sun.tools.javac.api |
|
31 |
* jdk.compiler/com.sun.tools.javac.main |
|
32 |
* jdk.jdeps/com.sun.tools.javap |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
33 |
* @build toolbox.ToolBox toolbox.JavacTask ModuleTestBase |
36526 | 34 |
* @run main ModuleInfoTest |
35 |
*/ |
|
36 |
||
37 |
import java.nio.file.Files; |
|
38 |
import java.nio.file.Path; |
|
38916
d118cb2cffab
8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents:
37758
diff
changeset
|
39 |
import java.util.Arrays; |
36526 | 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 ModuleInfoTest extends ModuleTestBase { |
46 |
||
47 |
public static void main(String... args) throws Exception { |
|
48 |
ModuleInfoTest t = new ModuleInfoTest(); |
|
49 |
t.runTests(); |
|
50 |
} |
|
51 |
||
52 |
/** |
|
53 |
* Check error message if module declaration not in module-info.java. |
|
54 |
*/ |
|
55 |
@Test |
|
37758 | 56 |
public void testModuleDeclNotInModuleJava(Path base) throws Exception { |
36526 | 57 |
Path src = base.resolve("src"); |
58 |
tb.writeFile(src.resolve("M.java"), "module M { }"); |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
59 |
String log = new JavacTask(tb) |
36526 | 60 |
.options("-XDrawDiagnostics") |
61 |
.files(findJavaFiles(src)) |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
62 |
.run(Task.Expect.FAIL) |
36526 | 63 |
.writeAll() |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
64 |
.getOutput(Task.OutputKind.DIRECT); |
36526 | 65 |
|
66 |
if (!log.contains("M.java:1:1: compiler.err.module.decl.sb.in.module-info.java")) |
|
67 |
throw new Exception("expected output not found"); |
|
68 |
} |
|
69 |
||
70 |
/** |
|
71 |
* Verify that a package private class can be put in module-info.java. |
|
72 |
*/ |
|
73 |
@Test |
|
37758 | 74 |
public void testNotModuleDeclInModuleJava_1(Path base) throws Exception { |
36526 | 75 |
Path src = base.resolve("src"); |
76 |
tb.writeFile(src.resolve("module-info.java"), "class C { }"); |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
77 |
new JavacTask(tb) |
36526 | 78 |
.options("-XDrawDiagnostics") |
79 |
.files(findJavaFiles(src)) |
|
80 |
.run() |
|
81 |
.writeAll(); |
|
82 |
} |
|
83 |
||
84 |
/** |
|
85 |
* Verify that a public class cannot be put in module-info.java. |
|
86 |
*/ |
|
87 |
@Test |
|
37758 | 88 |
public void testNotModuleDeclInModuleJava_2(Path base) throws Exception { |
36526 | 89 |
Path src = base.resolve("src"); |
90 |
tb.writeFile(src.resolve("module-info.java"), "public class C { }"); |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
91 |
String log = new JavacTask(tb) |
36526 | 92 |
.options("-XDrawDiagnostics") |
93 |
.files(findJavaFiles(src)) |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
94 |
.run(Task.Expect.FAIL) |
36526 | 95 |
.writeAll() |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
96 |
.getOutput(Task.OutputKind.DIRECT); |
36526 | 97 |
|
98 |
if (!log.contains("module-info.java:1:8: compiler.err.class.public.should.be.in.file: C")) |
|
99 |
throw new Exception("expected output not found"); |
|
100 |
} |
|
101 |
||
102 |
/** |
|
103 |
* Verify that only one module decl can be put in module-info.java. |
|
104 |
*/ |
|
105 |
@Test |
|
37758 | 106 |
public void testSingleModuleDecl(Path base) throws Exception { |
36526 | 107 |
Path src = base.resolve("src"); |
108 |
tb.writeJavaFiles(src, "module M1 { } /*...*/ module M2 { }"); |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
109 |
String log = new JavacTask(tb) |
36526 | 110 |
.options("-XDrawDiagnostics") |
111 |
.files(findJavaFiles(src)) |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
112 |
.run(Task.Expect.FAIL) |
36526 | 113 |
.writeAll() |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
114 |
.getOutput(Task.OutputKind.DIRECT); |
36526 | 115 |
|
116 |
if (!log.contains("module-info.java:1:14: compiler.err.expected: token.end-of-input")) |
|
117 |
throw new Exception("expected output not found"); |
|
118 |
} |
|
119 |
||
120 |
/** |
|
121 |
* Verify that missing requires are reported. |
|
122 |
*/ |
|
123 |
@Test |
|
37758 | 124 |
public void testRequiresNotFound(Path base) throws Exception { |
36526 | 125 |
Path src = base.resolve("src"); |
126 |
tb.writeJavaFiles(src, "module M1 { requires M2; }"); |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
127 |
String log = new JavacTask(tb) |
36526 | 128 |
.options("-XDrawDiagnostics") |
129 |
.files(findJavaFiles(src)) |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
130 |
.run(Task.Expect.FAIL) |
36526 | 131 |
.writeAll() |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
132 |
.getOutput(Task.OutputKind.DIRECT); |
36526 | 133 |
|
134 |
if (!log.contains("module-info.java:1:22: compiler.err.module.not.found: M2")) |
|
135 |
throw new Exception("expected output not found"); |
|
136 |
} |
|
137 |
||
138 |
/** |
|
139 |
* Verify that missing exports are reported. |
|
140 |
*/ |
|
141 |
@Test |
|
37758 | 142 |
public void testExportsNotFound(Path base) throws Exception { |
36526 | 143 |
Path src = base.resolve("src"); |
144 |
tb.writeJavaFiles(src, "module M1 { exports p to M2; }"); |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
145 |
String log = new JavacTask(tb) |
36526 | 146 |
.options("-XDrawDiagnostics") |
147 |
.files(findJavaFiles(src)) |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
148 |
.run(Task.Expect.FAIL) |
36526 | 149 |
.writeAll() |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
150 |
.getOutput(Task.OutputKind.DIRECT); |
36526 | 151 |
|
152 |
if (!log.contains("module-info.java:1:26: compiler.err.module.not.found: M2")) |
|
153 |
throw new Exception("expected output not found"); |
|
154 |
} |
|
155 |
||
156 |
/** |
|
157 |
* Verify that a simple loop is detected. |
|
158 |
*/ |
|
159 |
@Test |
|
37758 | 160 |
public void testRequiresSelf(Path base) throws Exception { |
36526 | 161 |
Path src = base.resolve("src"); |
162 |
tb.writeJavaFiles(src, "module M { requires M; }"); |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
163 |
String log = new JavacTask(tb) |
36526 | 164 |
.options("-XDrawDiagnostics") |
165 |
.files(findJavaFiles(src)) |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
166 |
.run(Task.Expect.FAIL) |
36526 | 167 |
.writeAll() |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
168 |
.getOutput(Task.OutputKind.DIRECT); |
36526 | 169 |
|
170 |
if (!log.contains("module-info.java:1:21: compiler.err.cyclic.requires: M")) |
|
171 |
throw new Exception("expected output not found"); |
|
172 |
} |
|
173 |
||
174 |
/** |
|
175 |
* Verify that a multi-module loop is detected. |
|
176 |
*/ |
|
177 |
@Test |
|
37758 | 178 |
public void testRequiresLoop(Path base) throws Exception { |
36526 | 179 |
Path src = base.resolve("src"); |
180 |
Path src_m1 = src.resolve("m1"); |
|
181 |
tb.writeFile(src_m1.resolve("module-info.java"), "module m1 { requires m2; }"); |
|
182 |
Path src_m2 = src.resolve("m2"); |
|
183 |
tb.writeFile(src_m2.resolve("module-info.java"), "module m2 { requires m3; }"); |
|
184 |
Path src_m3 = src.resolve("m3"); |
|
185 |
tb.writeFile(src_m3.resolve("module-info.java"), "module m3 { requires m1; }"); |
|
186 |
||
187 |
Path classes = base.resolve("classes"); |
|
188 |
Files.createDirectories(classes); |
|
189 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
190 |
String log = new JavacTask(tb) |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
38916
diff
changeset
|
191 |
.options("-XDrawDiagnostics", "--module-source-path", src.toString()) |
36526 | 192 |
.outdir(classes) |
193 |
.files(findJavaFiles(src)) |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
194 |
.run(Task.Expect.FAIL) |
36526 | 195 |
.writeAll() |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
196 |
.getOutput(Task.OutputKind.DIRECT); |
36526 | 197 |
|
198 |
if (!log.contains("module-info.java:1:22: compiler.err.cyclic.requires: m3")) |
|
199 |
throw new Exception("expected output not found"); |
|
200 |
} |
|
201 |
||
202 |
/** |
|
203 |
* Verify that a multi-module loop is detected. |
|
204 |
*/ |
|
205 |
@Test |
|
37758 | 206 |
public void testRequiresPublicLoop(Path base) throws Exception { |
36526 | 207 |
Path src = base.resolve("src"); |
208 |
Path src_m1 = src.resolve("m1"); |
|
209 |
tb.writeFile(src_m1.resolve("module-info.java"), "module m1 { requires m2; }"); |
|
210 |
Path src_m2 = src.resolve("m2"); |
|
211 |
tb.writeFile(src_m2.resolve("module-info.java"), "module m2 { requires public m3; }"); |
|
212 |
Path src_m3 = src.resolve("m3"); |
|
213 |
tb.writeFile(src_m3.resolve("module-info.java"), "module m3 { requires m1; }"); |
|
214 |
||
215 |
Path classes = base.resolve("classes"); |
|
216 |
Files.createDirectories(classes); |
|
217 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
218 |
String log = new JavacTask(tb) |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
38916
diff
changeset
|
219 |
.options("-XDrawDiagnostics", "--module-source-path", src.toString()) |
36526 | 220 |
.outdir(classes) |
221 |
.files(findJavaFiles(src)) |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
222 |
.run(Task.Expect.FAIL) |
36526 | 223 |
.writeAll() |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
224 |
.getOutput(Task.OutputKind.DIRECT); |
36526 | 225 |
|
226 |
if (!log.contains("module-info.java:1:29: compiler.err.cyclic.requires: m3")) |
|
227 |
throw new Exception("expected output not found"); |
|
228 |
} |
|
229 |
||
230 |
/** |
|
231 |
* Verify that duplicate requires are detected. |
|
232 |
*/ |
|
233 |
@Test |
|
37758 | 234 |
public void testDuplicateRequires(Path base) throws Exception { |
36526 | 235 |
Path src = base.resolve("src"); |
236 |
Path src_m1 = src.resolve("m1"); |
|
237 |
tb.writeFile(src_m1.resolve("module-info.java"), "module m1 { }"); |
|
238 |
Path src_m2 = src.resolve("m2"); |
|
239 |
tb.writeFile(src_m2.resolve("module-info.java"), "module m2 { requires m1; requires m1; }"); |
|
240 |
||
241 |
Path classes = base.resolve("classes"); |
|
242 |
Files.createDirectories(classes); |
|
243 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
244 |
String log = new JavacTask(tb) |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
38916
diff
changeset
|
245 |
.options("-XDrawDiagnostics", "--module-source-path", src.toString()) |
36526 | 246 |
.outdir(classes) |
247 |
.files(findJavaFiles(src)) |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
248 |
.run(Task.Expect.FAIL) |
36526 | 249 |
.writeAll() |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
250 |
.getOutput(Task.OutputKind.DIRECT); |
36526 | 251 |
|
252 |
if (!log.contains("module-info.java:1:35: compiler.err.duplicate.requires: m1")) |
|
253 |
throw new Exception("expected output not found"); |
|
254 |
} |
|
255 |
||
256 |
/** |
|
257 |
* Verify that duplicate exported packages are detected. |
|
258 |
*/ |
|
259 |
@Test |
|
37758 | 260 |
public void testDuplicateExports_packages(Path base) throws Exception { |
36526 | 261 |
Path src = base.resolve("src"); |
262 |
tb.writeJavaFiles(src, "module m1 { exports p; exports p; }"); |
|
263 |
||
264 |
Path classes = base.resolve("classes"); |
|
265 |
Files.createDirectories(classes); |
|
266 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
267 |
String log = new JavacTask(tb) |
36526 | 268 |
.options("-XDrawDiagnostics") |
269 |
.outdir(classes) |
|
270 |
.files(findJavaFiles(src)) |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
271 |
.run(Task.Expect.FAIL) |
36526 | 272 |
.writeAll() |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
273 |
.getOutput(Task.OutputKind.DIRECT); |
36526 | 274 |
|
275 |
if (!log.contains("module-info.java:1:32: compiler.err.duplicate.exports: p")) |
|
276 |
throw new Exception("expected output not found"); |
|
277 |
} |
|
278 |
||
279 |
/** |
|
280 |
* Verify that duplicate exported packages are detected. |
|
281 |
*/ |
|
282 |
@Test |
|
37758 | 283 |
public void testDuplicateExports_packages2(Path base) throws Exception { |
36526 | 284 |
Path src = base.resolve("src"); |
285 |
tb.writeJavaFiles(src.resolve("m1"), "module m1 { exports p; exports p to m2; }"); |
|
286 |
tb.writeJavaFiles(src.resolve("m2"), "module m2 { }"); |
|
287 |
||
288 |
Path classes = base.resolve("classes"); |
|
289 |
Files.createDirectories(classes); |
|
290 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
291 |
String log = new JavacTask(tb) |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
38916
diff
changeset
|
292 |
.options("-XDrawDiagnostics", "--module-source-path", src.toString()) |
36526 | 293 |
.outdir(classes) |
294 |
.files(findJavaFiles(src)) |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
295 |
.run(Task.Expect.FAIL) |
36526 | 296 |
.writeAll() |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
297 |
.getOutput(Task.OutputKind.DIRECT); |
36526 | 298 |
|
299 |
if (!log.contains("module-info.java:1:32: compiler.err.duplicate.exports: p")) |
|
300 |
throw new Exception("expected output not found"); |
|
301 |
} |
|
302 |
||
303 |
/** |
|
304 |
* Verify that duplicate exported packages are detected. |
|
305 |
*/ |
|
306 |
@Test |
|
37758 | 307 |
public void testDuplicateExports_modules(Path base) throws Exception { |
36526 | 308 |
Path src = base.resolve("src"); |
309 |
Path src_m1 = src.resolve("m1"); |
|
310 |
tb.writeFile(src_m1.resolve("module-info.java"), "module m1 { }"); |
|
311 |
Path src_m2 = src.resolve("m2"); |
|
312 |
tb.writeFile(src_m2.resolve("module-info.java"), "module m2 { exports p to m1, m1; }"); |
|
313 |
||
314 |
Path classes = base.resolve("classes"); |
|
315 |
Files.createDirectories(classes); |
|
316 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
317 |
String log = new JavacTask(tb) |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
38916
diff
changeset
|
318 |
.options("-XDrawDiagnostics", "--module-source-path", src.toString()) |
36526 | 319 |
.outdir(classes) |
320 |
.files(findJavaFiles(src)) |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
321 |
.run(Task.Expect.FAIL) |
36526 | 322 |
.writeAll() |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
323 |
.getOutput(Task.OutputKind.DIRECT); |
36526 | 324 |
|
325 |
if (!log.contains("module-info.java:1:30: compiler.err.duplicate.exports: m1")) |
|
326 |
throw new Exception("expected output not found"); |
|
327 |
} |
|
38916
d118cb2cffab
8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents:
37758
diff
changeset
|
328 |
|
d118cb2cffab
8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents:
37758
diff
changeset
|
329 |
/** |
d118cb2cffab
8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents:
37758
diff
changeset
|
330 |
* Verify that annotations are not permitted at |
d118cb2cffab
8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents:
37758
diff
changeset
|
331 |
* any of the module names or the package names. |
d118cb2cffab
8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents:
37758
diff
changeset
|
332 |
*/ |
d118cb2cffab
8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents:
37758
diff
changeset
|
333 |
@Test |
d118cb2cffab
8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents:
37758
diff
changeset
|
334 |
public void testAnnotations(Path base) throws Exception { |
d118cb2cffab
8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents:
37758
diff
changeset
|
335 |
Path src = base.resolve("src"); |
d118cb2cffab
8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents:
37758
diff
changeset
|
336 |
Path src_m1 = src.resolve("m1.sub"); |
d118cb2cffab
8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents:
37758
diff
changeset
|
337 |
Path classes = base.resolve("classes"); |
d118cb2cffab
8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents:
37758
diff
changeset
|
338 |
Files.createDirectories(classes); |
d118cb2cffab
8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents:
37758
diff
changeset
|
339 |
|
d118cb2cffab
8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents:
37758
diff
changeset
|
340 |
String code = "module @m1.@sub { " + |
d118cb2cffab
8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents:
37758
diff
changeset
|
341 |
"requires @p1.@p2; " + |
d118cb2cffab
8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents:
37758
diff
changeset
|
342 |
"exports @p1.@p2; " + |
d118cb2cffab
8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents:
37758
diff
changeset
|
343 |
"exports @p1.@p2 to @m2.@sub; " + |
d118cb2cffab
8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents:
37758
diff
changeset
|
344 |
"exports @p1.@p2 to @m2.@sub, @m3.@sub; " + |
d118cb2cffab
8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents:
37758
diff
changeset
|
345 |
"uses @p1.@Interface; " + |
d118cb2cffab
8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents:
37758
diff
changeset
|
346 |
"provides @p1.@Interface with @p2.@Concrete; " + |
d118cb2cffab
8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents:
37758
diff
changeset
|
347 |
"}"; |
d118cb2cffab
8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents:
37758
diff
changeset
|
348 |
String[] splittedCode = code.split("@"); |
d118cb2cffab
8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents:
37758
diff
changeset
|
349 |
int length = splittedCode.length; |
d118cb2cffab
8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents:
37758
diff
changeset
|
350 |
String anno = "@Anno "; |
d118cb2cffab
8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents:
37758
diff
changeset
|
351 |
|
d118cb2cffab
8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents:
37758
diff
changeset
|
352 |
for (int i = 1; i < length; i++) { |
d118cb2cffab
8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents:
37758
diff
changeset
|
353 |
String preAnno = String.join("", Arrays.copyOfRange(splittedCode, 0, i)); |
d118cb2cffab
8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents:
37758
diff
changeset
|
354 |
String postAnno = String.join("", Arrays.copyOfRange(splittedCode, i, length)); |
d118cb2cffab
8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents:
37758
diff
changeset
|
355 |
String moduleInfo = preAnno + anno + postAnno; |
d118cb2cffab
8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents:
37758
diff
changeset
|
356 |
tb.writeFile(src_m1.resolve("module-info.java"), moduleInfo); |
d118cb2cffab
8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents:
37758
diff
changeset
|
357 |
|
d118cb2cffab
8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents:
37758
diff
changeset
|
358 |
String log = new JavacTask(tb) |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
38916
diff
changeset
|
359 |
.options("-XDrawDiagnostics", "--module-source-path", src.toString()) |
38916
d118cb2cffab
8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents:
37758
diff
changeset
|
360 |
.outdir(classes) |
d118cb2cffab
8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents:
37758
diff
changeset
|
361 |
.files(findJavaFiles(src)) |
d118cb2cffab
8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents:
37758
diff
changeset
|
362 |
.run(Task.Expect.FAIL) |
d118cb2cffab
8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents:
37758
diff
changeset
|
363 |
.writeAll() |
d118cb2cffab
8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents:
37758
diff
changeset
|
364 |
.getOutput(Task.OutputKind.DIRECT); |
d118cb2cffab
8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents:
37758
diff
changeset
|
365 |
|
d118cb2cffab
8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents:
37758
diff
changeset
|
366 |
if (!log.matches("(?s)^module\\-info\\.java:\\d+:\\d+: compiler\\.err\\.expected: token\\.identifier.*")) |
d118cb2cffab
8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents:
37758
diff
changeset
|
367 |
throw new Exception("expected output not found"); |
d118cb2cffab
8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents:
37758
diff
changeset
|
368 |
} |
d118cb2cffab
8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents:
37758
diff
changeset
|
369 |
} |
36526 | 370 |
} |