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 Test the --add-exports option
27 * @library /tools/lib
28 * @modules jdk.compiler/com.sun.tools.javac.api
29 * jdk.compiler/com.sun.tools.javac.main
30 * @build toolbox.ToolBox toolbox.JavacTask ModuleTestBase
31 * @run main AddExportsTest
32 */
33
34 import java.nio.file.Path;
35
36 import toolbox.JavacTask;
37 import toolbox.Task;
38
39 public class AddExportsTest extends ModuleTestBase {
40
41 public static void main(String... args) throws Exception {
42 new AddExportsTest().runTests();
43 }
44
45 @Test
46 public void testEmpty(Path base) throws Exception {
47 Path src = base.resolve("src");
48 tb.writeJavaFiles(src, "class Dummy { }");
49 Path classes = base.resolve("classes");
50 tb.createDirectories(classes);
51 testEmpty(src, classes, "--add-exports", "");
52 testEmpty(src, classes, "--add-exports=");
53 }
54
55 private void testEmpty(Path src, Path classes, String... options) throws Exception {
56 String log = new JavacTask(tb, Task.Mode.CMDLINE)
57 .options(options)
58 .outdir(classes)
59 .files(findJavaFiles(src))
60 .run(Task.Expect.FAIL)
61 .writeAll()
62 .getOutput(Task.OutputKind.DIRECT);
63
64 checkOutputContains(log,
65 "error: no value for --add-exports option");
66 }
67
68 @Test
69 public void testEmptyItem(Path base) throws Exception {
70 Path src = base.resolve("src");
71 Path src_m1 = src.resolve("m1x");
72 tb.writeJavaFiles(src_m1,
73 "module m1x { }",
74 "package p1; public class C1 { }");
75 Path src_m2 = src.resolve("m2x");
76 tb.writeJavaFiles(src_m2,
77 "module m2x { }",
78 "package p2; class C2 { p1.C1 c1; }");
79 Path src_m3 = src.resolve("m3x");
80 tb.writeJavaFiles(src_m3,
81 "module m3x { }",
82 "package p3; class C3 { p1.C1 c1; }");
83 Path classes = base.resolve("classes");
84 tb.createDirectories(classes);
85
86 testEmptyItem(src, classes, "m1x/p1=,m2x,m3x");
87 testEmptyItem(src, classes, "m1x/p1=m2x,,m3x");
88 testEmptyItem(src, classes, "m1x/p1=m2x,m3x,");
89 }
90
91 void testEmptyItem(Path src, Path classes, String option) throws Exception {
92 new JavacTask(tb)
93 .options("--module-source-path", src.toString(),
94 "--add-exports", option)
95 .outdir(classes)
96 .files(findJavaFiles(src))
97 .run()
98 .writeAll();
99 }
100
101 @Test
258 "--add-exports", "m1x/p1=DoesNotExist")
259 .outdir(classes)
260 .files(findJavaFiles(src))
261 .run()
262 .writeAll()
263 .getOutput(Task.OutputKind.DIRECT);
264
265 checkOutputContains(log,
266 "- compiler.warn.module.for.option.not.found: --add-exports, DoesNotExist");
267 }
268
269 @Test
270 public void testDuplicate(Path base) throws Exception {
271 Path src = base.resolve("src");
272 Path src_m1 = src.resolve("m1x");
273 tb.writeJavaFiles(src_m1,
274 "module m1x { }",
275 "package p1; public class C1 { }");
276 Path src_m2 = src.resolve("m2x");
277 tb.writeJavaFiles(src_m2,
278 "module m2x { }",
279 "package p2; class C2 { p1.C1 c1; }");
280 Path classes = base.resolve("classes");
281 tb.createDirectories(classes);
282
283 new JavacTask(tb)
284 .options("--module-source-path", src.toString(),
285 "--add-exports", "m1x/p1=m2x,m2x")
286 .outdir(classes)
287 .files(findJavaFiles(src))
288 .run()
289 .writeAll();
290 }
291
292 @Test
293 public void testRepeated_SameTarget(Path base) throws Exception {
294 Path src = base.resolve("src");
295 Path src_m1 = src.resolve("m1x");
296 tb.writeJavaFiles(src_m1,
297 "module m1x { }",
298 "package p1; public class C1 { }");
299 Path src_m2 = src.resolve("m2x");
300 tb.writeJavaFiles(src_m2,
301 "module m2x { }",
302 "package p2; class C2 { p1.C1 c1; }");
303 Path classes = base.resolve("classes");
304 tb.createDirectories(classes);
305
306 new JavacTask(tb)
307 .options("--module-source-path", src.toString(),
308 "--add-exports", "m1x/p1=m2x",
309 "--add-exports", "m1x/p1=m2x")
310 .outdir(classes)
311 .files(findJavaFiles(src))
312 .run()
313 .writeAll();
314 }
315
316 @Test
317 public void testRepeated_DifferentTarget(Path base) throws Exception {
318 Path src = base.resolve("src");
319 Path src_m1 = src.resolve("m1x");
320 tb.writeJavaFiles(src_m1,
321 "module m1x { }",
322 "package p1; public class C1 { }");
323 Path src_m2 = src.resolve("m2x");
324 tb.writeJavaFiles(src_m2,
325 "module m2x { }",
326 "package p2; class C2 { p1.C1 c1; }");
327 Path src_m3 = src.resolve("m3x");
328 tb.writeJavaFiles(src_m3,
329 "module m3x { }",
330 "package p3; class C3 { p1.C1 c1; }");
331 Path classes = base.resolve("classes");
332 tb.createDirectories(classes);
333
334 new JavacTask(tb)
335 .options("--module-source-path", src.toString(),
336 "--add-exports", "m1x/p1=m2x",
337 "--add-exports", "m1x/p1=m3x")
338 .outdir(classes)
339 .files(findJavaFiles(src))
340 .run()
341 .writeAll();
342 }
343 }
|
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 * @bug 8207032
27 * @summary Test the --add-exports option
28 * @library /tools/lib
29 * @modules jdk.compiler/com.sun.tools.javac.api
30 * jdk.compiler/com.sun.tools.javac.main
31 * @build toolbox.ToolBox toolbox.JavacTask ModuleTestBase
32 * @run main AddExportsTest
33 */
34
35 import java.nio.file.Path;
36
37 import toolbox.JavacTask;
38 import toolbox.Task;
39 import toolbox.Task.Expect;
40 import toolbox.Task.OutputKind;
41
42 public class AddExportsTest extends ModuleTestBase {
43
44 public static void main(String... args) throws Exception {
45 new AddExportsTest().runTests();
46 }
47
48 @Test
49 public void testEmpty(Path base) throws Exception {
50 Path src = base.resolve("src");
51 tb.writeJavaFiles(src, "class Dummy { }");
52 Path classes = base.resolve("classes");
53 tb.createDirectories(classes);
54 testEmpty(src, classes, "--add-exports", "");
55 testEmpty(src, classes, "--add-exports=");
56 }
57
58 private void testEmpty(Path src, Path classes, String... options) throws Exception {
59 String log = new JavacTask(tb, Task.Mode.CMDLINE)
60 .options(options)
61 .outdir(classes)
62 .files(findJavaFiles(src))
63 .run(Task.Expect.FAIL)
64 .writeAll()
65 .getOutput(Task.OutputKind.DIRECT);
66
67 checkOutputContains(log,
68 "error: no value for --add-exports option");
69 }
70
71 @Test
72 public void testEmptyItem(Path base) throws Exception {
73 Path src = base.resolve("src");
74 Path src_m1 = src.resolve("m1x");
75 tb.writeJavaFiles(src_m1,
76 "module m1x { }",
77 "package p1; public class C1 { }");
78 Path src_m2 = src.resolve("m2x");
79 tb.writeJavaFiles(src_m2,
80 "module m2x { requires m1x; }",
81 "package p2; class C2 { p1.C1 c1; }");
82 Path src_m3 = src.resolve("m3x");
83 tb.writeJavaFiles(src_m3,
84 "module m3x { requires m1x; }",
85 "package p3; class C3 { p1.C1 c1; }");
86 Path classes = base.resolve("classes");
87 tb.createDirectories(classes);
88
89 testEmptyItem(src, classes, "m1x/p1=,m2x,m3x");
90 testEmptyItem(src, classes, "m1x/p1=m2x,,m3x");
91 testEmptyItem(src, classes, "m1x/p1=m2x,m3x,");
92 }
93
94 void testEmptyItem(Path src, Path classes, String option) throws Exception {
95 new JavacTask(tb)
96 .options("--module-source-path", src.toString(),
97 "--add-exports", option)
98 .outdir(classes)
99 .files(findJavaFiles(src))
100 .run()
101 .writeAll();
102 }
103
104 @Test
261 "--add-exports", "m1x/p1=DoesNotExist")
262 .outdir(classes)
263 .files(findJavaFiles(src))
264 .run()
265 .writeAll()
266 .getOutput(Task.OutputKind.DIRECT);
267
268 checkOutputContains(log,
269 "- compiler.warn.module.for.option.not.found: --add-exports, DoesNotExist");
270 }
271
272 @Test
273 public void testDuplicate(Path base) throws Exception {
274 Path src = base.resolve("src");
275 Path src_m1 = src.resolve("m1x");
276 tb.writeJavaFiles(src_m1,
277 "module m1x { }",
278 "package p1; public class C1 { }");
279 Path src_m2 = src.resolve("m2x");
280 tb.writeJavaFiles(src_m2,
281 "module m2x { requires m1x; }",
282 "package p2; class C2 { p1.C1 c1; }");
283 Path classes = base.resolve("classes");
284 tb.createDirectories(classes);
285
286 new JavacTask(tb)
287 .options("--module-source-path", src.toString(),
288 "--add-exports", "m1x/p1=m2x,m2x")
289 .outdir(classes)
290 .files(findJavaFiles(src))
291 .run()
292 .writeAll();
293 }
294
295 @Test
296 public void testRepeated_SameTarget(Path base) throws Exception {
297 Path src = base.resolve("src");
298 Path src_m1 = src.resolve("m1x");
299 tb.writeJavaFiles(src_m1,
300 "module m1x { }",
301 "package p1; public class C1 { }");
302 Path src_m2 = src.resolve("m2x");
303 tb.writeJavaFiles(src_m2,
304 "module m2x { requires m1x; }",
305 "package p2; class C2 { p1.C1 c1; }");
306 Path classes = base.resolve("classes");
307 tb.createDirectories(classes);
308
309 new JavacTask(tb)
310 .options("--module-source-path", src.toString(),
311 "--add-exports", "m1x/p1=m2x",
312 "--add-exports", "m1x/p1=m2x")
313 .outdir(classes)
314 .files(findJavaFiles(src))
315 .run()
316 .writeAll();
317 }
318
319 @Test
320 public void testRepeated_DifferentTarget(Path base) throws Exception {
321 Path src = base.resolve("src");
322 Path src_m1 = src.resolve("m1x");
323 tb.writeJavaFiles(src_m1,
324 "module m1x { }",
325 "package p1; public class C1 { }");
326 Path src_m2 = src.resolve("m2x");
327 tb.writeJavaFiles(src_m2,
328 "module m2x { requires m1x; }",
329 "package p2; class C2 { p1.C1 c1; }");
330 Path src_m3 = src.resolve("m3x");
331 tb.writeJavaFiles(src_m3,
332 "module m3x { requires m1x; }",
333 "package p3; class C3 { p1.C1 c1; }");
334 Path classes = base.resolve("classes");
335 tb.createDirectories(classes);
336
337 new JavacTask(tb)
338 .options("--module-source-path", src.toString(),
339 "--add-exports", "m1x/p1=m2x",
340 "--add-exports", "m1x/p1=m3x")
341 .outdir(classes)
342 .files(findJavaFiles(src))
343 .run()
344 .writeAll();
345 }
346
347 @Test
348 public void testNoReads(Path base) throws Exception {
349 Path src = base.resolve("src");
350 Path src_m1 = src.resolve("m1x");
351 tb.writeJavaFiles(src_m1,
352 "module m1x { }",
353 "package p1; public class C1 { }");
354 Path src_m2 = src.resolve("m2x");
355 tb.writeJavaFiles(src_m2,
356 "module m2x { }",
357 "package p2; class C2 { p1.C1 c1; }");
358 Path classes = base.resolve("classes");
359 tb.createDirectories(classes);
360
361 String log;
362
363 log = new JavacTask(tb)
364 .options("--module-source-path", src.toString(),
365 "-XDrawDiagnostics")
366 .outdir(classes)
367 .files(findJavaFiles(src))
368 .run(Expect.FAIL)
369 .writeAll()
370 .getOutput(OutputKind.DIRECT);
371
372 checkOutputContains(log,
373 "C2.java:1:24: compiler.err.package.not.visible: p1, (compiler.misc.not.def.access.does.not.read: m2x, p1, m1x)");
374
375 log = new JavacTask(tb)
376 .options("--module-source-path", src.toString(),
377 "-XDrawDiagnostics",
378 "--add-exports", "m1x/p1=m2x")
379 .outdir(classes)
380 .files(findJavaFiles(src))
381 .run(Expect.FAIL)
382 .writeAll()
383 .getOutput(OutputKind.DIRECT);
384
385 checkOutputContains(log,
386 "C2.java:1:24: compiler.err.package.not.visible: p1, (compiler.misc.not.def.access.does.not.read: m2x, p1, m1x)");
387
388 Path mp = base.resolve("mp");
389 tb.createDirectories(mp);
390
391 new JavacTask(tb)
392 .options("--module-source-path", src.toString(),
393 "-XDrawDiagnostics",
394 "--add-exports", "m1x/p1=m2x",
395 "--add-reads", "m2x=m1x")
396 .outdir(mp)
397 .files(findJavaFiles(src))
398 .run(Expect.SUCCESS)
399 .writeAll();
400
401 log = new JavacTask(tb)
402 .options("-XDrawDiagnostics",
403 "--add-exports", "m1x/p1=m2x",
404 "--add-reads", "m2x=m1x",
405 "--module-path", mp.toString())
406 .outdir(classes)
407 .files(findJavaFiles(src_m2))
408 .run(Expect.FAIL)
409 .writeAll()
410 .getOutput(OutputKind.DIRECT);
411
412 checkOutputContains(log,
413 "C2.java:1:24: compiler.err.package.not.visible: p1, (compiler.misc.not.def.access.does.not.read: m2x, p1, m1x)");
414 checkOutputContains(log,
415 "- compiler.warn.module.for.option.not.found: --add-reads, m1x");
416 checkOutputContains(log,
417 "- compiler.warn.module.for.option.not.found: --add-exports, m1x");
418
419 new JavacTask(tb)
420 .options("-XDrawDiagnostics",
421 "--add-exports", "m1x/p1=m2x",
422 "--add-reads", "m2x=m1x",
423 "--module-path", mp.toString(),
424 "--add-modules", "m1x")
425 .outdir(classes)
426 .files(findJavaFiles(src_m2))
427 .run(Expect.SUCCESS)
428 .writeAll()
429 .getOutput(OutputKind.DIRECT);
430 }
431 }
|