author | jjg |
Fri, 17 Jun 2016 17:40:01 -0700 | |
changeset 39103 | 91a64ec5b970 |
parent 37758 | 3ecf9b414e05 |
child 40308 | 274367a99f98 |
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 test module/package conflicts |
|
27 |
* @library /tools/lib |
|
28 |
* @modules |
|
29 |
* jdk.compiler/com.sun.tools.javac.api |
|
30 |
* jdk.compiler/com.sun.tools.javac.main |
|
37758 | 31 |
* @build toolbox.ToolBox toolbox.JavacTask toolbox.ModuleBuilder ModuleTestBase |
36526 | 32 |
* @run main PackageConflictTest |
33 |
*/ |
|
34 |
||
35 |
import java.nio.file.Files; |
|
36 |
import java.nio.file.Path; |
|
37 |
import java.util.Arrays; |
|
38 |
import java.util.List; |
|
39 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
40 |
import toolbox.JavacTask; |
37758 | 41 |
import toolbox.ModuleBuilder; |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
42 |
import toolbox.Task; |
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
43 |
import toolbox.ToolBox; |
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
44 |
|
36526 | 45 |
public class PackageConflictTest extends ModuleTestBase { |
46 |
public static void main(String... args) throws Exception { |
|
47 |
PackageConflictTest t = new PackageConflictTest(); |
|
48 |
t.runTests(); |
|
49 |
} |
|
50 |
||
51 |
@Test |
|
37758 | 52 |
public void testSimple(Path base) throws Exception { |
36526 | 53 |
Path src = base.resolve("src"); |
54 |
tb.writeJavaFiles(src, |
|
55 |
"package java.util; public class MyList { }"); |
|
56 |
Path classes = base.resolve("classes"); |
|
57 |
Files.createDirectories(classes); |
|
58 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
59 |
String log = new JavacTask(tb) |
36526 | 60 |
.options("-XDrawDiagnostics") |
61 |
.outdir(classes) |
|
62 |
.files(findJavaFiles(src)) |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
63 |
.run(Task.Expect.FAIL) |
36526 | 64 |
.writeAll() |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
65 |
.getOutput(Task.OutputKind.DIRECT); |
36526 | 66 |
|
67 |
if (!log.contains("MyList.java:1:1: compiler.err.package.in.other.module: java.base")) |
|
68 |
throw new Exception("expected output not found"); |
|
69 |
} |
|
70 |
||
71 |
@Test |
|
37758 | 72 |
public void testDisjoint(Path base) throws Exception { |
36526 | 73 |
Path m1 = base.resolve("m1"); |
74 |
Path m2 = base.resolve("m2"); |
|
75 |
tb.writeJavaFiles(m1, |
|
76 |
"module m1 { }", |
|
77 |
"package test; public class A { }"); |
|
78 |
tb.writeJavaFiles(m2, |
|
79 |
"module m2 { }", |
|
80 |
"package test; public class B { }"); |
|
81 |
Path classes = base.resolve("classes"); |
|
82 |
Files.createDirectories(classes); |
|
83 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
84 |
new JavacTask(tb) |
36526 | 85 |
.options("-Werror", "-modulesourcepath", base.toString()) |
86 |
.outdir(classes) |
|
87 |
.files(findJavaFiles(base)) |
|
88 |
.run() |
|
89 |
.writeAll(); |
|
90 |
} |
|
91 |
||
92 |
@Test |
|
37758 | 93 |
public void testConflictInDependencies(Path base) throws Exception { |
36526 | 94 |
Path m1 = base.resolve("m1"); |
95 |
Path m2 = base.resolve("m2"); |
|
96 |
Path m3 = base.resolve("m3"); |
|
97 |
tb.writeJavaFiles(m1, |
|
98 |
"module m1 { exports test; }", |
|
99 |
"package test; public class A { }"); |
|
100 |
tb.writeJavaFiles(m2, |
|
101 |
"module m2 { exports test; }", |
|
102 |
"package test; public class B { }"); |
|
103 |
tb.writeJavaFiles(m3, |
|
104 |
"module m3 { requires m1; requires m2; }", |
|
105 |
"package impl; public class Impl { }"); |
|
106 |
Path classes = base.resolve("classes"); |
|
107 |
Files.createDirectories(classes); |
|
108 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
109 |
List<String> log = new JavacTask(tb) |
36526 | 110 |
.options("-XDrawDiagnostics", "-modulesourcepath", base.toString()) |
111 |
.outdir(classes) |
|
112 |
.files(findJavaFiles(base)) |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
113 |
.run(Task.Expect.FAIL) |
36526 | 114 |
.writeAll() |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
115 |
.getOutputLines(Task.OutputKind.DIRECT); |
36526 | 116 |
|
117 |
List<String> expected = |
|
118 |
Arrays.asList("module-info.java:1:1: compiler.err.package.clash.from.requires: m3, test, m1, m2", |
|
119 |
"1 error"); |
|
120 |
||
121 |
if (!expected.equals(log)) { |
|
122 |
throw new AssertionError("Unexpected output: " + log); |
|
123 |
} |
|
124 |
} |
|
125 |
||
126 |
@Test |
|
37758 | 127 |
public void testSimple2(Path base) throws Exception { |
39103
91a64ec5b970
8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents:
37758
diff
changeset
|
128 |
Path modSrc = base.resolve("modSrc"); |
36526 | 129 |
Path modules = base.resolve("modules"); |
37758 | 130 |
new ModuleBuilder(tb, "N") |
36526 | 131 |
.exports("pack") |
132 |
.classes("package pack; public class A { }") |
|
133 |
.build(modules); |
|
37758 | 134 |
new ModuleBuilder(tb, "M") |
36526 | 135 |
.requires("N") |
136 |
.classes("package pack; public class B { pack.A f; }") |
|
39103
91a64ec5b970
8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents:
37758
diff
changeset
|
137 |
.write(modSrc); |
36526 | 138 |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
139 |
String log = new JavacTask(tb) |
36526 | 140 |
.options("-XDrawDiagnostics", "-mp", modules.toString()) |
141 |
.outdir(Files.createDirectories(base.resolve("classes"))) |
|
39103
91a64ec5b970
8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents:
37758
diff
changeset
|
142 |
.files(findJavaFiles(modSrc.resolve("M"))) |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
143 |
.run(Task.Expect.FAIL) |
36526 | 144 |
.writeAll() |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
145 |
.getOutput(Task.OutputKind.DIRECT); |
36526 | 146 |
|
147 |
if (!log.contains("B.java:1:1: compiler.err.package.in.other.module: N")) |
|
148 |
throw new Exception("expected output not found"); |
|
149 |
} |
|
150 |
||
151 |
@Test |
|
37758 | 152 |
public void testPrivateConflict(Path base) throws Exception { |
39103
91a64ec5b970
8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents:
37758
diff
changeset
|
153 |
Path modSrc = base.resolve("modSrc"); |
37758 | 154 |
new ModuleBuilder(tb, "N") |
36526 | 155 |
.exports("publ") |
156 |
.classes("package pack; public class A { }") |
|
157 |
.classes("package publ; public class B { }") |
|
39103
91a64ec5b970
8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents:
37758
diff
changeset
|
158 |
.write(modSrc); |
37758 | 159 |
new ModuleBuilder(tb, "M") |
36526 | 160 |
.requires("N") |
161 |
.classes("package pack; public class C { publ.B b; }") |
|
39103
91a64ec5b970
8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents:
37758
diff
changeset
|
162 |
.write(modSrc); |
36526 | 163 |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
164 |
String log = new JavacTask(tb) |
39103
91a64ec5b970
8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents:
37758
diff
changeset
|
165 |
.options("-XDrawDiagnostics", "-modulesourcepath", modSrc.toString()) |
36526 | 166 |
.outdir(Files.createDirectories(base.resolve("classes"))) |
39103
91a64ec5b970
8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents:
37758
diff
changeset
|
167 |
.files(findJavaFiles(modSrc)) |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
168 |
.run(Task.Expect.SUCCESS) |
36526 | 169 |
.writeAll() |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
170 |
.getOutput(Task.OutputKind.DIRECT); |
36526 | 171 |
|
172 |
if (!log.contains("")) |
|
173 |
throw new Exception("unexpected output not found"); |
|
174 |
||
175 |
} |
|
176 |
||
177 |
@Test |
|
37758 | 178 |
public void testPrivateConflictOnModulePath(Path base) throws Exception { |
39103
91a64ec5b970
8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents:
37758
diff
changeset
|
179 |
Path modSrc = base.resolve("modSrc"); |
36526 | 180 |
Path modules = base.resolve("modules"); |
37758 | 181 |
new ModuleBuilder(tb, "N") |
36526 | 182 |
.exports("publ") |
183 |
.classes("package pack; public class A { }") |
|
184 |
.classes("package publ; public class B { }") |
|
185 |
.build(modules); |
|
37758 | 186 |
new ModuleBuilder(tb, "M") |
36526 | 187 |
.requires("N") |
188 |
.classes("package pack; public class C { publ.B b; }") |
|
39103
91a64ec5b970
8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents:
37758
diff
changeset
|
189 |
.write(modSrc); |
36526 | 190 |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
191 |
String log = new JavacTask(tb) |
36526 | 192 |
.options("-XDrawDiagnostics", "-mp", modules.toString()) |
193 |
.outdir(Files.createDirectories(base.resolve("classes"))) |
|
39103
91a64ec5b970
8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents:
37758
diff
changeset
|
194 |
.files(findJavaFiles(modSrc.resolve("M"))) |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
195 |
.run(Task.Expect.SUCCESS) |
36526 | 196 |
.writeAll() |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
197 |
.getOutput(Task.OutputKind.DIRECT); |
36526 | 198 |
|
199 |
if (!log.contains("")) |
|
200 |
throw new Exception("expected output not found"); |
|
201 |
||
202 |
} |
|
203 |
||
204 |
@Test |
|
37758 | 205 |
public void testRequiresConflictExports(Path base) throws Exception { |
39103
91a64ec5b970
8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents:
37758
diff
changeset
|
206 |
Path modSrc = base.resolve("modSrc"); |
36526 | 207 |
Path modules = base.resolve("modules"); |
37758 | 208 |
new ModuleBuilder(tb, "M") |
36526 | 209 |
.exports("pack") |
210 |
.classes("package pack; public class A { }") |
|
211 |
.build(modules); |
|
37758 | 212 |
new ModuleBuilder(tb, "N") |
36526 | 213 |
.exports("pack") |
214 |
.classes("package pack; public class B { }") |
|
215 |
.build(modules); |
|
37758 | 216 |
new ModuleBuilder(tb, "K") |
36526 | 217 |
.requires("M") |
218 |
.requires("N") |
|
219 |
.classes("package pkg; public class C { pack.A a; pack.B b; }") |
|
39103
91a64ec5b970
8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents:
37758
diff
changeset
|
220 |
.write(modSrc); |
36526 | 221 |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
222 |
List<String> log = new JavacTask(tb) |
36526 | 223 |
.options("-XDrawDiagnostics", "-mp", modules.toString()) |
224 |
.outdir(Files.createDirectories(base.resolve("classes"))) |
|
39103
91a64ec5b970
8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents:
37758
diff
changeset
|
225 |
.files(findJavaFiles(modSrc.resolve("K"))) |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
226 |
.run(Task.Expect.FAIL) |
36526 | 227 |
.writeAll() |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
228 |
.getOutputLines(Task.OutputKind.DIRECT); |
36526 | 229 |
|
230 |
List<String> expected = |
|
231 |
Arrays.asList("module-info.java:1:1: compiler.err.package.clash.from.requires: K, pack, M, N", |
|
232 |
"1 error"); |
|
233 |
if (!log.containsAll(expected)) |
|
234 |
throw new Exception("expected output not found"); |
|
235 |
} |
|
236 |
||
237 |
@Test |
|
39103
91a64ec5b970
8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents:
37758
diff
changeset
|
238 |
public void testQualifiedExportsToDifferentModules(Path base) throws Exception { |
91a64ec5b970
8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents:
37758
diff
changeset
|
239 |
Path modSrc = base.resolve("modSrc"); |
91a64ec5b970
8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents:
37758
diff
changeset
|
240 |
new ModuleBuilder(tb, "U").write(modSrc); |
37758 | 241 |
new ModuleBuilder(tb, "M") |
36526 | 242 |
.exports("pkg to U") |
243 |
.classes("package pkg; public class A { public static boolean flagM; }") |
|
39103
91a64ec5b970
8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents:
37758
diff
changeset
|
244 |
.write(modSrc); |
37758 | 245 |
new ModuleBuilder(tb, "N") |
36526 | 246 |
.exports("pkg to K") |
247 |
.classes("package pkg; public class A { public static boolean flagN; }") |
|
39103
91a64ec5b970
8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents:
37758
diff
changeset
|
248 |
.write(modSrc); |
37758 | 249 |
ModuleBuilder moduleK = new ModuleBuilder(tb, "K"); |
36526 | 250 |
moduleK.requires("M") |
251 |
.requires("N") |
|
252 |
.classes("package p; public class DependsOnN { boolean f = pkg.A.flagN; } ") |
|
39103
91a64ec5b970
8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents:
37758
diff
changeset
|
253 |
.write(modSrc); |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
254 |
new JavacTask(tb) |
39103
91a64ec5b970
8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents:
37758
diff
changeset
|
255 |
.options("-modulesourcepath", modSrc.toString()) |
36526 | 256 |
.outdir(Files.createDirectories(base.resolve("classes"))) |
39103
91a64ec5b970
8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents:
37758
diff
changeset
|
257 |
.files(findJavaFiles(modSrc.resolve("K"))) |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
258 |
.run(Task.Expect.SUCCESS) |
36526 | 259 |
.writeAll(); |
260 |
||
261 |
//negative case |
|
262 |
moduleK.classes("package pkg; public class DuplicatePackage { } ") |
|
263 |
.classes("package p; public class DependsOnM { boolean f = pkg.A.flagM; } ") |
|
39103
91a64ec5b970
8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents:
37758
diff
changeset
|
264 |
.write(modSrc); |
36526 | 265 |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
266 |
List<String> output = new JavacTask(tb) |
36526 | 267 |
.options("-XDrawDiagnostics", |
39103
91a64ec5b970
8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents:
37758
diff
changeset
|
268 |
"-modulesourcepath", modSrc.toString()) |
36526 | 269 |
.outdir(Files.createDirectories(base.resolve("classes"))) |
39103
91a64ec5b970
8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents:
37758
diff
changeset
|
270 |
.files(findJavaFiles(modSrc.resolve("K"))) |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
271 |
.run(Task.Expect.FAIL) |
36526 | 272 |
.writeAll() |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
273 |
.getOutputLines(Task.OutputKind.DIRECT); |
36526 | 274 |
|
275 |
List<String> expected = Arrays.asList( |
|
276 |
"DependsOnM.java:1:55: compiler.err.cant.resolve.location: kindname.variable, flagM, , , (compiler.misc.location: kindname.class, pkg.A, null)"); |
|
277 |
if (!output.containsAll(expected)) { |
|
278 |
throw new Exception("expected output not found"); |
|
279 |
} |
|
280 |
} |
|
281 |
} |