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 |
/* |
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 |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
31 |
* @build toolbox.ToolBox toolbox.JarTask toolbox.JavacTask ModuleTestBase |
36526 | 32 |
* @run main GraphsTest |
33 |
*/ |
|
34 |
||
35 |
import java.io.File; |
|
36 |
import java.nio.file.Files; |
|
37 |
import java.nio.file.Path; |
|
38 |
import java.util.Arrays; |
|
39 |
import java.util.List; |
|
40 |
import java.util.regex.Pattern; |
|
41 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
42 |
import toolbox.JarTask; |
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
43 |
import toolbox.JavacTask; |
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
44 |
import toolbox.Task; |
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
45 |
import toolbox.ToolBox; |
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
46 |
|
36526 | 47 |
public class GraphsTest extends ModuleTestBase { |
48 |
||
49 |
public static void main(String... args) throws Exception { |
|
50 |
GraphsTest t = new GraphsTest(); |
|
51 |
t.runTests(); |
|
52 |
} |
|
53 |
||
54 |
/** |
|
55 |
* Tests diamond graph with an automatic module added in. |
|
56 |
* +-------------+ +--------------------+ +------------------+ |
|
57 |
* | module M | | module N | | module O | |
|
58 |
* | | -----> | | ---> | | --> J.jar |
|
59 |
* | require N | | requires public O | | | |
|
60 |
* | require L | | | +------------------+ |
|
61 |
* +-------------+ +--------------------+ ^ |
|
62 |
* | | |
|
63 |
* | +--------------------+ | |
|
64 |
* ------------------>| module L | | |
|
65 |
* | |------------------ |
|
66 |
* | requires public O | |
|
67 |
* | | |
|
68 |
* +--------------------+ |
|
69 |
* |
|
70 |
*/ |
|
71 |
@Test |
|
72 |
void diamond(Path base) throws Exception { |
|
73 |
||
74 |
Path modules = Files.createDirectories(base.resolve("modules")); |
|
75 |
||
76 |
new ModuleBuilder("J") |
|
77 |
.exports("openJ") |
|
78 |
.classes("package openJ; public class J { }") |
|
79 |
.classes("package closedJ; public class J { }") |
|
80 |
.build(base.resolve("jar")); |
|
81 |
||
82 |
Path jarModules = Files.createDirectories(base.resolve("jarModules")); |
|
83 |
Path jar = jarModules.resolve("J.jar"); |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
84 |
new JarTask(tb, jar) |
36526 | 85 |
.baseDir(base.resolve("jar/J")) |
86 |
.files(".") |
|
87 |
.run() |
|
88 |
.writeAll(); |
|
89 |
||
90 |
new ModuleBuilder("O") |
|
91 |
.exports("openO") |
|
92 |
.requiresPublic("J", jarModules) |
|
93 |
.classes("package openO; public class O { openJ.J j; }") |
|
94 |
.classes("package closedO; public class O { }") |
|
95 |
.build(modules); |
|
96 |
new ModuleBuilder("N") |
|
97 |
.requiresPublic("O", modules, jarModules) |
|
98 |
.exports("openN") |
|
99 |
.classes("package openN; public class N { }") |
|
100 |
.classes("package closedN; public class N { }") |
|
101 |
.build(modules); |
|
102 |
new ModuleBuilder("L") |
|
103 |
.requiresPublic("O", modules, jarModules) |
|
104 |
.exports("openL") |
|
105 |
.classes("package openL; public class L { }") |
|
106 |
.classes("package closedL; public class L { }") |
|
107 |
.build(modules); |
|
108 |
ModuleBuilder m = new ModuleBuilder("M"); |
|
109 |
//positive case |
|
110 |
Path positiveSrc = m |
|
111 |
.requires("N", modules) |
|
112 |
.requires("L", modules) |
|
113 |
.classes("package p; public class Positive { openO.O o; openN.N n; openL.L l; }") |
|
114 |
.write(base.resolve("positiveSrc")); |
|
115 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
116 |
new JavacTask(tb) |
36526 | 117 |
.options("-XDrawDiagnostics", "-mp", modules + File.pathSeparator + jarModules) |
118 |
.outdir(Files.createDirectories(base.resolve("positive"))) |
|
119 |
.files(findJavaFiles(positiveSrc)) |
|
120 |
.run() |
|
121 |
.writeAll(); |
|
122 |
//negative case |
|
123 |
Path negativeSrc = m.classes("package p; public class Negative { closedO.O o; closedN.N n; closedL.L l; }") |
|
124 |
.write(base.resolve("negativeSrc")); |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
125 |
List<String> log = new JavacTask(tb) |
36526 | 126 |
.options("-XDrawDiagnostics", "-mp", modules + File.pathSeparator + jarModules) |
127 |
.outdir(Files.createDirectories(base.resolve("negative"))) |
|
128 |
.files(findJavaFiles(negativeSrc)) |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
129 |
.run(Task.Expect.FAIL) |
36526 | 130 |
.writeAll() |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
131 |
.getOutputLines(Task.OutputKind.DIRECT); |
36526 | 132 |
|
133 |
List<String> expected = Arrays.asList( |
|
134 |
"Negative.java:1:43: compiler.err.doesnt.exist: closedO", |
|
135 |
"Negative.java:1:56: compiler.err.doesnt.exist: closedN", |
|
136 |
"Negative.java:1:69: compiler.err.doesnt.exist: closedL"); |
|
137 |
if (!log.containsAll(expected)) { |
|
138 |
throw new Exception("Expected output not found"); |
|
139 |
} |
|
140 |
//multi module mode |
|
141 |
m.write(modules); |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
142 |
List<String> out = new JavacTask(tb) |
36526 | 143 |
.options("-XDrawDiagnostics", |
144 |
"-modulesourcepath", modules + "/*/src", |
|
145 |
"-mp", jarModules.toString() |
|
146 |
) |
|
147 |
.outdir(Files.createDirectories(base.resolve("negative"))) |
|
148 |
.files(findJavaFiles(modules)) |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
149 |
.run(Task.Expect.FAIL) |
36526 | 150 |
.writeAll() |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
151 |
.getOutputLines(Task.OutputKind.DIRECT); |
36526 | 152 |
expected = Arrays.asList( |
153 |
"Negative.java:1:43: compiler.err.not.def.access.package.cant.access: closedO.O, closedO", |
|
154 |
"Negative.java:1:56: compiler.err.not.def.access.package.cant.access: closedN.N, closedN", |
|
155 |
"Negative.java:1:69: compiler.err.not.def.access.package.cant.access: closedL.L, closedL"); |
|
156 |
if (!out.containsAll(expected)) { |
|
157 |
throw new Exception("Expected output not found"); |
|
158 |
} |
|
159 |
//checks if the output does not contain messages about exported packages. |
|
160 |
Pattern regex = Pattern.compile("compiler\\.err.*(openO\\.O|openN\\.N|openL\\.L)"); |
|
161 |
for (String s : out) { |
|
162 |
if (regex.matcher(s).find()) { |
|
163 |
throw new Exception("Unexpected output: " + s); |
|
164 |
} |
|
165 |
} |
|
166 |
} |
|
167 |
||
168 |
/** |
|
169 |
* Tests graph where module M reexport package of N, but N export the package only to M. |
|
170 |
* |
|
171 |
+-------------+ +--------------------+ +---------------+ |
|
172 |
| module L | | module M | | module N | |
|
173 |
| | -----> | | -----> | | |
|
174 |
| requires M | | requires public N | | exports P to M| |
|
175 |
+-------------+ | | +---------------+ |
|
176 |
+--------------------+ |
|
177 |
*/ |
|
178 |
@Test |
|
179 |
public void reexportOfQualifiedExport(Path base) throws Exception { |
|
180 |
Path modules = base.resolve("modules"); |
|
181 |
new ModuleBuilder("M") |
|
182 |
.requiresPublic("N") |
|
183 |
.write(modules); |
|
184 |
new ModuleBuilder("N") |
|
185 |
.exportsTo("pack", "M") |
|
186 |
.classes("package pack; public class Clazz { }") |
|
187 |
.write(modules); |
|
188 |
new ModuleBuilder("L") |
|
189 |
.requires("M") |
|
190 |
.classes("package p; public class A { A(pack.Clazz cl){} } ") |
|
191 |
.write(modules); |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
192 |
String log = new JavacTask(tb) |
36526 | 193 |
.options("-XDrawDiagnostics", |
194 |
"-modulesourcepath", modules + "/*/src") |
|
195 |
.outdir(Files.createDirectories(base.resolve("negative"))) |
|
196 |
.files(findJavaFiles(modules)) |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
197 |
.run(Task.Expect.FAIL) |
36526 | 198 |
.writeAll() |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
199 |
.getOutput(Task.OutputKind.DIRECT); |
36526 | 200 |
|
201 |
String expected = "A.java:1:35: compiler.err.not.def.access.package.cant.access: pack.Clazz, pack"; |
|
202 |
if (!log.contains(expected)) { |
|
203 |
throw new Exception("Expected output not found"); |
|
204 |
} |
|
205 |
} |
|
206 |
} |