author | jjg |
Tue, 22 Nov 2016 15:57:32 -0800 | |
changeset 42269 | 24a766b7c106 |
parent 41521 | 9f45ffccd1c8 |
child 42407 | f3702cff2933 |
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 |
|
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
39103
diff
changeset
|
26 |
* @summary tests for --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 |
|
31 |
* jdk.jdeps/com.sun.tools.javap |
|
41521
9f45ffccd1c8
8164689: Retrofit jar, jlink, jmod as a ToolProvider
mchung
parents:
40308
diff
changeset
|
32 |
* jdk.jlink |
37758 | 33 |
* @build toolbox.ToolBox toolbox.JarTask toolbox.JavacTask toolbox.ModuleBuilder |
34 |
* ModuleTestBase |
|
36526 | 35 |
* @run main ModulePathTest |
36 |
*/ |
|
37 |
||
38 |
import java.io.File; |
|
39 |
import java.io.IOException; |
|
40 |
import java.nio.file.Files; |
|
41 |
import java.nio.file.Path; |
|
41521
9f45ffccd1c8
8164689: Retrofit jar, jlink, jmod as a ToolProvider
mchung
parents:
40308
diff
changeset
|
42 |
import java.util.spi.ToolProvider; |
36526 | 43 |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
44 |
import toolbox.JarTask; |
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
45 |
import toolbox.JavacTask; |
37758 | 46 |
import toolbox.ModuleBuilder; |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
47 |
import toolbox.Task; |
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
48 |
import toolbox.ToolBox; |
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
49 |
|
36526 | 50 |
public class ModulePathTest extends ModuleTestBase { |
51 |
||
52 |
public static final String PATH_SEP = File.pathSeparator; |
|
53 |
||
54 |
public static void main(String... args) throws Exception { |
|
55 |
ModulePathTest t = new ModulePathTest(); |
|
56 |
t.runTests(); |
|
57 |
} |
|
58 |
||
59 |
@Test |
|
37758 | 60 |
public void testNotExistsOnPath(Path base) throws Exception { |
36526 | 61 |
Path src = base.resolve("src"); |
62 |
tb.writeJavaFiles(src, "class C { }"); |
|
63 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
64 |
String log = new JavacTask(tb, Task.Mode.CMDLINE) |
36526 | 65 |
.options("-XDrawDiagnostics", |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
39103
diff
changeset
|
66 |
"--module-path", "doesNotExist") |
36526 | 67 |
.files(findJavaFiles(src)) |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
68 |
.run(Task.Expect.FAIL) |
36526 | 69 |
.writeAll() |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
70 |
.getOutput(Task.OutputKind.DIRECT); |
36526 | 71 |
|
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
39103
diff
changeset
|
72 |
if (!log.contains("- compiler.err.illegal.argument.for.option: --module-path, doesNotExist")) |
36526 | 73 |
throw new Exception("expected output not found"); |
74 |
} |
|
75 |
||
76 |
@Test |
|
37758 | 77 |
public void testNotADirOnPath_1(Path base) throws Exception { |
36526 | 78 |
Path src = base.resolve("src"); |
79 |
tb.writeJavaFiles(src, "class C { }"); |
|
80 |
tb.writeFile("dummy.txt", ""); |
|
81 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
82 |
String log = new JavacTask(tb, Task.Mode.CMDLINE) |
36526 | 83 |
.options("-XDrawDiagnostics", |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
39103
diff
changeset
|
84 |
"--module-path", "dummy.txt") |
36526 | 85 |
.files(findJavaFiles(src)) |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
86 |
.run(Task.Expect.FAIL) |
36526 | 87 |
.writeAll() |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
88 |
.getOutput(Task.OutputKind.DIRECT); |
36526 | 89 |
|
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
39103
diff
changeset
|
90 |
if (!log.contains("- compiler.err.illegal.argument.for.option: --module-path, dummy.txt")) |
36526 | 91 |
throw new Exception("expected output not found"); |
92 |
} |
|
93 |
||
94 |
@Test |
|
37758 | 95 |
public void testNotADirOnPath_2(Path base) throws Exception { |
36526 | 96 |
Path src = base.resolve("src"); |
97 |
tb.writeJavaFiles(src, "class C { }"); |
|
98 |
tb.writeFile("dummy.jimage", ""); |
|
99 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
100 |
String log = new JavacTask(tb, Task.Mode.CMDLINE) |
36526 | 101 |
.options("-XDrawDiagnostics", |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
39103
diff
changeset
|
102 |
"--module-path", "dummy.jimage") |
36526 | 103 |
.files(findJavaFiles(src)) |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
104 |
.run(Task.Expect.FAIL) |
36526 | 105 |
.writeAll() |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
106 |
.getOutput(Task.OutputKind.DIRECT); |
36526 | 107 |
|
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
39103
diff
changeset
|
108 |
if (!log.contains("- compiler.err.illegal.argument.for.option: --module-path, dummy.jimage")) |
36526 | 109 |
throw new Exception("expected output not found"); |
110 |
} |
|
111 |
||
112 |
@Test |
|
37758 | 113 |
public void testExplodedModuleOnPath(Path base) throws Exception { |
36526 | 114 |
Path modSrc = base.resolve("modSrc"); |
115 |
tb.writeJavaFiles(modSrc, |
|
116 |
"module m1 { exports p; }", |
|
117 |
"package p; public class CC { }"); |
|
118 |
Path modClasses = base.resolve("modClasses"); |
|
119 |
Files.createDirectories(modClasses); |
|
120 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
121 |
new JavacTask(tb, Task.Mode.CMDLINE) |
36526 | 122 |
.outdir(modClasses) |
123 |
.files(findJavaFiles(modSrc)) |
|
124 |
.run() |
|
125 |
.writeAll(); |
|
126 |
||
127 |
Path src = base.resolve("src"); |
|
128 |
tb.writeJavaFiles(src, |
|
129 |
"module m { requires m1 ; }", |
|
130 |
"class C { }"); |
|
131 |
Path classes = base.resolve("classes"); |
|
132 |
Files.createDirectories(classes); |
|
133 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
134 |
new JavacTask(tb, Task.Mode.CMDLINE) |
36526 | 135 |
.outdir(classes) |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
39103
diff
changeset
|
136 |
.options("--module-path", modClasses.toString()) |
36526 | 137 |
.files(findJavaFiles(src)) |
138 |
.run() |
|
139 |
.writeAll(); |
|
140 |
} |
|
141 |
||
142 |
@Test |
|
37758 | 143 |
public void testBadExplodedModuleOnPath(Path base) throws Exception { |
36526 | 144 |
Path modClasses = base.resolve("modClasses"); |
145 |
tb.writeFile(modClasses.resolve("module-info.class"), "module m1 { }"); |
|
146 |
||
147 |
Path src = base.resolve("src"); |
|
148 |
tb.writeJavaFiles(src, |
|
149 |
"module m { requires m1 ; }", |
|
150 |
"class C { }"); |
|
151 |
Path classes = base.resolve("classes"); |
|
152 |
Files.createDirectories(classes); |
|
153 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
154 |
String log = new JavacTask(tb, Task.Mode.CMDLINE) |
36526 | 155 |
.outdir(classes) |
156 |
.options("-XDrawDiagnostics", |
|
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
39103
diff
changeset
|
157 |
"--module-path", modClasses.toString()) |
36526 | 158 |
.files(findJavaFiles(src)) |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
159 |
.run(Task.Expect.FAIL) |
36526 | 160 |
.writeAll() |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
161 |
.getOutput(Task.OutputKind.DIRECT); |
36526 | 162 |
|
163 |
if (!log.contains("- compiler.err.locn.bad.module-info: " + modClasses.toString())) |
|
164 |
throw new Exception("expected output not found"); |
|
165 |
} |
|
166 |
||
167 |
@Test |
|
37758 | 168 |
public void testAutoJarOnPath(Path base) throws Exception { |
36526 | 169 |
Path jarSrc = base.resolve("jarSrc"); |
170 |
tb.writeJavaFiles(jarSrc, |
|
171 |
"package p; public class CC { }"); |
|
172 |
Path jarClasses = base.resolve("jarClasses"); |
|
173 |
Files.createDirectories(jarClasses); |
|
174 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
175 |
new JavacTask(tb, Task.Mode.CMDLINE) |
36526 | 176 |
.outdir(jarClasses) |
177 |
.files(findJavaFiles(jarSrc)) |
|
178 |
.run() |
|
179 |
.writeAll(); |
|
180 |
||
181 |
Path moduleJar = base.resolve("m1.jar"); |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
182 |
new JarTask(tb, moduleJar) |
36526 | 183 |
.baseDir(jarClasses) |
184 |
.files("p/CC.class") |
|
185 |
.run(); |
|
186 |
||
187 |
Path src = base.resolve("src"); |
|
188 |
tb.writeJavaFiles(src, "class C { p.CC cc; }"); |
|
189 |
Path classes = base.resolve("classes"); |
|
190 |
Files.createDirectories(classes); |
|
191 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
192 |
new JavacTask(tb, Task.Mode.CMDLINE) |
36526 | 193 |
.outdir(classes) |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
39103
diff
changeset
|
194 |
.options("--module-path", moduleJar.toString(), "--add-modules", "m1") |
36526 | 195 |
.files(findJavaFiles(src)) |
196 |
.run() |
|
197 |
.writeAll(); |
|
198 |
} |
|
199 |
||
200 |
@Test |
|
37758 | 201 |
public void testModJarOnPath(Path base) throws Exception { |
36526 | 202 |
Path jarSrc = base.resolve("jarSrc"); |
203 |
tb.writeJavaFiles(jarSrc, |
|
204 |
"module m1 { exports p; }", |
|
205 |
"package p; public class CC { }"); |
|
206 |
Path jarClasses = base.resolve("jarClasses"); |
|
207 |
Files.createDirectories(jarClasses); |
|
208 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
209 |
new JavacTask(tb, Task.Mode.CMDLINE) |
36526 | 210 |
.outdir(jarClasses) |
211 |
.files(findJavaFiles(jarSrc)) |
|
212 |
.run() |
|
213 |
.writeAll(); |
|
214 |
||
215 |
Path moduleJar = base.resolve("myModule.jar"); // deliberately not m1 |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
216 |
new JarTask(tb, moduleJar) |
36526 | 217 |
.baseDir(jarClasses) |
218 |
.files("module-info.class", "p/CC.class") |
|
219 |
.run(); |
|
220 |
||
221 |
Path src = base.resolve("src"); |
|
222 |
tb.writeJavaFiles(src, |
|
223 |
"module m { requires m1 ; }", |
|
224 |
"class C { }"); |
|
225 |
Path classes = base.resolve("classes"); |
|
226 |
Files.createDirectories(classes); |
|
227 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
228 |
new JavacTask(tb, Task.Mode.CMDLINE) |
36526 | 229 |
.outdir(classes) |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
39103
diff
changeset
|
230 |
.options("--module-path", moduleJar.toString()) |
36526 | 231 |
.files(findJavaFiles(src)) |
232 |
.run() |
|
233 |
.writeAll(); |
|
234 |
} |
|
235 |
||
236 |
@Test |
|
37758 | 237 |
public void testBadJarOnPath(Path base) throws Exception { |
36526 | 238 |
Path src = base.resolve("src"); |
239 |
tb.writeJavaFiles(src, "class C { }"); |
|
240 |
tb.writeFile("dummy.jar", ""); |
|
241 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
242 |
String log = new JavacTask(tb, Task.Mode.CMDLINE) |
36526 | 243 |
.options("-XDrawDiagnostics", |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
39103
diff
changeset
|
244 |
"--module-path", "dummy.jar") |
36526 | 245 |
.files(findJavaFiles(src)) |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
246 |
.run(Task.Expect.FAIL) |
36526 | 247 |
.writeAll() |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
248 |
.getOutput(Task.OutputKind.DIRECT); |
36526 | 249 |
|
250 |
if (!log.contains("- compiler.err.locn.cant.read.file: dummy.jar")) |
|
251 |
throw new Exception("expected output not found"); |
|
252 |
} |
|
253 |
||
254 |
@Test |
|
37758 | 255 |
public void testJModOnPath(Path base) throws Exception { |
36526 | 256 |
Path jmodSrc = base.resolve("jmodSrc"); |
257 |
tb.writeJavaFiles(jmodSrc, |
|
258 |
"module m1 { exports p; }", |
|
259 |
"package p; public class CC { }"); |
|
260 |
Path jmodClasses = base.resolve("jmodClasses"); |
|
261 |
Files.createDirectories(jmodClasses); |
|
262 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
263 |
new JavacTask(tb, Task.Mode.CMDLINE) |
36526 | 264 |
.outdir(jmodClasses) |
265 |
.files(findJavaFiles(jmodSrc)) |
|
266 |
.run() |
|
267 |
.writeAll(); |
|
268 |
||
269 |
Path jmod = base.resolve("myModule.jmod"); // deliberately not m1 |
|
270 |
jmod(jmodClasses, jmod); |
|
271 |
||
272 |
Path src = base.resolve("src"); |
|
273 |
tb.writeJavaFiles(src, |
|
274 |
"module m { requires m1 ; }", |
|
275 |
"class C { }"); |
|
276 |
Path classes = base.resolve("classes"); |
|
277 |
Files.createDirectories(classes); |
|
278 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
279 |
new JavacTask(tb, Task.Mode.CMDLINE) |
36526 | 280 |
.outdir(classes) |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
39103
diff
changeset
|
281 |
.options("--module-path", jmod.toString()) |
36526 | 282 |
.files(findJavaFiles(src)) |
283 |
.run() |
|
284 |
.writeAll(); |
|
285 |
} |
|
286 |
||
287 |
@Test |
|
37758 | 288 |
public void testBadJModOnPath(Path base) throws Exception { |
36526 | 289 |
Path src = base.resolve("src"); |
290 |
tb.writeJavaFiles(src, "class C { }"); |
|
291 |
tb.writeFile("dummy.jmod", ""); |
|
292 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
293 |
String log = new JavacTask(tb, Task.Mode.CMDLINE) |
36526 | 294 |
.options("-XDrawDiagnostics", |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
39103
diff
changeset
|
295 |
"--module-path", "dummy.jmod") |
36526 | 296 |
.files(findJavaFiles(src)) |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
297 |
.run(Task.Expect.FAIL) |
36526 | 298 |
.writeAll() |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
299 |
.getOutput(Task.OutputKind.DIRECT); |
36526 | 300 |
|
301 |
if (!log.contains("- compiler.err.locn.cant.read.file: dummy.jmod")) |
|
302 |
throw new Exception("expected output not found"); |
|
303 |
} |
|
304 |
||
305 |
@Test |
|
37758 | 306 |
public void relativePath(Path base) throws Exception { |
39103
91a64ec5b970
8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents:
37758
diff
changeset
|
307 |
Path modules = base.resolve("modules"); |
37758 | 308 |
new ModuleBuilder(tb, "m1").build(modules); |
36526 | 309 |
|
310 |
Path src = base.resolve("src"); |
|
311 |
tb.writeJavaFiles(src, "module m2 { requires m1; }", "class A { }"); |
|
312 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
313 |
new JavacTask(tb, Task.Mode.CMDLINE) |
36526 | 314 |
.options("-XDrawDiagnostics", |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
39103
diff
changeset
|
315 |
"--module-path", modules + "/./../modules") |
36526 | 316 |
.files(findJavaFiles(src)) |
317 |
.run() |
|
318 |
.writeAll(); |
|
319 |
} |
|
320 |
||
321 |
@Test |
|
37758 | 322 |
public void duplicatePaths_1(Path base) throws Exception { |
39103
91a64ec5b970
8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents:
37758
diff
changeset
|
323 |
Path modules = base.resolve("modules"); |
37758 | 324 |
new ModuleBuilder(tb, "m1").build(modules); |
36526 | 325 |
|
326 |
Path src = base.resolve("src"); |
|
327 |
tb.writeJavaFiles(src, "module m2 { requires m1; }", "class A { }"); |
|
328 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
329 |
new JavacTask(tb, Task.Mode.CMDLINE) |
36526 | 330 |
.options("-XDrawDiagnostics", |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
39103
diff
changeset
|
331 |
"--module-path", modules + "/./../modules" + PATH_SEP + modules) |
36526 | 332 |
.files(findJavaFiles(src)) |
333 |
.run() |
|
334 |
.writeAll(); |
|
335 |
} |
|
336 |
||
337 |
@Test |
|
37758 | 338 |
public void duplicatePaths_2(Path base) throws Exception { |
39103
91a64ec5b970
8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents:
37758
diff
changeset
|
339 |
Path modules = base.resolve("modules"); |
37758 | 340 |
new ModuleBuilder(tb, "m1").build(modules); |
36526 | 341 |
|
342 |
Path src = base.resolve("src"); |
|
343 |
tb.writeJavaFiles(src, "module m2 { requires m1; }", "class A { }"); |
|
344 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
345 |
new JavacTask(tb, Task.Mode.CMDLINE) |
36526 | 346 |
.options("-XDrawDiagnostics", |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
39103
diff
changeset
|
347 |
"--module-path", modules.toString(), |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
39103
diff
changeset
|
348 |
"--module-path", modules.toString()) |
36526 | 349 |
.files(findJavaFiles(src)) |
350 |
.run() |
|
351 |
.writeAll(); |
|
352 |
} |
|
353 |
||
354 |
@Test |
|
37758 | 355 |
public void oneModuleHidesAnother(Path base) throws Exception { |
39103
91a64ec5b970
8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents:
37758
diff
changeset
|
356 |
Path modules = base.resolve("modules"); |
37758 | 357 |
new ModuleBuilder(tb, "m1") |
36526 | 358 |
.exports("pkg1") |
359 |
.classes("package pkg1; public class E { }") |
|
39103
91a64ec5b970
8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents:
37758
diff
changeset
|
360 |
.build(modules); |
36526 | 361 |
|
39103
91a64ec5b970
8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents:
37758
diff
changeset
|
362 |
Path deepModuleDirSrc = base.resolve("deepModuleDirSrc"); |
91a64ec5b970
8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents:
37758
diff
changeset
|
363 |
Path deepModuleDir = modules.resolve("deepModuleDir"); |
37758 | 364 |
new ModuleBuilder(tb, "m1") |
36526 | 365 |
.exports("pkg2") |
366 |
.classes("package pkg2; public class E { }") |
|
39103
91a64ec5b970
8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents:
37758
diff
changeset
|
367 |
.build(deepModuleDirSrc, deepModuleDir); |
36526 | 368 |
|
369 |
Path src = base.resolve("src"); |
|
370 |
tb.writeJavaFiles(src, "module m2 { requires m1; }", " package p; class A { void main() { pkg2.E.class.getName(); } }"); |
|
371 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
372 |
new JavacTask(tb, Task.Mode.CMDLINE) |
36526 | 373 |
.options("-XDrawDiagnostics", |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
39103
diff
changeset
|
374 |
"--module-path", deepModuleDir + PATH_SEP + modules) |
36526 | 375 |
.files(findJavaFiles(src)) |
376 |
.run() |
|
377 |
.writeAll(); |
|
378 |
} |
|
379 |
||
380 |
@Test |
|
37758 | 381 |
public void modulesInDifferentContainers(Path base) throws Exception { |
39103
91a64ec5b970
8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents:
37758
diff
changeset
|
382 |
Path modules = base.resolve("modules"); |
37758 | 383 |
new ModuleBuilder(tb, "m1") |
36526 | 384 |
.exports("one") |
385 |
.classes("package one; public class A { }") |
|
386 |
.build(modules); |
|
387 |
||
37758 | 388 |
new ModuleBuilder(tb, "m2") |
36526 | 389 |
.requires("m1", modules) |
390 |
.build(base.resolve("tmp")); |
|
391 |
jar(base.resolve("tmp/m2"), modules.resolve("m2.jar")); |
|
392 |
||
37758 | 393 |
new ModuleBuilder(tb, "m3") |
36526 | 394 |
.requires("m2", modules) |
395 |
.build(base.resolve("tmp")); |
|
396 |
jmod(base.resolve("tmp/m3"), modules.resolve("m3.jmod")); |
|
397 |
||
398 |
Path src = base.resolve("src"); |
|
399 |
tb.writeJavaFiles(src, "module m { requires m3; requires m2; requires m1; }", |
|
400 |
"package p; class A { void main() { one.A.class.getName(); } }"); |
|
401 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
402 |
new JavacTask(tb, Task.Mode.CMDLINE) |
36526 | 403 |
.options("-XDrawDiagnostics", |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
39103
diff
changeset
|
404 |
"--module-path", modules.toString()) |
36526 | 405 |
.files(findJavaFiles(src)) |
406 |
.run() |
|
407 |
.writeAll(); |
|
408 |
} |
|
409 |
||
410 |
private void jar(Path dir, Path jar) throws IOException { |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
411 |
new JarTask(tb, jar) |
36526 | 412 |
.baseDir(dir) |
413 |
.files(".") |
|
414 |
.run() |
|
415 |
.writeAll(); |
|
416 |
} |
|
417 |
||
418 |
private void jmod(Path dir, Path jmod) throws Exception { |
|
419 |
String[] args = { |
|
420 |
"create", |
|
421 |
"--class-path", dir.toString(), |
|
422 |
jmod.toString() |
|
423 |
}; |
|
41521
9f45ffccd1c8
8164689: Retrofit jar, jlink, jmod as a ToolProvider
mchung
parents:
40308
diff
changeset
|
424 |
ToolProvider jmodTool = ToolProvider.findFirst("jmod").orElseThrow(() -> |
9f45ffccd1c8
8164689: Retrofit jar, jlink, jmod as a ToolProvider
mchung
parents:
40308
diff
changeset
|
425 |
new RuntimeException("jmod tool not found") |
9f45ffccd1c8
8164689: Retrofit jar, jlink, jmod as a ToolProvider
mchung
parents:
40308
diff
changeset
|
426 |
); |
9f45ffccd1c8
8164689: Retrofit jar, jlink, jmod as a ToolProvider
mchung
parents:
40308
diff
changeset
|
427 |
jmodTool.run(System.out, System.err, args); |
36526 | 428 |
} |
429 |
} |