author | darcy |
Fri, 02 Feb 2018 10:29:25 -0800 | |
changeset 48723 | 6cb86bf0b51e |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
36526 | 1 |
/* |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
2 |
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. |
36526 | 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 module graph resolution issues |
|
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.JarTask toolbox.JavacTask toolbox.ModuleBuilder |
32 |
* ModuleTestBase |
|
36526 | 33 |
* @run main GraphsTest |
34 |
*/ |
|
35 |
||
36 |
import java.io.File; |
|
37 |
import java.nio.file.Files; |
|
38 |
import java.nio.file.Path; |
|
39 |
import java.util.Arrays; |
|
40 |
import java.util.List; |
|
41 |
import java.util.regex.Pattern; |
|
42 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
43 |
import toolbox.JarTask; |
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
44 |
import toolbox.JavacTask; |
37758 | 45 |
import toolbox.ModuleBuilder; |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
46 |
import toolbox.Task; |
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
47 |
import toolbox.ToolBox; |
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
48 |
|
36526 | 49 |
public class GraphsTest extends ModuleTestBase { |
50 |
||
51 |
public static void main(String... args) throws Exception { |
|
52 |
GraphsTest t = new GraphsTest(); |
|
53 |
t.runTests(); |
|
54 |
} |
|
55 |
||
56 |
/** |
|
57 |
* Tests diamond graph with an automatic module added in. |
|
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41932
diff
changeset
|
58 |
* +-------------+ +-----------------------+ +------------------+ |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41932
diff
changeset
|
59 |
* | module M | | module N | | module O | |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41932
diff
changeset
|
60 |
* | | -----> | | ---> | | --> J.jar |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41932
diff
changeset
|
61 |
* | require N | | requires transitive O | | | |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41932
diff
changeset
|
62 |
* | require L | | | +------------------+ |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41932
diff
changeset
|
63 |
* +-------------+ +-----------------------+ ^ |
36526 | 64 |
* | | |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41932
diff
changeset
|
65 |
* | +-----------------------+ | |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41932
diff
changeset
|
66 |
* ------------------>| module L | | |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41932
diff
changeset
|
67 |
* | |------------------ |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41932
diff
changeset
|
68 |
* | requires transitive O | |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41932
diff
changeset
|
69 |
* | | |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41932
diff
changeset
|
70 |
* +-----------------------+ |
36526 | 71 |
* |
72 |
*/ |
|
73 |
@Test |
|
37758 | 74 |
public void diamond(Path base) throws Exception { |
36526 | 75 |
|
39103
91a64ec5b970
8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents:
37758
diff
changeset
|
76 |
Path modSrc = Files.createDirectories(base.resolve("modSrc")); |
36526 | 77 |
Path modules = Files.createDirectories(base.resolve("modules")); |
78 |
||
37758 | 79 |
new ModuleBuilder(tb, "J") |
36526 | 80 |
.exports("openJ") |
81 |
.classes("package openJ; public class J { }") |
|
82 |
.classes("package closedJ; public class J { }") |
|
83 |
.build(base.resolve("jar")); |
|
84 |
||
85 |
Path jarModules = Files.createDirectories(base.resolve("jarModules")); |
|
86 |
Path jar = jarModules.resolve("J.jar"); |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
87 |
new JarTask(tb, jar) |
36526 | 88 |
.baseDir(base.resolve("jar/J")) |
89 |
.files(".") |
|
90 |
.run() |
|
91 |
.writeAll(); |
|
92 |
||
37758 | 93 |
new ModuleBuilder(tb, "O") |
36526 | 94 |
.exports("openO") |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41932
diff
changeset
|
95 |
.requiresTransitive("J", jarModules) |
36526 | 96 |
.classes("package openO; public class O { openJ.J j; }") |
97 |
.classes("package closedO; public class O { }") |
|
39103
91a64ec5b970
8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents:
37758
diff
changeset
|
98 |
.build(modSrc, modules); |
37758 | 99 |
new ModuleBuilder(tb, "N") |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41932
diff
changeset
|
100 |
.requiresTransitive("O", modules, jarModules) |
36526 | 101 |
.exports("openN") |
102 |
.classes("package openN; public class N { }") |
|
103 |
.classes("package closedN; public class N { }") |
|
39103
91a64ec5b970
8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents:
37758
diff
changeset
|
104 |
.build(modSrc, modules); |
37758 | 105 |
new ModuleBuilder(tb, "L") |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41932
diff
changeset
|
106 |
.requiresTransitive("O", modules, jarModules) |
36526 | 107 |
.exports("openL") |
108 |
.classes("package openL; public class L { }") |
|
109 |
.classes("package closedL; public class L { }") |
|
39103
91a64ec5b970
8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents:
37758
diff
changeset
|
110 |
.build(modSrc, modules); |
37758 | 111 |
ModuleBuilder m = new ModuleBuilder(tb, "M"); |
36526 | 112 |
//positive case |
113 |
Path positiveSrc = m |
|
114 |
.requires("N", modules) |
|
115 |
.requires("L", modules) |
|
116 |
.classes("package p; public class Positive { openO.O o; openN.N n; openL.L l; }") |
|
117 |
.write(base.resolve("positiveSrc")); |
|
118 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
119 |
new JavacTask(tb) |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
39103
diff
changeset
|
120 |
.options("-XDrawDiagnostics", "-p", modules + File.pathSeparator + jarModules) |
36526 | 121 |
.outdir(Files.createDirectories(base.resolve("positive"))) |
122 |
.files(findJavaFiles(positiveSrc)) |
|
123 |
.run() |
|
124 |
.writeAll(); |
|
125 |
//negative case |
|
126 |
Path negativeSrc = m.classes("package p; public class Negative { closedO.O o; closedN.N n; closedL.L l; }") |
|
127 |
.write(base.resolve("negativeSrc")); |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
128 |
List<String> log = new JavacTask(tb) |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
39103
diff
changeset
|
129 |
.options("-XDrawDiagnostics", "-p", modules + File.pathSeparator + jarModules) |
36526 | 130 |
.outdir(Files.createDirectories(base.resolve("negative"))) |
131 |
.files(findJavaFiles(negativeSrc)) |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
132 |
.run(Task.Expect.FAIL) |
36526 | 133 |
.writeAll() |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
134 |
.getOutputLines(Task.OutputKind.DIRECT); |
36526 | 135 |
|
136 |
List<String> expected = Arrays.asList( |
|
43138
680d378b9d64
8169197: Improve error reporting for compiling against unexported package
jlahoda
parents:
42407
diff
changeset
|
137 |
"Negative.java:1:36: compiler.err.package.not.visible: closedO, (compiler.misc.not.def.access.not.exported: closedO, O)", |
680d378b9d64
8169197: Improve error reporting for compiling against unexported package
jlahoda
parents:
42407
diff
changeset
|
138 |
"Negative.java:1:49: compiler.err.package.not.visible: closedN, (compiler.misc.not.def.access.not.exported: closedN, N)", |
680d378b9d64
8169197: Improve error reporting for compiling against unexported package
jlahoda
parents:
42407
diff
changeset
|
139 |
"Negative.java:1:62: compiler.err.package.not.visible: closedL, (compiler.misc.not.def.access.not.exported: closedL, L)"); |
36526 | 140 |
if (!log.containsAll(expected)) { |
141 |
throw new Exception("Expected output not found"); |
|
142 |
} |
|
143 |
//multi module mode |
|
39103
91a64ec5b970
8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents:
37758
diff
changeset
|
144 |
m.write(modSrc); |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
145 |
List<String> out = new JavacTask(tb) |
36526 | 146 |
.options("-XDrawDiagnostics", |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
39103
diff
changeset
|
147 |
"--module-source-path", modSrc.toString(), |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
39103
diff
changeset
|
148 |
"-p", jarModules.toString() |
36526 | 149 |
) |
150 |
.outdir(Files.createDirectories(base.resolve("negative"))) |
|
39103
91a64ec5b970
8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents:
37758
diff
changeset
|
151 |
.files(findJavaFiles(modSrc)) |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
152 |
.run(Task.Expect.FAIL) |
36526 | 153 |
.writeAll() |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
154 |
.getOutputLines(Task.OutputKind.DIRECT); |
36526 | 155 |
expected = Arrays.asList( |
43138
680d378b9d64
8169197: Improve error reporting for compiling against unexported package
jlahoda
parents:
42407
diff
changeset
|
156 |
"Negative.java:1:36: compiler.err.package.not.visible: closedO, (compiler.misc.not.def.access.not.exported: closedO, O)", |
680d378b9d64
8169197: Improve error reporting for compiling against unexported package
jlahoda
parents:
42407
diff
changeset
|
157 |
"Negative.java:1:49: compiler.err.package.not.visible: closedN, (compiler.misc.not.def.access.not.exported: closedN, N)", |
680d378b9d64
8169197: Improve error reporting for compiling against unexported package
jlahoda
parents:
42407
diff
changeset
|
158 |
"Negative.java:1:62: compiler.err.package.not.visible: closedL, (compiler.misc.not.def.access.not.exported: closedL, L)"); |
36526 | 159 |
if (!out.containsAll(expected)) { |
160 |
throw new Exception("Expected output not found"); |
|
161 |
} |
|
162 |
//checks if the output does not contain messages about exported packages. |
|
163 |
Pattern regex = Pattern.compile("compiler\\.err.*(openO\\.O|openN\\.N|openL\\.L)"); |
|
164 |
for (String s : out) { |
|
165 |
if (regex.matcher(s).find()) { |
|
166 |
throw new Exception("Unexpected output: " + s); |
|
167 |
} |
|
168 |
} |
|
169 |
} |
|
170 |
||
171 |
/** |
|
172 |
* Tests graph where module M reexport package of N, but N export the package only to M. |
|
173 |
* |
|
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41932
diff
changeset
|
174 |
+-------------+ +------------------------+ +---------------+ |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41932
diff
changeset
|
175 |
| module L | | module M | | module N | |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41932
diff
changeset
|
176 |
| | -----> | | -----> | | |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41932
diff
changeset
|
177 |
| requires M | | requires transitive N | | exports P to M| |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41932
diff
changeset
|
178 |
+-------------+ | | +---------------+ |
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41932
diff
changeset
|
179 |
+------------------------+ |
36526 | 180 |
*/ |
181 |
@Test |
|
182 |
public void reexportOfQualifiedExport(Path base) throws Exception { |
|
39103
91a64ec5b970
8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents:
37758
diff
changeset
|
183 |
Path modSrc = base.resolve("modSrc"); |
37758 | 184 |
new ModuleBuilder(tb, "M") |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41932
diff
changeset
|
185 |
.requiresTransitive("N") |
39103
91a64ec5b970
8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents:
37758
diff
changeset
|
186 |
.write(modSrc); |
37758 | 187 |
new ModuleBuilder(tb, "N") |
36526 | 188 |
.exportsTo("pack", "M") |
189 |
.classes("package pack; public class Clazz { }") |
|
39103
91a64ec5b970
8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents:
37758
diff
changeset
|
190 |
.write(modSrc); |
37758 | 191 |
new ModuleBuilder(tb, "L") |
36526 | 192 |
.requires("M") |
193 |
.classes("package p; public class A { A(pack.Clazz cl){} } ") |
|
39103
91a64ec5b970
8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents:
37758
diff
changeset
|
194 |
.write(modSrc); |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
195 |
String log = new JavacTask(tb) |
36526 | 196 |
.options("-XDrawDiagnostics", |
40599
be40838eb215
8164887: update tests to remove use of old-style options
jjg
parents:
40308
diff
changeset
|
197 |
"--module-source-path", modSrc.toString()) |
36526 | 198 |
.outdir(Files.createDirectories(base.resolve("negative"))) |
39103
91a64ec5b970
8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents:
37758
diff
changeset
|
199 |
.files(findJavaFiles(modSrc)) |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
200 |
.run(Task.Expect.FAIL) |
36526 | 201 |
.writeAll() |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
202 |
.getOutput(Task.OutputKind.DIRECT); |
36526 | 203 |
|
43138
680d378b9d64
8169197: Improve error reporting for compiling against unexported package
jlahoda
parents:
42407
diff
changeset
|
204 |
String expected = "A.java:1:31: compiler.err.package.not.visible: pack, (compiler.misc.not.def.access.not.exported.to.module: pack, N, L)"; |
36526 | 205 |
if (!log.contains(expected)) { |
206 |
throw new Exception("Expected output not found"); |
|
207 |
} |
|
208 |
} |
|
209 |
} |