author | jjg |
Thu, 31 Mar 2016 15:20:50 -0700 | |
changeset 36778 | e04318f39f92 |
parent 36526 | 3b41f1c69604 |
child 37758 | 3ecf9b414e05 |
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 |
|
26 |
* @summary tests for multi-module mode compilation |
|
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 XModuleTest |
33 |
*/ |
|
34 |
||
35 |
import java.nio.file.Path; |
|
36 |
import java.util.Arrays; |
|
37 |
import java.util.List; |
|
38 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
39 |
import toolbox.JavacTask; |
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
40 |
import toolbox.Task; |
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
41 |
import toolbox.ToolBox; |
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
42 |
|
36526 | 43 |
public class XModuleTest extends ModuleTestBase { |
44 |
||
45 |
public static void main(String... args) throws Exception { |
|
46 |
new XModuleTest().runTests(); |
|
47 |
} |
|
48 |
||
49 |
@Test |
|
50 |
void testCorrectXModule(Path base) throws Exception { |
|
51 |
//note: avoiding use of java.base, as that gets special handling on some places: |
|
52 |
Path src = base.resolve("src"); |
|
53 |
tb.writeJavaFiles(src, "package javax.lang.model.element; public interface Extra extends Element { }"); |
|
54 |
Path classes = base.resolve("classes"); |
|
55 |
tb.createDirectories(classes); |
|
56 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
57 |
String log = new JavacTask(tb) |
36526 | 58 |
.options("-Xmodule:java.compiler") |
59 |
.outdir(classes) |
|
60 |
.files(findJavaFiles(src)) |
|
61 |
.run() |
|
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.isEmpty()) |
|
66 |
throw new Exception("expected output not found: " + log); |
|
67 |
} |
|
68 |
||
69 |
@Test |
|
70 |
void testSourcePath(Path base) throws Exception { |
|
71 |
//note: avoiding use of java.base, as that gets special handling on some places: |
|
72 |
Path src = base.resolve("src"); |
|
73 |
tb.writeJavaFiles(src, "package javax.lang.model.element; public interface Extra extends Element, Other { }", "package javax.lang.model.element; interface Other { }"); |
|
74 |
Path classes = base.resolve("classes"); |
|
75 |
tb.createDirectories(classes); |
|
76 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
77 |
String log = new JavacTask(tb) |
36526 | 78 |
.options("-Xmodule:java.compiler", "-sourcepath", src.toString()) |
79 |
.outdir(classes) |
|
80 |
.files(src.resolve("javax/lang/model/element/Extra.java")) |
|
81 |
.run() |
|
82 |
.writeAll() |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
83 |
.getOutput(Task.OutputKind.DIRECT); |
36526 | 84 |
|
85 |
if (!log.isEmpty()) |
|
86 |
throw new Exception("expected output not found: " + log); |
|
87 |
} |
|
88 |
||
89 |
@Test |
|
90 |
void testClassPath(Path base) throws Exception { |
|
91 |
Path cpSrc = base.resolve("cpSrc"); |
|
92 |
tb.writeJavaFiles(cpSrc, "package p; public interface Other { }"); |
|
93 |
Path cpClasses = base.resolve("cpClasses"); |
|
94 |
tb.createDirectories(cpClasses); |
|
95 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
96 |
String cpLog = new JavacTask(tb) |
36526 | 97 |
.outdir(cpClasses) |
98 |
.files(findJavaFiles(cpSrc)) |
|
99 |
.run() |
|
100 |
.writeAll() |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
101 |
.getOutput(Task.OutputKind.DIRECT); |
36526 | 102 |
|
103 |
if (!cpLog.isEmpty()) |
|
104 |
throw new Exception("expected output not found: " + cpLog); |
|
105 |
||
106 |
Path src = base.resolve("src"); |
|
107 |
//note: avoiding use of java.base, as that gets special handling on some places: |
|
108 |
tb.writeJavaFiles(src, "package javax.lang.model.element; public interface Extra extends Element, p.Other { }"); |
|
109 |
Path classes = base.resolve("classes"); |
|
110 |
tb.createDirectories(classes); |
|
111 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
112 |
String log = new JavacTask(tb) |
36526 | 113 |
.options("-Xmodule:java.compiler", "-classpath", cpClasses.toString()) |
114 |
.outdir(classes) |
|
115 |
.files(src.resolve("javax/lang/model/element/Extra.java")) |
|
116 |
.run() |
|
117 |
.writeAll() |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
118 |
.getOutput(Task.OutputKind.DIRECT); |
36526 | 119 |
|
120 |
if (!log.isEmpty()) |
|
121 |
throw new Exception("expected output not found: " + log); |
|
122 |
} |
|
123 |
||
124 |
@Test |
|
125 |
void testNoModuleInfoOnSourcePath(Path base) throws Exception { |
|
126 |
//note: avoiding use of java.base, as that gets special handling on some places: |
|
127 |
Path src = base.resolve("src"); |
|
128 |
tb.writeJavaFiles(src, |
|
129 |
"module java.compiler {}", |
|
130 |
"package javax.lang.model.element; public interface Extra { }"); |
|
131 |
Path classes = base.resolve("classes"); |
|
132 |
tb.createDirectories(classes); |
|
133 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
134 |
List<String> log = new JavacTask(tb) |
36526 | 135 |
.options("-XDrawDiagnostics", "-Xmodule:java.compiler") |
136 |
.outdir(classes) |
|
137 |
.files(findJavaFiles(src)) |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
138 |
.run(Task.Expect.FAIL) |
36526 | 139 |
.writeAll() |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
140 |
.getOutputLines(Task.OutputKind.DIRECT); |
36526 | 141 |
|
142 |
List<String> expected = Arrays.asList("Extra.java:1:1: compiler.err.module-info.with.xmodule.sourcepath", |
|
143 |
"1 error"); |
|
144 |
||
145 |
if (!expected.equals(log)) |
|
146 |
throw new Exception("expected output not found: " + log); |
|
147 |
} |
|
148 |
||
149 |
@Test |
|
150 |
void testNoModuleInfoInClassOutput(Path base) throws Exception { |
|
151 |
//note: avoiding use of java.base, as that gets special handling on some places: |
|
152 |
Path srcMod = base.resolve("src-mod"); |
|
153 |
tb.writeJavaFiles(srcMod, |
|
154 |
"module mod {}"); |
|
155 |
Path classes = base.resolve("classes"); |
|
156 |
tb.createDirectories(classes); |
|
157 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
158 |
String logMod = new JavacTask(tb) |
36526 | 159 |
.options() |
160 |
.outdir(classes) |
|
161 |
.files(findJavaFiles(srcMod)) |
|
162 |
.run() |
|
163 |
.writeAll() |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
164 |
.getOutput(Task.OutputKind.DIRECT); |
36526 | 165 |
|
166 |
if (!logMod.isEmpty()) |
|
167 |
throw new Exception("unexpected output found: " + logMod); |
|
168 |
||
169 |
Path src = base.resolve("src"); |
|
170 |
tb.writeJavaFiles(src, |
|
171 |
"package javax.lang.model.element; public interface Extra { }"); |
|
172 |
tb.createDirectories(classes); |
|
173 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
174 |
List<String> log = new JavacTask(tb) |
36526 | 175 |
.options("-XDrawDiagnostics", "-Xmodule:java.compiler") |
176 |
.outdir(classes) |
|
177 |
.files(findJavaFiles(src)) |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
178 |
.run(Task.Expect.FAIL) |
36526 | 179 |
.writeAll() |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
180 |
.getOutputLines(Task.OutputKind.DIRECT); |
36526 | 181 |
|
182 |
List<String> expected = Arrays.asList("Extra.java:1:1: compiler.err.module-info.with.xmodule.classpath", |
|
183 |
"1 error"); |
|
184 |
||
185 |
if (!expected.equals(log)) |
|
186 |
throw new Exception("expected output not found: " + log); |
|
187 |
} |
|
188 |
||
189 |
@Test |
|
190 |
void testModuleSourcePathXModule(Path base) throws Exception { |
|
191 |
//note: avoiding use of java.base, as that gets special handling on some places: |
|
192 |
Path src = base.resolve("src"); |
|
193 |
tb.writeJavaFiles(src, "package javax.lang.model.element; public interface Extra extends Element { }"); |
|
194 |
Path classes = base.resolve("classes"); |
|
195 |
tb.createDirectories(classes); |
|
196 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
197 |
List<String> log = new JavacTask(tb) |
36526 | 198 |
.options("-XDrawDiagnostics", "-Xmodule:java.compiler", "-modulesourcepath", src.toString()) |
199 |
.outdir(classes) |
|
200 |
.files(findJavaFiles(src)) |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
201 |
.run(Task.Expect.FAIL) |
36526 | 202 |
.writeAll() |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
203 |
.getOutputLines(Task.OutputKind.DIRECT); |
36526 | 204 |
|
205 |
List<String> expected = Arrays.asList("- compiler.err.xmodule.no.module.sourcepath", |
|
206 |
"1 error"); |
|
207 |
||
208 |
if (!expected.equals(log)) |
|
209 |
throw new Exception("expected output not found: " + log); |
|
210 |
} |
|
211 |
||
212 |
@Test |
|
213 |
void testXModuleTooMany(Path base) throws Exception { |
|
214 |
//note: avoiding use of java.base, as that gets special handling on some places: |
|
215 |
Path src = base.resolve("src"); |
|
216 |
tb.writeJavaFiles(src, "package javax.lang.model.element; public interface Extra extends Element { }"); |
|
217 |
Path classes = base.resolve("classes"); |
|
218 |
tb.createDirectories(classes); |
|
219 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
220 |
List<String> log = new JavacTask(tb, Task.Mode.CMDLINE) |
36526 | 221 |
.options("-XDrawDiagnostics", "-Xmodule:java.compiler", "-Xmodule:java.compiler") |
222 |
.outdir(classes) |
|
223 |
.files(findJavaFiles(src)) |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
224 |
.run(Task.Expect.FAIL) |
36526 | 225 |
.writeAll() |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
226 |
.getOutputLines(Task.OutputKind.DIRECT); |
36526 | 227 |
|
228 |
List<String> expected = Arrays.asList("javac: option -Xmodule: can only be specified once", |
|
229 |
"Usage: javac <options> <source files>", |
|
230 |
"use -help for a list of possible options"); |
|
231 |
||
232 |
if (!expected.equals(log)) |
|
233 |
throw new Exception("expected output not found: " + log); |
|
234 |
} |
|
235 |
||
236 |
@Test |
|
237 |
void testWithModulePath(Path base) throws Exception { |
|
238 |
Path module = base.resolve("modules"); |
|
239 |
new ModuleBuilder("m1") |
|
240 |
.classes("package pkg1; public interface E { }") |
|
241 |
.build(module); |
|
242 |
||
243 |
Path src = base.resolve("src"); |
|
244 |
tb.writeJavaFiles(src, "package p; interface A extends pkg1.E { }"); |
|
245 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
246 |
new JavacTask(tb, Task.Mode.CMDLINE) |
36526 | 247 |
.options("-modulepath", module.toString(), |
248 |
"-Xmodule:m1") |
|
249 |
.files(findJavaFiles(src)) |
|
250 |
.run() |
|
251 |
.writeAll(); |
|
252 |
||
253 |
//checks module bounds still exist |
|
254 |
new ModuleBuilder("m2") |
|
255 |
.classes("package pkg2; public interface D { }") |
|
256 |
.build(module); |
|
257 |
||
258 |
Path src2 = base.resolve("src2"); |
|
259 |
tb.writeJavaFiles(src2, "package p; interface A extends pkg2.D { }"); |
|
260 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
261 |
List<String> log = new JavacTask(tb, Task.Mode.CMDLINE) |
36526 | 262 |
.options("-XDrawDiagnostics", |
263 |
"-modulepath", module.toString(), |
|
264 |
"-Xmodule:m1") |
|
265 |
.files(findJavaFiles(src2)) |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
266 |
.run(Task.Expect.FAIL) |
36526 | 267 |
.writeAll() |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
268 |
.getOutputLines(Task.OutputKind.DIRECT); |
36526 | 269 |
|
270 |
List<String> expected = Arrays.asList("A.java:1:36: compiler.err.doesnt.exist: pkg2", |
|
271 |
"1 error"); |
|
272 |
||
273 |
if (!expected.equals(log)) |
|
274 |
throw new Exception("expected output not found: " + log); |
|
275 |
} |
|
276 |
||
277 |
@Test |
|
278 |
void testWithUpgradeModulePath(Path base) throws Exception { |
|
279 |
Path module = base.resolve("modules"); |
|
280 |
new ModuleBuilder("m1") |
|
281 |
.classes("package pkg1; public interface E { }") |
|
282 |
.build(module); |
|
283 |
||
284 |
Path upgrade = base.resolve("upgrade"); |
|
285 |
new ModuleBuilder("m1") |
|
286 |
.classes("package pkg1; public interface D { }") |
|
287 |
.build(upgrade); |
|
288 |
||
289 |
Path src = base.resolve("src"); |
|
290 |
tb.writeJavaFiles(src, "package p; interface A extends pkg1.D { }"); |
|
291 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
292 |
new JavacTask(tb, Task.Mode.CMDLINE) |
36526 | 293 |
.options("-modulepath", module.toString(), |
294 |
"-upgrademodulepath", upgrade.toString(), |
|
295 |
"-Xmodule:m1") |
|
296 |
.files(findJavaFiles(src)) |
|
297 |
.run() |
|
298 |
.writeAll(); |
|
299 |
} |
|
300 |
} |