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
|
|
31 |
* jdk.jdeps/com.sun.tools.javap
|
|
32 |
* @build ToolBox ModuleTestBase
|
|
33 |
* @run main MultiModuleModeTest
|
|
34 |
*/
|
|
35 |
|
|
36 |
import java.nio.file.Files;
|
|
37 |
import java.nio.file.Path;
|
|
38 |
import java.util.ArrayList;
|
|
39 |
import java.util.Arrays;
|
|
40 |
import java.util.List;
|
|
41 |
|
|
42 |
public class MultiModuleModeTest extends ModuleTestBase {
|
|
43 |
|
|
44 |
public static void main(String... args) throws Exception {
|
|
45 |
new MultiModuleModeTest().runTests();
|
|
46 |
}
|
|
47 |
|
|
48 |
@Test
|
|
49 |
void testDuplicateModules(Path base) throws Exception {
|
|
50 |
Path src = base.resolve("src");
|
|
51 |
Path src_m1 = src.resolve("m1");
|
|
52 |
tb.writeJavaFiles(src_m1, "module m1 { }");
|
|
53 |
Path src_m2 = src.resolve("m2");
|
|
54 |
tb.writeJavaFiles(src_m2, "module m1 { }");
|
|
55 |
Path classes = base.resolve("classes");
|
|
56 |
tb.createDirectories(classes);
|
|
57 |
|
|
58 |
String log = tb.new JavacTask()
|
|
59 |
.options("-XDrawDiagnostics",
|
|
60 |
"-modulesourcepath", src.toString())
|
|
61 |
.outdir(classes)
|
|
62 |
.files(findJavaFiles(src))
|
|
63 |
.run(ToolBox.Expect.FAIL)
|
|
64 |
.writeAll()
|
|
65 |
.getOutput(ToolBox.OutputKind.DIRECT);
|
|
66 |
|
|
67 |
if (!log.contains("module-info.java:1:1: compiler.err.duplicate.module: m1"))
|
|
68 |
throw new Exception("expected output not found");
|
|
69 |
}
|
|
70 |
|
|
71 |
@Test
|
|
72 |
void testCantFindModule(Path base) throws Exception {
|
|
73 |
Path src = base.resolve("src");
|
|
74 |
Path src_m1 = src.resolve("m1");
|
|
75 |
tb.writeJavaFiles(src_m1, "module m1 { }");
|
|
76 |
Path misc = base.resolve("misc");
|
|
77 |
tb.writeJavaFiles(misc, "package p; class C { }");
|
|
78 |
Path classes = base.resolve("classes");
|
|
79 |
tb.createDirectories(classes);
|
|
80 |
|
|
81 |
String log = tb.new JavacTask()
|
|
82 |
.options("-XDrawDiagnostics",
|
|
83 |
"-modulesourcepath", src.toString())
|
|
84 |
.outdir(classes)
|
|
85 |
.files(join(findJavaFiles(src), findJavaFiles(misc)))
|
|
86 |
.run(ToolBox.Expect.FAIL)
|
|
87 |
.writeAll()
|
|
88 |
.getOutput(ToolBox.OutputKind.DIRECT);
|
|
89 |
|
|
90 |
if (!log.contains("C.java:1:1: compiler.err.unnamed.pkg.not.allowed.named.modules"))
|
|
91 |
throw new Exception("expected output not found");
|
|
92 |
}
|
|
93 |
|
|
94 |
@Test
|
|
95 |
void testModuleNameMismatch(Path base) throws Exception {
|
|
96 |
Path src = base.resolve("src");
|
|
97 |
Path src_m1 = src.resolve("m1");
|
|
98 |
tb.writeJavaFiles(src_m1, "module m2 { }");
|
|
99 |
Path classes = base.resolve("classes");
|
|
100 |
tb.createDirectories(classes);
|
|
101 |
|
|
102 |
String log = tb.new JavacTask()
|
|
103 |
.options("-XDrawDiagnostics",
|
|
104 |
"-modulesourcepath", src.toString())
|
|
105 |
.outdir(classes)
|
|
106 |
.files(findJavaFiles(src))
|
|
107 |
.run(ToolBox.Expect.FAIL)
|
|
108 |
.writeAll()
|
|
109 |
.getOutput(ToolBox.OutputKind.DIRECT);
|
|
110 |
|
|
111 |
if (!log.contains("module-info.java:1:8: compiler.err.module.name.mismatch: m2, m1"))
|
|
112 |
throw new Exception("expected output not found");
|
|
113 |
}
|
|
114 |
|
|
115 |
@Test
|
|
116 |
void testImplicitModuleSource(Path base) throws Exception {
|
|
117 |
Path src = base.resolve("src");
|
|
118 |
tb.writeJavaFiles(src.resolve("m1"), "module m1 { }");
|
|
119 |
tb.writeJavaFiles(src.resolve("m2"), "module m2 { requires m1; }");
|
|
120 |
Path modules = base.resolve("modules");
|
|
121 |
Files.createDirectories(modules);
|
|
122 |
|
|
123 |
tb.new JavacTask()
|
|
124 |
.options("-modulesourcepath", src.toString())
|
|
125 |
.outdir(modules)
|
|
126 |
.files(src.resolve("m2/module-info.java"))
|
|
127 |
.run()
|
|
128 |
.writeAll();
|
|
129 |
}
|
|
130 |
|
|
131 |
@Test
|
|
132 |
void testImplicitModuleClass(Path base) throws Exception {
|
|
133 |
Path src1 = base.resolve("src1");
|
|
134 |
tb.writeJavaFiles(src1.resolve("m1"), "module m1 { }");
|
|
135 |
Path modules1 = base.resolve("modules1");
|
|
136 |
Files.createDirectories(modules1);
|
|
137 |
|
|
138 |
tb.new JavacTask()
|
|
139 |
.options("-modulesourcepath", src1.toString())
|
|
140 |
.outdir(modules1)
|
|
141 |
.files(src1.resolve("m1/module-info.java"))
|
|
142 |
.run()
|
|
143 |
.writeAll();
|
|
144 |
|
|
145 |
Path src2= base.resolve("src2");
|
|
146 |
tb.writeJavaFiles(src2.resolve("m2"), "module m2 { requires m1; }");
|
|
147 |
Path modules2 = base.resolve("modules2");
|
|
148 |
Files.createDirectories(modules2);
|
|
149 |
|
|
150 |
tb.new JavacTask()
|
|
151 |
.options("-modulepath", modules1.toString(),
|
|
152 |
"-modulesourcepath", src2.toString())
|
|
153 |
.outdir(modules2)
|
|
154 |
.files(src2.resolve("m2/module-info.java"))
|
|
155 |
.run()
|
|
156 |
.writeAll();
|
|
157 |
}
|
|
158 |
|
|
159 |
Path[] join(Path[] a, Path[] b) {
|
|
160 |
List<Path> result = new ArrayList<>();
|
|
161 |
result.addAll(Arrays.asList(a));
|
|
162 |
result.addAll(Arrays.asList(b));
|
|
163 |
return result.toArray(new Path[result.size()]);
|
|
164 |
}
|
|
165 |
}
|