author | jlahoda |
Tue, 17 Jan 2017 07:41:04 +0100 | |
changeset 43149 | 047a57b0839a |
parent 42822 | a84956e7ee4d |
child 44690 | aec722d1b538 |
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 |
|
40599
be40838eb215
8164887: update tests to remove use of old-style options
jjg
parents:
40308
diff
changeset
|
26 |
* @summary tests for --module-source-path |
36526 | 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 ModuleSourcePathTest |
33 |
*/ |
|
34 |
||
35 |
import java.io.File; |
|
36 |
import java.io.IOException; |
|
37 |
import java.nio.file.Files; |
|
38 |
import java.nio.file.Path; |
|
39 |
import java.nio.file.Paths; |
|
40 |
import java.util.Arrays; |
|
41 |
import java.util.List; |
|
42 |
import java.util.stream.Collectors; |
|
43 |
import java.util.stream.Stream; |
|
44 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
45 |
import toolbox.JavacTask; |
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
46 |
import toolbox.Task; |
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
47 |
import toolbox.ToolBox; |
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
48 |
|
36526 | 49 |
public class ModuleSourcePathTest extends ModuleTestBase { |
50 |
||
51 |
public static final char PATH_SEP = File.pathSeparatorChar; |
|
52 |
||
53 |
public static void main(String... args) throws Exception { |
|
54 |
ModuleSourcePathTest t = new ModuleSourcePathTest(); |
|
55 |
t.runTests(); |
|
56 |
} |
|
57 |
||
58 |
@Test |
|
37758 | 59 |
public void testSourcePathConflict(Path base) throws Exception { |
36526 | 60 |
Path sp = base.resolve("src"); |
61 |
Path msp = base.resolve("srcmodules"); |
|
62 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
63 |
String log = new JavacTask(tb, Task.Mode.CMDLINE) |
36526 | 64 |
.options("-XDrawDiagnostics", |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
37758
diff
changeset
|
65 |
"--source-path", sp.toString().replace('/', File.separatorChar), |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
37758
diff
changeset
|
66 |
"--module-source-path", msp.toString().replace('/', File.separatorChar), |
36526 | 67 |
"dummyClass") |
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:
37758
diff
changeset
|
72 |
if (!log.contains("cannot specify both --source-path and --module-source-path")) |
36526 | 73 |
throw new Exception("expected diagnostic not found"); |
74 |
} |
|
75 |
||
76 |
@Test |
|
37758 | 77 |
public void testUnnormalizedPath1(Path base) throws Exception { |
36526 | 78 |
Path src = base.resolve("src"); |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
40599
diff
changeset
|
79 |
Path src_m1 = src.resolve("m1x"); |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
40599
diff
changeset
|
80 |
tb.writeJavaFiles(src_m1, "module m1x { }"); |
36526 | 81 |
Path modules = base.resolve("modules"); |
82 |
Files.createDirectories(modules); |
|
83 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
84 |
new JavacTask(tb, Task.Mode.CMDLINE) |
36526 | 85 |
.options("-XDrawDiagnostics", |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
37758
diff
changeset
|
86 |
"--module-source-path", src.toString()) |
36526 | 87 |
.outdir(modules) |
88 |
.files(prefixAll(findJavaFiles(src), Paths.get("./"))) |
|
89 |
.run() |
|
90 |
.writeAll(); |
|
91 |
} |
|
92 |
||
93 |
@Test |
|
37758 | 94 |
public void testUnnormalizedPath2(Path base) throws Exception { |
36526 | 95 |
Path src = base.resolve("src"); |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
40599
diff
changeset
|
96 |
Path src_m1 = src.resolve("m1x"); |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
40599
diff
changeset
|
97 |
tb.writeJavaFiles(src_m1, "module m1x { }"); |
36526 | 98 |
Path modules = base.resolve("modules"); |
99 |
Files.createDirectories(modules); |
|
100 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
101 |
new JavacTask(tb, Task.Mode.CMDLINE) |
36526 | 102 |
.options("-XDrawDiagnostics", |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
37758
diff
changeset
|
103 |
"--module-source-path", "./" + src) |
36526 | 104 |
.outdir(modules) |
105 |
.files(findJavaFiles(src)) |
|
106 |
.run() |
|
107 |
.writeAll(); |
|
108 |
} |
|
109 |
||
110 |
private Path[] prefixAll(Path[] paths, Path prefix) { |
|
111 |
return Stream.of(paths) |
|
112 |
.map(prefix::resolve) |
|
113 |
.collect(Collectors.toList()) |
|
114 |
.toArray(new Path[paths.length]); |
|
115 |
} |
|
116 |
||
117 |
@Test |
|
37758 | 118 |
public void regularBraces(Path base) throws Exception { |
36526 | 119 |
generateModules(base, "src1", "src2/inner_dir"); |
120 |
||
121 |
final Path modules = base.resolve("modules"); |
|
122 |
tb.createDirectories(modules); |
|
123 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
124 |
new JavacTask(tb, Task.Mode.CMDLINE) |
36526 | 125 |
.options("-XDrawDiagnostics", |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
37758
diff
changeset
|
126 |
"--module-source-path", base + "/{src1,src2/inner_dir}") |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
40599
diff
changeset
|
127 |
.files(base.resolve("src1/m0x/pkg0/A.java"), base.resolve("src2/inner_dir/m1x/pkg1/A.java")) |
36526 | 128 |
.outdir(modules) |
129 |
.run() |
|
130 |
.writeAll(); |
|
131 |
||
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
40599
diff
changeset
|
132 |
checkFiles(modules.resolve("m0x/pkg0/A.class"), |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
40599
diff
changeset
|
133 |
modules.resolve("m1x/pkg1/A.class"), |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
40599
diff
changeset
|
134 |
modules.resolve("m0x/module-info.class"), |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
40599
diff
changeset
|
135 |
modules.resolve("m1x/module-info.class")); |
36526 | 136 |
} |
137 |
||
138 |
@Test |
|
37758 | 139 |
public void mismatchedBraces(Path base) throws Exception { |
36526 | 140 |
final List<String> sourcePaths = Arrays.asList( |
141 |
"{", |
|
142 |
"}", |
|
143 |
"}{", |
|
144 |
"./}", |
|
145 |
".././{./", |
|
146 |
"src{}}", |
|
147 |
"{{}{}}{}}", |
|
148 |
"src/{a,b}/{", |
|
149 |
"src/{a,{,{}}", |
|
150 |
"{.,..{}/src", |
|
151 |
"*}{", |
|
152 |
"{}*}" |
|
153 |
); |
|
154 |
for (String sourcepath : sourcePaths) { |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
155 |
String log = new JavacTask(tb, Task.Mode.CMDLINE) |
36526 | 156 |
.options("-XDrawDiagnostics", |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
37758
diff
changeset
|
157 |
"--module-source-path", sourcepath.replace('/', File.separatorChar)) |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
158 |
.run(Task.Expect.FAIL) |
36526 | 159 |
.writeAll() |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
160 |
.getOutput(Task.OutputKind.DIRECT); |
36526 | 161 |
|
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
37758
diff
changeset
|
162 |
if (!log.contains("- compiler.err.illegal.argument.for.option: --module-source-path, mismatched braces")) |
36526 | 163 |
throw new Exception("expected output for path [" + sourcepath + "] not found"); |
164 |
} |
|
165 |
} |
|
166 |
||
167 |
@Test |
|
37758 | 168 |
public void deepBraces(Path base) throws Exception { |
36526 | 169 |
String[] modulePaths = {"src/src1", |
170 |
"src/src2", |
|
171 |
"src/src3", |
|
172 |
"src/srcB/src1", |
|
173 |
"src/srcB/src2/srcXX", |
|
174 |
"src/srcB/src2/srcXY", |
|
175 |
"src/srcC/src1", |
|
176 |
"src/srcC/src2/srcXX", |
|
177 |
"src/srcC/src2/srcXY"}; |
|
178 |
generateModules(base, modulePaths); |
|
179 |
||
180 |
final Path modules = base.resolve("modules"); |
|
181 |
tb.createDirectories(modules); |
|
182 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
183 |
new JavacTask(tb, Task.Mode.CMDLINE) |
36526 | 184 |
.options("-XDrawDiagnostics", |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
37758
diff
changeset
|
185 |
"--module-source-path", |
36526 | 186 |
base + "/{src/{{src1,src2,src3},{srcB,srcC}/{src1,src2/srcX{X,Y}/}},.}" |
187 |
.replace('/', File.separatorChar)) |
|
188 |
.files(findJavaFiles(base.resolve(modulePaths[modulePaths.length - 1]))) |
|
189 |
.outdir(modules) |
|
190 |
.run() |
|
191 |
.writeAll(); |
|
192 |
||
193 |
for (int i = 0; i < modulePaths.length; i++) { |
|
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
40599
diff
changeset
|
194 |
checkFiles(modules.resolve("m" + i + "x/module-info.class")); |
36526 | 195 |
} |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
40599
diff
changeset
|
196 |
checkFiles(modules.resolve("m8x/pkg8/A.class")); |
36526 | 197 |
} |
198 |
||
199 |
@Test |
|
37758 | 200 |
public void fileInPath(Path base) throws Exception { |
36526 | 201 |
Path src = base.resolve("src"); |
202 |
tb.writeJavaFiles(src.resolve("kettle$"), "module kettle$ { }", "package electric; class Heater { }"); |
|
203 |
tb.writeFile(base.resolve("dummy.txt"), ""); |
|
204 |
||
205 |
final Path modules = base.resolve("modules"); |
|
206 |
tb.createDirectories(modules); |
|
207 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
208 |
new JavacTask(tb, Task.Mode.CMDLINE) |
36526 | 209 |
.options("-XDrawDiagnostics", |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
37758
diff
changeset
|
210 |
"--module-source-path", base + "/{dummy.txt,src}") |
36526 | 211 |
.files(src.resolve("kettle$/electric/Heater.java")) |
212 |
.outdir(modules) |
|
213 |
.run() |
|
214 |
.writeAll(); |
|
215 |
||
216 |
checkFiles(modules.resolve("kettle$/electric/Heater.class")); |
|
217 |
checkFiles(modules.resolve("kettle$/module-info.class")); |
|
218 |
} |
|
219 |
||
220 |
@Test |
|
37758 | 221 |
public void noAlternative(Path base) throws Exception { |
36526 | 222 |
Path src = base.resolve("src"); |
223 |
tb.writeJavaFiles(src.resolve("kettle$"), "module kettle$ { }", "package electric; class Heater { }"); |
|
224 |
||
225 |
final Path modules = base.resolve("modules"); |
|
226 |
tb.createDirectories(modules); |
|
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 |
.options("-XDrawDiagnostics", |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
37758
diff
changeset
|
230 |
"--module-source-path", base + "/{src}") |
36526 | 231 |
.files(src.resolve("kettle$/electric/Heater.java")) |
232 |
.outdir(modules) |
|
233 |
.run() |
|
234 |
.writeAll(); |
|
235 |
||
236 |
checkFiles(modules.resolve("kettle$/electric/Heater.class")); |
|
237 |
checkFiles(modules.resolve("kettle$/module-info.class")); |
|
238 |
} |
|
239 |
||
240 |
@Test |
|
37758 | 241 |
public void noChoice(Path base) throws Exception { |
36526 | 242 |
tb.writeJavaFiles(base.resolve("kettle$"), "module kettle$ { }", "package electric; class Heater { }"); |
243 |
||
244 |
final Path modules = base.resolve("modules"); |
|
245 |
tb.createDirectories(modules); |
|
246 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
247 |
new JavacTask(tb, Task.Mode.CMDLINE) |
36526 | 248 |
.options("-XDrawDiagnostics", |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
37758
diff
changeset
|
249 |
"--module-source-path", base + "/{}") |
36526 | 250 |
.files(base.resolve("kettle$/electric/Heater.java")) |
251 |
.outdir(modules) |
|
252 |
.run() |
|
253 |
.writeAll(); |
|
254 |
||
255 |
checkFiles(modules.resolve("kettle$/electric/Heater.class")); |
|
256 |
checkFiles(modules.resolve("kettle$/module-info.class")); |
|
257 |
} |
|
258 |
||
259 |
@Test |
|
37758 | 260 |
public void nestedModules(Path src) throws Exception { |
36526 | 261 |
Path carModule = src.resolve("car"); |
262 |
tb.writeJavaFiles(carModule, "module car { }", "package light; class Headlight { }"); |
|
263 |
tb.writeJavaFiles(carModule.resolve("engine"), "module engine { }", "package flat; class Piston { }"); |
|
264 |
||
265 |
final Path modules = src.resolve("modules"); |
|
266 |
tb.createDirectories(modules); |
|
267 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
268 |
new JavacTask(tb, Task.Mode.CMDLINE) |
36526 | 269 |
.options("-XDrawDiagnostics", |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
37758
diff
changeset
|
270 |
"--module-source-path", "{" + src + "," + src + "/car}") |
36526 | 271 |
.files(findJavaFiles(src)) |
272 |
.outdir(modules) |
|
273 |
.run() |
|
274 |
.writeAll(); |
|
275 |
checkFiles(modules.resolve("car/light/Headlight.class")); |
|
276 |
checkFiles(modules.resolve("engine/flat/Piston.class")); |
|
277 |
} |
|
278 |
||
279 |
@Test |
|
37758 | 280 |
public void relativePaths(Path base) throws Exception { |
36526 | 281 |
Path src = base.resolve("src"); |
282 |
tb.writeJavaFiles(src.resolve("kettle"), "module kettle { }", "package electric; class Heater { }"); |
|
283 |
||
284 |
final Path modules = base.resolve("modules"); |
|
285 |
tb.createDirectories(modules); |
|
286 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
287 |
new JavacTask(tb, Task.Mode.CMDLINE) |
36526 | 288 |
.options("-XDrawDiagnostics", |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
37758
diff
changeset
|
289 |
"--module-source-path", base + "/src/./../src") |
36526 | 290 |
.files(src.resolve("kettle/electric/Heater.java")) |
291 |
.outdir(modules) |
|
292 |
.run() |
|
293 |
.writeAll(); |
|
294 |
checkFiles(modules.resolve("kettle/electric/Heater.class")); |
|
295 |
checkFiles(modules.resolve("kettle/module-info.class")); |
|
296 |
} |
|
297 |
||
298 |
@Test |
|
37758 | 299 |
public void duplicatePaths(Path base) throws Exception { |
36526 | 300 |
Path src = base.resolve("src"); |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
40599
diff
changeset
|
301 |
tb.writeJavaFiles(src.resolve("m1x"), "module m1x { }", "package a; class A { }"); |
36526 | 302 |
|
303 |
final Path modules = base.resolve("modules"); |
|
304 |
tb.createDirectories(modules); |
|
305 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
306 |
new JavacTask(tb, Task.Mode.CMDLINE) |
36526 | 307 |
.options("-XDrawDiagnostics", |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
37758
diff
changeset
|
308 |
"--module-source-path", base + "/{src,src,src}") |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
40599
diff
changeset
|
309 |
.files(src.resolve("m1x/a/A.java")) |
36526 | 310 |
.outdir(modules) |
311 |
.run() |
|
312 |
.writeAll(); |
|
313 |
||
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
40599
diff
changeset
|
314 |
checkFiles(modules.resolve("m1x/module-info.class")); |
36526 | 315 |
} |
316 |
||
317 |
@Test |
|
37758 | 318 |
public void notExistentPaths(Path base) throws Exception { |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
40599
diff
changeset
|
319 |
tb.writeJavaFiles(base.resolve("m1x"), "module m1x { requires m0x; }", "package a; class A { }"); |
36526 | 320 |
|
321 |
final Path modules = base.resolve("modules"); |
|
322 |
tb.createDirectories(modules); |
|
323 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
324 |
String log = new JavacTask(tb, Task.Mode.CMDLINE) |
36526 | 325 |
.options("-XDrawDiagnostics", |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
37758
diff
changeset
|
326 |
"--module-source-path", base + "/not_exist" + PATH_SEP + base + "/{not_exist,}") |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
40599
diff
changeset
|
327 |
.files(base.resolve("m1x/a/A.java")) |
36526 | 328 |
.outdir(modules) |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
329 |
.run(Task.Expect.FAIL) |
36526 | 330 |
.writeAll() |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
331 |
.getOutput(Task.OutputKind.DIRECT); |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
40599
diff
changeset
|
332 |
if (!log.contains("compiler.err.module.not.found: m0x")) |
36526 | 333 |
throw new Exception("expected output for not existent module source path not found"); |
334 |
} |
|
335 |
||
336 |
@Test |
|
37758 | 337 |
public void notExistentPathShouldBeSkipped(Path base) throws Exception { |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
40599
diff
changeset
|
338 |
tb.writeJavaFiles(base.resolve("m1x"), "module m1x { }", "package a; class A { }"); |
36526 | 339 |
|
340 |
final Path modules = base.resolve("modules"); |
|
341 |
tb.createDirectories(modules); |
|
342 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
343 |
new JavacTask(tb, Task.Mode.CMDLINE) |
36526 | 344 |
.options("-XDrawDiagnostics", |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
37758
diff
changeset
|
345 |
"--module-source-path", base + "{/not_exist,/}") |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
40599
diff
changeset
|
346 |
.files(base.resolve("m1x/a/A.java")) |
36526 | 347 |
.outdir(modules) |
348 |
.run() |
|
349 |
.writeAll(); |
|
350 |
||
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
40599
diff
changeset
|
351 |
checkFiles(modules.resolve("m1x/module-info.class")); |
36526 | 352 |
} |
353 |
||
354 |
@Test |
|
37758 | 355 |
public void commas(Path base) throws Exception { |
36526 | 356 |
Path src = base.resolve("src"); |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
40599
diff
changeset
|
357 |
tb.writeJavaFiles(src.resolve("m1x"), "module m1x { }", "package a; class A { }"); |
36526 | 358 |
|
359 |
final Path modules = base.resolve("modules"); |
|
360 |
tb.createDirectories(modules); |
|
361 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
362 |
new JavacTask(tb, Task.Mode.CMDLINE) |
36526 | 363 |
.options("-XDrawDiagnostics", |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
37758
diff
changeset
|
364 |
"--module-source-path", base + "/{,{,,,,src,,,}}") |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
40599
diff
changeset
|
365 |
.files(src.resolve("m1x/a/A.java")) |
36526 | 366 |
.outdir(modules) |
367 |
.run() |
|
368 |
.writeAll(); |
|
369 |
||
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
40599
diff
changeset
|
370 |
checkFiles(modules.resolve("m1x/module-info.class")); |
36526 | 371 |
} |
372 |
||
373 |
@Test |
|
37758 | 374 |
public void asterisk(Path base) throws Exception { |
36526 | 375 |
tb.writeJavaFiles(base.resolve("kettle").resolve("classes"), "module kettle { }", |
376 |
"package electric; class Heater { }"); |
|
377 |
||
378 |
final Path modules = base.resolve("modules"); |
|
379 |
tb.createDirectories(modules); |
|
380 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
381 |
new JavacTask(tb, Task.Mode.CMDLINE) |
36526 | 382 |
.options("-XDrawDiagnostics", |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
37758
diff
changeset
|
383 |
"--module-source-path", base + "/*/classes/") |
36526 | 384 |
.files(base.resolve("kettle/classes/electric/Heater.java")) |
385 |
.outdir(modules) |
|
386 |
.run() |
|
387 |
.writeAll(); |
|
388 |
||
389 |
checkFiles(modules.resolve("kettle/electric/Heater.class")); |
|
390 |
checkFiles(modules.resolve("kettle/module-info.class")); |
|
391 |
} |
|
392 |
||
393 |
@Test |
|
37758 | 394 |
public void asteriskInDifferentSets(Path base) throws Exception { |
36526 | 395 |
Path src = base.resolve("src"); |
396 |
final Path module = src.resolve("kettle"); |
|
397 |
tb.writeJavaFiles(module.resolve("classes"), "module kettle { }", "package electric; class Heater { }"); |
|
398 |
tb.writeJavaFiles(module.resolve("gensrc"), "package model; class Java { }"); |
|
399 |
tb.writeJavaFiles(module.resolve("special/classes"), "package gas; class Heater { }"); |
|
400 |
||
401 |
final Path modules = base.resolve("modules"); |
|
402 |
tb.createDirectories(modules); |
|
403 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
404 |
new JavacTask(tb, Task.Mode.CMDLINE) |
36526 | 405 |
.options("-XDrawDiagnostics", |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
37758
diff
changeset
|
406 |
"--module-source-path", src + "{/*/gensrc/,/*/classes/}" + PATH_SEP |
36526 | 407 |
+ src + "/*/special/classes") |
408 |
.files(findJavaFiles(src)) |
|
409 |
.outdir(modules) |
|
410 |
.run() |
|
411 |
.writeAll(); |
|
412 |
||
413 |
checkFiles(modules.resolve("kettle/electric/Heater.class")); |
|
414 |
checkFiles(modules.resolve("kettle/gas/Heater.class")); |
|
415 |
checkFiles(modules.resolve("kettle/model/Java.class")); |
|
416 |
checkFiles(modules.resolve("kettle/module-info.class")); |
|
417 |
} |
|
418 |
||
419 |
@Test |
|
37758 | 420 |
public void asteriskIllegalUse(Path base) throws Exception { |
36526 | 421 |
final List<String> sourcePaths = Arrays.asList( |
422 |
"*", |
|
423 |
"**", |
|
424 |
"***", |
|
425 |
"*.*", |
|
426 |
".*", |
|
427 |
"*.", |
|
428 |
"src/*/*/", |
|
429 |
"{*,*}", |
|
430 |
"src/module*/" |
|
431 |
); |
|
432 |
for (String sourcepath : sourcePaths) { |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
433 |
String log = new JavacTask(tb, Task.Mode.CMDLINE) |
36526 | 434 |
.options("-XDrawDiagnostics", |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
37758
diff
changeset
|
435 |
"--module-source-path", sourcepath.replace('/', File.separatorChar)) |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
436 |
.run(Task.Expect.FAIL) |
36526 | 437 |
.writeAll() |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
438 |
.getOutput(Task.OutputKind.DIRECT); |
36526 | 439 |
|
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
37758
diff
changeset
|
440 |
if (!log.contains("- compiler.err.illegal.argument.for.option: --module-source-path, illegal use of *")) |
36526 | 441 |
throw new Exception("expected output for path [" + sourcepath + "] not found"); |
442 |
} |
|
443 |
} |
|
444 |
||
445 |
private void generateModules(Path base, String... paths) throws IOException { |
|
446 |
for (int i = 0; i < paths.length; i++) { |
|
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
40599
diff
changeset
|
447 |
String moduleName = "m" + i + "x"; |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
40599
diff
changeset
|
448 |
String dependency = i > 0 ? "requires m" + (i - 1) + "x;" : ""; |
36526 | 449 |
tb.writeJavaFiles(base.resolve(paths[i]).resolve(moduleName), |
450 |
"module " + moduleName + " { " + dependency + " }", |
|
451 |
"package pkg" + i + "; class A { }"); |
|
452 |
} |
|
453 |
} |
|
454 |
||
455 |
private void checkFiles(Path... files) throws Exception { |
|
456 |
for (Path file : files) { |
|
457 |
if (!Files.exists(file)) { |
|
458 |
throw new Exception("File not exists: " + file); |
|
459 |
} |
|
460 |
} |
|
461 |
} |
|
462 |
} |