|
1 /* |
|
2 * Copyright (c) 2016, 2017, 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 * @bug 8156962 |
|
27 * @summary Tests use of JDK_JAVAC_OPTIONS env variable |
|
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 EnvVarTest |
|
33 */ |
|
34 |
|
35 import java.nio.file.Path; |
|
36 |
|
37 import toolbox.JavacTask; |
|
38 import toolbox.Task.Expect; |
|
39 import toolbox.Task.Mode; |
|
40 |
|
41 public class EnvVarTest extends ModuleTestBase { |
|
42 |
|
43 public static void main(String... args) throws Exception { |
|
44 new EnvVarTest().runTests(); |
|
45 } |
|
46 |
|
47 @Test |
|
48 public void testAddExports(Path base) throws Exception { |
|
49 Path src = base.resolve("src"); |
|
50 // the package in the following call should be one that is not |
|
51 // available by default, including via @modules |
|
52 tb.writeJavaFiles(src, |
|
53 "package p; public class C { com.sun.tools.javac.jvm.Target t; }"); |
|
54 Path classes = base.resolve("classes"); |
|
55 tb.createDirectories(classes); |
|
56 |
|
57 tb.out.println("test that compilation fails if addExports is not provided"); |
|
58 new JavacTask(tb) |
|
59 .outdir(classes) |
|
60 .files(findJavaFiles(src)) |
|
61 .run(Expect.FAIL) |
|
62 .writeAll(); |
|
63 |
|
64 tb.out.println("test that addExports can be given to javac"); |
|
65 new JavacTask(tb) |
|
66 .options("--add-exports", "jdk.compiler/com.sun.tools.javac.jvm=ALL-UNNAMED") |
|
67 .outdir(classes) |
|
68 .files(findJavaFiles(src)) |
|
69 .run(Expect.SUCCESS) |
|
70 .writeAll(); |
|
71 |
|
72 tb.out.println("test that addExports can be provided with env variable"); |
|
73 new JavacTask(tb, Mode.EXEC) |
|
74 .envVar("JDK_JAVAC_OPTIONS", "--add-exports jdk.compiler/com.sun.tools.javac.jvm=ALL-UNNAMED") |
|
75 .outdir(classes) |
|
76 .files(findJavaFiles(src)) |
|
77 .run(Expect.SUCCESS) |
|
78 .writeAll(); |
|
79 |
|
80 tb.out.println("test that addExports can be provided with env variable using @file"); |
|
81 Path atFile = src.resolve("at-file.txt"); |
|
82 tb.writeFile(atFile, |
|
83 "--add-exports jdk.compiler/com.sun.tools.javac.jvm=ALL-UNNAMED"); |
|
84 |
|
85 new JavacTask(tb, Mode.EXEC) |
|
86 .envVar("JDK_JAVAC_OPTIONS", "@" + atFile) |
|
87 .outdir(classes) |
|
88 .files(findJavaFiles(src)) |
|
89 .run(Expect.SUCCESS) |
|
90 .writeAll(); |
|
91 } |
|
92 |
|
93 } |
|
94 |