author | sadayapalam |
Mon, 06 Feb 2017 18:14:51 +0530 | |
changeset 43584 | 63e67712246b |
parent 42822 | a84956e7ee4d |
child 43756 | 118221d3960d |
permissions | -rw-r--r-- |
36526 | 1 |
/* |
2 |
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. |
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
22 |
*/ |
|
23 |
||
24 |
/* |
|
25 |
* @test |
|
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
26 |
* @bug 8158123 8161906 8162713 |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
27 |
* @summary tests for module declarations |
36526 | 28 |
* @library /tools/lib |
29 |
* @modules |
|
30 |
* jdk.compiler/com.sun.tools.javac.api |
|
31 |
* jdk.compiler/com.sun.tools.javac.main |
|
32 |
* jdk.jdeps/com.sun.tools.javap |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
33 |
* @build toolbox.ToolBox toolbox.JavacTask ModuleTestBase |
36526 | 34 |
* @run main ModuleInfoTest |
35 |
*/ |
|
36 |
||
37 |
import java.nio.file.Files; |
|
38 |
import java.nio.file.Path; |
|
38916
d118cb2cffab
8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents:
37758
diff
changeset
|
39 |
import java.util.Arrays; |
36526 | 40 |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
41 |
import toolbox.JavacTask; |
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
42 |
import toolbox.Task; |
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
43 |
|
36526 | 44 |
public class ModuleInfoTest extends ModuleTestBase { |
45 |
||
46 |
public static void main(String... args) throws Exception { |
|
47 |
ModuleInfoTest t = new ModuleInfoTest(); |
|
48 |
t.runTests(); |
|
49 |
} |
|
50 |
||
51 |
/** |
|
52 |
* Check error message if module declaration not in module-info.java. |
|
53 |
*/ |
|
54 |
@Test |
|
37758 | 55 |
public void testModuleDeclNotInModuleJava(Path base) throws Exception { |
36526 | 56 |
Path src = base.resolve("src"); |
57 |
tb.writeFile(src.resolve("M.java"), "module M { }"); |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
58 |
String log = new JavacTask(tb) |
36526 | 59 |
.options("-XDrawDiagnostics") |
60 |
.files(findJavaFiles(src)) |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
61 |
.run(Task.Expect.FAIL) |
36526 | 62 |
.writeAll() |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
63 |
.getOutput(Task.OutputKind.DIRECT); |
36526 | 64 |
|
65 |
if (!log.contains("M.java:1:1: compiler.err.module.decl.sb.in.module-info.java")) |
|
66 |
throw new Exception("expected output not found"); |
|
67 |
} |
|
68 |
||
69 |
/** |
|
70 |
* Verify that a package private class can be put in module-info.java. |
|
71 |
*/ |
|
72 |
@Test |
|
37758 | 73 |
public void testNotModuleDeclInModuleJava_1(Path base) throws Exception { |
36526 | 74 |
Path src = base.resolve("src"); |
75 |
tb.writeFile(src.resolve("module-info.java"), "class C { }"); |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
76 |
new JavacTask(tb) |
36526 | 77 |
.options("-XDrawDiagnostics") |
78 |
.files(findJavaFiles(src)) |
|
79 |
.run() |
|
80 |
.writeAll(); |
|
81 |
} |
|
82 |
||
83 |
/** |
|
84 |
* Verify that a public class cannot be put in module-info.java. |
|
85 |
*/ |
|
86 |
@Test |
|
37758 | 87 |
public void testNotModuleDeclInModuleJava_2(Path base) throws Exception { |
36526 | 88 |
Path src = base.resolve("src"); |
89 |
tb.writeFile(src.resolve("module-info.java"), "public class C { }"); |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
90 |
String log = new JavacTask(tb) |
36526 | 91 |
.options("-XDrawDiagnostics") |
92 |
.files(findJavaFiles(src)) |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
93 |
.run(Task.Expect.FAIL) |
36526 | 94 |
.writeAll() |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
95 |
.getOutput(Task.OutputKind.DIRECT); |
36526 | 96 |
|
97 |
if (!log.contains("module-info.java:1:8: compiler.err.class.public.should.be.in.file: C")) |
|
98 |
throw new Exception("expected output not found"); |
|
99 |
} |
|
100 |
||
101 |
/** |
|
102 |
* Verify that only one module decl can be put in module-info.java. |
|
103 |
*/ |
|
104 |
@Test |
|
37758 | 105 |
public void testSingleModuleDecl(Path base) throws Exception { |
36526 | 106 |
Path src = base.resolve("src"); |
107 |
tb.writeJavaFiles(src, "module M1 { } /*...*/ module M2 { }"); |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
108 |
String log = new JavacTask(tb) |
36526 | 109 |
.options("-XDrawDiagnostics") |
110 |
.files(findJavaFiles(src)) |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
111 |
.run(Task.Expect.FAIL) |
36526 | 112 |
.writeAll() |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
113 |
.getOutput(Task.OutputKind.DIRECT); |
36526 | 114 |
|
115 |
if (!log.contains("module-info.java:1:14: compiler.err.expected: token.end-of-input")) |
|
116 |
throw new Exception("expected output not found"); |
|
117 |
} |
|
118 |
||
119 |
/** |
|
120 |
* Verify that missing requires are reported. |
|
121 |
*/ |
|
122 |
@Test |
|
37758 | 123 |
public void testRequiresNotFound(Path base) throws Exception { |
36526 | 124 |
Path src = base.resolve("src"); |
125 |
tb.writeJavaFiles(src, "module M1 { requires M2; }"); |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
126 |
String log = new JavacTask(tb) |
36526 | 127 |
.options("-XDrawDiagnostics") |
128 |
.files(findJavaFiles(src)) |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
129 |
.run(Task.Expect.FAIL) |
36526 | 130 |
.writeAll() |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
131 |
.getOutput(Task.OutputKind.DIRECT); |
36526 | 132 |
|
133 |
if (!log.contains("module-info.java:1:22: compiler.err.module.not.found: M2")) |
|
134 |
throw new Exception("expected output not found"); |
|
135 |
} |
|
136 |
||
137 |
/** |
|
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
138 |
* Verify that missing exports targets are reported. |
36526 | 139 |
*/ |
140 |
@Test |
|
37758 | 141 |
public void testExportsNotFound(Path base) throws Exception { |
36526 | 142 |
Path src = base.resolve("src"); |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
143 |
tb.writeJavaFiles(src, |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
144 |
"module M { exports p to N; }", |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
145 |
"package p; public class C {}"); |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
146 |
String log = new JavacTask(tb) |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
147 |
.options("-XDrawDiagnostics", |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
148 |
"-Xlint:module") |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
149 |
.files(findJavaFiles(src)) |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
150 |
.run() |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
151 |
.writeAll() |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
152 |
.getOutput(Task.OutputKind.DIRECT); |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
153 |
|
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
154 |
if (!log.contains("module-info.java:1:25: compiler.warn.module.not.found: N")) |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
155 |
throw new Exception("expected output not found, actual output: " + log); |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
156 |
} |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
157 |
|
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
158 |
/** |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
159 |
* Verify that duplicated qualified missing exports targets are reported. |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
160 |
*/ |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
161 |
@Test |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
162 |
public void testExportsNotFoundDuplicated(Path base) throws Exception { |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
163 |
Path src = base.resolve("src"); |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
164 |
tb.writeJavaFiles(src, |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
165 |
"module M { exports p to N, N; }", |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
166 |
"package p; public class C {}"); |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
167 |
String log = new JavacTask(tb) |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
168 |
.options("-XDrawDiagnostics", |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
169 |
"-Xlint:module") |
36526 | 170 |
.files(findJavaFiles(src)) |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
171 |
.run(Task.Expect.FAIL) |
36526 | 172 |
.writeAll() |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
173 |
.getOutput(Task.OutputKind.DIRECT); |
36526 | 174 |
|
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
175 |
if (!log.contains("module-info.java:1:28: compiler.err.conflicting.exports.to.module: N")) |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
176 |
throw new Exception("expected output not found, actual output: " + log); |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
177 |
} |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
178 |
|
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
179 |
/** |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
180 |
* Verify that missing exports target warning can be suppressed. |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
181 |
*/ |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
182 |
@Test |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
183 |
public void testExportsNotFoundSuppress(Path base) throws Exception { |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
184 |
Path src = base.resolve("src"); |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
185 |
tb.writeJavaFiles(src, |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
186 |
"@SuppressWarnings(\"module\") module M { exports p to N; }", |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
187 |
"package p; public class C {}"); |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
188 |
String log = new JavacTask(tb) |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
189 |
.options("-XDrawDiagnostics", |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
190 |
"-Xlint:module") |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
191 |
.files(findJavaFiles(src)) |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
192 |
.run() |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
193 |
.writeAll() |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
194 |
.getOutput(Task.OutputKind.DIRECT); |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
195 |
|
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
196 |
if (!log.isEmpty()) |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
197 |
throw new Exception("expected output not found, actual output: " + log); |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
198 |
} |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
199 |
|
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
200 |
/** |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
201 |
* Verify that missing opens targets are reported. |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
202 |
*/ |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
203 |
@Test |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
204 |
public void testOpensNotFound(Path base) throws Exception { |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
205 |
Path src = base.resolve("src"); |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
206 |
tb.writeJavaFiles(src, |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
207 |
"module M { opens p to N; }", |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
208 |
"package p; public class C {}"); |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
209 |
String log = new JavacTask(tb) |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
210 |
.options("-XDrawDiagnostics", |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
211 |
"-Xlint:module") |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
212 |
.files(findJavaFiles(src)) |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
213 |
.run() |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
214 |
.writeAll() |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
215 |
.getOutput(Task.OutputKind.DIRECT); |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
216 |
|
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
217 |
if (!log.contains("module-info.java:1:23: compiler.warn.module.not.found: N")) |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
218 |
throw new Exception("expected output not found, actual output: " + log); |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
219 |
} |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
220 |
|
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
221 |
/** |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
222 |
* Verify that duplicated qualified missing opens targets are reported. |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
223 |
*/ |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
224 |
@Test |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
225 |
public void testOpensNotFoundDuplicated(Path base) throws Exception { |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
226 |
Path src = base.resolve("src"); |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
227 |
tb.writeJavaFiles(src, |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
228 |
"module M { opens p to N, N; }", |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
229 |
"package p; public class C {}"); |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
230 |
String log = new JavacTask(tb) |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
231 |
.options("-XDrawDiagnostics", |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
232 |
"-Xlint:module") |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
233 |
.files(findJavaFiles(src)) |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
234 |
.run(Task.Expect.FAIL) |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
235 |
.writeAll() |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
236 |
.getOutput(Task.OutputKind.DIRECT); |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
237 |
|
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
238 |
if (!log.contains("module-info.java:1:26: compiler.err.conflicting.opens.to.module: N")) |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
239 |
throw new Exception("expected output not found, actual output: " + log); |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
240 |
} |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
241 |
|
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
242 |
/** |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
243 |
* Verify that missing opens target warning can be suppressed. |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
244 |
*/ |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
245 |
@Test |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
246 |
public void testOpensNotFoundSuppress(Path base) throws Exception { |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
247 |
Path src = base.resolve("src"); |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
248 |
tb.writeJavaFiles(src, |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
249 |
"@SuppressWarnings(\"module\") module M { opens p to N; }", |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
250 |
"package p; public class C {}"); |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
251 |
String log = new JavacTask(tb) |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
252 |
.options("-XDrawDiagnostics", |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
253 |
"-Xlint:module") |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
254 |
.files(findJavaFiles(src)) |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
255 |
.run() |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
256 |
.writeAll() |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
257 |
.getOutput(Task.OutputKind.DIRECT); |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
258 |
|
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
259 |
if (!log.isEmpty()) |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
260 |
throw new Exception("expected output not found, actual output: " + log); |
36526 | 261 |
} |
262 |
||
263 |
/** |
|
264 |
* Verify that a simple loop is detected. |
|
265 |
*/ |
|
266 |
@Test |
|
37758 | 267 |
public void testRequiresSelf(Path base) throws Exception { |
36526 | 268 |
Path src = base.resolve("src"); |
269 |
tb.writeJavaFiles(src, "module M { requires M; }"); |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
270 |
String log = new JavacTask(tb) |
36526 | 271 |
.options("-XDrawDiagnostics") |
272 |
.files(findJavaFiles(src)) |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
273 |
.run(Task.Expect.FAIL) |
36526 | 274 |
.writeAll() |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
275 |
.getOutput(Task.OutputKind.DIRECT); |
36526 | 276 |
|
277 |
if (!log.contains("module-info.java:1:21: compiler.err.cyclic.requires: M")) |
|
278 |
throw new Exception("expected output not found"); |
|
279 |
} |
|
280 |
||
281 |
/** |
|
282 |
* Verify that a multi-module loop is detected. |
|
283 |
*/ |
|
284 |
@Test |
|
37758 | 285 |
public void testRequiresLoop(Path base) throws Exception { |
36526 | 286 |
Path src = base.resolve("src"); |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
287 |
Path src_m1 = src.resolve("m1x"); |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
288 |
tb.writeFile(src_m1.resolve("module-info.java"), "module m1x { requires m2x; }"); |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
289 |
Path src_m2 = src.resolve("m2x"); |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
290 |
tb.writeFile(src_m2.resolve("module-info.java"), "module m2x { requires m3x; }"); |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
291 |
Path src_m3 = src.resolve("m3x"); |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
292 |
tb.writeFile(src_m3.resolve("module-info.java"), "module m3x { requires m1x; }"); |
36526 | 293 |
|
294 |
Path classes = base.resolve("classes"); |
|
295 |
Files.createDirectories(classes); |
|
296 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
297 |
String log = new JavacTask(tb) |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
38916
diff
changeset
|
298 |
.options("-XDrawDiagnostics", "--module-source-path", src.toString()) |
36526 | 299 |
.outdir(classes) |
300 |
.files(findJavaFiles(src)) |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
301 |
.run(Task.Expect.FAIL) |
36526 | 302 |
.writeAll() |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
303 |
.getOutput(Task.OutputKind.DIRECT); |
36526 | 304 |
|
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
305 |
if (!log.contains("module-info.java:1:23: compiler.err.cyclic.requires: m3x")) |
36526 | 306 |
throw new Exception("expected output not found"); |
307 |
} |
|
308 |
||
309 |
/** |
|
310 |
* Verify that a multi-module loop is detected. |
|
311 |
*/ |
|
312 |
@Test |
|
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
313 |
public void testRequiresTransitiveLoop(Path base) throws Exception { |
36526 | 314 |
Path src = base.resolve("src"); |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
315 |
Path src_m1 = src.resolve("m1x"); |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
316 |
tb.writeFile(src_m1.resolve("module-info.java"), "module m1x { requires m2x; }"); |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
317 |
Path src_m2 = src.resolve("m2x"); |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
318 |
tb.writeFile(src_m2.resolve("module-info.java"), "module m2x { requires transitive m3x; }"); |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
319 |
Path src_m3 = src.resolve("m3x"); |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
320 |
tb.writeFile(src_m3.resolve("module-info.java"), "module m3x { requires m1x; }"); |
36526 | 321 |
|
322 |
Path classes = base.resolve("classes"); |
|
323 |
Files.createDirectories(classes); |
|
324 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
325 |
String log = new JavacTask(tb) |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
38916
diff
changeset
|
326 |
.options("-XDrawDiagnostics", "--module-source-path", src.toString()) |
36526 | 327 |
.outdir(classes) |
328 |
.files(findJavaFiles(src)) |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
329 |
.run(Task.Expect.FAIL) |
36526 | 330 |
.writeAll() |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
331 |
.getOutput(Task.OutputKind.DIRECT); |
36526 | 332 |
|
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
333 |
if (!log.contains("module-info.java:1:34: compiler.err.cyclic.requires: m3x")) |
36526 | 334 |
throw new Exception("expected output not found"); |
335 |
} |
|
336 |
||
337 |
/** |
|
338 |
* Verify that duplicate requires are detected. |
|
339 |
*/ |
|
340 |
@Test |
|
37758 | 341 |
public void testDuplicateRequires(Path base) throws Exception { |
36526 | 342 |
Path src = base.resolve("src"); |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
343 |
Path src_m1 = src.resolve("m1x"); |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
344 |
tb.writeFile(src_m1.resolve("module-info.java"), "module m1x { }"); |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
345 |
Path src_m2 = src.resolve("m2x"); |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
346 |
tb.writeFile(src_m2.resolve("module-info.java"), "module m2x { requires m1x; requires m1x; }"); |
36526 | 347 |
|
348 |
Path classes = base.resolve("classes"); |
|
349 |
Files.createDirectories(classes); |
|
350 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
351 |
String log = new JavacTask(tb) |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
38916
diff
changeset
|
352 |
.options("-XDrawDiagnostics", "--module-source-path", src.toString()) |
36526 | 353 |
.outdir(classes) |
354 |
.files(findJavaFiles(src)) |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
355 |
.run(Task.Expect.FAIL) |
36526 | 356 |
.writeAll() |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
357 |
.getOutput(Task.OutputKind.DIRECT); |
36526 | 358 |
|
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
359 |
if (!log.contains("module-info.java:1:37: compiler.err.duplicate.requires: m1x")) |
36526 | 360 |
throw new Exception("expected output not found"); |
361 |
} |
|
362 |
||
363 |
/** |
|
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
364 |
* Verify that duplicate requires are detected. |
36526 | 365 |
*/ |
366 |
@Test |
|
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
367 |
public void testDuplicateRequiresTransitiveStatic(Path base) throws Exception { |
36526 | 368 |
Path src = base.resolve("src"); |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
369 |
Path src_m1 = src.resolve("m1x"); |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
370 |
tb.writeFile(src_m1.resolve("module-info.java"), "module m1x { }"); |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
371 |
Path src_m2 = src.resolve("m2x"); |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
372 |
tb.writeFile(src_m2.resolve("module-info.java"), "module m2x { requires transitive m1x; requires static m1x; }"); |
36526 | 373 |
|
374 |
Path classes = base.resolve("classes"); |
|
375 |
Files.createDirectories(classes); |
|
376 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
377 |
String log = new JavacTask(tb) |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
38916
diff
changeset
|
378 |
.options("-XDrawDiagnostics", "--module-source-path", src.toString()) |
36526 | 379 |
.outdir(classes) |
380 |
.files(findJavaFiles(src)) |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
381 |
.run(Task.Expect.FAIL) |
36526 | 382 |
.writeAll() |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
383 |
.getOutput(Task.OutputKind.DIRECT); |
36526 | 384 |
|
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
385 |
if (!log.contains("module-info.java:1:55: compiler.err.duplicate.requires: m1x")) |
36526 | 386 |
throw new Exception("expected output not found"); |
387 |
} |
|
388 |
||
389 |
/** |
|
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
390 |
* Verify that duplicate exported packages are detected correctly. |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
391 |
*/ |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
392 |
@Test |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
393 |
public void testConflictingExports_packages(Path base) throws Exception { |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
394 |
verifyConflictingExports_packages(base, |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
395 |
"exports p; exports q;", |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
396 |
null); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
397 |
verifyConflictingExports_packages(base, |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
398 |
"exports p; exports p;", |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
399 |
"module-info.java:1:33: compiler.err.conflicting.exports: p"); |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
400 |
verifyConflictingExports_packages(base, |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
401 |
"exports p; opens p;", |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
402 |
null); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
403 |
verifyConflictingExports_packages(base, |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
404 |
"exports p; exports p to m2x;", |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
405 |
"module-info.java:1:33: compiler.err.conflicting.exports: p"); |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
406 |
verifyConflictingExports_packages(base, |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
407 |
"exports p; opens p to m2x;", |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
408 |
null); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
409 |
verifyConflictingExports_packages(base, |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
410 |
"opens p; exports p;", |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
411 |
null); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
412 |
verifyConflictingExports_packages(base, |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
413 |
"opens p; opens p;", |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
414 |
"module-info.java:1:29: compiler.err.conflicting.opens: p"); |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
415 |
verifyConflictingExports_packages(base, |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
416 |
"opens p; exports p to m2x;", |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
417 |
null); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
418 |
verifyConflictingExports_packages(base, |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
419 |
"opens p; opens p to m2x;", |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
420 |
"module-info.java:1:29: compiler.err.conflicting.opens: p"); |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
421 |
verifyConflictingExports_packages(base, |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
422 |
"exports p to m2x; exports p;", |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
423 |
"module-info.java:1:40: compiler.err.conflicting.exports: p"); |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
424 |
verifyConflictingExports_packages(base, |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
425 |
"exports p to m2x; opens p;", |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
426 |
null); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
427 |
verifyConflictingExports_packages(base, |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
428 |
"exports p to m2x; exports p to m2x;", |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
429 |
"module-info.java:1:45: compiler.err.conflicting.exports.to.module: m2x"); |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
430 |
verifyConflictingExports_packages(base, |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
431 |
"exports p to m2x; opens p to m2x;", |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
432 |
null); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
433 |
verifyConflictingExports_packages(base, |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
434 |
"opens p to m2x; exports p;", |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
435 |
null); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
436 |
verifyConflictingExports_packages(base, |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
437 |
"opens p to m2x; opens p;", |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
438 |
"module-info.java:1:36: compiler.err.conflicting.opens: p"); |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
439 |
verifyConflictingExports_packages(base, |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
440 |
"opens p to m2x; exports p to m2x;", |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
441 |
null); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
442 |
verifyConflictingExports_packages(base, |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
443 |
"opens p to m2x; opens p to m2x;", |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
444 |
"module-info.java:1:36: compiler.err.conflicting.opens: p"); |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
445 |
verifyConflictingExports_packages(base, |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
446 |
"exports p to m2x; exports p to m3x;", |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
447 |
"module-info.java:1:40: compiler.err.conflicting.exports: p"); |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
448 |
verifyConflictingExports_packages(base, |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
449 |
"exports p to m2x; opens p to m3x;", |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
450 |
null); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
451 |
verifyConflictingExports_packages(base, |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
452 |
"opens p to m2x; exports p to m3x;", |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
453 |
null); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
454 |
verifyConflictingExports_packages(base, |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
455 |
"opens p to m2x; opens p to m3x;", |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
456 |
"module-info.java:1:36: compiler.err.conflicting.opens: p"); |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
457 |
} |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
458 |
|
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
459 |
private void verifyConflictingExports_packages(Path base, String code, String expected) throws Exception { |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
460 |
Files.createDirectories(base); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
461 |
tb.cleanDirectory(base); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
462 |
|
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
463 |
Path src = base.resolve("src"); |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
464 |
tb.writeJavaFiles(src.resolve("m1x"), |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
465 |
"module m1x { " + code + " }", |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
466 |
"package p; public class P {}", |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
467 |
"package q; public class Q {}"); |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
468 |
tb.writeJavaFiles(src.resolve("m2x"), |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
469 |
"module m2x { requires m1x; }"); |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
470 |
tb.writeJavaFiles(src.resolve("m3x"), |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
471 |
"module m3x { requires m1x; }"); |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
472 |
|
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
473 |
Path classes = base.resolve("classes"); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
474 |
Files.createDirectories(classes); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
475 |
|
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
476 |
String log = new JavacTask(tb) |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
477 |
.options("-XDrawDiagnostics", |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
478 |
"--module-source-path", src.toString()) |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
479 |
.outdir(classes) |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
480 |
.files(findJavaFiles(src)) |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
481 |
.run(expected != null ? Task.Expect.FAIL : Task.Expect.SUCCESS) |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
482 |
.writeAll() |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
483 |
.getOutput(Task.OutputKind.DIRECT); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
484 |
|
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
485 |
if (expected != null && !log.contains(expected)) |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
486 |
throw new Exception("expected output not found, actual output: " + log); |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
487 |
} |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
488 |
|
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
489 |
/** |
36526 | 490 |
* Verify that duplicate exported packages are detected. |
491 |
*/ |
|
492 |
@Test |
|
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
493 |
public void testConflictingExports_modules(Path base) throws Exception { |
36526 | 494 |
Path src = base.resolve("src"); |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
495 |
Path src_m1 = src.resolve("m1x"); |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
496 |
tb.writeFile(src_m1.resolve("module-info.java"), "module m1x { }"); |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
497 |
Path src_m2 = src.resolve("m2x"); |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
498 |
tb.writeFile(src_m2.resolve("module-info.java"), "module m2x { exports p to m1x, m1x; }"); |
36526 | 499 |
|
500 |
Path classes = base.resolve("classes"); |
|
501 |
Files.createDirectories(classes); |
|
502 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
503 |
String log = new JavacTask(tb) |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
38916
diff
changeset
|
504 |
.options("-XDrawDiagnostics", "--module-source-path", src.toString()) |
36526 | 505 |
.outdir(classes) |
506 |
.files(findJavaFiles(src)) |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
507 |
.run(Task.Expect.FAIL) |
36526 | 508 |
.writeAll() |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
509 |
.getOutput(Task.OutputKind.DIRECT); |
36526 | 510 |
|
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
511 |
if (!log.contains("module-info.java:1:32: compiler.err.conflicting.exports.to.module: m1x")) |
36526 | 512 |
throw new Exception("expected output not found"); |
513 |
} |
|
38916
d118cb2cffab
8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents:
37758
diff
changeset
|
514 |
|
d118cb2cffab
8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents:
37758
diff
changeset
|
515 |
/** |
d118cb2cffab
8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents:
37758
diff
changeset
|
516 |
* Verify that annotations are not permitted at |
d118cb2cffab
8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents:
37758
diff
changeset
|
517 |
* any of the module names or the package names. |
d118cb2cffab
8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents:
37758
diff
changeset
|
518 |
*/ |
d118cb2cffab
8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents:
37758
diff
changeset
|
519 |
@Test |
d118cb2cffab
8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents:
37758
diff
changeset
|
520 |
public void testAnnotations(Path base) throws Exception { |
d118cb2cffab
8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents:
37758
diff
changeset
|
521 |
Path src = base.resolve("src"); |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
522 |
Path src_m1 = src.resolve("m1x.sub"); |
38916
d118cb2cffab
8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents:
37758
diff
changeset
|
523 |
Path classes = base.resolve("classes"); |
d118cb2cffab
8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents:
37758
diff
changeset
|
524 |
Files.createDirectories(classes); |
d118cb2cffab
8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents:
37758
diff
changeset
|
525 |
|
d118cb2cffab
8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents:
37758
diff
changeset
|
526 |
String code = "module @m1.@sub { " + |
d118cb2cffab
8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents:
37758
diff
changeset
|
527 |
"requires @p1.@p2; " + |
d118cb2cffab
8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents:
37758
diff
changeset
|
528 |
"exports @p1.@p2; " + |
d118cb2cffab
8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents:
37758
diff
changeset
|
529 |
"exports @p1.@p2 to @m2.@sub; " + |
d118cb2cffab
8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents:
37758
diff
changeset
|
530 |
"exports @p1.@p2 to @m2.@sub, @m3.@sub; " + |
d118cb2cffab
8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents:
37758
diff
changeset
|
531 |
"uses @p1.@Interface; " + |
d118cb2cffab
8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents:
37758
diff
changeset
|
532 |
"provides @p1.@Interface with @p2.@Concrete; " + |
d118cb2cffab
8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents:
37758
diff
changeset
|
533 |
"}"; |
d118cb2cffab
8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents:
37758
diff
changeset
|
534 |
String[] splittedCode = code.split("@"); |
d118cb2cffab
8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents:
37758
diff
changeset
|
535 |
int length = splittedCode.length; |
d118cb2cffab
8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents:
37758
diff
changeset
|
536 |
String anno = "@Anno "; |
d118cb2cffab
8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents:
37758
diff
changeset
|
537 |
|
d118cb2cffab
8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents:
37758
diff
changeset
|
538 |
for (int i = 1; i < length; i++) { |
d118cb2cffab
8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents:
37758
diff
changeset
|
539 |
String preAnno = String.join("", Arrays.copyOfRange(splittedCode, 0, i)); |
d118cb2cffab
8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents:
37758
diff
changeset
|
540 |
String postAnno = String.join("", Arrays.copyOfRange(splittedCode, i, length)); |
d118cb2cffab
8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents:
37758
diff
changeset
|
541 |
String moduleInfo = preAnno + anno + postAnno; |
d118cb2cffab
8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents:
37758
diff
changeset
|
542 |
tb.writeFile(src_m1.resolve("module-info.java"), moduleInfo); |
d118cb2cffab
8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents:
37758
diff
changeset
|
543 |
|
d118cb2cffab
8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents:
37758
diff
changeset
|
544 |
String log = new JavacTask(tb) |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
38916
diff
changeset
|
545 |
.options("-XDrawDiagnostics", "--module-source-path", src.toString()) |
38916
d118cb2cffab
8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents:
37758
diff
changeset
|
546 |
.outdir(classes) |
d118cb2cffab
8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents:
37758
diff
changeset
|
547 |
.files(findJavaFiles(src)) |
d118cb2cffab
8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents:
37758
diff
changeset
|
548 |
.run(Task.Expect.FAIL) |
d118cb2cffab
8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents:
37758
diff
changeset
|
549 |
.writeAll() |
d118cb2cffab
8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents:
37758
diff
changeset
|
550 |
.getOutput(Task.OutputKind.DIRECT); |
d118cb2cffab
8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents:
37758
diff
changeset
|
551 |
|
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
552 |
String expect_prefix = "(?s)^module\\-info\\.java:\\d+:\\d+: "; |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
553 |
String expect_message = "compiler\\.err\\.expected: token\\.identifier"; |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
554 |
String expect_suffix = ".*"; |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
555 |
String expect = expect_prefix + expect_message + expect_suffix; |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
556 |
if (!log.matches(expect)) |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40308
diff
changeset
|
557 |
throw new Exception("expected output not found for: " + moduleInfo + "; actual: " + log); |
38916
d118cb2cffab
8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents:
37758
diff
changeset
|
558 |
} |
d118cb2cffab
8158123: NPE when the annotations is used in export-to of module-info
shinyafox
parents:
37758
diff
changeset
|
559 |
} |
36526 | 560 |
} |