author | sadayapalam |
Mon, 06 Feb 2017 18:14:51 +0530 | |
changeset 43584 | 63e67712246b |
parent 40514 | fa42e8040550 |
child 43772 | 4e5350b7be75 |
permissions | -rw-r--r-- |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
1 |
/* |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
2 |
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
4 |
* |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
8 |
* |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
13 |
* accompanied this code). |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
14 |
* |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
18 |
* |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
21 |
* questions. |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
22 |
*/ |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
23 |
|
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
24 |
/** |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
25 |
* @test |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
26 |
* @bug 8156998 |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
27 |
* @summary Test --inherit-runtime-environment |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
28 |
* @library /tools/lib |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
29 |
* @modules |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
30 |
* jdk.compiler/com.sun.tools.javac.api |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
31 |
* jdk.compiler/com.sun.tools.javac.main |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
32 |
* @build toolbox.ToolBox toolbox.JarTask toolbox.JavacTask toolbox.JavaTask ModuleTestBase |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
33 |
* @run main InheritRuntimeEnvironmentTest |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
34 |
*/ |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
35 |
|
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
36 |
import java.io.IOException; |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
37 |
import java.nio.file.Files; |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
38 |
import java.nio.file.Path; |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
39 |
import java.util.Arrays; |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
40 |
import java.util.Collections; |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
41 |
import java.util.List; |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
42 |
import java.util.stream.Collectors; |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
43 |
|
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
44 |
import toolbox.ModuleBuilder; |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
45 |
import toolbox.JavaTask; |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
46 |
import toolbox.JavacTask; |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
47 |
import toolbox.Task; |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
48 |
|
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
49 |
/** |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
50 |
* Tests that javac picks up runtime options with --inherit-runtime-environment. |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
51 |
* For each option, javac is first run using the option directly, as a control. |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
52 |
* javac is then run again, with the same option(s) being passed to the runtime, |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
53 |
* and --inherit-runtime-environment being used by javac. |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
54 |
* @author jjg |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
55 |
*/ |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
56 |
public class InheritRuntimeEnvironmentTest extends ModuleTestBase { |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
57 |
public static void main(String... args) throws Exception { |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
58 |
InheritRuntimeEnvironmentTest t = new InheritRuntimeEnvironmentTest(); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
59 |
t.runTests(); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
60 |
} |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
61 |
|
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
62 |
/** |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
63 |
* Tests that code being compiled can access JDK-internal API using -add-exports. |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
64 |
* @param base |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
65 |
* @throws Exception |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
66 |
*/ |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
67 |
@Test |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
68 |
public void testAddExports(Path base) throws Exception { |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
69 |
Path src = base.resolve("src"); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
70 |
tb.writeJavaFiles(src, |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
71 |
"class C { com.sun.tools.javac.main.Main main; }"); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
72 |
|
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
73 |
new TestCase(base) |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
74 |
.testOpts("--add-exports", "jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED") |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
75 |
.files(findJavaFiles(src)) |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
76 |
.run(); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
77 |
} |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
78 |
|
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
79 |
/** |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
80 |
* Tests that code in the unnamed module can access a module on the module path using --add-modules. |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
81 |
*/ |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
82 |
@Test |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
83 |
public void testAddModules(Path base) throws Exception { |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
84 |
Path modules = base.resolve("modules"); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
85 |
new ModuleBuilder(tb, "m1") |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
86 |
.exports("pkg1") |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
87 |
.classes("package pkg1; public class C1 { }") |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
88 |
.build(modules); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
89 |
|
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
90 |
Path src = base.resolve("src"); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
91 |
tb.writeJavaFiles(src, |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
92 |
"class C { pkg1.C1 c1; }"); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
93 |
|
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
94 |
new TestCase(base) |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
95 |
.testOpts("--module-path", modules.toString(), "--add-modules", "m1") |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
96 |
.files(findJavaFiles(src)) |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
97 |
.run(); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
98 |
} |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
99 |
|
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
100 |
/** |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
101 |
* Tests that a module on the module path is not visible when --limit-modules is used to |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
102 |
* restrict the set of observable modules. |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
103 |
*/ |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
104 |
@Test |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
105 |
public void testLimitModules(Path base) throws Exception { |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
106 |
Path modules = base.resolve("modules"); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
107 |
new ModuleBuilder(tb, "m1") |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
108 |
.exports("pkg1") |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
109 |
.classes("package pkg1; public class C1 { }") |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
110 |
.build(modules); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
111 |
|
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
112 |
Path src = base.resolve("src"); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
113 |
new ModuleBuilder(tb, "m2") |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
114 |
.requires("m1") |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
115 |
.classes("package pkg2; public class C2 { pkg1.C1 c1; }") |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
116 |
.write(src); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
117 |
|
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
118 |
// This is the control, to verify that by default, the module being compiled will |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
119 |
// be able to read modules on the module path |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
120 |
new TestCase(base) |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
121 |
.testOpts("--module-path", modules.toString()) |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
122 |
.otherOpts("--module-source-path", src.toString()) |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
123 |
.files(findJavaFiles(src)) |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
124 |
.run(); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
125 |
|
40514
fa42e8040550
8164550: tools/javac/modules/InheritRuntimeEnvironmentTest.java fails on Windows after JDK-8153391
jlahoda
parents:
40513
diff
changeset
|
126 |
Path emptyClassPath = base.resolve("emptyClassPath"); |
fa42e8040550
8164550: tools/javac/modules/InheritRuntimeEnvironmentTest.java fails on Windows after JDK-8153391
jlahoda
parents:
40513
diff
changeset
|
127 |
|
fa42e8040550
8164550: tools/javac/modules/InheritRuntimeEnvironmentTest.java fails on Windows after JDK-8153391
jlahoda
parents:
40513
diff
changeset
|
128 |
Files.createDirectories(emptyClassPath); |
fa42e8040550
8164550: tools/javac/modules/InheritRuntimeEnvironmentTest.java fails on Windows after JDK-8153391
jlahoda
parents:
40513
diff
changeset
|
129 |
|
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
130 |
// This is the test, to verify that the module being compiled will not be able to read |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
131 |
// modules on the module path when a --limit-modules is used |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
132 |
new TestCase(base) |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
133 |
.testOpts("--module-path", modules.toString(), "--limit-modules", "jdk.compiler") |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
134 |
.otherOpts("-XDrawDiagnostics", |
40513
39b67170b045
8153391: an image created for \"jdk.compiler\" fails to run javac
jlahoda
parents:
40308
diff
changeset
|
135 |
"--module-source-path", src.toString(), |
40514
fa42e8040550
8164550: tools/javac/modules/InheritRuntimeEnvironmentTest.java fails on Windows after JDK-8153391
jlahoda
parents:
40513
diff
changeset
|
136 |
"-classpath", emptyClassPath.toString()) |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
137 |
.files(findJavaFiles(src)) |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
138 |
.expect(Task.Expect.FAIL, "compiler.err.module.not.found") |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
139 |
.run(); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
140 |
} |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
141 |
|
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
142 |
/** |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
143 |
* Tests that a module being compiled can see another module on the module path |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
144 |
* using --module-path. |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
145 |
*/ |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
146 |
@Test |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
147 |
public void testModulePath(Path base) throws Exception { |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
148 |
Path modules = base.resolve("modules"); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
149 |
new ModuleBuilder(tb, "m1") |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
150 |
.exports("pkg1") |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
151 |
.classes("package pkg1; public class C1 { }") |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
152 |
.build(modules); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
153 |
|
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
154 |
Path src = base.resolve("src"); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
155 |
new ModuleBuilder(tb, "m2") |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
156 |
.requires("m1") |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
157 |
.classes("package pkg2; public class C2 { pkg1.C1 c1; }") |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
158 |
.write(src); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
159 |
|
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
160 |
new TestCase(base) |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
161 |
.testOpts("--module-path", modules.toString()) |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
162 |
.otherOpts("--module-source-path", src.toString()) |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
163 |
.files(findJavaFiles(src)) |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
164 |
.run(); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
165 |
} |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
166 |
|
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
167 |
/** |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
168 |
* Tests that a module being compiled can see classes patches into an existing module |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
169 |
* with --patch-module |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
170 |
*/ |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
171 |
@Test |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
172 |
public void testPatchModule(Path base) throws Exception { |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
173 |
Path patchSrc = base.resolve("patchSrc"); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
174 |
tb.writeJavaFiles(patchSrc, |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
175 |
"package java.util; public class Xyzzy { }"); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
176 |
Path patch = base.resolve("patch"); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
177 |
Files.createDirectories(patch); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
178 |
|
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
179 |
new JavacTask(tb) |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
180 |
.options("-Xmodule:java.base") |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
181 |
.outdir(patch) |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
182 |
.sourcepath(patchSrc) |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
183 |
.files(findJavaFiles(patchSrc)) |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
184 |
.run() |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
185 |
.writeAll(); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
186 |
|
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
187 |
Path src = base.resolve("src"); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
188 |
tb.writeJavaFiles(src, |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
189 |
"public class C { java.util.Xyzzy x; }"); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
190 |
|
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
191 |
new TestCase(base) |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
192 |
.testOpts("--patch-module", "java.base=" + patch) |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
193 |
.files(findJavaFiles(src)) |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
194 |
.run(); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
195 |
} |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
196 |
|
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
197 |
/** |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
198 |
* Tests that options in @files are also effective. |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
199 |
* The test is similar to testModulePath, except that the test options are provided in an @-file. |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
200 |
*/ |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
201 |
@Test |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
202 |
public void testAtFile(Path base) throws Exception { |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
203 |
Path modules = base.resolve("modules"); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
204 |
new ModuleBuilder(tb, "m1") |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
205 |
.exports("pkg1") |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
206 |
.classes("package pkg1; public class C1 { }") |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
207 |
.build(modules); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
208 |
|
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
209 |
Path src = base.resolve("src"); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
210 |
new ModuleBuilder(tb, "m2") |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
211 |
.requires("m1") |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
212 |
.classes("package pkg2; public class C2 { pkg1.C1 c1; }") |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
213 |
.write(src); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
214 |
|
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
215 |
Path atFile = base.resolve("atFile"); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
216 |
tb.writeFile(atFile, "--module-path " + modules); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
217 |
|
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
218 |
new TestCase(base) |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
219 |
.testOpts("@" + atFile) |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
220 |
.otherOpts("--module-source-path", src.toString()) |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
221 |
.files(findJavaFiles(src)) |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
222 |
.run(); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
223 |
} |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
224 |
|
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
225 |
/** |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
226 |
* Tests that --inherit-runtime-environment works in conjunction with |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
227 |
* environment variables. |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
228 |
* This is a variant of testAddExports. |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
229 |
* The use of environment variables is sufficiently custom that it is |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
230 |
* not easy to do this directly with a simple TestCase. |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
231 |
*/ |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
232 |
@Test |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
233 |
public void testEnvVars(Path base) throws Exception { |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
234 |
Path src = base.resolve("src"); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
235 |
tb.writeJavaFiles(src, |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
236 |
"class C { com.sun.tools.javac.main.Main main; }"); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
237 |
List<String> testOpts = |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
238 |
Arrays.asList("--add-exports", "jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED"); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
239 |
List<Path> files = Arrays.asList(findJavaFiles(src)); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
240 |
|
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
241 |
String envName = "_JAVAC_OPTIONS"; |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
242 |
String envValue = String.join(" ", testOpts); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
243 |
|
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
244 |
out.println(" javac:"); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
245 |
Path javacOutDir = base.resolve("out-javac"); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
246 |
Files.createDirectories(javacOutDir); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
247 |
|
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
248 |
out.println(" env: " + envName + "=" + envValue); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
249 |
out.println(" outdir: " + javacOutDir); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
250 |
out.println(" files: " + files); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
251 |
|
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
252 |
new JavacTask(tb, Task.Mode.EXEC) |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
253 |
.envVar(envName, envValue) |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
254 |
.outdir(javacOutDir) |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
255 |
.files(files) |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
256 |
.run() |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
257 |
.writeAll() |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
258 |
.getOutput(Task.OutputKind.DIRECT); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
259 |
|
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
260 |
out.println(" java:"); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
261 |
Path javaOutDir = base.resolve("out-java"); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
262 |
Files.createDirectories(javaOutDir); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
263 |
|
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
264 |
Path atFile = base.resolve("atFile"); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
265 |
tb.writeFile(atFile, String.join(" ", testOpts)); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
266 |
|
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
267 |
List<String> vmOpts = Arrays.asList( |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
268 |
"@" + atFile, |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
269 |
"--module", "jdk.compiler/com.sun.tools.javac.Main" |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
270 |
); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
271 |
|
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
272 |
List<String> classArgs = join( |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
273 |
Arrays.asList("-d", javaOutDir.toString()), |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
274 |
files.stream() |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
275 |
.map(p -> p.toString()) |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
276 |
.collect(Collectors.toList()) |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
277 |
); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
278 |
|
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
279 |
envValue = "--inherit-runtime-environment"; |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
280 |
|
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
281 |
out.println(" env: " + envName + "=" + envValue); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
282 |
out.println(" vmOpts: " + vmOpts); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
283 |
out.println(" classArgs: " + classArgs); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
284 |
|
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
285 |
new JavaTask(tb) |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
286 |
.envVar(envName, envValue) |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
287 |
.vmOptions(vmOpts) |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
288 |
.classArgs(classArgs) |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
289 |
.run() |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
290 |
.writeAll() |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
291 |
.getOutput(Task.OutputKind.STDERR); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
292 |
} |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
293 |
|
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
294 |
/** |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
295 |
* Runs javac with given test options, first directly, and then again, specifying the |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
296 |
* options to the runtime, and using --inherit-runtime-environment. |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
297 |
*/ |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
298 |
class TestCase { |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
299 |
final Path base; |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
300 |
List<String> testOpts = Collections.emptyList(); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
301 |
List<String> otherOpts = Collections.emptyList(); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
302 |
List<Path> files = Collections.emptyList(); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
303 |
Task.Expect expect = Task.Expect.SUCCESS; |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
304 |
String expectedText; |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
305 |
|
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
306 |
/** |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
307 |
* Creates a test case, specifying a base directory for work files. |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
308 |
*/ |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
309 |
TestCase(Path base) { |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
310 |
this.base = base; |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
311 |
} |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
312 |
|
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
313 |
/** |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
314 |
* Set the "test options" to be passed to javac or to the runtime. |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
315 |
*/ |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
316 |
TestCase testOpts(String... testOpts) { |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
317 |
this.testOpts = Arrays.asList(testOpts); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
318 |
return this; |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
319 |
} |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
320 |
|
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
321 |
/** |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
322 |
* Sets additional options required for the compilation. |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
323 |
*/ |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
324 |
TestCase otherOpts(String... otherOpts) { |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
325 |
this.otherOpts = Arrays.asList(otherOpts); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
326 |
return this; |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
327 |
} |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
328 |
|
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
329 |
/** |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
330 |
* Sets the files to be compiled. |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
331 |
*/ |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
332 |
TestCase files(Path... files) { |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
333 |
this.files = Arrays.asList(files); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
334 |
return this; |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
335 |
} |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
336 |
|
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
337 |
/** |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
338 |
* Sets the expected output, and any expected output from javac. |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
339 |
* The default is {@code Expect.SUCCESS} and no specific output expected. |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
340 |
*/ |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
341 |
TestCase expect(Task.Expect expect, String expectedText) { |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
342 |
this.expect = expect; |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
343 |
this.expectedText = expectedText; |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
344 |
return this; |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
345 |
} |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
346 |
|
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
347 |
/** |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
348 |
* Runs the test case. |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
349 |
* First, javac is run passing the test options directly to javac. |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
350 |
* Then, javac is run again, passing the test options to the runtime, |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
351 |
* and using --inherit-runtime-environment. |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
352 |
*/ |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
353 |
void run() throws IOException { |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
354 |
runJavac(); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
355 |
runJava(); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
356 |
} |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
357 |
|
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
358 |
private void runJavac() throws IOException { |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
359 |
out.println(" javac:"); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
360 |
Path javacOutDir = base.resolve("out-javac"); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
361 |
Files.createDirectories(javacOutDir); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
362 |
|
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
363 |
List<String> options = join(testOpts, otherOpts); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
364 |
|
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
365 |
out.println(" options: " + options); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
366 |
out.println(" outdir: " + javacOutDir); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
367 |
out.println(" files: " + files); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
368 |
|
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
369 |
String log = new JavacTask(tb, Task.Mode.CMDLINE) |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
370 |
.options(options) |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
371 |
.outdir(javacOutDir) |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
372 |
.files(files) |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
373 |
.run(expect) |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
374 |
.writeAll() |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
375 |
.getOutput(Task.OutputKind.DIRECT); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
376 |
|
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
377 |
if (expectedText != null && !log.contains(expectedText)) |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
378 |
error("expected text not found"); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
379 |
} |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
380 |
|
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
381 |
private void runJava() throws IOException { |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
382 |
out.println(" java:"); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
383 |
Path javaOutDir = base.resolve("out-java"); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
384 |
Files.createDirectories(javaOutDir); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
385 |
|
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
386 |
List<String> vmOpts = join( |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
387 |
testOpts, |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
388 |
Arrays.asList("--module", "jdk.compiler/com.sun.tools.javac.Main") |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
389 |
); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
390 |
|
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
391 |
List<String> classArgs = join( |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
392 |
Arrays.asList("--inherit-runtime-environment", |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
393 |
"-d", javaOutDir.toString()), |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
394 |
otherOpts, |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
395 |
files.stream() |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
396 |
.map(p -> p.toString()) |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
397 |
.collect(Collectors.toList()) |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
398 |
); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
399 |
|
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
400 |
out.println(" vmOpts: " + vmOpts); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
401 |
out.println(" classArgs: " + classArgs); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
402 |
|
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
403 |
String log = new JavaTask(tb) |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
404 |
.vmOptions(vmOpts) |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
405 |
.classArgs(classArgs) |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
406 |
.run(expect) |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
407 |
.writeAll() |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
408 |
.getOutput(Task.OutputKind.STDERR); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
409 |
|
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
410 |
if (expectedText != null && !log.contains(expectedText)) |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
411 |
error("expected text not found"); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
412 |
} |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
413 |
} |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
414 |
|
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
415 |
/** |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
416 |
* Join a series of lists. |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
417 |
*/ |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
418 |
@SafeVarargs |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
419 |
private <T> List<T> join(List<T>... lists) { |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
420 |
return Arrays.stream(lists) |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
421 |
.flatMap(list -> list.stream()) |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
422 |
.collect(Collectors.toList()); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
423 |
} |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
424 |
|
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
425 |
} |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
diff
changeset
|
426 |