author | sadayapalam |
Mon, 06 Feb 2017 18:14:51 +0530 | |
changeset 43584 | 63e67712246b |
parent 43138 | 680d378b9d64 |
permissions | -rw-r--r-- |
36526 | 1 |
/* |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
2 |
* Copyright (c) 2013, 2016, 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 |
|
26 |
* @summary tests for module resolution |
|
27 |
* @library /tools/lib |
|
28 |
* @modules |
|
29 |
* jdk.compiler/com.sun.tools.javac.api |
|
30 |
* jdk.compiler/com.sun.tools.javac.main |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
31 |
* @build toolbox.ToolBox toolbox.JavacTask ModuleTestBase |
36526 | 32 |
* @run main ResolveTest |
33 |
*/ |
|
34 |
||
35 |
import java.nio.file.*; |
|
36 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
37 |
import toolbox.JavacTask; |
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
38 |
import toolbox.Task; |
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
39 |
|
36526 | 40 |
public class ResolveTest extends ModuleTestBase { |
41 |
public static void main(String... args) throws Exception { |
|
42 |
ResolveTest t = new ResolveTest(); |
|
43 |
t.runTests(); |
|
44 |
} |
|
45 |
||
46 |
@Test |
|
37758 | 47 |
public void testMissingSimpleTypeUnnamedModule(Path base) throws Exception { |
36526 | 48 |
Path src = base.resolve("src"); |
49 |
tb.writeJavaFiles(src, "class C { D d; }"); |
|
50 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
51 |
String log = new JavacTask(tb) |
36526 | 52 |
.options("-XDrawDiagnostics") |
53 |
.files(findJavaFiles(src)) |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
54 |
.run(Task.Expect.FAIL) |
36526 | 55 |
.writeAll() |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
56 |
.getOutput(Task.OutputKind.DIRECT); |
36526 | 57 |
|
58 |
if (!log.contains("C.java:1:11: compiler.err.cant.resolve.location: " |
|
59 |
+ "kindname.class, D, , , (compiler.misc.location: kindname.class, C, null)")) |
|
60 |
throw new Exception("expected output not found"); |
|
61 |
} |
|
62 |
||
63 |
@Test |
|
37758 | 64 |
public void testMissingSimpleTypeNamedModule(Path base) throws Exception { |
36526 | 65 |
Path src = base.resolve("src"); |
66 |
tb.writeJavaFiles(src, |
|
67 |
"module m { }", |
|
68 |
"class C { D d; }"); |
|
69 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
70 |
String log = new JavacTask(tb) |
36526 | 71 |
.options("-XDrawDiagnostics") |
72 |
.files(findJavaFiles(src)) |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
73 |
.run(Task.Expect.FAIL) |
36526 | 74 |
.writeAll() |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
75 |
.getOutput(Task.OutputKind.DIRECT); |
36526 | 76 |
|
77 |
if (!log.contains("C.java:1:11: compiler.err.cant.resolve.location: " |
|
78 |
+ "kindname.class, D, , , (compiler.misc.location: kindname.class, C, null)")) |
|
79 |
throw new Exception("expected output not found"); |
|
80 |
} |
|
81 |
||
82 |
@Test |
|
37758 | 83 |
public void testUnexportedTypeUnreadableModule(Path base) throws Exception { |
36526 | 84 |
Path src = base.resolve("src"); |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
41932
diff
changeset
|
85 |
tb.writeJavaFiles(src.resolve("m1x"), |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
41932
diff
changeset
|
86 |
"module m1x { }", |
36526 | 87 |
"package p1; public class C1 { }"); |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
41932
diff
changeset
|
88 |
tb.writeJavaFiles(src.resolve("m2x"), |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
41932
diff
changeset
|
89 |
"module m2x { }", |
36526 | 90 |
"package p2; public class C2 { p1.C1 c; }"); |
91 |
Path modules = base.resolve("modules"); |
|
92 |
Files.createDirectories(modules); |
|
93 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
94 |
String log = new JavacTask(tb) |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
37758
diff
changeset
|
95 |
.options("-XDrawDiagnostics", "--module-source-path", src.toString()) |
36526 | 96 |
.outdir(modules) |
97 |
.files(findJavaFiles(src)) |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
98 |
.run(Task.Expect.FAIL) |
36526 | 99 |
.writeAll() |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
100 |
.getOutput(Task.OutputKind.DIRECT); |
36526 | 101 |
|
43138
680d378b9d64
8169197: Improve error reporting for compiling against unexported package
jlahoda
parents:
42822
diff
changeset
|
102 |
if (!log.contains("C2.java:1:31: compiler.err.package.not.visible: p1, (compiler.misc.not.def.access.does.not.read: m2x, p1, m1x)")) |
36526 | 103 |
throw new Exception("expected output not found"); |
104 |
} |
|
105 |
||
106 |
@Test |
|
37758 | 107 |
public void testUnexportedTypeReadableModule(Path base) throws Exception { |
36526 | 108 |
Path src = base.resolve("src"); |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
41932
diff
changeset
|
109 |
tb.writeJavaFiles(src.resolve("m1x"), |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
41932
diff
changeset
|
110 |
"module m1x { }", |
36526 | 111 |
"package p1; public class C1 { }"); |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
41932
diff
changeset
|
112 |
tb.writeJavaFiles(src.resolve("m2x"), |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
41932
diff
changeset
|
113 |
"module m2x { requires m1x; }", |
36526 | 114 |
"package p2; public class C2 { p1.C1 c; }"); |
115 |
Path modules = base.resolve("modules"); |
|
116 |
Files.createDirectories(modules); |
|
117 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
118 |
String log = new JavacTask(tb) |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
37758
diff
changeset
|
119 |
.options("-XDrawDiagnostics", "--module-source-path", src.toString()) |
36526 | 120 |
.outdir(modules) |
121 |
.files(findJavaFiles(src)) |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
122 |
.run(Task.Expect.FAIL) |
36526 | 123 |
.writeAll() |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
124 |
.getOutput(Task.OutputKind.DIRECT); |
36526 | 125 |
|
43138
680d378b9d64
8169197: Improve error reporting for compiling against unexported package
jlahoda
parents:
42822
diff
changeset
|
126 |
if (!log.contains("C2.java:1:31: compiler.err.package.not.visible: p1, (compiler.misc.not.def.access.not.exported: p1, m1x)")) |
36526 | 127 |
throw new Exception("expected output not found"); |
128 |
} |
|
129 |
||
130 |
@Test |
|
37758 | 131 |
public void testQualifiedExportedTypeReadableModule(Path base) throws Exception { |
36526 | 132 |
Path src = base.resolve("src"); |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
41932
diff
changeset
|
133 |
tb.writeJavaFiles(src.resolve("m1x"), |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
41932
diff
changeset
|
134 |
"module m1x { exports p1 to m3x; }", |
36526 | 135 |
"package p1; public class C1 { }"); |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
41932
diff
changeset
|
136 |
tb.writeJavaFiles(src.resolve("m2x"), |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
41932
diff
changeset
|
137 |
"module m2x { requires m1x; }", |
36526 | 138 |
"package p2; public class C2 { p1.C1 c; }"); |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
41932
diff
changeset
|
139 |
tb.writeJavaFiles(src.resolve("m3x"), |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
41932
diff
changeset
|
140 |
"module m3x { requires m1x; }"); |
36526 | 141 |
Path modules = base.resolve("modules"); |
142 |
Files.createDirectories(modules); |
|
143 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
144 |
String log = new JavacTask(tb) |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
37758
diff
changeset
|
145 |
.options("-XDrawDiagnostics", "--module-source-path", src.toString()) |
36526 | 146 |
.outdir(modules) |
147 |
.files(findJavaFiles(src)) |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
148 |
.run(Task.Expect.FAIL) |
36526 | 149 |
.writeAll() |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
150 |
.getOutput(Task.OutputKind.DIRECT); |
36526 | 151 |
|
43138
680d378b9d64
8169197: Improve error reporting for compiling against unexported package
jlahoda
parents:
42822
diff
changeset
|
152 |
if (!log.contains("C2.java:1:31: compiler.err.package.not.visible: p1, (compiler.misc.not.def.access.not.exported.to.module: p1, m1x, m2x)")) |
36526 | 153 |
throw new Exception("expected output not found"); |
154 |
} |
|
155 |
||
156 |
@Test |
|
37758 | 157 |
public void testExportedTypeUnreadableModule(Path base) throws Exception { |
36526 | 158 |
Path src = base.resolve("src"); |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
41932
diff
changeset
|
159 |
tb.writeJavaFiles(src.resolve("m1x"), |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
41932
diff
changeset
|
160 |
"module m1x { exports p1; }", |
36526 | 161 |
"package p1; public class C1 { }"); |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
41932
diff
changeset
|
162 |
tb.writeJavaFiles(src.resolve("m2x"), |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
41932
diff
changeset
|
163 |
"module m2x { }", |
36526 | 164 |
"package p2; public class C2 { p1.C1 c; }"); |
165 |
Path modules = base.resolve("modules"); |
|
166 |
Files.createDirectories(modules); |
|
167 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
168 |
String log = new JavacTask(tb) |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
37758
diff
changeset
|
169 |
.options("-XDrawDiagnostics", "--module-source-path", src.toString()) |
36526 | 170 |
.outdir(modules) |
171 |
.files(findJavaFiles(src)) |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
172 |
.run(Task.Expect.FAIL) |
36526 | 173 |
.writeAll() |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
174 |
.getOutput(Task.OutputKind.DIRECT); |
36526 | 175 |
|
43138
680d378b9d64
8169197: Improve error reporting for compiling against unexported package
jlahoda
parents:
42822
diff
changeset
|
176 |
if (!log.contains("C2.java:1:31: compiler.err.package.not.visible: p1, (compiler.misc.not.def.access.does.not.read: m2x, p1, m1x)")) |
36526 | 177 |
throw new Exception("expected output not found"); |
178 |
} |
|
179 |
||
180 |
@Test |
|
37758 | 181 |
public void testExportedTypeReadableModule(Path base) throws Exception { |
36526 | 182 |
Path src = base.resolve("src"); |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
41932
diff
changeset
|
183 |
tb.writeJavaFiles(src.resolve("m1x"), |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
41932
diff
changeset
|
184 |
"module m1x { exports p1; }", |
36526 | 185 |
"package p1; public class C1 { }"); |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
41932
diff
changeset
|
186 |
tb.writeJavaFiles(src.resolve("m2x"), |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
41932
diff
changeset
|
187 |
"module m2x { requires m1x; }", |
36526 | 188 |
"package p2; public class C2 { p1.C1 c; }"); |
189 |
Path modules = base.resolve("modules"); |
|
190 |
Files.createDirectories(modules); |
|
191 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
192 |
new JavacTask(tb) |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
37758
diff
changeset
|
193 |
.options("-XDrawDiagnostics", "--module-source-path", src.toString()) |
36526 | 194 |
.outdir(modules) |
195 |
.files(findJavaFiles(src)) |
|
196 |
.run() |
|
197 |
.writeAll(); |
|
198 |
} |
|
199 |
||
200 |
@Test |
|
37758 | 201 |
public void testExportedTypeReadableModule2(Path base) throws Exception { |
36526 | 202 |
Path src = base.resolve("src"); |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
41932
diff
changeset
|
203 |
tb.writeJavaFiles(src.resolve("m1x"), |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
41932
diff
changeset
|
204 |
"module m1x { exports p1 to m2x; }", |
36526 | 205 |
"package p1; public class C1 { }"); |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
41932
diff
changeset
|
206 |
tb.writeJavaFiles(src.resolve("m2x"), |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
41932
diff
changeset
|
207 |
"module m2x { requires m1x; }", |
36526 | 208 |
"package p2; public class C2 { p1.C1 c; }"); |
209 |
Path modules = base.resolve("modules"); |
|
210 |
Files.createDirectories(modules); |
|
211 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
212 |
new JavacTask(tb) |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
37758
diff
changeset
|
213 |
.options("-XDrawDiagnostics", "--module-source-path", src.toString()) |
36526 | 214 |
.outdir(modules) |
215 |
.files(findJavaFiles(src)) |
|
216 |
.run() |
|
217 |
.writeAll(); |
|
218 |
} |
|
219 |
} |