author | alanb |
Fri, 16 Dec 2016 05:47:58 +0000 | |
changeset 42822 | a84956e7ee4d |
parent 40763 | 209113892b0d |
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 |
|
40763
209113892b0d
8165109: langtools/test switches to use new CLI options
mchung
parents:
40308
diff
changeset
|
26 |
* @summary tests for --upgrade-module-path |
36526 | 27 |
* @library /tools/lib |
28 |
* @modules |
|
29 |
* jdk.compiler/com.sun.tools.javac.api |
|
30 |
* jdk.compiler/com.sun.tools.javac.main |
|
37758 | 31 |
* @build toolbox.ToolBox toolbox.JavacTask toolbox.ModuleBuilder ModuleTestBase |
36526 | 32 |
* @run main UpgradeModulePathTest |
33 |
*/ |
|
34 |
||
35 |
import java.io.File; |
|
36 |
import java.nio.file.Path; |
|
37 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
38 |
import toolbox.JavacTask; |
37758 | 39 |
import toolbox.ModuleBuilder; |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
40 |
import toolbox.Task; |
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
41 |
|
36526 | 42 |
public class UpgradeModulePathTest extends ModuleTestBase { |
43 |
||
44 |
public static void main(String... args) throws Exception { |
|
45 |
UpgradeModulePathTest t = new UpgradeModulePathTest(); |
|
46 |
t.runTests(); |
|
47 |
} |
|
48 |
||
49 |
@Test |
|
37758 | 50 |
public void simpleUsage(Path base) throws Exception { |
39103
91a64ec5b970
8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents:
37758
diff
changeset
|
51 |
Path modules = base.resolve("modules"); |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
40763
diff
changeset
|
52 |
new ModuleBuilder(tb, "m1x") |
36526 | 53 |
.exports("pkg1") |
54 |
.classes("package pkg1; public class E { }") |
|
39103
91a64ec5b970
8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents:
37758
diff
changeset
|
55 |
.build(modules); |
36526 | 56 |
|
39103
91a64ec5b970
8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents:
37758
diff
changeset
|
57 |
final Path upgradeModules = base.resolve("upgradeModules"); |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
40763
diff
changeset
|
58 |
new ModuleBuilder(tb, "m1x") |
36526 | 59 |
.exports("pkg2") |
60 |
.classes("package pkg2; public class E { }") |
|
39103
91a64ec5b970
8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents:
37758
diff
changeset
|
61 |
.build(upgradeModules); |
36526 | 62 |
|
63 |
Path src = base.resolve("src"); |
|
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
40763
diff
changeset
|
64 |
tb.writeJavaFiles(src, "module m2x { requires m1x; }", |
36526 | 65 |
"package p; class A { void main() { pkg2.E.class.getName(); } }"); |
66 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
67 |
new JavacTask(tb, Task.Mode.CMDLINE) |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
39103
diff
changeset
|
68 |
.options("--module-path", modules.toString(), |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
39103
diff
changeset
|
69 |
"--upgrade-module-path", upgradeModules.toString()) |
36526 | 70 |
.files(findJavaFiles(src)) |
71 |
.run() |
|
72 |
.writeAll(); |
|
73 |
} |
|
74 |
||
75 |
@Test |
|
37758 | 76 |
public void onlyUpgradeModulePath(Path base) throws Exception { |
36526 | 77 |
final Path module = base.resolve("modules"); |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
40763
diff
changeset
|
78 |
new ModuleBuilder(tb, "m1x") |
36526 | 79 |
.exports("pkg1") |
80 |
.classes("package pkg1; public class E { }") |
|
81 |
.build(module); |
|
82 |
||
83 |
final Path upgradeModule = base.resolve("upgradeModule"); |
|
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
40763
diff
changeset
|
84 |
new ModuleBuilder(tb, "m1x") |
36526 | 85 |
.exports("pkg2") |
86 |
.classes("package pkg2; public class E { }") |
|
87 |
.build(upgradeModule); |
|
88 |
||
89 |
Path src = base.resolve("src"); |
|
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
40763
diff
changeset
|
90 |
tb.writeJavaFiles(src, "module m2x { requires m1x; }", |
36526 | 91 |
"package p; class A { void main() { pkg2.E.class.getName(); } }"); |
92 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
93 |
new JavacTask(tb, Task.Mode.CMDLINE) |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
39103
diff
changeset
|
94 |
.options("--upgrade-module-path", upgradeModule + File.pathSeparator + module) |
36526 | 95 |
.files(findJavaFiles(src)) |
96 |
.run() |
|
97 |
.writeAll(); |
|
98 |
} |
|
99 |
||
100 |
@Test |
|
37758 | 101 |
public void withModuleSourcePath(Path base) throws Exception { |
36526 | 102 |
final Path module = base.resolve("modules"); |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
40763
diff
changeset
|
103 |
new ModuleBuilder(tb, "m1x") |
36526 | 104 |
.exports("pkg1") |
105 |
.classes("package pkg1; public class E { }") |
|
106 |
.build(module); |
|
107 |
||
108 |
final Path upgradeModule = base.resolve("upgradeModule"); |
|
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
40763
diff
changeset
|
109 |
new ModuleBuilder(tb, "m1x") |
36526 | 110 |
.exports("pkg2") |
111 |
.classes("package pkg2; public class E { }") |
|
112 |
.build(upgradeModule); |
|
113 |
||
114 |
final Path s = base.resolve("source"); |
|
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
40763
diff
changeset
|
115 |
tb.writeJavaFiles(s.resolve("m3x"), "module m3x { }"); |
36526 | 116 |
|
117 |
final Path upgradeModule3 = base.resolve("upgradeModule"); |
|
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
40763
diff
changeset
|
118 |
new ModuleBuilder(tb, "m3x") |
36526 | 119 |
.exports("pkg3") |
120 |
.classes("package pkg3; public class E { }") |
|
121 |
.build(upgradeModule); |
|
122 |
||
123 |
Path src = base.resolve("src"); |
|
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
40763
diff
changeset
|
124 |
tb.writeJavaFiles(src.resolve("m2x"), "module m2x { requires m1x; requires m3x; }", |
36526 | 125 |
"package p; class A { void main() { pkg2.E.class.getName(); } }"); |
126 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
127 |
new JavacTask(tb, Task.Mode.CMDLINE) |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
39103
diff
changeset
|
128 |
.options("--module-path", module.toString(), |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
39103
diff
changeset
|
129 |
"--module-source-path", src + File.pathSeparator + s, |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
39103
diff
changeset
|
130 |
"--upgrade-module-path", upgradeModule + File.pathSeparator + upgradeModule3) |
36526 | 131 |
.outdir(module) |
132 |
.files(findJavaFiles(src)) |
|
133 |
.run() |
|
134 |
.writeAll(); |
|
135 |
} |
|
136 |
||
137 |
@Test |
|
37758 | 138 |
public void sameUpgradeAndModulePath(Path base) throws Exception { |
36526 | 139 |
final Path module = base.resolve("modules"); |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
40763
diff
changeset
|
140 |
new ModuleBuilder(tb, "m1x") |
36526 | 141 |
.exports("pkg1") |
142 |
.classes("package pkg1; public class E { }") |
|
143 |
.build(module); |
|
144 |
||
145 |
final Path upgradeModule = base.resolve("upgradeModule"); |
|
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
40763
diff
changeset
|
146 |
new ModuleBuilder(tb, "m1x") |
36526 | 147 |
.exports("pkg2") |
148 |
.classes("package pkg2; public class E { }") |
|
149 |
.build(upgradeModule); |
|
150 |
||
151 |
Path src = base.resolve("src"); |
|
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
40763
diff
changeset
|
152 |
tb.writeJavaFiles(src, "module m2x { requires m1x; }", |
36526 | 153 |
"package p; class A { void main() { pkg2.E.class.getName(); } }"); |
154 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
155 |
new JavacTask(tb, Task.Mode.CMDLINE) |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
39103
diff
changeset
|
156 |
.options("--module-path", upgradeModule + File.pathSeparator + module, |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
39103
diff
changeset
|
157 |
"--upgrade-module-path", upgradeModule.toString()) |
36526 | 158 |
.files(findJavaFiles(src)) |
159 |
.run() |
|
160 |
.writeAll(); |
|
161 |
} |
|
162 |
||
163 |
@Test |
|
37758 | 164 |
public void dummyFileInUpgradeModulePath(Path base) throws Exception { |
36526 | 165 |
final Path module = base.resolve("modules"); |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
40763
diff
changeset
|
166 |
new ModuleBuilder(tb, "m1x") |
36526 | 167 |
.exports("pkg1") |
168 |
.classes("package pkg1; public class E { }") |
|
169 |
.build(module); |
|
170 |
||
171 |
Path dummy = base.resolve("dummy.txt"); |
|
172 |
tb.writeFile(dummy, ""); |
|
173 |
||
174 |
Path src = base.resolve("src"); |
|
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
40763
diff
changeset
|
175 |
tb.writeJavaFiles(src, "module m2x { requires m1x; }", |
36526 | 176 |
"package p; class A { void main() { pkg2.E.class.getName(); } }"); |
177 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
178 |
String output = new JavacTask(tb, Task.Mode.CMDLINE) |
36526 | 179 |
.options("-XDrawDiagnostics", |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
39103
diff
changeset
|
180 |
"--module-path", module.toString(), |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
39103
diff
changeset
|
181 |
"--upgrade-module-path", dummy.toString()) |
36526 | 182 |
.files(findJavaFiles(src)) |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
183 |
.run(Task.Expect.FAIL) |
36526 | 184 |
.writeAll() |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
185 |
.getOutput(Task.OutputKind.DIRECT); |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
39103
diff
changeset
|
186 |
if (!output.contains("compiler.err.illegal.argument.for.option: --upgrade-module-path, " + dummy)) { |
36526 | 187 |
throw new Exception("Expected output was not found"); |
188 |
} |
|
189 |
} |
|
190 |
||
191 |
@Test |
|
37758 | 192 |
public void severalUpgradeModules(Path base) throws Exception { |
36526 | 193 |
final Path module = base.resolve("modules"); |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
40763
diff
changeset
|
194 |
new ModuleBuilder(tb, "m1x") |
36526 | 195 |
.exports("pkg1") |
196 |
.classes("package pkg1; public class A { }") |
|
197 |
.build(module); |
|
198 |
||
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
40763
diff
changeset
|
199 |
new ModuleBuilder(tb, "m2x") |
36526 | 200 |
.exports("pkg2") |
201 |
.classes("package pkg2; public class B { }") |
|
202 |
.build(module); |
|
203 |
||
204 |
Path upgradeModule = base.resolve("upgradeModule"); |
|
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
40763
diff
changeset
|
205 |
new ModuleBuilder(tb, "m2x") |
36526 | 206 |
.exports("pkg2") |
207 |
.classes("package pkg2; public class BC { }") |
|
208 |
.build(upgradeModule); |
|
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
40763
diff
changeset
|
209 |
new ModuleBuilder(tb, "m3x") |
36526 | 210 |
.exports("pkg3") |
211 |
.classes("package pkg3; public class DC { }") |
|
212 |
.build(upgradeModule); |
|
213 |
||
214 |
Path src = base.resolve("src"); |
|
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
40763
diff
changeset
|
215 |
tb.writeJavaFiles(src, "module m4x { requires m1x; requires m2x; requires m3x; }", |
36526 | 216 |
"package p; class A { void main() { pkg1.A.class.getName(); pkg2.BC.class.getName(); pkg3.DC.class.getName(); } }"); |
217 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
218 |
new JavacTask(tb, Task.Mode.CMDLINE) |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
39103
diff
changeset
|
219 |
.options("--module-path", module.toString(), |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
39103
diff
changeset
|
220 |
"--upgrade-module-path", upgradeModule.toString()) |
36526 | 221 |
.files(findJavaFiles(src)) |
222 |
.run() |
|
223 |
.writeAll(); |
|
224 |
||
225 |
Path src2 = base.resolve("src2"); |
|
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
40763
diff
changeset
|
226 |
tb.writeJavaFiles(src2, "module m4x { requires m1x; }", |
36526 | 227 |
"package p; class A { void main() { pkg2.B.class.getName(); } }"); |
228 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
229 |
String log = new JavacTask(tb, Task.Mode.CMDLINE) |
36526 | 230 |
.options("-XDrawDiagnostics", |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
39103
diff
changeset
|
231 |
"--module-path", module.toString(), |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
39103
diff
changeset
|
232 |
"--upgrade-module-path", upgradeModule.toString()) |
36526 | 233 |
.files(findJavaFiles(src2)) |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
234 |
.run(Task.Expect.FAIL) |
36526 | 235 |
.writeAll() |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
236 |
.getOutput(Task.OutputKind.DIRECT); |
36526 | 237 |
if (!log.contains("compiler.err.doesnt.exist: pkg2")) { |
238 |
throw new Exception("Expected output was not found"); |
|
239 |
} |
|
240 |
} |
|
241 |
||
242 |
@Test |
|
37758 | 243 |
public void severalUpgradeModulePathsLastWin(Path base) throws Exception { |
36526 | 244 |
final Path module = base.resolve("modules"); |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
40763
diff
changeset
|
245 |
new ModuleBuilder(tb, "m1x") |
36526 | 246 |
.exports("pkg1") |
247 |
.classes("package pkg1; public class E { }") |
|
248 |
.build(module); |
|
249 |
||
250 |
final Path upgradeModule1 = base.resolve("upgradeModule1"); |
|
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
40763
diff
changeset
|
251 |
new ModuleBuilder(tb, "m1x") |
36526 | 252 |
.exports("pkg2") |
253 |
.classes("package pkg2; public class EC1 { }") |
|
254 |
.build(upgradeModule1); |
|
255 |
||
256 |
final Path upgradeModule2 = base.resolve("upgradeModule2"); |
|
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
40763
diff
changeset
|
257 |
new ModuleBuilder(tb, "m1x") |
36526 | 258 |
.exports("pkg2") |
259 |
.classes("package pkg2; public class EC2 { }") |
|
260 |
.build(upgradeModule2); |
|
261 |
||
262 |
Path src = base.resolve("src"); |
|
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
40763
diff
changeset
|
263 |
tb.writeJavaFiles(src, "module m2x { requires m1x; }", |
36526 | 264 |
"package p; class A { void main() { pkg2.EC2.class.getName(); } }"); |
265 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
266 |
new JavacTask(tb, Task.Mode.CMDLINE) |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
39103
diff
changeset
|
267 |
.options("--module-path", module.toString(), |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
39103
diff
changeset
|
268 |
"--upgrade-module-path", upgradeModule1.toString(), |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
39103
diff
changeset
|
269 |
"--upgrade-module-path", upgradeModule2.toString()) |
36526 | 270 |
.files(findJavaFiles(src)) |
271 |
.run() |
|
272 |
.writeAll(); |
|
273 |
||
274 |
Path src2 = base.resolve("src2"); |
|
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
40763
diff
changeset
|
275 |
tb.writeJavaFiles(src2, "module m2x { requires m1x; }", |
36526 | 276 |
"package p; class A { void main() { pkg2.EC1.class.getName(); } }"); |
277 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
278 |
final String log = new JavacTask(tb, Task.Mode.CMDLINE) |
36526 | 279 |
.options("-XDrawDiagnostics", |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
39103
diff
changeset
|
280 |
"--module-path", module.toString(), |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
39103
diff
changeset
|
281 |
"--upgrade-module-path", upgradeModule1.toString(), |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
39103
diff
changeset
|
282 |
"--upgrade-module-path", upgradeModule2.toString()) |
36526 | 283 |
.files(findJavaFiles(src2)) |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
284 |
.run(Task.Expect.FAIL) |
36526 | 285 |
.writeAll() |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
286 |
.getOutput(Task.OutputKind.DIRECT); |
36526 | 287 |
|
288 |
if (!log.contains("compiler.err.cant.resolve.location: kindname.class, EC1, , , (compiler.misc.location: kindname.package, pkg2, null)")) { |
|
289 |
throw new Exception("Expected output was not found"); |
|
290 |
} |
|
291 |
} |
|
292 |
} |