36526
|
1 |
/*
|
|
2 |
* Copyright (c) 2015, 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 Module attribute tests
|
|
27 |
* @bug 8080878
|
|
28 |
* @modules jdk.compiler/com.sun.tools.javac.api
|
|
29 |
* jdk.compiler/com.sun.tools.javac.main
|
|
30 |
* jdk.compiler/com.sun.tools.javac.util
|
|
31 |
* jdk.jdeps/com.sun.tools.classfile
|
|
32 |
* jdk.jdeps/com.sun.tools.javap
|
|
33 |
* @library /tools/lib ../lib /tools/javac/lib
|
|
34 |
* @build ToolBox TestBase TestResult ModuleTestBase
|
|
35 |
* @run main ModuleTest
|
|
36 |
*/
|
|
37 |
|
|
38 |
import java.nio.file.Path;
|
|
39 |
|
|
40 |
public class ModuleTest extends ModuleTestBase {
|
|
41 |
|
|
42 |
public static void main(String[] args) throws Exception {
|
|
43 |
new ModuleTest().run();
|
|
44 |
}
|
|
45 |
|
|
46 |
@Test
|
|
47 |
public void testEmptyModule(Path base) throws Exception {
|
|
48 |
ModuleDescriptor moduleDescriptor = new ModuleDescriptor("m1")
|
|
49 |
.write(base);
|
|
50 |
compile(base);
|
|
51 |
testModuleAttribute(base, moduleDescriptor);
|
|
52 |
}
|
|
53 |
|
|
54 |
@Test
|
|
55 |
public void testExports(Path base) throws Exception {
|
|
56 |
ModuleDescriptor moduleDescriptor = new ModuleDescriptor("m1")
|
|
57 |
.exports("pack")
|
|
58 |
.write(base);
|
|
59 |
tb.writeJavaFiles(base, "package pack; public class C extends java.util.ArrayList{}");
|
|
60 |
compile(base);
|
|
61 |
testModuleAttribute(base, moduleDescriptor);
|
|
62 |
}
|
|
63 |
|
|
64 |
@Test
|
|
65 |
public void testSeveralExports(Path base) throws Exception {
|
|
66 |
ModuleDescriptor moduleDescriptor = new ModuleDescriptor("m1")
|
|
67 |
.exports("pack")
|
|
68 |
.exports("pack2")
|
|
69 |
.exports("pack3")
|
|
70 |
.write(base);
|
|
71 |
tb.writeJavaFiles(base,
|
|
72 |
"package pack; public class A {}",
|
|
73 |
"package pack2; public class B {}",
|
|
74 |
"package pack3; public class C {}");
|
|
75 |
compile(base);
|
|
76 |
testModuleAttribute(base, moduleDescriptor);
|
|
77 |
}
|
|
78 |
|
|
79 |
@Test
|
|
80 |
public void testQualifiedExports(Path base) throws Exception {
|
|
81 |
ModuleDescriptor moduleDescriptor = new ModuleDescriptor("m1")
|
|
82 |
.exportsTo("pack", "jdk.compiler")
|
|
83 |
.write(base);
|
|
84 |
tb.writeJavaFiles(base, "package pack; public class A {}");
|
|
85 |
compile(base);
|
|
86 |
testModuleAttribute(base, moduleDescriptor);
|
|
87 |
}
|
|
88 |
|
|
89 |
@Test
|
|
90 |
public void testSeveralQualifiedExports(Path base) throws Exception {
|
|
91 |
ModuleDescriptor moduleDescriptor = new ModuleDescriptor("m1")
|
|
92 |
.exportsTo("pack", "jdk.compiler, java.xml")
|
|
93 |
.exportsTo("pack2", "java.xml")
|
|
94 |
.exportsTo("pack3", "jdk.compiler")
|
|
95 |
.write(base);
|
|
96 |
tb.writeJavaFiles(base,
|
|
97 |
"package pack; public class A {}",
|
|
98 |
"package pack2; public class B {}",
|
|
99 |
"package pack3; public class C {}");
|
|
100 |
compile(base);
|
|
101 |
testModuleAttribute(base, moduleDescriptor);
|
|
102 |
}
|
|
103 |
|
|
104 |
@Test
|
|
105 |
public void testRequires(Path base) throws Exception {
|
|
106 |
ModuleDescriptor moduleDescriptor = new ModuleDescriptor("m1")
|
|
107 |
.requires("jdk.compiler")
|
|
108 |
.write(base);
|
|
109 |
compile(base);
|
|
110 |
testModuleAttribute(base, moduleDescriptor);
|
|
111 |
}
|
|
112 |
|
|
113 |
@Test
|
|
114 |
public void testRequiresPublic(Path base) throws Exception {
|
|
115 |
ModuleDescriptor moduleDescriptor = new ModuleDescriptor("m1")
|
|
116 |
.requiresPublic("java.xml")
|
|
117 |
.write(base);
|
|
118 |
compile(base);
|
|
119 |
testModuleAttribute(base, moduleDescriptor);
|
|
120 |
}
|
|
121 |
|
|
122 |
@Test
|
|
123 |
public void testSeveralRequires(Path base) throws Exception {
|
|
124 |
ModuleDescriptor moduleDescriptor = new ModuleDescriptor("m1")
|
|
125 |
.requiresPublic("java.xml")
|
|
126 |
.requires("java.compiler")
|
|
127 |
.requires("jdk.compiler")
|
|
128 |
.requiresPublic("jdk.scripting.nashorn")
|
|
129 |
.write(base);
|
|
130 |
compile(base);
|
|
131 |
testModuleAttribute(base, moduleDescriptor);
|
|
132 |
}
|
|
133 |
|
|
134 |
@Test
|
|
135 |
public void testProvides(Path base) throws Exception {
|
|
136 |
ModuleDescriptor moduleDescriptor = new ModuleDescriptor("m1")
|
|
137 |
.provides("java.util.Collection", "pack2.D")
|
|
138 |
.write(base);
|
|
139 |
tb.writeJavaFiles(base, "package pack2; public class D extends java.util.ArrayList{}");
|
|
140 |
compile(base);
|
|
141 |
testModuleAttribute(base, moduleDescriptor);
|
|
142 |
}
|
|
143 |
|
|
144 |
@Test
|
|
145 |
public void testSeveralProvides(Path base) throws Exception {
|
|
146 |
ModuleDescriptor moduleDescriptor = new ModuleDescriptor("m1")
|
|
147 |
.provides("java.util.Collection", "pack2.D")
|
|
148 |
.provides("java.util.List", "pack2.D")
|
|
149 |
.requires("java.logging")
|
|
150 |
.provides("java.util.logging.Logger", "pack2.C")
|
|
151 |
.write(base);
|
|
152 |
tb.writeJavaFiles(base, "package pack2; public class D extends java.util.ArrayList{}",
|
|
153 |
"package pack2; public class C extends java.util.logging.Logger{ " +
|
|
154 |
"public C() { super(\"\",\"\"); } \n" +
|
|
155 |
"C(String a,String b){" +
|
|
156 |
" super(a,b);" +
|
|
157 |
"}}");
|
|
158 |
compile(base);
|
|
159 |
testModuleAttribute(base, moduleDescriptor);
|
|
160 |
}
|
|
161 |
|
|
162 |
@Test
|
|
163 |
public void testUses(Path base) throws Exception {
|
|
164 |
ModuleDescriptor moduleDescriptor = new ModuleDescriptor("m1")
|
|
165 |
.uses("java.util.List")
|
|
166 |
.write(base);
|
|
167 |
compile(base);
|
|
168 |
testModuleAttribute(base, moduleDescriptor);
|
|
169 |
}
|
|
170 |
|
|
171 |
@Test
|
|
172 |
public void testSeveralUses(Path base) throws Exception {
|
|
173 |
ModuleDescriptor moduleDescriptor = new ModuleDescriptor("m1")
|
|
174 |
.uses("java.util.List")
|
|
175 |
.uses("java.util.Collection")
|
|
176 |
.requires("java.logging")
|
|
177 |
.uses("java.util.logging.Logger")
|
|
178 |
.write(base);
|
|
179 |
compile(base);
|
|
180 |
testModuleAttribute(base, moduleDescriptor);
|
|
181 |
}
|
|
182 |
|
|
183 |
@Test
|
|
184 |
public void testComplex(Path base) throws Exception {
|
|
185 |
ModuleDescriptor moduleDescriptor = new ModuleDescriptor("m1")
|
|
186 |
.exports("pack1")
|
|
187 |
.exportsTo("packTo1", "java.xml")
|
|
188 |
.requires("jdk.compiler")
|
|
189 |
.requiresPublic("java.xml")
|
|
190 |
.provides("java.util.List", "pack1.C")
|
|
191 |
.uses("java.util.List")
|
|
192 |
.uses("java.nio.file.Path")
|
|
193 |
.provides("java.util.List", "pack2.D")
|
|
194 |
.requiresPublic("java.desktop")
|
|
195 |
.requires("java.compiler")
|
|
196 |
.exportsTo("packTo2", "java.compiler")
|
|
197 |
.exports("pack2")
|
|
198 |
.write(base);
|
|
199 |
tb.writeJavaFiles(base, "package pack1; public class C extends java.util.ArrayList{}",
|
|
200 |
"package pack2; public class D extends java.util.ArrayList{}");
|
|
201 |
tb.writeJavaFiles(base,
|
|
202 |
"package packTo1; public class T1 {}",
|
|
203 |
"package packTo2; public class T2 {}");
|
|
204 |
compile(base);
|
|
205 |
testModuleAttribute(base, moduleDescriptor);
|
|
206 |
}
|
|
207 |
}
|