101 Path modulePath = base.resolve("module-path"); |
101 Path modulePath = base.resolve("module-path"); |
102 |
102 |
103 Files.createDirectories(modulePath); |
103 Files.createDirectories(modulePath); |
104 |
104 |
105 new JavacTask(tb) |
105 new JavacTask(tb) |
106 .options("-modulesourcepath", moduleSrc.toString()) |
106 .options("--module-source-path", moduleSrc.toString()) |
107 .outdir(modulePath) |
107 .outdir(modulePath) |
108 .files(findJavaFiles(m3)) |
108 .files(findJavaFiles(m3)) |
109 .run() |
109 .run() |
110 .writeAll(); |
110 .writeAll(); |
111 |
111 |
112 new JavacTask(tb) |
112 new JavacTask(tb) |
113 .options("-modulesourcepath", moduleSrc.toString()) |
113 .options("--module-source-path", moduleSrc.toString()) |
114 .outdir(modulePath) |
114 .outdir(modulePath) |
115 .files(findJavaFiles(m2)) |
115 .files(findJavaFiles(m2)) |
116 .run() |
116 .run() |
117 .writeAll(); |
117 .writeAll(); |
118 |
118 |
119 //real test |
119 //real test |
120 new JavacTask(tb) |
120 new JavacTask(tb) |
121 .options("-modulepath", modulePath.toString(), |
121 .options("--module-path", modulePath.toString(), |
122 "-Xshouldstop:ifNoError=FLOW", |
122 "-Xshouldstop:ifNoError=FLOW", |
123 "-limitmods", "java.base") |
123 "--limit-modules", "java.base") |
124 .outdir(modulePath) |
124 .outdir(modulePath) |
125 .files(findJavaFiles(m1)) |
125 .files(findJavaFiles(m1)) |
126 .run(Task.Expect.FAIL) |
126 .run(Task.Expect.FAIL) |
127 .writeAll(); |
127 .writeAll(); |
128 |
128 |
129 new JavacTask(tb) |
129 new JavacTask(tb) |
130 .options("-modulepath", modulePath.toString(), |
130 .options("--module-path", modulePath.toString(), |
131 "-Xshouldstop:ifNoError=FLOW", |
131 "-Xshouldstop:ifNoError=FLOW", |
132 "-limitmods", "java.base", |
132 "--limit-modules", "java.base", |
133 "-addmods", "m2") |
133 "--add-modules", "m2") |
134 .outdir(modulePath) |
134 .outdir(modulePath) |
135 .files(findJavaFiles(m1)) |
135 .files(findJavaFiles(m1)) |
136 .run(Task.Expect.FAIL) |
136 .run(Task.Expect.FAIL) |
137 .writeAll(); |
137 .writeAll(); |
138 |
138 |
139 new JavacTask(tb) |
139 new JavacTask(tb) |
140 .options("-modulepath", modulePath.toString(), |
140 .options("--module-path", modulePath.toString(), |
141 "-Xshouldstop:ifNoError=FLOW", |
141 "-Xshouldstop:ifNoError=FLOW", |
142 "-limitmods", "java.base", |
142 "--limit-modules", "java.base", |
143 "-addmods", "m2,m3") |
143 "--add-modules", "m2,m3") |
144 .outdir(modulePath) |
144 .outdir(modulePath) |
145 .files(findJavaFiles(m1)) |
145 .files(findJavaFiles(m1)) |
146 .run() |
146 .run() |
147 .writeAll(); |
147 .writeAll(); |
148 |
148 |
149 new JavacTask(tb) |
149 new JavacTask(tb) |
150 .options("-modulepath", modulePath.toString(), |
150 .options("--module-path", modulePath.toString(), |
151 "-Xshouldstop:ifNoError=FLOW", |
151 "-Xshouldstop:ifNoError=FLOW", |
152 "-limitmods", "m2") |
152 "--limit-modules", "m2") |
153 .outdir(modulePath) |
153 .outdir(modulePath) |
154 .files(findJavaFiles(m1)) |
154 .files(findJavaFiles(m1)) |
155 .run() |
155 .run() |
156 .writeAll(); |
156 .writeAll(); |
157 |
157 |
158 new JavacTask(tb) |
158 new JavacTask(tb) |
159 .options("-modulepath", modulePath.toString(), |
159 .options("--module-path", modulePath.toString(), |
160 "-Xshouldstop:ifNoError=FLOW", |
160 "-Xshouldstop:ifNoError=FLOW", |
161 "-limitmods", "m3") |
161 "--limit-modules", "m3") |
162 .outdir(modulePath) |
162 .outdir(modulePath) |
163 .files(findJavaFiles(m1)) |
163 .files(findJavaFiles(m1)) |
164 .run(Task.Expect.FAIL) |
164 .run(Task.Expect.FAIL) |
165 .writeAll(); |
165 .writeAll(); |
166 |
166 |
167 new JavacTask(tb) |
167 new JavacTask(tb) |
168 .options("-modulepath", modulePath.toString(), |
168 .options("--module-path", modulePath.toString(), |
169 "-Xshouldstop:ifNoError=FLOW", |
169 "-Xshouldstop:ifNoError=FLOW", |
170 "-limitmods", "m3", |
170 "--limit-modules", "m3", |
171 "-addmods", "m2") |
171 "--add-modules", "m2") |
172 .outdir(modulePath) |
172 .outdir(modulePath) |
173 .files(findJavaFiles(m1)) |
173 .files(findJavaFiles(m1)) |
174 .run() |
174 .run() |
175 .writeAll(); |
175 .writeAll(); |
176 } |
176 } |
217 private static final List<Entry<String[], String>> variants = Arrays.asList( |
217 private static final List<Entry<String[], String>> variants = Arrays.asList( |
218 new SimpleEntry<String[], String>(new String[] {}, |
218 new SimpleEntry<String[], String>(new String[] {}, |
219 "Test.java:2:18: compiler.err.doesnt.exist: javax.annotation\n" |
219 "Test.java:2:18: compiler.err.doesnt.exist: javax.annotation\n" |
220 + "Test.java:5:19: compiler.err.doesnt.exist: javax.xml.bind\n" |
220 + "Test.java:5:19: compiler.err.doesnt.exist: javax.xml.bind\n" |
221 + "2 errors\n"), |
221 + "2 errors\n"), |
222 new SimpleEntry<String[], String>(new String[] {"-addmods", "java.annotations.common,java.xml.bind"}, |
222 new SimpleEntry<String[], String>(new String[] {"--add-modules", "java.annotations.common,java.xml.bind"}, |
223 null), |
223 null), |
224 new SimpleEntry<String[], String>(new String[] {"-limitmods", "java.xml.ws,jdk.compiler"}, |
224 new SimpleEntry<String[], String>(new String[] {"--limit-modules", "java.xml.ws,jdk.compiler"}, |
225 null), |
225 null), |
226 new SimpleEntry<String[], String>(new String[] {"-addmods", "ALL-SYSTEM"}, |
226 new SimpleEntry<String[], String>(new String[] {"--add-modules", "ALL-SYSTEM"}, |
227 null) |
227 null) |
228 ); |
228 ); |
229 |
229 |
230 @Test |
230 @Test |
231 public void testAllModulePath(Path base) throws Exception { |
231 public void testAllModulePath(Path base) throws Exception { |
256 Path cpOut = base.resolve("cp-out"); |
256 Path cpOut = base.resolve("cp-out"); |
257 |
257 |
258 Files.createDirectories(cpOut); |
258 Files.createDirectories(cpOut); |
259 |
259 |
260 new JavacTask(tb) |
260 new JavacTask(tb) |
261 .options("-modulepath", modulePath.toString()) |
261 .options("--module-path", modulePath.toString()) |
262 .outdir(cpOut) |
262 .outdir(cpOut) |
263 .files(findJavaFiles(cpSrc)) |
263 .files(findJavaFiles(cpSrc)) |
264 .run(Task.Expect.FAIL) |
264 .run(Task.Expect.FAIL) |
265 .writeAll(); |
265 .writeAll(); |
266 |
266 |
267 new JavacTask(tb) |
267 new JavacTask(tb) |
268 .options("-modulepath", modulePath.toString(), |
268 .options("--module-path", modulePath.toString(), |
269 "-addmods", "ALL-MODULE-PATH") |
269 "--add-modules", "ALL-MODULE-PATH") |
270 .outdir(cpOut) |
270 .outdir(cpOut) |
271 .files(findJavaFiles(cpSrc)) |
271 .files(findJavaFiles(cpSrc)) |
272 .run() |
272 .run() |
273 .writeAll(); |
273 .writeAll(); |
274 |
274 |
276 List<String> expected = Arrays.asList( |
276 List<String> expected = Arrays.asList( |
277 "- compiler.err.addmods.all.module.path.invalid", |
277 "- compiler.err.addmods.all.module.path.invalid", |
278 "1 error"); |
278 "1 error"); |
279 |
279 |
280 actual = new JavacTask(tb) |
280 actual = new JavacTask(tb) |
281 .options("-modulesourcepath", moduleSrc.toString(), |
281 .options("--module-source-path", moduleSrc.toString(), |
282 "-XDrawDiagnostics", |
282 "-XDrawDiagnostics", |
283 "-addmods", "ALL-MODULE-PATH") |
283 "--add-modules", "ALL-MODULE-PATH") |
284 .outdir(modulePath) |
284 .outdir(modulePath) |
285 .files(findJavaFiles(moduleSrc)) |
285 .files(findJavaFiles(moduleSrc)) |
286 .run(Task.Expect.FAIL) |
286 .run(Task.Expect.FAIL) |
287 .writeAll() |
287 .writeAll() |
288 .getOutputLines(Task.OutputKind.DIRECT); |
288 .getOutputLines(Task.OutputKind.DIRECT); |
306 } |
306 } |
307 |
307 |
308 actual = new JavacTask(tb, Task.Mode.CMDLINE) |
308 actual = new JavacTask(tb, Task.Mode.CMDLINE) |
309 .options("-source", "8", "-target", "8", |
309 .options("-source", "8", "-target", "8", |
310 "-XDrawDiagnostics", |
310 "-XDrawDiagnostics", |
311 "-addmods", "ALL-MODULE-PATH") |
311 "--add-modules", "ALL-MODULE-PATH") |
312 .outdir(cpOut) |
312 .outdir(cpOut) |
313 .files(findJavaFiles(cpSrc)) |
313 .files(findJavaFiles(cpSrc)) |
314 .run(Task.Expect.FAIL) |
314 .run(Task.Expect.FAIL) |
315 .writeAll() |
315 .writeAll() |
316 .getOutputLines(Task.OutputKind.DIRECT); |
316 .getOutputLines(Task.OutputKind.DIRECT); |
317 |
317 |
318 if (!actual.contains("javac: option -addmods not allowed with target 1.8")) { |
318 if (!actual.contains("javac: option --add-modules not allowed with target 1.8")) { |
319 throw new IllegalStateException("incorrect errors; actual=" + actual); |
319 throw new IllegalStateException("incorrect errors; actual=" + actual); |
320 } |
320 } |
321 |
321 |
322 tb.writeJavaFiles(cpSrc, "module m1 {}"); |
322 tb.writeJavaFiles(cpSrc, "module m1 {}"); |
323 |
323 |
324 actual = new JavacTask(tb) |
324 actual = new JavacTask(tb) |
325 .options("-XDrawDiagnostics", |
325 .options("-XDrawDiagnostics", |
326 "-addmods", "ALL-MODULE-PATH") |
326 "--add-modules", "ALL-MODULE-PATH") |
327 .outdir(cpOut) |
327 .outdir(cpOut) |
328 .files(findJavaFiles(cpSrc)) |
328 .files(findJavaFiles(cpSrc)) |
329 .run(Task.Expect.FAIL) |
329 .run(Task.Expect.FAIL) |
330 .writeAll() |
330 .writeAll() |
331 .getOutputLines(Task.OutputKind.DIRECT); |
331 .getOutputLines(Task.OutputKind.DIRECT); |
439 |
439 |
440 try { |
440 try { |
441 output = new JavaTask(tb) |
441 output = new JavaTask(tb) |
442 .vmOptions(augmentOptions(options, |
442 .vmOptions(augmentOptions(options, |
443 Collections.emptyList(), |
443 Collections.emptyList(), |
444 "-modulepath", modulePath.toString() + File.pathSeparator + out.getParent().toString(), |
444 "--module-path", modulePath.toString() + File.pathSeparator + out.getParent().toString(), |
445 "-classpath", classpathOut.toString(), |
445 "--class-path", classpathOut.toString(), |
446 "-XaddReads:m2=ALL-UNNAMED,automatic", |
446 "--add-reads", "m2=ALL-UNNAMED,automatic", |
447 "-m", "m2/test.Test")) |
447 "-m", "m2/test.Test")) |
448 .run() |
448 .run() |
449 .writeAll() |
449 .writeAll() |
450 .getOutput(Task.OutputKind.STDERR); |
450 .getOutput(Task.OutputKind.STDERR); |
451 |
451 |
461 moduleInfo, |
461 moduleInfo, |
462 "package test;\n" + |
462 "package test;\n" + |
463 "public class Test {}\n"); |
463 "public class Test {}\n"); |
464 |
464 |
465 List<String> auxOptions = success ? Arrays.asList( |
465 List<String> auxOptions = success ? Arrays.asList( |
466 "-processorpath", System.getProperty("test.class.path"), |
466 "--processor-path", System.getProperty("test.class.path"), |
467 "-processor", CheckVisibleModule.class.getName(), |
467 "-processor", CheckVisibleModule.class.getName(), |
468 "-Aoutput=" + output, |
468 "-Aoutput=" + output, |
469 "-XDaccessInternalAPI=true" |
469 "-XDaccessInternalAPI=true" |
470 ) : Collections.emptyList(); |
470 ) : Collections.emptyList(); |
471 new JavacTask(tb) |
471 new JavacTask(tb) |
472 .options(augmentOptions(options, |
472 .options(augmentOptions(options, |
473 auxOptions, |
473 auxOptions, |
474 "-modulepath", modulePath.toString(), |
474 "--module-path", modulePath.toString(), |
475 "-classpath", classpathOut.toString(), |
475 "--class-path", classpathOut.toString(), |
476 "-Xshouldstop:ifNoError=FLOW")) |
476 "-Xshouldstop:ifNoError=FLOW")) |
477 .outdir(modulePath) |
477 .outdir(modulePath) |
478 .files(findJavaFiles(m2)) |
478 .files(findJavaFiles(m2)) |
479 .run(success ? Task.Expect.SUCCESS : Task.Expect.FAIL) |
479 .run(success ? Task.Expect.SUCCESS : Task.Expect.FAIL) |
480 .writeAll(); |
480 .writeAll(); |
576 "module m2 { requires m1; exports test; }", |
576 "module m2 { requires m1; exports test; }", |
577 "module m2 { requires jdk.compiler; exports test; }", |
577 "module m2 { requires jdk.compiler; exports test; }", |
578 }; |
578 }; |
579 |
579 |
580 private static final String[][] OPTIONS_VARIANTS = { |
580 private static final String[][] OPTIONS_VARIANTS = { |
581 {"-addmods", "automatic"}, |
581 {"--add-modules", "automatic"}, |
582 {"-addmods", "m1,automatic"}, |
582 {"--add-modules", "m1,automatic"}, |
583 {"-addmods", "jdk.compiler,automatic"}, |
583 {"--add-modules", "jdk.compiler,automatic"}, |
584 {"-addmods", "m1,jdk.compiler,automatic"}, |
584 {"--add-modules", "m1,jdk.compiler,automatic"}, |
585 {"-addmods", "ALL-SYSTEM,automatic"}, |
585 {"--add-modules", "ALL-SYSTEM,automatic"}, |
586 {"-limitmods", "java.base", "-addmods", "automatic"}, |
586 {"--limit-modules", "java.base", "--add-modules", "automatic"}, |
587 {"-limitmods", "java.base", "-addmods", "ALL-SYSTEM,automatic"}, |
587 {"--limit-modules", "java.base", "--add-modules", "ALL-SYSTEM,automatic"}, |
588 {"-limitmods", "m2", "-addmods", "automatic"}, |
588 {"--limit-modules", "m2", "--add-modules", "automatic"}, |
589 {"-limitmods", "jdk.compiler", "-addmods", "automatic"}, |
589 {"--limit-modules", "jdk.compiler", "--add-modules", "automatic"}, |
590 }; |
590 }; |
591 } |
591 } |