author | sadayapalam |
Mon, 06 Feb 2017 18:14:51 +0530 | |
changeset 43584 | 63e67712246b |
parent 43369 | aafd33c96bac |
child 44289 | 842ccb558d7d |
permissions | -rw-r--r-- |
36526 | 1 |
/* |
43269
12f989542165
8171098: NPE when --add-modules java.corba is used
jlahoda
parents:
43138
diff
changeset
|
2 |
* Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved. |
36526 | 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 |
|
43369
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
26 |
* @bug 8154283 8167320 8171098 8172809 8173068 8173117 |
36526 | 27 |
* @summary tests for multi-module mode compilation |
28 |
* @library /tools/lib |
|
29 |
* @modules |
|
30 |
* jdk.compiler/com.sun.tools.javac.api |
|
31 |
* jdk.compiler/com.sun.tools.javac.code |
|
32 |
* jdk.compiler/com.sun.tools.javac.main |
|
43369
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
33 |
* jdk.compiler/com.sun.tools.javac.processing |
43271
ce89609dde7c
8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents:
43269
diff
changeset
|
34 |
* jdk.compiler/com.sun.tools.javac.util |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
35 |
* @build toolbox.ToolBox toolbox.JarTask toolbox.JavacTask ModuleTestBase |
36526 | 36 |
* @run main EdgeCases |
37 |
*/ |
|
38 |
||
39 |
import java.io.Writer; |
|
40 |
import java.nio.file.Files; |
|
41 |
import java.nio.file.Path; |
|
42 |
import java.nio.file.Paths; |
|
43 |
import java.util.Arrays; |
|
44 |
import java.util.HashSet; |
|
45 |
import java.util.List; |
|
46 |
import java.util.Objects; |
|
47 |
import java.util.Set; |
|
48 |
||
43271
ce89609dde7c
8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents:
43269
diff
changeset
|
49 |
import javax.annotation.processing.AbstractProcessor; |
ce89609dde7c
8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents:
43269
diff
changeset
|
50 |
import javax.annotation.processing.RoundEnvironment; |
ce89609dde7c
8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents:
43269
diff
changeset
|
51 |
import javax.annotation.processing.SupportedAnnotationTypes; |
ce89609dde7c
8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents:
43269
diff
changeset
|
52 |
import javax.annotation.processing.SupportedOptions; |
ce89609dde7c
8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents:
43269
diff
changeset
|
53 |
import javax.lang.model.SourceVersion; |
36526 | 54 |
import javax.lang.model.element.Element; |
43271
ce89609dde7c
8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents:
43269
diff
changeset
|
55 |
import javax.lang.model.element.ModuleElement; |
ce89609dde7c
8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents:
43269
diff
changeset
|
56 |
import javax.lang.model.element.ModuleElement.RequiresDirective; |
43369
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
57 |
import javax.lang.model.element.PackageElement; |
43271
ce89609dde7c
8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents:
43269
diff
changeset
|
58 |
import javax.lang.model.element.TypeElement; |
ce89609dde7c
8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents:
43269
diff
changeset
|
59 |
import javax.lang.model.util.ElementFilter; |
43369
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
60 |
import javax.lang.model.util.Elements; |
36526 | 61 |
import javax.tools.JavaCompiler; |
62 |
import javax.tools.JavaFileObject; |
|
63 |
import javax.tools.StandardJavaFileManager; |
|
64 |
import javax.tools.ToolProvider; |
|
65 |
||
66 |
import com.sun.source.tree.CompilationUnitTree; |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
67 |
//import com.sun.source.util.JavacTask; // conflicts with toolbox.JavacTask |
36526 | 68 |
import com.sun.tools.javac.api.JavacTaskImpl; |
69 |
import com.sun.tools.javac.code.Symbol.ModuleSymbol; |
|
43369
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
70 |
import com.sun.tools.javac.code.Symbol.PackageSymbol; |
41516
0a5838f027a4
8167320: Trying to document only java.base causes a NPE in javac
jlahoda
parents:
41254
diff
changeset
|
71 |
import com.sun.tools.javac.code.Symtab; |
43369
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
72 |
import com.sun.tools.javac.processing.JavacProcessingEnvironment; |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
73 |
import com.sun.tools.javac.util.Context; |
36526 | 74 |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
75 |
import toolbox.JarTask; |
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
76 |
import toolbox.JavacTask; |
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
77 |
import toolbox.Task; |
41254
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
78 |
import toolbox.Task.Expect; |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
79 |
import toolbox.Task.OutputKind; |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
80 |
|
36526 | 81 |
public class EdgeCases extends ModuleTestBase { |
82 |
||
83 |
public static void main(String... args) throws Exception { |
|
84 |
new EdgeCases().runTests(); |
|
85 |
} |
|
86 |
||
87 |
@Test |
|
37758 | 88 |
public void testAddExportUndefinedModule(Path base) throws Exception { |
36526 | 89 |
Path src = base.resolve("src"); |
41938
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41932
diff
changeset
|
90 |
tb.writeJavaFiles(src, "package test; import undefPackage.Any; public class Test {}"); |
36526 | 91 |
Path classes = base.resolve("classes"); |
92 |
tb.createDirectories(classes); |
|
93 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
94 |
List<String> log = new JavacTask(tb) |
41938
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41932
diff
changeset
|
95 |
.options("--add-exports", "undefModule/undefPackage=ALL-UNNAMED", |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41932
diff
changeset
|
96 |
"-XDrawDiagnostics") |
36526 | 97 |
.outdir(classes) |
98 |
.files(findJavaFiles(src)) |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
99 |
.run(Task.Expect.FAIL) |
36526 | 100 |
.writeAll() |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
101 |
.getOutputLines(Task.OutputKind.DIRECT); |
36526 | 102 |
|
41938
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41932
diff
changeset
|
103 |
List<String> expected = Arrays.asList("- compiler.warn.module.for.option.not.found: --add-exports, undefModule", |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41932
diff
changeset
|
104 |
"Test.java:1:34: compiler.err.doesnt.exist: undefPackage", |
8e66bf10fcec
8167975: align javac --add-* modules options with launcher
jjg
parents:
41932
diff
changeset
|
105 |
"1 error", "1 warning"); |
36526 | 106 |
|
107 |
if (!expected.equals(log)) |
|
108 |
throw new Exception("expected output not found: " + log); |
|
109 |
} |
|
110 |
||
111 |
@Test |
|
37758 | 112 |
public void testModuleSymbolOutterMostClass(Path base) throws Exception { |
36526 | 113 |
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); |
114 |
try (StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null)) { |
|
115 |
Path moduleSrc = base.resolve("module-src"); |
|
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
116 |
Path m1 = moduleSrc.resolve("m1x"); |
36526 | 117 |
|
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
118 |
tb.writeJavaFiles(m1, "module m1x { }"); |
36526 | 119 |
|
120 |
Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(findJavaFiles(moduleSrc)); |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
121 |
com.sun.source.util.JavacTask task = |
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
122 |
(com.sun.source.util.JavacTask) compiler.getTask(null, fm, null, null, null, files); |
36526 | 123 |
|
124 |
task.analyze(); |
|
125 |
||
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
126 |
ModuleSymbol msym = (ModuleSymbol) task.getElements().getModuleElement("m1x"); |
36526 | 127 |
|
128 |
msym.outermostClass(); |
|
129 |
} |
|
130 |
} |
|
131 |
||
132 |
@Test |
|
37758 | 133 |
public void testParseEnterAnalyze(Path base) throws Exception { |
36526 | 134 |
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); |
135 |
try (StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null)) { |
|
136 |
Path moduleSrc = base.resolve("module-src"); |
|
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
137 |
Path m1 = moduleSrc.resolve("m1x"); |
36526 | 138 |
|
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
139 |
tb.writeJavaFiles(m1, "module m1x { }", |
36526 | 140 |
"package p;", |
141 |
"package p; class T { }"); |
|
142 |
||
143 |
Path classes = base.resolve("classes"); |
|
144 |
Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(findJavaFiles(moduleSrc)); |
|
145 |
List<String> options = Arrays.asList("-d", classes.toString(), "-Xpkginfo:always"); |
|
146 |
JavacTaskImpl task = (JavacTaskImpl) compiler.getTask(null, fm, null, options, null, files); |
|
147 |
||
148 |
Iterable<? extends CompilationUnitTree> parsed = task.parse(); |
|
149 |
Iterable<? extends Element> entered = task.enter(parsed); |
|
150 |
Iterable<? extends Element> analyzed = task.analyze(entered); |
|
151 |
Iterable<? extends JavaFileObject> generatedFiles = task.generate(analyzed); |
|
152 |
||
153 |
Set<String> generated = new HashSet<>(); |
|
154 |
||
155 |
for (JavaFileObject jfo : generatedFiles) { |
|
156 |
generated.add(jfo.getName()); |
|
157 |
} |
|
158 |
||
159 |
Set<String> expected = new HashSet<>( |
|
160 |
Arrays.asList(Paths.get("testParseEnterAnalyze", "classes", "p", "package-info.class").toString(), |
|
161 |
Paths.get("testParseEnterAnalyze", "classes", "module-info.class").toString(), |
|
162 |
Paths.get("testParseEnterAnalyze", "classes", "p", "T.class").toString()) |
|
163 |
); |
|
164 |
||
165 |
if (!Objects.equals(expected, generated)) |
|
166 |
throw new AssertionError("Incorrect generated files: " + generated); |
|
167 |
} |
|
168 |
} |
|
169 |
||
170 |
@Test |
|
37758 | 171 |
public void testModuleImplicitModuleBoundaries(Path base) throws Exception { |
36526 | 172 |
Path src = base.resolve("src"); |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
173 |
Path src_m1 = src.resolve("m1x"); |
36526 | 174 |
tb.writeJavaFiles(src_m1, |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
175 |
"module m1x { exports api1; }", |
36526 | 176 |
"package api1; public class Api1 { public void call() { } }"); |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
177 |
Path src_m2 = src.resolve("m2x"); |
36526 | 178 |
tb.writeJavaFiles(src_m2, |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
179 |
"module m2x { requires m1x; exports api2; }", |
36526 | 180 |
"package api2; public class Api2 { public static api1.Api1 get() { return null; } }"); |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
181 |
Path src_m3 = src.resolve("m3x"); |
36526 | 182 |
tb.writeJavaFiles(src_m3, |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
183 |
"module m3x { requires m2x; }", |
36526 | 184 |
"package test; public class Test { { api2.Api2.get().call(); api2.Api2.get().toString(); } }"); |
185 |
Path classes = base.resolve("classes"); |
|
186 |
tb.createDirectories(classes); |
|
187 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
188 |
String log = new JavacTask(tb) |
36526 | 189 |
.options("-XDrawDiagnostics", |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
37758
diff
changeset
|
190 |
"--module-source-path", src.toString()) |
36526 | 191 |
.outdir(classes) |
192 |
.files(findJavaFiles(src)) |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
193 |
.run(Task.Expect.FAIL) |
36526 | 194 |
.writeAll() |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
195 |
.getOutput(Task.OutputKind.DIRECT); |
36526 | 196 |
|
43138
680d378b9d64
8169197: Improve error reporting for compiling against unexported package
jlahoda
parents:
42822
diff
changeset
|
197 |
if (!log.contains("Test.java:1:52: compiler.err.not.def.access.class.intf.cant.access.reason: call(), api1.Api1, api1, (compiler.misc.not.def.access.does.not.read: m3x, api1, m1x)") || |
36526 | 198 |
!log.contains("Test.java:1:76: compiler.err.not.def.access.class.intf.cant.access: toString(), java.lang.Object")) |
199 |
throw new Exception("expected output not found"); |
|
200 |
} |
|
201 |
||
202 |
@Test |
|
37758 | 203 |
public void testAssignClassToAutomaticModule(Path base) throws Exception { |
36526 | 204 |
//check that if a ClassSymbol belongs to an automatic module, it is properly assigned and not |
205 |
//duplicated when being accessed through a classfile. |
|
206 |
Path automaticSrc = base.resolve("automaticSrc"); |
|
207 |
tb.writeJavaFiles(automaticSrc, "package api1; public class Api1 {}"); |
|
208 |
Path automaticClasses = base.resolve("automaticClasses"); |
|
209 |
tb.createDirectories(automaticClasses); |
|
210 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
211 |
String automaticLog = new JavacTask(tb) |
36526 | 212 |
.outdir(automaticClasses) |
213 |
.files(findJavaFiles(automaticSrc)) |
|
214 |
.run() |
|
215 |
.writeAll() |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
216 |
.getOutput(Task.OutputKind.DIRECT); |
36526 | 217 |
|
218 |
if (!automaticLog.isEmpty()) |
|
219 |
throw new Exception("expected output not found: " + automaticLog); |
|
220 |
||
221 |
Path modulePath = base.resolve("module-path"); |
|
222 |
||
223 |
Files.createDirectories(modulePath); |
|
224 |
||
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41938
diff
changeset
|
225 |
Path automaticJar = modulePath.resolve("a-1.0.jar"); |
36526 | 226 |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
227 |
new JarTask(tb, automaticJar) |
36526 | 228 |
.baseDir(automaticClasses) |
229 |
.files("api1/Api1.class") |
|
230 |
.run(); |
|
231 |
||
232 |
Path src = base.resolve("src"); |
|
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
233 |
Path src_m2 = src.resolve("m2x"); |
36526 | 234 |
tb.writeJavaFiles(src_m2, |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
235 |
"module m2x { requires a; exports api2; }", |
36526 | 236 |
"package api2; public class Api2 { public static api1.Api1 get() { return null; } }"); |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
237 |
Path src_m3 = src.resolve("m3x"); |
36526 | 238 |
tb.writeJavaFiles(src_m3, |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
239 |
"module m3x { requires a; requires m2x; }", |
36526 | 240 |
"package test; public class Test { { api2.Api2.get(); api1.Api1 a1; } }"); |
241 |
Path classes = base.resolve("classes"); |
|
242 |
tb.createDirectories(classes); |
|
243 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
244 |
new JavacTask(tb) |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
37758
diff
changeset
|
245 |
.options("--module-path", modulePath.toString(), |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
37758
diff
changeset
|
246 |
"--module-source-path", src.toString()) |
36526 | 247 |
.outdir(classes) |
248 |
.files(findJavaFiles(src_m2)) |
|
249 |
.run() |
|
250 |
.writeAll(); |
|
251 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
252 |
new JavacTask(tb) |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
37758
diff
changeset
|
253 |
.options("--module-path", modulePath.toString(), |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
37758
diff
changeset
|
254 |
"--module-source-path", src.toString()) |
36526 | 255 |
.outdir(classes) |
256 |
.files(findJavaFiles(src_m3)) |
|
257 |
.run() |
|
258 |
.writeAll(); |
|
259 |
} |
|
260 |
||
261 |
@Test |
|
37758 | 262 |
public void testEmptyImplicitModuleInfo(Path base) throws Exception { |
36526 | 263 |
Path src = base.resolve("src"); |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
264 |
Path src_m1 = src.resolve("m1x"); |
36526 | 265 |
Files.createDirectories(src_m1); |
266 |
try (Writer w = Files.newBufferedWriter(src_m1.resolve("module-info.java"))) {} |
|
267 |
tb.writeJavaFiles(src_m1, |
|
268 |
"package test; public class Test {}"); |
|
269 |
Path classes = base.resolve("classes"); |
|
270 |
tb.createDirectories(classes); |
|
271 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
272 |
new JavacTask(tb) |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
37758
diff
changeset
|
273 |
.options("--source-path", src_m1.toString(), |
36526 | 274 |
"-XDrawDiagnostics") |
275 |
.outdir(classes) |
|
276 |
.files(findJavaFiles(src_m1.resolve("test"))) |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
277 |
.run(Task.Expect.FAIL) |
36526 | 278 |
.writeAll(); |
279 |
||
280 |
tb.writeJavaFiles(src_m1, |
|
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
281 |
"module m1x {}"); |
36526 | 282 |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
283 |
new JavacTask(tb) |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
37758
diff
changeset
|
284 |
.options("--source-path", src_m1.toString()) |
36526 | 285 |
.outdir(classes) |
286 |
.files(findJavaFiles(src_m1.resolve("test"))) |
|
287 |
.run() |
|
288 |
.writeAll(); |
|
289 |
||
290 |
} |
|
291 |
||
37744
bf4fd5e022c5
8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents:
36778
diff
changeset
|
292 |
@Test |
37758 | 293 |
public void testClassPackageClash(Path base) throws Exception { |
37744
bf4fd5e022c5
8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents:
36778
diff
changeset
|
294 |
Path src = base.resolve("src"); |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
295 |
Path src_m1 = src.resolve("m1x"); |
37744
bf4fd5e022c5
8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents:
36778
diff
changeset
|
296 |
tb.writeJavaFiles(src_m1, |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
297 |
"module m1x { exports test.m1x; }", |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
298 |
"package test.m1x;\n" + |
37744
bf4fd5e022c5
8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents:
36778
diff
changeset
|
299 |
"public class Test {}\n"); |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
300 |
Path src_m2 = src.resolve("m2x"); |
37744
bf4fd5e022c5
8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents:
36778
diff
changeset
|
301 |
tb.writeJavaFiles(src_m2, |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
302 |
"module m2x { requires m1x; }", |
37744
bf4fd5e022c5
8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents:
36778
diff
changeset
|
303 |
"package test;\n" + |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
304 |
"public class m1x {}\n"); |
37744
bf4fd5e022c5
8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents:
36778
diff
changeset
|
305 |
Path classes = base.resolve("classes"); |
bf4fd5e022c5
8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents:
36778
diff
changeset
|
306 |
tb.createDirectories(classes); |
bf4fd5e022c5
8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents:
36778
diff
changeset
|
307 |
|
bf4fd5e022c5
8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents:
36778
diff
changeset
|
308 |
List<String> log = new JavacTask(tb) |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
37758
diff
changeset
|
309 |
.options("--module-source-path", src.toString(), |
37744
bf4fd5e022c5
8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents:
36778
diff
changeset
|
310 |
"-XDrawDiagnostics") |
bf4fd5e022c5
8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents:
36778
diff
changeset
|
311 |
.outdir(classes) |
bf4fd5e022c5
8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents:
36778
diff
changeset
|
312 |
.files(findJavaFiles(src)) |
bf4fd5e022c5
8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents:
36778
diff
changeset
|
313 |
.run(Task.Expect.FAIL) |
bf4fd5e022c5
8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents:
36778
diff
changeset
|
314 |
.writeAll() |
bf4fd5e022c5
8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents:
36778
diff
changeset
|
315 |
.getOutputLines(Task.OutputKind.DIRECT); |
bf4fd5e022c5
8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents:
36778
diff
changeset
|
316 |
|
bf4fd5e022c5
8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents:
36778
diff
changeset
|
317 |
List<String> expected = Arrays.asList( |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
318 |
"m1x.java:2:8: compiler.err.clash.with.pkg.of.same.name: kindname.class, test.m1x", |
37744
bf4fd5e022c5
8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents:
36778
diff
changeset
|
319 |
"1 error" |
bf4fd5e022c5
8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents:
36778
diff
changeset
|
320 |
); |
bf4fd5e022c5
8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents:
36778
diff
changeset
|
321 |
|
bf4fd5e022c5
8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents:
36778
diff
changeset
|
322 |
if (!expected.equals(log)) { |
bf4fd5e022c5
8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents:
36778
diff
changeset
|
323 |
throw new IllegalStateException(log.toString()); |
bf4fd5e022c5
8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents:
36778
diff
changeset
|
324 |
} |
bf4fd5e022c5
8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents:
36778
diff
changeset
|
325 |
} |
bf4fd5e022c5
8154283: Check for clash between package and class not working when package in a different module
jlahoda
parents:
36778
diff
changeset
|
326 |
|
41254
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
327 |
@Test |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
328 |
public void testImplicitJavaBase(Path base) throws Exception { |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
329 |
Path src = base.resolve("src"); |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
330 |
Path src_java_base = src.resolve("java.base"); |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
331 |
Files.createDirectories(src_java_base); |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
332 |
tb.writeJavaFiles(src_java_base, "module java.base { exports java.lang; }"); |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
333 |
tb.writeJavaFiles(src_java_base, |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
334 |
"package java.lang; public class Object {}"); |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
335 |
Path classes = base.resolve("classes"); |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
336 |
tb.createDirectories(classes); |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
337 |
|
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
338 |
//module-info from source: |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
339 |
new JavacTask(tb) |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
340 |
.options("-sourcepath", src_java_base.toString()) |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
341 |
.outdir(classes) |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
342 |
.files(findJavaFiles(src_java_base.resolve("java").resolve("lang").resolve("Object.java"))) |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
343 |
.run() |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
344 |
.writeAll(); |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
345 |
|
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
346 |
//module-info from class: |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
347 |
if (!Files.exists(classes.resolve("module-info.class"))) { |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
348 |
throw new AssertionError("module-info.class not created!"); |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
349 |
} |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
350 |
|
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
351 |
new JavacTask(tb) |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
352 |
.outdir(classes) |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
353 |
.files(findJavaFiles(src_java_base.resolve("java").resolve("lang").resolve("Object.java"))) |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
354 |
.run() |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
355 |
.writeAll(); |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
356 |
|
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
357 |
//broken module-info.class: |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
358 |
Files.newOutputStream(classes.resolve("module-info.class")).close(); |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
359 |
|
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
360 |
List<String> log = new JavacTask(tb) |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
361 |
.options("-XDrawDiagnostics") |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
362 |
.outdir(classes) |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
363 |
.files(findJavaFiles(src_java_base.resolve("java").resolve("lang").resolve("Object.java"))) |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
364 |
.run(Expect.FAIL) |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
365 |
.writeAll() |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
366 |
.getOutputLines(OutputKind.DIRECT); |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
367 |
|
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
368 |
List<String> expected = Arrays.asList( |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
369 |
"- compiler.err.cant.access: <error>.module-info, (compiler.misc.bad.class.file.header: module-info.class, (compiler.misc.illegal.start.of.class.file))", |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
370 |
"1 error"); |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
371 |
|
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
372 |
if (!expected.equals(log)) { |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
373 |
throw new AssertionError("Unexpected output: " + log); |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
374 |
} |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
375 |
|
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
376 |
//broken module-info.java: |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
377 |
Files.delete(classes.resolve("module-info.class")); |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
378 |
|
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
379 |
try (Writer out = Files.newBufferedWriter(src_java_base.resolve("module-info.java"))) { |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
380 |
out.write("class Broken {}"); |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
381 |
} |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
382 |
|
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
383 |
log = new JavacTask(tb) |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
384 |
.options("-sourcepath", src_java_base.toString(), |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
385 |
"-XDrawDiagnostics") |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
386 |
.outdir(classes) |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
387 |
.files(findJavaFiles(src_java_base.resolve("java").resolve("lang").resolve("Object.java"))) |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
388 |
.run(Expect.FAIL) |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
389 |
.writeAll() |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
390 |
.getOutputLines(OutputKind.DIRECT); |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
391 |
|
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
392 |
expected = Arrays.asList("X"); |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
393 |
|
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
394 |
if (expected.equals(log)) { |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
395 |
throw new AssertionError("Unexpected output: " + log); |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
396 |
} |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
397 |
} |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
398 |
|
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
399 |
@Test |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
400 |
public void testModuleInfoNameMismatchSource(Path base) throws Exception { |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
401 |
Path src = base.resolve("src"); |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
402 |
Path m1 = src.resolve("m1x"); |
41254
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
403 |
Files.createDirectories(m1); |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
404 |
tb.writeJavaFiles(m1, "module other { }", |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
405 |
"package test; public class Test {}"); |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
406 |
Path classes = base.resolve("classes"); |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
407 |
tb.createDirectories(classes); |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
408 |
|
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
409 |
List<String> log = new JavacTask(tb) |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
410 |
.options("--module-source-path", src.toString(), |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
411 |
"-XDrawDiagnostics") |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
412 |
.outdir(classes) |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
413 |
.files(findJavaFiles(m1.resolve("test").resolve("Test.java"))) |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
414 |
.run(Expect.FAIL) |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
415 |
.writeAll() |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
416 |
.getOutputLines(OutputKind.DIRECT); |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
417 |
|
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
418 |
List<String> expected = Arrays.asList( |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
419 |
"module-info.java:1:1: compiler.err.module.name.mismatch: other, m1x", |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
420 |
"- compiler.err.cant.access: m1x.module-info, (compiler.misc.cant.resolve.modules)", |
41254
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
421 |
"2 errors"); |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
422 |
|
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
423 |
if (!expected.equals(log)) { |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
424 |
throw new AssertionError("Unexpected output: " + log); |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
425 |
} |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
426 |
} |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
427 |
|
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
428 |
@Test |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
429 |
public void testModuleInfoNameMismatchClass(Path base) throws Exception { |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
430 |
Path src = base.resolve("src"); |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
431 |
Files.createDirectories(src); |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
432 |
tb.writeJavaFiles(src, "module other { }", |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
433 |
"package test; public class Test {}"); |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
434 |
Path classes = base.resolve("classes"); |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
435 |
Path m1Classes = classes.resolve("m1x"); |
41254
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
436 |
tb.createDirectories(m1Classes); |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
437 |
|
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
438 |
new JavacTask(tb) |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
439 |
.outdir(m1Classes) |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
440 |
.files(findJavaFiles(src)) |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
441 |
.run() |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
442 |
.writeAll() |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
443 |
.getOutputLines(OutputKind.DIRECT); |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
444 |
|
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
445 |
Path src2 = base.resolve("src2"); |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
446 |
Files.createDirectories(src2); |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
447 |
tb.writeJavaFiles(src2, "module use { requires m1x; }"); |
41254
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
448 |
|
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
449 |
Path classes2 = base.resolve("classes2"); |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
450 |
tb.createDirectories(classes2); |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
451 |
|
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
452 |
List<String> log = new JavacTask(tb) |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
453 |
.options("--module-path", classes.toString(), |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
454 |
"-XDrawDiagnostics") |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
455 |
.outdir(classes2) |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
456 |
.files(findJavaFiles(src2)) |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
457 |
.run(Expect.FAIL) |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
458 |
.writeAll() |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
459 |
.getOutputLines(OutputKind.DIRECT); |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
460 |
|
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
461 |
List<String> expected = Arrays.asList( |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
462 |
"- compiler.err.cant.access: m1x.module-info, (compiler.misc.bad.class.file.header: module-info.class, (compiler.misc.module.name.mismatch: other, m1x))", |
41254
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
463 |
"1 error"); |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
464 |
|
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
465 |
if (!expected.equals(log)) { |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
466 |
throw new AssertionError("Unexpected output: " + log); |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
467 |
} |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
468 |
} |
08f8dbf7741e
8152911: javac assertion error when compiling overlay sources
jlahoda
parents:
40308
diff
changeset
|
469 |
|
41516
0a5838f027a4
8167320: Trying to document only java.base causes a NPE in javac
jlahoda
parents:
41254
diff
changeset
|
470 |
@Test |
0a5838f027a4
8167320: Trying to document only java.base causes a NPE in javac
jlahoda
parents:
41254
diff
changeset
|
471 |
public void testGetDirectivesComplete(Path base) throws Exception { |
0a5838f027a4
8167320: Trying to document only java.base causes a NPE in javac
jlahoda
parents:
41254
diff
changeset
|
472 |
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); |
0a5838f027a4
8167320: Trying to document only java.base causes a NPE in javac
jlahoda
parents:
41254
diff
changeset
|
473 |
JavacTaskImpl task = (JavacTaskImpl) compiler.getTask(null, null, null, null, null, null); |
0a5838f027a4
8167320: Trying to document only java.base causes a NPE in javac
jlahoda
parents:
41254
diff
changeset
|
474 |
Symtab syms = Symtab.instance(task.getContext()); |
0a5838f027a4
8167320: Trying to document only java.base causes a NPE in javac
jlahoda
parents:
41254
diff
changeset
|
475 |
|
0a5838f027a4
8167320: Trying to document only java.base causes a NPE in javac
jlahoda
parents:
41254
diff
changeset
|
476 |
syms.java_base.getDirectives(); |
0a5838f027a4
8167320: Trying to document only java.base causes a NPE in javac
jlahoda
parents:
41254
diff
changeset
|
477 |
} |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41938
diff
changeset
|
478 |
|
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41938
diff
changeset
|
479 |
@Test |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41938
diff
changeset
|
480 |
public void testPackageInModuleInfo(Path base) throws Exception { |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41938
diff
changeset
|
481 |
Path src = base.resolve("src"); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41938
diff
changeset
|
482 |
Files.createDirectories(src); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41938
diff
changeset
|
483 |
tb.writeJavaFiles(src, "package p; module foo { }"); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41938
diff
changeset
|
484 |
Path classes = base.resolve("classes"); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41938
diff
changeset
|
485 |
tb.createDirectories(classes); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41938
diff
changeset
|
486 |
|
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41938
diff
changeset
|
487 |
List<String> log = new JavacTask(tb) |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41938
diff
changeset
|
488 |
.options("-XDrawDiagnostics", "-XDshould-stop.ifError=FLOW") |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41938
diff
changeset
|
489 |
.outdir(classes) |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41938
diff
changeset
|
490 |
.files(findJavaFiles(src)) |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41938
diff
changeset
|
491 |
.run(Expect.FAIL) |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41938
diff
changeset
|
492 |
.writeAll() |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41938
diff
changeset
|
493 |
.getOutputLines(OutputKind.DIRECT); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41938
diff
changeset
|
494 |
|
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41938
diff
changeset
|
495 |
List<String> expected = Arrays.asList( |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41938
diff
changeset
|
496 |
"module-info.java:1:1: compiler.err.no.pkg.in.module-info.java", |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41938
diff
changeset
|
497 |
"1 error"); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41938
diff
changeset
|
498 |
|
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41938
diff
changeset
|
499 |
if (!expected.equals(log)) { |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41938
diff
changeset
|
500 |
throw new AssertionError("Unexpected output: " + log); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41938
diff
changeset
|
501 |
} |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41938
diff
changeset
|
502 |
} |
43269
12f989542165
8171098: NPE when --add-modules java.corba is used
jlahoda
parents:
43138
diff
changeset
|
503 |
|
12f989542165
8171098: NPE when --add-modules java.corba is used
jlahoda
parents:
43138
diff
changeset
|
504 |
@Test |
43272
421ae1e38d2d
8173117: Compilation significantly slower after JDK-8169197
jlahoda
parents:
43271
diff
changeset
|
505 |
public void testInvisibleClassVisiblePackageClash(Path base) throws Exception { |
421ae1e38d2d
8173117: Compilation significantly slower after JDK-8169197
jlahoda
parents:
43271
diff
changeset
|
506 |
Path src = base.resolve("src"); |
421ae1e38d2d
8173117: Compilation significantly slower after JDK-8169197
jlahoda
parents:
43271
diff
changeset
|
507 |
Path src_m1 = src.resolve("m1x"); |
421ae1e38d2d
8173117: Compilation significantly slower after JDK-8169197
jlahoda
parents:
43271
diff
changeset
|
508 |
tb.writeJavaFiles(src_m1, |
421ae1e38d2d
8173117: Compilation significantly slower after JDK-8169197
jlahoda
parents:
43271
diff
changeset
|
509 |
"module m1x { }", |
421ae1e38d2d
8173117: Compilation significantly slower after JDK-8169197
jlahoda
parents:
43271
diff
changeset
|
510 |
"package m1x;\n" + |
421ae1e38d2d
8173117: Compilation significantly slower after JDK-8169197
jlahoda
parents:
43271
diff
changeset
|
511 |
"import m1x.a.*; public class Test { A a; }\n", |
421ae1e38d2d
8173117: Compilation significantly slower after JDK-8169197
jlahoda
parents:
43271
diff
changeset
|
512 |
"package m1x.a;\n" + |
421ae1e38d2d
8173117: Compilation significantly slower after JDK-8169197
jlahoda
parents:
43271
diff
changeset
|
513 |
"public class A { }\n"); |
421ae1e38d2d
8173117: Compilation significantly slower after JDK-8169197
jlahoda
parents:
43271
diff
changeset
|
514 |
Path src_m2 = src.resolve("m2x"); |
421ae1e38d2d
8173117: Compilation significantly slower after JDK-8169197
jlahoda
parents:
43271
diff
changeset
|
515 |
tb.writeJavaFiles(src_m2, |
421ae1e38d2d
8173117: Compilation significantly slower after JDK-8169197
jlahoda
parents:
43271
diff
changeset
|
516 |
"module m2x { }", |
421ae1e38d2d
8173117: Compilation significantly slower after JDK-8169197
jlahoda
parents:
43271
diff
changeset
|
517 |
"package m1x;\n" + |
421ae1e38d2d
8173117: Compilation significantly slower after JDK-8169197
jlahoda
parents:
43271
diff
changeset
|
518 |
"public class a { public static class A { } }\n"); |
421ae1e38d2d
8173117: Compilation significantly slower after JDK-8169197
jlahoda
parents:
43271
diff
changeset
|
519 |
Path classes = base.resolve("classes"); |
421ae1e38d2d
8173117: Compilation significantly slower after JDK-8169197
jlahoda
parents:
43271
diff
changeset
|
520 |
tb.createDirectories(classes); |
421ae1e38d2d
8173117: Compilation significantly slower after JDK-8169197
jlahoda
parents:
43271
diff
changeset
|
521 |
|
421ae1e38d2d
8173117: Compilation significantly slower after JDK-8169197
jlahoda
parents:
43271
diff
changeset
|
522 |
new JavacTask(tb) |
421ae1e38d2d
8173117: Compilation significantly slower after JDK-8169197
jlahoda
parents:
43271
diff
changeset
|
523 |
.options("--module-source-path", src.toString(), |
421ae1e38d2d
8173117: Compilation significantly slower after JDK-8169197
jlahoda
parents:
43271
diff
changeset
|
524 |
"-XDrawDiagnostics") |
421ae1e38d2d
8173117: Compilation significantly slower after JDK-8169197
jlahoda
parents:
43271
diff
changeset
|
525 |
.outdir(classes) |
421ae1e38d2d
8173117: Compilation significantly slower after JDK-8169197
jlahoda
parents:
43271
diff
changeset
|
526 |
.files(findJavaFiles(src)) |
421ae1e38d2d
8173117: Compilation significantly slower after JDK-8169197
jlahoda
parents:
43271
diff
changeset
|
527 |
.run() |
421ae1e38d2d
8173117: Compilation significantly slower after JDK-8169197
jlahoda
parents:
43271
diff
changeset
|
528 |
.writeAll(); |
421ae1e38d2d
8173117: Compilation significantly slower after JDK-8169197
jlahoda
parents:
43271
diff
changeset
|
529 |
} |
421ae1e38d2d
8173117: Compilation significantly slower after JDK-8169197
jlahoda
parents:
43271
diff
changeset
|
530 |
|
421ae1e38d2d
8173117: Compilation significantly slower after JDK-8169197
jlahoda
parents:
43271
diff
changeset
|
531 |
@Test |
43271
ce89609dde7c
8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents:
43269
diff
changeset
|
532 |
public void testStripUnknownRequired(Path base) throws Exception { |
ce89609dde7c
8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents:
43269
diff
changeset
|
533 |
Path src = base.resolve("src"); |
ce89609dde7c
8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents:
43269
diff
changeset
|
534 |
Path src_m1 = src.resolve("m1x"); |
ce89609dde7c
8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents:
43269
diff
changeset
|
535 |
tb.writeJavaFiles(src_m1, |
ce89609dde7c
8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents:
43269
diff
changeset
|
536 |
"module m1x { }"); |
ce89609dde7c
8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents:
43269
diff
changeset
|
537 |
Path src_m2 = src.resolve("m2x"); |
ce89609dde7c
8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents:
43269
diff
changeset
|
538 |
tb.writeJavaFiles(src_m2, |
ce89609dde7c
8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents:
43269
diff
changeset
|
539 |
"module m2x { }"); |
ce89609dde7c
8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents:
43269
diff
changeset
|
540 |
Path src_m3 = src.resolve("m3x"); |
ce89609dde7c
8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents:
43269
diff
changeset
|
541 |
tb.writeJavaFiles(src_m3, |
ce89609dde7c
8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents:
43269
diff
changeset
|
542 |
"module m3x { }"); |
ce89609dde7c
8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents:
43269
diff
changeset
|
543 |
Path src_m4 = src.resolve("m4x"); |
ce89609dde7c
8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents:
43269
diff
changeset
|
544 |
tb.writeJavaFiles(src_m4, |
ce89609dde7c
8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents:
43269
diff
changeset
|
545 |
"module m4x { }"); |
ce89609dde7c
8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents:
43269
diff
changeset
|
546 |
Path src_test = src.resolve("test"); |
ce89609dde7c
8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents:
43269
diff
changeset
|
547 |
tb.writeJavaFiles(src_test, |
ce89609dde7c
8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents:
43269
diff
changeset
|
548 |
"module test { requires m1x; requires m2x; requires java.base; requires m3x; requires m4x; }"); |
ce89609dde7c
8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents:
43269
diff
changeset
|
549 |
Path src_compile = src.resolve("compile"); |
ce89609dde7c
8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents:
43269
diff
changeset
|
550 |
tb.writeJavaFiles(src_compile, |
ce89609dde7c
8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents:
43269
diff
changeset
|
551 |
"module compile { exports p to test; }", |
ce89609dde7c
8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents:
43269
diff
changeset
|
552 |
"package p; public class Test { }"); |
ce89609dde7c
8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents:
43269
diff
changeset
|
553 |
Path classes = base.resolve("classes"); |
ce89609dde7c
8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents:
43269
diff
changeset
|
554 |
tb.createDirectories(classes); |
ce89609dde7c
8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents:
43269
diff
changeset
|
555 |
|
ce89609dde7c
8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents:
43269
diff
changeset
|
556 |
List<String> log = new JavacTask(tb) |
ce89609dde7c
8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents:
43269
diff
changeset
|
557 |
.options("-processor", ListRequires.class.getName(), |
ce89609dde7c
8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents:
43269
diff
changeset
|
558 |
"--module-source-path", src.toString(), |
ce89609dde7c
8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents:
43269
diff
changeset
|
559 |
"--limit-modules", "compile", |
ce89609dde7c
8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents:
43269
diff
changeset
|
560 |
"-XDaccessInternalAPI=true") |
ce89609dde7c
8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents:
43269
diff
changeset
|
561 |
.outdir(classes) |
ce89609dde7c
8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents:
43269
diff
changeset
|
562 |
.files(findJavaFiles(src_compile)) |
ce89609dde7c
8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents:
43269
diff
changeset
|
563 |
.run(Expect.FAIL) |
ce89609dde7c
8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents:
43269
diff
changeset
|
564 |
.writeAll() |
ce89609dde7c
8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents:
43269
diff
changeset
|
565 |
.getOutputLines(Task.OutputKind.STDOUT); |
ce89609dde7c
8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents:
43269
diff
changeset
|
566 |
|
ce89609dde7c
8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents:
43269
diff
changeset
|
567 |
List<String> expected = Arrays.asList( |
ce89609dde7c
8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents:
43269
diff
changeset
|
568 |
"from directives:", |
ce89609dde7c
8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents:
43269
diff
changeset
|
569 |
"java.base", |
ce89609dde7c
8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents:
43269
diff
changeset
|
570 |
"from requires:", |
ce89609dde7c
8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents:
43269
diff
changeset
|
571 |
"java.base" |
ce89609dde7c
8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents:
43269
diff
changeset
|
572 |
); |
ce89609dde7c
8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents:
43269
diff
changeset
|
573 |
if (!Objects.equals(log, expected)) |
ce89609dde7c
8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents:
43269
diff
changeset
|
574 |
throw new AssertionError("Unexpected output: " + log); |
ce89609dde7c
8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents:
43269
diff
changeset
|
575 |
} |
ce89609dde7c
8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents:
43269
diff
changeset
|
576 |
|
ce89609dde7c
8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents:
43269
diff
changeset
|
577 |
@SupportedAnnotationTypes("*") |
ce89609dde7c
8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents:
43269
diff
changeset
|
578 |
@SupportedOptions("expectedEnclosedElements") |
ce89609dde7c
8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents:
43269
diff
changeset
|
579 |
public static final class ListRequires extends AbstractProcessor { |
ce89609dde7c
8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents:
43269
diff
changeset
|
580 |
|
ce89609dde7c
8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents:
43269
diff
changeset
|
581 |
private int round; |
ce89609dde7c
8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents:
43269
diff
changeset
|
582 |
|
ce89609dde7c
8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents:
43269
diff
changeset
|
583 |
@Override |
ce89609dde7c
8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents:
43269
diff
changeset
|
584 |
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { |
ce89609dde7c
8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents:
43269
diff
changeset
|
585 |
if (round++ == 0) { |
ce89609dde7c
8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents:
43269
diff
changeset
|
586 |
ModuleElement compileE = processingEnv.getElementUtils().getModuleElement("compile"); |
ce89609dde7c
8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents:
43269
diff
changeset
|
587 |
ModuleElement testE = ElementFilter.exportsIn(compileE.getDirectives()).get(0).getTargetModules().get(0); |
ce89609dde7c
8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents:
43269
diff
changeset
|
588 |
|
ce89609dde7c
8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents:
43269
diff
changeset
|
589 |
System.out.println("from directives:"); |
ce89609dde7c
8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents:
43269
diff
changeset
|
590 |
for (RequiresDirective rd : ElementFilter.requiresIn(testE.getDirectives())) { |
ce89609dde7c
8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents:
43269
diff
changeset
|
591 |
System.out.println(rd.getDependency().getSimpleName()); |
ce89609dde7c
8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents:
43269
diff
changeset
|
592 |
} |
ce89609dde7c
8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents:
43269
diff
changeset
|
593 |
|
ce89609dde7c
8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents:
43269
diff
changeset
|
594 |
System.out.println("from requires:"); |
ce89609dde7c
8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents:
43269
diff
changeset
|
595 |
for (RequiresDirective rd : ((ModuleSymbol) testE).requires) { |
ce89609dde7c
8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents:
43269
diff
changeset
|
596 |
System.out.println(rd.getDependency().getSimpleName()); |
ce89609dde7c
8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents:
43269
diff
changeset
|
597 |
} |
ce89609dde7c
8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents:
43269
diff
changeset
|
598 |
} |
ce89609dde7c
8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents:
43269
diff
changeset
|
599 |
|
ce89609dde7c
8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents:
43269
diff
changeset
|
600 |
return false; |
ce89609dde7c
8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents:
43269
diff
changeset
|
601 |
} |
ce89609dde7c
8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents:
43269
diff
changeset
|
602 |
|
ce89609dde7c
8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents:
43269
diff
changeset
|
603 |
@Override |
ce89609dde7c
8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents:
43269
diff
changeset
|
604 |
public SourceVersion getSupportedSourceVersion() { |
ce89609dde7c
8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents:
43269
diff
changeset
|
605 |
return SourceVersion.latest(); |
ce89609dde7c
8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents:
43269
diff
changeset
|
606 |
} |
ce89609dde7c
8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents:
43269
diff
changeset
|
607 |
|
ce89609dde7c
8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents:
43269
diff
changeset
|
608 |
} |
ce89609dde7c
8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents:
43269
diff
changeset
|
609 |
|
ce89609dde7c
8172809: Error compiling javafx modules after fix for JDK-8169197
jlahoda
parents:
43269
diff
changeset
|
610 |
@Test |
43269
12f989542165
8171098: NPE when --add-modules java.corba is used
jlahoda
parents:
43138
diff
changeset
|
611 |
public void testOnDemandCompletionModuleInfoJava(Path base) throws Exception { |
12f989542165
8171098: NPE when --add-modules java.corba is used
jlahoda
parents:
43138
diff
changeset
|
612 |
Path src = base.resolve("src"); |
12f989542165
8171098: NPE when --add-modules java.corba is used
jlahoda
parents:
43138
diff
changeset
|
613 |
Path src_m1 = src.resolve("m1x"); |
12f989542165
8171098: NPE when --add-modules java.corba is used
jlahoda
parents:
43138
diff
changeset
|
614 |
tb.writeJavaFiles(src_m1, |
12f989542165
8171098: NPE when --add-modules java.corba is used
jlahoda
parents:
43138
diff
changeset
|
615 |
"@Deprecated module m1x { }"); |
12f989542165
8171098: NPE when --add-modules java.corba is used
jlahoda
parents:
43138
diff
changeset
|
616 |
Path src_m2 = src.resolve("m2x"); |
12f989542165
8171098: NPE when --add-modules java.corba is used
jlahoda
parents:
43138
diff
changeset
|
617 |
tb.writeJavaFiles(src_m2, |
12f989542165
8171098: NPE when --add-modules java.corba is used
jlahoda
parents:
43138
diff
changeset
|
618 |
"module m2x { requires m1x; }"); |
12f989542165
8171098: NPE when --add-modules java.corba is used
jlahoda
parents:
43138
diff
changeset
|
619 |
Path src_m3 = src.resolve("m3x"); |
12f989542165
8171098: NPE when --add-modules java.corba is used
jlahoda
parents:
43138
diff
changeset
|
620 |
tb.writeJavaFiles(src_m3, |
12f989542165
8171098: NPE when --add-modules java.corba is used
jlahoda
parents:
43138
diff
changeset
|
621 |
"module m3x { requires m2x; requires m1x; }"); |
12f989542165
8171098: NPE when --add-modules java.corba is used
jlahoda
parents:
43138
diff
changeset
|
622 |
Path classes = base.resolve("classes"); |
12f989542165
8171098: NPE when --add-modules java.corba is used
jlahoda
parents:
43138
diff
changeset
|
623 |
tb.createDirectories(classes); |
12f989542165
8171098: NPE when --add-modules java.corba is used
jlahoda
parents:
43138
diff
changeset
|
624 |
|
12f989542165
8171098: NPE when --add-modules java.corba is used
jlahoda
parents:
43138
diff
changeset
|
625 |
List<String> log; |
12f989542165
8171098: NPE when --add-modules java.corba is used
jlahoda
parents:
43138
diff
changeset
|
626 |
List<String> expected; |
12f989542165
8171098: NPE when --add-modules java.corba is used
jlahoda
parents:
43138
diff
changeset
|
627 |
|
12f989542165
8171098: NPE when --add-modules java.corba is used
jlahoda
parents:
43138
diff
changeset
|
628 |
log = new JavacTask(tb) |
12f989542165
8171098: NPE when --add-modules java.corba is used
jlahoda
parents:
43138
diff
changeset
|
629 |
.options("--module-source-path", src.toString()) |
12f989542165
8171098: NPE when --add-modules java.corba is used
jlahoda
parents:
43138
diff
changeset
|
630 |
.outdir(classes) |
12f989542165
8171098: NPE when --add-modules java.corba is used
jlahoda
parents:
43138
diff
changeset
|
631 |
.files(findJavaFiles(src_m1)) |
12f989542165
8171098: NPE when --add-modules java.corba is used
jlahoda
parents:
43138
diff
changeset
|
632 |
.run() |
12f989542165
8171098: NPE when --add-modules java.corba is used
jlahoda
parents:
43138
diff
changeset
|
633 |
.writeAll() |
12f989542165
8171098: NPE when --add-modules java.corba is used
jlahoda
parents:
43138
diff
changeset
|
634 |
.getOutputLines(Task.OutputKind.DIRECT); |
12f989542165
8171098: NPE when --add-modules java.corba is used
jlahoda
parents:
43138
diff
changeset
|
635 |
|
12f989542165
8171098: NPE when --add-modules java.corba is used
jlahoda
parents:
43138
diff
changeset
|
636 |
expected = Arrays.asList(""); |
12f989542165
8171098: NPE when --add-modules java.corba is used
jlahoda
parents:
43138
diff
changeset
|
637 |
|
12f989542165
8171098: NPE when --add-modules java.corba is used
jlahoda
parents:
43138
diff
changeset
|
638 |
if (!expected.equals(log)) { |
12f989542165
8171098: NPE when --add-modules java.corba is used
jlahoda
parents:
43138
diff
changeset
|
639 |
throw new IllegalStateException(log.toString()); |
12f989542165
8171098: NPE when --add-modules java.corba is used
jlahoda
parents:
43138
diff
changeset
|
640 |
} |
12f989542165
8171098: NPE when --add-modules java.corba is used
jlahoda
parents:
43138
diff
changeset
|
641 |
|
12f989542165
8171098: NPE when --add-modules java.corba is used
jlahoda
parents:
43138
diff
changeset
|
642 |
log = new JavacTask(tb) |
12f989542165
8171098: NPE when --add-modules java.corba is used
jlahoda
parents:
43138
diff
changeset
|
643 |
.options("--module-source-path", src.toString(), |
12f989542165
8171098: NPE when --add-modules java.corba is used
jlahoda
parents:
43138
diff
changeset
|
644 |
"-XDrawDiagnostics", |
12f989542165
8171098: NPE when --add-modules java.corba is used
jlahoda
parents:
43138
diff
changeset
|
645 |
"-Xlint:deprecation") |
12f989542165
8171098: NPE when --add-modules java.corba is used
jlahoda
parents:
43138
diff
changeset
|
646 |
.outdir(classes) |
12f989542165
8171098: NPE when --add-modules java.corba is used
jlahoda
parents:
43138
diff
changeset
|
647 |
.files(findJavaFiles(src_m3)) |
12f989542165
8171098: NPE when --add-modules java.corba is used
jlahoda
parents:
43138
diff
changeset
|
648 |
.run() |
12f989542165
8171098: NPE when --add-modules java.corba is used
jlahoda
parents:
43138
diff
changeset
|
649 |
.writeAll() |
12f989542165
8171098: NPE when --add-modules java.corba is used
jlahoda
parents:
43138
diff
changeset
|
650 |
.getOutputLines(Task.OutputKind.DIRECT); |
12f989542165
8171098: NPE when --add-modules java.corba is used
jlahoda
parents:
43138
diff
changeset
|
651 |
|
12f989542165
8171098: NPE when --add-modules java.corba is used
jlahoda
parents:
43138
diff
changeset
|
652 |
expected = Arrays.asList( |
12f989542165
8171098: NPE when --add-modules java.corba is used
jlahoda
parents:
43138
diff
changeset
|
653 |
"module-info.java:1:23: compiler.warn.has.been.deprecated.module: m1x", |
12f989542165
8171098: NPE when --add-modules java.corba is used
jlahoda
parents:
43138
diff
changeset
|
654 |
"module-info.java:1:37: compiler.warn.has.been.deprecated.module: m1x", |
12f989542165
8171098: NPE when --add-modules java.corba is used
jlahoda
parents:
43138
diff
changeset
|
655 |
"2 warnings" |
12f989542165
8171098: NPE when --add-modules java.corba is used
jlahoda
parents:
43138
diff
changeset
|
656 |
); |
12f989542165
8171098: NPE when --add-modules java.corba is used
jlahoda
parents:
43138
diff
changeset
|
657 |
|
12f989542165
8171098: NPE when --add-modules java.corba is used
jlahoda
parents:
43138
diff
changeset
|
658 |
if (!expected.equals(log)) { |
12f989542165
8171098: NPE when --add-modules java.corba is used
jlahoda
parents:
43138
diff
changeset
|
659 |
throw new IllegalStateException(log.toString()); |
12f989542165
8171098: NPE when --add-modules java.corba is used
jlahoda
parents:
43138
diff
changeset
|
660 |
} |
12f989542165
8171098: NPE when --add-modules java.corba is used
jlahoda
parents:
43138
diff
changeset
|
661 |
} |
12f989542165
8171098: NPE when --add-modules java.corba is used
jlahoda
parents:
43138
diff
changeset
|
662 |
|
43369
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
663 |
@Test |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
664 |
public void testUnnamedPackage(Path base) throws Exception { |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
665 |
List<String> out; |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
666 |
List<String> expected; |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
667 |
|
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
668 |
//-source 8: |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
669 |
Path src8 = base.resolve("src8"); |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
670 |
Files.createDirectories(src8); |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
671 |
tb.writeJavaFiles(src8, |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
672 |
"package test; public class Test {}"); |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
673 |
Path classes = base.resolve("classes"); |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
674 |
tb.createDirectories(classes); |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
675 |
|
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
676 |
out = new JavacTask(tb) |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
677 |
.options("--source-path", src8.toString(), |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
678 |
"-processor", UnnamedPackageProcessor.class.getName(), |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
679 |
"-source", "8") |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
680 |
.outdir(classes) |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
681 |
.files(findJavaFiles(src8)) |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
682 |
.run() |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
683 |
.writeAll() |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
684 |
.getOutputLines(OutputKind.STDOUT); |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
685 |
|
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
686 |
expected = Arrays.asList("noModule"); |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
687 |
|
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
688 |
if (!expected.equals(out)) { |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
689 |
throw new AssertionError("Unexpected output: " + out); |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
690 |
} |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
691 |
|
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
692 |
//-source 9, unnamed: |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
693 |
Path srcUnnamed = base.resolve("srcUnnamed"); |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
694 |
Files.createDirectories(srcUnnamed); |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
695 |
tb.writeJavaFiles(srcUnnamed, |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
696 |
"public class Test {}"); |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
697 |
Path classesUnnamed = base.resolve("classesUnnamed"); |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
698 |
tb.createDirectories(classesUnnamed); |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
699 |
|
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
700 |
out = new JavacTask(tb) |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
701 |
.options("--source-path", srcUnnamed.toString(), |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
702 |
"-processor", UnnamedPackageProcessor.class.getName()) |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
703 |
.outdir(classesUnnamed) |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
704 |
.files(findJavaFiles(srcUnnamed)) |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
705 |
.run() |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
706 |
.writeAll() |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
707 |
.getOutputLines(OutputKind.STDOUT); |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
708 |
|
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
709 |
expected = Arrays.asList("unnamedModule"); |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
710 |
|
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
711 |
if (!expected.equals(out)) { |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
712 |
throw new AssertionError("Unexpected output: " + out); |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
713 |
} |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
714 |
|
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
715 |
//-source 9, named: |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
716 |
Path srcNamed = base.resolve("srcNamed"); |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
717 |
Files.createDirectories(srcNamed); |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
718 |
tb.writeJavaFiles(srcNamed, |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
719 |
"module m {}", |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
720 |
"public class Test {}"); |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
721 |
Path classesNamed = base.resolve("classesNamed"); |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
722 |
tb.createDirectories(classesNamed); |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
723 |
|
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
724 |
out = new JavacTask(tb) |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
725 |
.options("--source-path", srcNamed.toString(), |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
726 |
"-classpath", "", |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
727 |
"-processorpath", System.getProperty("test.class.path"), |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
728 |
"-processor", UnnamedPackageProcessor.class.getName()) |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
729 |
.outdir(classesNamed) |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
730 |
.files(findJavaFiles(srcNamed)) |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
731 |
.run() |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
732 |
.writeAll() |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
733 |
.getOutputLines(OutputKind.STDOUT); |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
734 |
|
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
735 |
expected = Arrays.asList("m"); |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
736 |
|
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
737 |
if (!expected.equals(out)) { |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
738 |
throw new AssertionError("Unexpected output: " + out); |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
739 |
} |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
740 |
|
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
741 |
//-source 9, conflict: |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
742 |
Path srcNamed2 = base.resolve("srcNamed2"); |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
743 |
Path srcNamed2m1 = srcNamed2.resolve("m1x"); |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
744 |
Files.createDirectories(srcNamed2m1); |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
745 |
tb.writeJavaFiles(srcNamed2m1, |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
746 |
"module m1x {}", |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
747 |
"public class Test {}"); |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
748 |
Path srcNamed2m2 = srcNamed2.resolve("m2x"); |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
749 |
Files.createDirectories(srcNamed2m2); |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
750 |
tb.writeJavaFiles(srcNamed2m2, |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
751 |
"module m2x {}", |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
752 |
"public class Test {}"); |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
753 |
Path classesNamed2 = base.resolve("classesNamed2"); |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
754 |
tb.createDirectories(classesNamed2); |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
755 |
|
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
756 |
out = new JavacTask(tb) |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
757 |
.options("--module-source-path", srcNamed2.toString(), |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
758 |
"-classpath", "", |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
759 |
"-processorpath", System.getProperty("test.class.path"), |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
760 |
"-processor", UnnamedPackageProcessor.class.getName(), |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
761 |
"-XDshould-stop.ifError=FLOW") |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
762 |
.outdir(classesNamed2) |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
763 |
.files(findJavaFiles(srcNamed2)) |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
764 |
.run(Expect.FAIL) |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
765 |
.writeAll() |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
766 |
.getOutputLines(OutputKind.STDOUT); |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
767 |
|
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
768 |
expected = Arrays.asList("null", |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
769 |
"m1x: true", |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
770 |
"m2x: true"); |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
771 |
|
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
772 |
if (!expected.equals(out)) { |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
773 |
throw new AssertionError("Unexpected output: " + out); |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
774 |
} |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
775 |
} |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
776 |
|
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
777 |
@SupportedAnnotationTypes("*") |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
778 |
public static final class UnnamedPackageProcessor extends AbstractProcessor { |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
779 |
|
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
780 |
int round = 0; |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
781 |
|
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
782 |
@Override |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
783 |
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
784 |
if (round++ != 0) |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
785 |
return false; |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
786 |
|
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
787 |
Elements elements = processingEnv.getElementUtils(); |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
788 |
PackageElement pe = elements.getPackageElement(""); |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
789 |
|
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
790 |
if (pe == null) { |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
791 |
System.out.println("null"); |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
792 |
} else { |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
793 |
ModuleElement mod = (ModuleElement) pe.getEnclosingElement(); |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
794 |
if (mod == null) { |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
795 |
System.out.println("noModule"); |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
796 |
} else if (mod.isUnnamed()) { |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
797 |
System.out.println("unnamedModule"); |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
798 |
} else { |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
799 |
System.out.println(mod); |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
800 |
} |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
801 |
} |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
802 |
|
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
803 |
ModuleElement m1x = elements.getModuleElement("m1x"); |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
804 |
ModuleElement m2x = elements.getModuleElement("m2x"); |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
805 |
|
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
806 |
if (m1x != null && m2x != null) { |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
807 |
System.out.println("m1x: " + (elements.getPackageElement(m1x, "") != null)); |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
808 |
System.out.println("m2x: " + (elements.getPackageElement(m2x, "") != null)); |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
809 |
} |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
810 |
|
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
811 |
return false; |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
812 |
} |
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
813 |
|
aafd33c96bac
8173068: ElementUtils getPackageElement does not allow for an unnamed package
jlahoda
parents:
43272
diff
changeset
|
814 |
} |
36526 | 815 |
} |