author | sadayapalam |
Mon, 06 Feb 2017 18:14:51 +0530 | |
changeset 43584 | 63e67712246b |
parent 43138 | 680d378b9d64 |
permissions | -rw-r--r-- |
42407 | 1 |
/* |
2 |
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. |
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
22 |
*/ |
|
23 |
||
24 |
/* |
|
25 |
* @test |
|
26 |
* @summary tests for "requires transitive" |
|
27 |
* @library /tools/lib |
|
28 |
* @modules |
|
29 |
* jdk.compiler/com.sun.tools.javac.api |
|
30 |
* jdk.compiler/com.sun.tools.javac.main |
|
31 |
* @build toolbox.ToolBox toolbox.JavacTask ModuleTestBase |
|
32 |
* @run main RequiresTransitiveTest |
|
33 |
*/ |
|
34 |
||
35 |
import java.nio.file.Files; |
|
36 |
import java.nio.file.Path; |
|
37 |
||
38 |
import toolbox.JavacTask; |
|
39 |
import toolbox.Task; |
|
40 |
import toolbox.ToolBox; |
|
41 |
||
42 |
public class RequiresTransitiveTest extends ModuleTestBase { |
|
43 |
||
44 |
public static void main(String... args) throws Exception { |
|
45 |
RequiresTransitiveTest t = new RequiresTransitiveTest(); |
|
46 |
t.runTests(); |
|
47 |
} |
|
48 |
||
49 |
@Test |
|
50 |
public void testJavaSE_OK(Path base) throws Exception { |
|
51 |
Path src = base.resolve("src"); |
|
52 |
tb.writeJavaFiles(src, |
|
53 |
"module m { requires java.se; }", |
|
54 |
"import java.awt.Frame;\n" // in java.se |
|
55 |
+ "class Test {\n" |
|
56 |
+ " Frame f;\n" |
|
57 |
+ "}"); |
|
58 |
Path classes = base.resolve("classes"); |
|
59 |
Files.createDirectories(classes); |
|
60 |
||
61 |
new JavacTask(tb, Task.Mode.CMDLINE) |
|
62 |
.files(findJavaFiles(src)) |
|
63 |
.outdir(classes) |
|
64 |
.run() |
|
65 |
.writeAll(); |
|
66 |
} |
|
67 |
||
68 |
@Test |
|
69 |
public void testJavaSE_Fail(Path base) throws Exception { |
|
70 |
Path src = base.resolve("src"); |
|
71 |
tb.writeJavaFiles(src, |
|
72 |
"module m { requires java.se; }", |
|
73 |
"import com.sun.source.tree.Tree;\n" // not in java.se (in jdk.compiler) |
|
74 |
+ "class Test {\n" |
|
75 |
+ " Tree t;\n" |
|
76 |
+ "}"); |
|
77 |
Path classes = base.resolve("classes"); |
|
78 |
Files.createDirectories(classes); |
|
79 |
||
80 |
String log = new JavacTask(tb, Task.Mode.CMDLINE) |
|
81 |
.options("-XDrawDiagnostics") |
|
82 |
.files(findJavaFiles(src)) |
|
83 |
.outdir(classes) |
|
84 |
.run(Task.Expect.FAIL) |
|
85 |
.writeAll() |
|
86 |
.getOutput(Task.OutputKind.DIRECT); |
|
87 |
||
43138
680d378b9d64
8169197: Improve error reporting for compiling against unexported package
jlahoda
parents:
42822
diff
changeset
|
88 |
if (!log.contains("Test.java:1:22: compiler.err.package.not.visible: com.sun.source.tree, (compiler.misc.not.def.access.does.not.read: m, com.sun.source.tree, jdk.compiler)")) |
42407 | 89 |
throw new Exception("expected output not found"); |
90 |
} |
|
91 |
||
92 |
@Test |
|
93 |
public void testComplex_OK(Path base) throws Exception { |
|
94 |
Path src = getComplexSrc(base, "", ""); |
|
95 |
Path classes = base.resolve("classes"); |
|
96 |
Files.createDirectories(classes); |
|
97 |
||
98 |
new JavacTask(tb, Task.Mode.CMDLINE) |
|
99 |
.options("--module-source-path", src.toString()) |
|
100 |
.files(findJavaFiles(src)) |
|
101 |
.outdir(classes) |
|
102 |
.run() |
|
103 |
.writeAll(); |
|
104 |
} |
|
105 |
||
106 |
@Test |
|
107 |
public void testComplex_Fail(Path base) throws Exception { |
|
108 |
Path src = getComplexSrc(base, |
|
109 |
"import p5.C5; import p6.C6; import p7.C7;\n", |
|
110 |
"C5 c5; C6 c6; C7 c7;\n"); |
|
111 |
Path classes = base.resolve("classes"); |
|
112 |
Files.createDirectories(classes); |
|
113 |
||
114 |
String log = new JavacTask(tb, Task.Mode.CMDLINE) |
|
115 |
.options("-XDrawDiagnostics", |
|
116 |
"--module-source-path", src.toString()) |
|
117 |
.files(findJavaFiles(src)) |
|
118 |
.outdir(classes) |
|
119 |
.run(Task.Expect.FAIL) |
|
120 |
.writeAll() |
|
121 |
.getOutput(Task.OutputKind.DIRECT); |
|
122 |
||
123 |
String[] expect = { |
|
43138
680d378b9d64
8169197: Improve error reporting for compiling against unexported package
jlahoda
parents:
42822
diff
changeset
|
124 |
"C1.java:5:8: compiler.err.package.not.visible: p5, (compiler.misc.not.def.access.does.not.read: m1x, p5, m5x)", |
680d378b9d64
8169197: Improve error reporting for compiling against unexported package
jlahoda
parents:
42822
diff
changeset
|
125 |
"C1.java:5:22: compiler.err.package.not.visible: p6, (compiler.misc.not.def.access.does.not.read: m1x, p6, m6x)", |
680d378b9d64
8169197: Improve error reporting for compiling against unexported package
jlahoda
parents:
42822
diff
changeset
|
126 |
"C1.java:5:36: compiler.err.package.not.visible: p7, (compiler.misc.not.def.access.does.not.read: m1x, p7, m7x)" |
42407 | 127 |
}; |
128 |
||
129 |
for (String e: expect) { |
|
130 |
if (!log.contains(e)) |
|
131 |
throw new Exception("expected output not found: " + e); |
|
132 |
} |
|
133 |
} |
|
134 |
||
135 |
/* |
|
136 |
* Set up the following module graph |
|
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
137 |
* m1x -> m2x => m3x => m4x -> m5x |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
138 |
* -> m6x => m7x |
42407 | 139 |
* where -> is requires, => is requires transitive |
140 |
*/ |
|
141 |
Path getComplexSrc(Path base, String m1_extraImports, String m1_extraUses) throws Exception { |
|
142 |
Path src = base.resolve("src"); |
|
143 |
||
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
144 |
Path src_m1 = src.resolve("m1x"); |
42407 | 145 |
tb.writeJavaFiles(src_m1, |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
146 |
"module m1x { requires m2x; }", |
42407 | 147 |
"package p1;\n" |
148 |
+ "import p2.C2;\n" |
|
149 |
+ "import p3.C3;\n" |
|
150 |
+ "import p4.C4;\n" |
|
151 |
+ m1_extraImports |
|
152 |
+ "class C1 {\n" |
|
153 |
+ " C2 c2; C3 c3; C4 c4;\n" |
|
154 |
+ m1_extraUses |
|
155 |
+ "}\n"); |
|
156 |
||
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
157 |
Path src_m2 = src.resolve("m2x"); |
42407 | 158 |
tb.writeJavaFiles(src_m2, |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
159 |
"module m2x {\n" |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
160 |
+ " requires transitive m3x;\n" |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
161 |
+ " requires m6x;\n" |
42407 | 162 |
+ " exports p2;\n" |
163 |
+ "}", |
|
164 |
"package p2;\n" |
|
165 |
+ "public class C2 { }\n"); |
|
166 |
||
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
167 |
Path src_m3 = src.resolve("m3x"); |
42407 | 168 |
tb.writeJavaFiles(src_m3, |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
169 |
"module m3x { requires transitive m4x; exports p3; }", |
42407 | 170 |
"package p3;\n" |
171 |
+ "public class C3 { }\n"); |
|
172 |
||
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
173 |
Path src_m4 = src.resolve("m4x"); |
42407 | 174 |
tb.writeJavaFiles(src_m4, |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
175 |
"module m4x { requires m5x; exports p4; }", |
42407 | 176 |
"package p4;\n" |
177 |
+ "public class C4 { }\n"); |
|
178 |
||
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
179 |
Path src_m5 = src.resolve("m5x"); |
42407 | 180 |
tb.writeJavaFiles(src_m5, |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
181 |
"module m5x { exports p5; }", |
42407 | 182 |
"package p5;\n" |
183 |
+ "public class C5 { }\n"); |
|
184 |
||
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
185 |
Path src_m6 = src.resolve("m6x"); |
42407 | 186 |
tb.writeJavaFiles(src_m6, |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
187 |
"module m6x { requires transitive m7x; exports p6; }", |
42407 | 188 |
"package p6;\n" |
189 |
+ "public class C6 { }\n"); |
|
190 |
||
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
191 |
Path src_m7 = src.resolve("m7x"); |
42407 | 192 |
tb.writeJavaFiles(src_m7, |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42407
diff
changeset
|
193 |
"module m7x { exports p7; }", |
42407 | 194 |
"package p7;\n" |
195 |
+ "public class C7 { }\n"); |
|
196 |
||
197 |
return src; |
|
198 |
} |
|
199 |
} |