author | jjg |
Thu, 31 Mar 2016 15:20:50 -0700 | |
changeset 36778 | e04318f39f92 |
parent 36526 | 3b41f1c69604 |
child 37758 | 3ecf9b414e05 |
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 |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
31 |
* @build toolbox.ToolBox toolbox.JavacTask 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; |
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
39 |
import toolbox.Task; |
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
40 |
import toolbox.ToolBox; |
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 |
|
50 |
void simpleUsage(Path base) throws Exception { |
|
51 |
final Path module = base.resolve("modules"); |
|
52 |
new ModuleBuilder("m1") |
|
53 |
.exports("pkg1") |
|
54 |
.classes("package pkg1; public class E { }") |
|
55 |
.build(module); |
|
56 |
||
57 |
final Path upgradeModule = base.resolve("upgradeModule"); |
|
58 |
new ModuleBuilder("m1") |
|
59 |
.exports("pkg2") |
|
60 |
.classes("package pkg2; public class E { }") |
|
61 |
.build(upgradeModule); |
|
62 |
||
63 |
Path src = base.resolve("src"); |
|
64 |
tb.writeJavaFiles(src, "module m2 { requires m1; }", |
|
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) |
36526 | 68 |
.options("-modulepath", module.toString(), |
69 |
"-upgrademodulepath", upgradeModule.toString()) |
|
70 |
.files(findJavaFiles(src)) |
|
71 |
.run() |
|
72 |
.writeAll(); |
|
73 |
} |
|
74 |
||
75 |
@Test |
|
76 |
void onlyUpgradeModulePath(Path base) throws Exception { |
|
77 |
final Path module = base.resolve("modules"); |
|
78 |
new ModuleBuilder("m1") |
|
79 |
.exports("pkg1") |
|
80 |
.classes("package pkg1; public class E { }") |
|
81 |
.build(module); |
|
82 |
||
83 |
final Path upgradeModule = base.resolve("upgradeModule"); |
|
84 |
new ModuleBuilder("m1") |
|
85 |
.exports("pkg2") |
|
86 |
.classes("package pkg2; public class E { }") |
|
87 |
.build(upgradeModule); |
|
88 |
||
89 |
Path src = base.resolve("src"); |
|
90 |
tb.writeJavaFiles(src, "module m2 { requires m1; }", |
|
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) |
36526 | 94 |
.options("-upgrademodulepath", upgradeModule + File.pathSeparator + module) |
95 |
.files(findJavaFiles(src)) |
|
96 |
.run() |
|
97 |
.writeAll(); |
|
98 |
} |
|
99 |
||
100 |
@Test |
|
101 |
void withModuleSourcePath(Path base) throws Exception { |
|
102 |
final Path module = base.resolve("modules"); |
|
103 |
new ModuleBuilder("m1") |
|
104 |
.exports("pkg1") |
|
105 |
.classes("package pkg1; public class E { }") |
|
106 |
.build(module); |
|
107 |
||
108 |
final Path upgradeModule = base.resolve("upgradeModule"); |
|
109 |
new ModuleBuilder("m1") |
|
110 |
.exports("pkg2") |
|
111 |
.classes("package pkg2; public class E { }") |
|
112 |
.build(upgradeModule); |
|
113 |
||
114 |
final Path s = base.resolve("source"); |
|
115 |
tb.writeJavaFiles(s.resolve("m3"), "module m3 { }"); |
|
116 |
||
117 |
final Path upgradeModule3 = base.resolve("upgradeModule"); |
|
118 |
new ModuleBuilder("m3") |
|
119 |
.exports("pkg3") |
|
120 |
.classes("package pkg3; public class E { }") |
|
121 |
.build(upgradeModule); |
|
122 |
||
123 |
Path src = base.resolve("src"); |
|
124 |
tb.writeJavaFiles(src.resolve("m2"), "module m2 { requires m1; requires m3; }", |
|
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) |
36526 | 128 |
.options("-modulepath", module.toString(), |
129 |
"-modulesourcepath", src + File.pathSeparator + s, |
|
130 |
"-upgrademodulepath", upgradeModule + File.pathSeparator + upgradeModule3) |
|
131 |
.outdir(module) |
|
132 |
.files(findJavaFiles(src)) |
|
133 |
.run() |
|
134 |
.writeAll(); |
|
135 |
} |
|
136 |
||
137 |
@Test |
|
138 |
void sameUpgradeAndModulePath(Path base) throws Exception { |
|
139 |
final Path module = base.resolve("modules"); |
|
140 |
new ModuleBuilder("m1") |
|
141 |
.exports("pkg1") |
|
142 |
.classes("package pkg1; public class E { }") |
|
143 |
.build(module); |
|
144 |
||
145 |
final Path upgradeModule = base.resolve("upgradeModule"); |
|
146 |
new ModuleBuilder("m1") |
|
147 |
.exports("pkg2") |
|
148 |
.classes("package pkg2; public class E { }") |
|
149 |
.build(upgradeModule); |
|
150 |
||
151 |
Path src = base.resolve("src"); |
|
152 |
tb.writeJavaFiles(src, "module m2 { requires m1; }", |
|
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) |
36526 | 156 |
.options("-modulepath", upgradeModule + File.pathSeparator + module, |
157 |
"-upgrademodulepath", upgradeModule.toString()) |
|
158 |
.files(findJavaFiles(src)) |
|
159 |
.run() |
|
160 |
.writeAll(); |
|
161 |
} |
|
162 |
||
163 |
@Test |
|
164 |
void dummyFileInUpgradeModulePath(Path base) throws Exception { |
|
165 |
final Path module = base.resolve("modules"); |
|
166 |
new ModuleBuilder("m1") |
|
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"); |
|
175 |
tb.writeJavaFiles(src, "module m2 { requires m1; }", |
|
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", |
180 |
"-modulepath", module.toString(), |
|
181 |
"-upgrademodulepath", dummy.toString()) |
|
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); |
36526 | 186 |
if (!output.contains("compiler.err.illegal.argument.for.option: -upgrademodulepath, " + dummy)) { |
187 |
throw new Exception("Expected output was not found"); |
|
188 |
} |
|
189 |
} |
|
190 |
||
191 |
@Test |
|
192 |
void severalUpgradeModules(Path base) throws Exception { |
|
193 |
final Path module = base.resolve("modules"); |
|
194 |
new ModuleBuilder("m1") |
|
195 |
.exports("pkg1") |
|
196 |
.classes("package pkg1; public class A { }") |
|
197 |
.build(module); |
|
198 |
||
199 |
new ModuleBuilder("m2") |
|
200 |
.exports("pkg2") |
|
201 |
.classes("package pkg2; public class B { }") |
|
202 |
.build(module); |
|
203 |
||
204 |
Path upgradeModule = base.resolve("upgradeModule"); |
|
205 |
new ModuleBuilder("m2") |
|
206 |
.exports("pkg2") |
|
207 |
.classes("package pkg2; public class BC { }") |
|
208 |
.build(upgradeModule); |
|
209 |
new ModuleBuilder("m3") |
|
210 |
.exports("pkg3") |
|
211 |
.classes("package pkg3; public class DC { }") |
|
212 |
.build(upgradeModule); |
|
213 |
||
214 |
Path src = base.resolve("src"); |
|
215 |
tb.writeJavaFiles(src, "module m4 { requires m1; requires m2; requires m3; }", |
|
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) |
36526 | 219 |
.options("-modulepath", module.toString(), |
220 |
"-upgrademodulepath", upgradeModule.toString()) |
|
221 |
.files(findJavaFiles(src)) |
|
222 |
.run() |
|
223 |
.writeAll(); |
|
224 |
||
225 |
Path src2 = base.resolve("src2"); |
|
226 |
tb.writeJavaFiles(src2, "module m4 { requires m1; }", |
|
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", |
231 |
"-modulepath", module.toString(), |
|
232 |
"-upgrademodulepath", upgradeModule.toString()) |
|
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 |
|
243 |
void severalUpgradeModulePathsLastWin(Path base) throws Exception { |
|
244 |
final Path module = base.resolve("modules"); |
|
245 |
new ModuleBuilder("m1") |
|
246 |
.exports("pkg1") |
|
247 |
.classes("package pkg1; public class E { }") |
|
248 |
.build(module); |
|
249 |
||
250 |
final Path upgradeModule1 = base.resolve("upgradeModule1"); |
|
251 |
new ModuleBuilder("m1") |
|
252 |
.exports("pkg2") |
|
253 |
.classes("package pkg2; public class EC1 { }") |
|
254 |
.build(upgradeModule1); |
|
255 |
||
256 |
final Path upgradeModule2 = base.resolve("upgradeModule2"); |
|
257 |
new ModuleBuilder("m1") |
|
258 |
.exports("pkg2") |
|
259 |
.classes("package pkg2; public class EC2 { }") |
|
260 |
.build(upgradeModule2); |
|
261 |
||
262 |
Path src = base.resolve("src"); |
|
263 |
tb.writeJavaFiles(src, "module m2 { requires m1; }", |
|
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) |
36526 | 267 |
.options("-modulepath", module.toString(), |
268 |
"-upgrademodulepath", upgradeModule1.toString(), |
|
269 |
"-upgrademodulepath", upgradeModule2.toString()) |
|
270 |
.files(findJavaFiles(src)) |
|
271 |
.run() |
|
272 |
.writeAll(); |
|
273 |
||
274 |
Path src2 = base.resolve("src2"); |
|
275 |
tb.writeJavaFiles(src2, "module m2 { requires m1; }", |
|
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", |
280 |
"-modulepath", module.toString(), |
|
281 |
"-upgrademodulepath", upgradeModule1.toString(), |
|
282 |
"-upgrademodulepath", upgradeModule2.toString()) |
|
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 |
} |