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