author | jjg |
Thu, 03 Nov 2016 13:59:15 -0700 | |
changeset 41938 | 8e66bf10fcec |
parent 41932 | b23b4712933b |
child 43138 | 680d378b9d64 |
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 multi-module mode compilation |
|
27 |
* @library /tools/lib |
|
28 |
* @modules |
|
29 |
* jdk.compiler/com.sun.tools.javac.api |
|
40768
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
30 |
* jdk.compiler/com.sun.tools.javac.code |
36526 | 31 |
* jdk.compiler/com.sun.tools.javac.main |
40768
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
32 |
* jdk.compiler/com.sun.tools.javac.processing |
37758 | 33 |
* @build toolbox.ToolBox toolbox.JavacTask toolbox.ModuleBuilder ModuleTestBase |
36526 | 34 |
* @run main XModuleTest |
35 |
*/ |
|
36 |
||
37 |
import java.nio.file.Path; |
|
38 |
import java.util.Arrays; |
|
39 |
import java.util.List; |
|
40768
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
40 |
import java.util.Set; |
36526 | 41 |
|
40768
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
42 |
import javax.annotation.processing.AbstractProcessor; |
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
43 |
import javax.annotation.processing.RoundEnvironment; |
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
44 |
import javax.annotation.processing.SupportedAnnotationTypes; |
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
45 |
import javax.lang.model.SourceVersion; |
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
46 |
import javax.lang.model.element.ModuleElement; |
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
47 |
import javax.lang.model.element.TypeElement; |
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
48 |
import javax.lang.model.util.Elements; |
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
49 |
|
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
50 |
import com.sun.tools.javac.code.Symtab; |
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
51 |
import com.sun.tools.javac.processing.JavacProcessingEnvironment; |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
52 |
import toolbox.JavacTask; |
37758 | 53 |
import toolbox.ModuleBuilder; |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
54 |
import toolbox.Task; |
40768
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
55 |
import toolbox.Task.Expect; |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
56 |
|
36526 | 57 |
public class XModuleTest extends ModuleTestBase { |
58 |
||
59 |
public static void main(String... args) throws Exception { |
|
60 |
new XModuleTest().runTests(); |
|
61 |
} |
|
62 |
||
63 |
@Test |
|
37758 | 64 |
public void testCorrectXModule(Path base) throws Exception { |
36526 | 65 |
//note: avoiding use of java.base, as that gets special handling on some places: |
66 |
Path src = base.resolve("src"); |
|
67 |
tb.writeJavaFiles(src, "package javax.lang.model.element; public interface Extra extends Element { }"); |
|
68 |
Path classes = base.resolve("classes"); |
|
69 |
tb.createDirectories(classes); |
|
70 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
71 |
String log = new JavacTask(tb) |
36526 | 72 |
.options("-Xmodule:java.compiler") |
73 |
.outdir(classes) |
|
74 |
.files(findJavaFiles(src)) |
|
75 |
.run() |
|
76 |
.writeAll() |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
77 |
.getOutput(Task.OutputKind.DIRECT); |
36526 | 78 |
|
79 |
if (!log.isEmpty()) |
|
80 |
throw new Exception("expected output not found: " + log); |
|
81 |
} |
|
82 |
||
83 |
@Test |
|
37758 | 84 |
public void testSourcePath(Path base) throws Exception { |
36526 | 85 |
//note: avoiding use of java.base, as that gets special handling on some places: |
86 |
Path src = base.resolve("src"); |
|
87 |
tb.writeJavaFiles(src, "package javax.lang.model.element; public interface Extra extends Element, Other { }", "package javax.lang.model.element; interface Other { }"); |
|
88 |
Path classes = base.resolve("classes"); |
|
89 |
tb.createDirectories(classes); |
|
90 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
91 |
String log = new JavacTask(tb) |
36526 | 92 |
.options("-Xmodule:java.compiler", "-sourcepath", src.toString()) |
93 |
.outdir(classes) |
|
94 |
.files(src.resolve("javax/lang/model/element/Extra.java")) |
|
95 |
.run() |
|
96 |
.writeAll() |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
97 |
.getOutput(Task.OutputKind.DIRECT); |
36526 | 98 |
|
99 |
if (!log.isEmpty()) |
|
100 |
throw new Exception("expected output not found: " + log); |
|
101 |
} |
|
102 |
||
103 |
@Test |
|
37758 | 104 |
public void testClassPath(Path base) throws Exception { |
36526 | 105 |
Path cpSrc = base.resolve("cpSrc"); |
106 |
tb.writeJavaFiles(cpSrc, "package p; public interface Other { }"); |
|
107 |
Path cpClasses = base.resolve("cpClasses"); |
|
108 |
tb.createDirectories(cpClasses); |
|
109 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
110 |
String cpLog = new JavacTask(tb) |
36526 | 111 |
.outdir(cpClasses) |
112 |
.files(findJavaFiles(cpSrc)) |
|
113 |
.run() |
|
114 |
.writeAll() |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
115 |
.getOutput(Task.OutputKind.DIRECT); |
36526 | 116 |
|
117 |
if (!cpLog.isEmpty()) |
|
118 |
throw new Exception("expected output not found: " + cpLog); |
|
119 |
||
120 |
Path src = base.resolve("src"); |
|
121 |
//note: avoiding use of java.base, as that gets special handling on some places: |
|
122 |
tb.writeJavaFiles(src, "package javax.lang.model.element; public interface Extra extends Element, p.Other { }"); |
|
123 |
Path classes = base.resolve("classes"); |
|
124 |
tb.createDirectories(classes); |
|
125 |
||
40768
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
126 |
List<String> log = new JavacTask(tb) |
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
127 |
.options("-Xmodule:java.compiler", |
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
128 |
"--class-path", cpClasses.toString(), |
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
129 |
"-XDrawDiagnostics") |
36526 | 130 |
.outdir(classes) |
131 |
.files(src.resolve("javax/lang/model/element/Extra.java")) |
|
40768
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
132 |
.run(Expect.FAIL) |
36526 | 133 |
.writeAll() |
40768
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
134 |
.getOutputLines(Task.OutputKind.DIRECT); |
36526 | 135 |
|
40768
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
136 |
List<String> expectedOut = Arrays.asList( |
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
137 |
"Extra.java:1:76: compiler.err.doesnt.exist: p", |
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
138 |
"1 error" |
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
139 |
); |
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
140 |
|
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
141 |
if (!expectedOut.equals(log)) |
36526 | 142 |
throw new Exception("expected output not found: " + log); |
143 |
} |
|
144 |
||
145 |
@Test |
|
37758 | 146 |
public void testNoModuleInfoOnSourcePath(Path base) throws Exception { |
36526 | 147 |
//note: avoiding use of java.base, as that gets special handling on some places: |
148 |
Path src = base.resolve("src"); |
|
149 |
tb.writeJavaFiles(src, |
|
150 |
"module java.compiler {}", |
|
151 |
"package javax.lang.model.element; public interface Extra { }"); |
|
152 |
Path classes = base.resolve("classes"); |
|
153 |
tb.createDirectories(classes); |
|
154 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
155 |
List<String> log = new JavacTask(tb) |
36526 | 156 |
.options("-XDrawDiagnostics", "-Xmodule:java.compiler") |
157 |
.outdir(classes) |
|
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 |
.getOutputLines(Task.OutputKind.DIRECT); |
36526 | 162 |
|
163 |
List<String> expected = Arrays.asList("Extra.java:1:1: compiler.err.module-info.with.xmodule.sourcepath", |
|
164 |
"1 error"); |
|
165 |
||
166 |
if (!expected.equals(log)) |
|
167 |
throw new Exception("expected output not found: " + log); |
|
168 |
} |
|
169 |
||
170 |
@Test |
|
37758 | 171 |
public void testNoModuleInfoInClassOutput(Path base) throws Exception { |
36526 | 172 |
//note: avoiding use of java.base, as that gets special handling on some places: |
173 |
Path srcMod = base.resolve("src-mod"); |
|
174 |
tb.writeJavaFiles(srcMod, |
|
175 |
"module mod {}"); |
|
176 |
Path classes = base.resolve("classes"); |
|
177 |
tb.createDirectories(classes); |
|
178 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
179 |
String logMod = new JavacTask(tb) |
36526 | 180 |
.options() |
181 |
.outdir(classes) |
|
182 |
.files(findJavaFiles(srcMod)) |
|
183 |
.run() |
|
184 |
.writeAll() |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
185 |
.getOutput(Task.OutputKind.DIRECT); |
36526 | 186 |
|
187 |
if (!logMod.isEmpty()) |
|
188 |
throw new Exception("unexpected output found: " + logMod); |
|
189 |
||
190 |
Path src = base.resolve("src"); |
|
191 |
tb.writeJavaFiles(src, |
|
192 |
"package javax.lang.model.element; public interface Extra { }"); |
|
193 |
tb.createDirectories(classes); |
|
194 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
195 |
List<String> log = new JavacTask(tb) |
36526 | 196 |
.options("-XDrawDiagnostics", "-Xmodule:java.compiler") |
197 |
.outdir(classes) |
|
198 |
.files(findJavaFiles(src)) |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
199 |
.run(Task.Expect.FAIL) |
36526 | 200 |
.writeAll() |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
201 |
.getOutputLines(Task.OutputKind.DIRECT); |
36526 | 202 |
|
203 |
List<String> expected = Arrays.asList("Extra.java:1:1: compiler.err.module-info.with.xmodule.classpath", |
|
204 |
"1 error"); |
|
205 |
||
206 |
if (!expected.equals(log)) |
|
207 |
throw new Exception("expected output not found: " + log); |
|
208 |
} |
|
209 |
||
210 |
@Test |
|
37758 | 211 |
public void testModuleSourcePathXModule(Path base) throws Exception { |
36526 | 212 |
//note: avoiding use of java.base, as that gets special handling on some places: |
213 |
Path src = base.resolve("src"); |
|
214 |
tb.writeJavaFiles(src, "package javax.lang.model.element; public interface Extra extends Element { }"); |
|
215 |
Path classes = base.resolve("classes"); |
|
216 |
tb.createDirectories(classes); |
|
217 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
218 |
List<String> log = new JavacTask(tb) |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
39103
diff
changeset
|
219 |
.options("-XDrawDiagnostics", "-Xmodule:java.compiler", "--module-source-path", src.toString()) |
36526 | 220 |
.outdir(classes) |
221 |
.files(findJavaFiles(src)) |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
222 |
.run(Task.Expect.FAIL) |
36526 | 223 |
.writeAll() |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
224 |
.getOutputLines(Task.OutputKind.DIRECT); |
36526 | 225 |
|
41938
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41932
diff
changeset
|
226 |
List<String> expected = Arrays.asList("- compiler.err.xmodule.no.module.sourcepath"); |
36526 | 227 |
|
228 |
if (!expected.equals(log)) |
|
229 |
throw new Exception("expected output not found: " + log); |
|
230 |
} |
|
231 |
||
232 |
@Test |
|
37758 | 233 |
public void testXModuleTooMany(Path base) throws Exception { |
36526 | 234 |
//note: avoiding use of java.base, as that gets special handling on some places: |
235 |
Path src = base.resolve("src"); |
|
236 |
tb.writeJavaFiles(src, "package javax.lang.model.element; public interface Extra extends Element { }"); |
|
237 |
Path classes = base.resolve("classes"); |
|
238 |
tb.createDirectories(classes); |
|
239 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
240 |
List<String> log = new JavacTask(tb, Task.Mode.CMDLINE) |
36526 | 241 |
.options("-XDrawDiagnostics", "-Xmodule:java.compiler", "-Xmodule:java.compiler") |
242 |
.outdir(classes) |
|
243 |
.files(findJavaFiles(src)) |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
244 |
.run(Task.Expect.FAIL) |
36526 | 245 |
.writeAll() |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
246 |
.getOutputLines(Task.OutputKind.DIRECT); |
36526 | 247 |
|
248 |
List<String> expected = Arrays.asList("javac: option -Xmodule: can only be specified once", |
|
249 |
"Usage: javac <options> <source files>", |
|
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
39103
diff
changeset
|
250 |
"use --help for a list of possible options"); |
36526 | 251 |
|
252 |
if (!expected.equals(log)) |
|
253 |
throw new Exception("expected output not found: " + log); |
|
254 |
} |
|
255 |
||
256 |
@Test |
|
37758 | 257 |
public void testWithModulePath(Path base) throws Exception { |
39103
91a64ec5b970
8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents:
37758
diff
changeset
|
258 |
Path modSrc = base.resolve("modSrc"); |
91a64ec5b970
8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents:
37758
diff
changeset
|
259 |
Path modules = base.resolve("modules"); |
37758 | 260 |
new ModuleBuilder(tb, "m1") |
36526 | 261 |
.classes("package pkg1; public interface E { }") |
39103
91a64ec5b970
8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents:
37758
diff
changeset
|
262 |
.build(modSrc, modules); |
36526 | 263 |
|
264 |
Path src = base.resolve("src"); |
|
265 |
tb.writeJavaFiles(src, "package p; interface A extends pkg1.E { }"); |
|
266 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
267 |
new JavacTask(tb, Task.Mode.CMDLINE) |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
39103
diff
changeset
|
268 |
.options("--module-path", modules.toString(), |
36526 | 269 |
"-Xmodule:m1") |
270 |
.files(findJavaFiles(src)) |
|
271 |
.run() |
|
272 |
.writeAll(); |
|
273 |
||
274 |
//checks module bounds still exist |
|
37758 | 275 |
new ModuleBuilder(tb, "m2") |
36526 | 276 |
.classes("package pkg2; public interface D { }") |
39103
91a64ec5b970
8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents:
37758
diff
changeset
|
277 |
.build(modSrc, modules); |
36526 | 278 |
|
279 |
Path src2 = base.resolve("src2"); |
|
280 |
tb.writeJavaFiles(src2, "package p; interface A extends pkg2.D { }"); |
|
281 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
282 |
List<String> log = new JavacTask(tb, Task.Mode.CMDLINE) |
36526 | 283 |
.options("-XDrawDiagnostics", |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
39103
diff
changeset
|
284 |
"--module-path", modules.toString(), |
36526 | 285 |
"-Xmodule:m1") |
286 |
.files(findJavaFiles(src2)) |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
287 |
.run(Task.Expect.FAIL) |
36526 | 288 |
.writeAll() |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
289 |
.getOutputLines(Task.OutputKind.DIRECT); |
36526 | 290 |
|
41932 | 291 |
List<String> expected = Arrays.asList("A.java:1:36: compiler.err.doesnt.exist: pkg2", |
36526 | 292 |
"1 error"); |
293 |
||
294 |
if (!expected.equals(log)) |
|
295 |
throw new Exception("expected output not found: " + log); |
|
296 |
} |
|
297 |
||
298 |
@Test |
|
37758 | 299 |
public void testWithUpgradeModulePath(Path base) throws Exception { |
39103
91a64ec5b970
8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents:
37758
diff
changeset
|
300 |
Path modSrc = base.resolve("modSrc"); |
91a64ec5b970
8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents:
37758
diff
changeset
|
301 |
Path modules = base.resolve("modules"); |
37758 | 302 |
new ModuleBuilder(tb, "m1") |
36526 | 303 |
.classes("package pkg1; public interface E { }") |
39103
91a64ec5b970
8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents:
37758
diff
changeset
|
304 |
.build(modSrc, modules); |
36526 | 305 |
|
39103
91a64ec5b970
8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents:
37758
diff
changeset
|
306 |
Path upgrSrc = base.resolve("upgradeSrc"); |
36526 | 307 |
Path upgrade = base.resolve("upgrade"); |
37758 | 308 |
new ModuleBuilder(tb, "m1") |
36526 | 309 |
.classes("package pkg1; public interface D { }") |
39103
91a64ec5b970
8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents:
37758
diff
changeset
|
310 |
.build(upgrSrc, upgrade); |
36526 | 311 |
|
312 |
Path src = base.resolve("src"); |
|
313 |
tb.writeJavaFiles(src, "package p; interface A extends pkg1.D { }"); |
|
314 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
315 |
new JavacTask(tb, Task.Mode.CMDLINE) |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
39103
diff
changeset
|
316 |
.options("--module-path", modules.toString(), |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
39103
diff
changeset
|
317 |
"--upgrade-module-path", upgrade.toString(), |
36526 | 318 |
"-Xmodule:m1") |
319 |
.files(findJavaFiles(src)) |
|
320 |
.run() |
|
321 |
.writeAll(); |
|
322 |
} |
|
40768
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
323 |
|
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
324 |
@Test |
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
325 |
public void testUnnamedIsolation(Path base) throws Exception { |
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
326 |
//note: avoiding use of java.base, as that gets special handling on some places: |
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
327 |
Path sourcePath = base.resolve("source-path"); |
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
328 |
tb.writeJavaFiles(sourcePath, "package src; public class Src {}"); |
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
329 |
|
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
330 |
Path classPathSrc = base.resolve("class-path-src"); |
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
331 |
tb.writeJavaFiles(classPathSrc, "package cp; public class CP { }"); |
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
332 |
Path classPath = base.resolve("classPath"); |
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
333 |
tb.createDirectories(classPath); |
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
334 |
|
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
335 |
String cpLog = new JavacTask(tb) |
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
336 |
.outdir(classPath) |
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
337 |
.files(findJavaFiles(classPathSrc)) |
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
338 |
.run() |
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
339 |
.writeAll() |
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
340 |
.getOutput(Task.OutputKind.DIRECT); |
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
341 |
|
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
342 |
if (!cpLog.isEmpty()) |
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
343 |
throw new Exception("expected output not found: " + cpLog); |
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
344 |
|
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
345 |
Path modulePathSrc = base.resolve("module-path-src"); |
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
346 |
tb.writeJavaFiles(modulePathSrc, |
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
347 |
"module m {}", |
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
348 |
"package m; public class M {}"); |
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
349 |
Path modulePath = base.resolve("modulePath"); |
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
350 |
tb.createDirectories(modulePath.resolve("m")); |
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
351 |
|
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
352 |
String modLog = new JavacTask(tb) |
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
353 |
.outdir(modulePath.resolve("m")) |
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
354 |
.files(findJavaFiles(modulePathSrc)) |
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
355 |
.run() |
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
356 |
.writeAll() |
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
357 |
.getOutput(Task.OutputKind.DIRECT); |
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
358 |
|
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
359 |
if (!modLog.isEmpty()) |
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
360 |
throw new Exception("expected output not found: " + modLog); |
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
361 |
|
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
362 |
Path src = base.resolve("src"); |
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
363 |
tb.writeJavaFiles(src, "package m; public class Extra { }"); |
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
364 |
Path classes = base.resolve("classes"); |
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
365 |
tb.createDirectories(classes); |
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
366 |
|
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
367 |
String log = new JavacTask(tb) |
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
368 |
.options("-Xmodule:m", |
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
369 |
"--class-path", classPath.toString(), |
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
370 |
"--source-path", sourcePath.toString(), |
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
371 |
"--module-path", modulePath.toString(), |
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
372 |
"--processor-path", System.getProperty("test.classes"), |
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
373 |
"-XDaccessInternalAPI=true", |
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
374 |
"-processor", CheckModuleContentProcessing.class.getName()) |
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
375 |
.outdir(classes) |
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
376 |
.files(findJavaFiles(sourcePath)) |
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
377 |
.run() |
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
378 |
.writeAll() |
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
379 |
.getOutput(Task.OutputKind.DIRECT); |
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
380 |
|
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
381 |
if (!log.isEmpty()) |
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
382 |
throw new Exception("expected output not found: " + log); |
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
383 |
} |
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
384 |
|
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
385 |
@SupportedAnnotationTypes("*") |
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
386 |
public static final class CheckModuleContentProcessing extends AbstractProcessor { |
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
387 |
|
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
388 |
@Override |
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
389 |
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { |
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
390 |
Symtab syms = Symtab.instance(((JavacProcessingEnvironment) processingEnv).getContext()); |
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
391 |
Elements elements = processingEnv.getElementUtils(); |
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
392 |
ModuleElement unnamedModule = syms.unnamedModule; |
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
393 |
ModuleElement mModule = elements.getModuleElement("m"); |
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
394 |
|
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
395 |
assertNonNull("mModule found", mModule); |
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
396 |
assertNonNull("src.Src from m", elements.getTypeElement(mModule, "src.Src")); |
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
397 |
assertNull("cp.CP not from m", elements.getTypeElement(mModule, "cp.CP")); |
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
398 |
assertNull("src.Src not from unnamed", elements.getTypeElement(unnamedModule, "src.Src")); |
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
399 |
assertNonNull("cp.CP from unnamed", elements.getTypeElement(unnamedModule, "cp.CP")); |
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
400 |
|
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
401 |
return false; |
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
402 |
} |
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
403 |
|
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
404 |
@Override |
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
405 |
public SourceVersion getSupportedSourceVersion() { |
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
406 |
return SourceVersion.latest(); |
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
407 |
} |
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
408 |
|
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
409 |
private static void assertNonNull(String msg, Object val) { |
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
410 |
if (val == null) { |
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
411 |
throw new AssertionError(msg); |
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
412 |
} |
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
413 |
} |
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
414 |
|
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
415 |
private static void assertNull(String msg, Object val) { |
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
416 |
if (val != null) { |
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
417 |
throw new AssertionError(msg); |
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
418 |
} |
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
419 |
} |
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
420 |
} |
8b6a878d8773
8165008: javac -Xmodule compiles the module in a way that reads the unnamed module
jlahoda
parents:
40604
diff
changeset
|
421 |
|
36526 | 422 |
} |