author | jjg |
Mon, 02 May 2016 16:17:39 -0700 | |
changeset 37758 | 3ecf9b414e05 |
parent 36778 | e04318f39f92 |
child 39366 | 8bf5fe72ca88 |
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 automatic modules |
|
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 toolbox.JarTask ModuleTestBase |
36526 | 32 |
* @run main AutomaticModules |
33 |
*/ |
|
34 |
||
35 |
import java.nio.file.Files; |
|
36 |
import java.nio.file.Path; |
|
37 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
38 |
import toolbox.JarTask; |
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 AutomaticModules extends ModuleTestBase { |
44 |
||
45 |
public static void main(String... args) throws Exception { |
|
46 |
AutomaticModules t = new AutomaticModules(); |
|
47 |
t.runTests(); |
|
48 |
} |
|
49 |
||
50 |
@Test |
|
37758 | 51 |
public void testSimple(Path base) throws Exception { |
36526 | 52 |
Path legacySrc = base.resolve("legacy-src"); |
53 |
tb.writeJavaFiles(legacySrc, |
|
54 |
"package api; import java.awt.event.ActionListener; public abstract class Api implements ActionListener {}"); |
|
55 |
Path legacyClasses = base.resolve("legacy-classes"); |
|
56 |
Files.createDirectories(legacyClasses); |
|
57 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
58 |
String log = new JavacTask(tb) |
36526 | 59 |
.options() |
60 |
.outdir(legacyClasses) |
|
61 |
.files(findJavaFiles(legacySrc)) |
|
62 |
.run() |
|
63 |
.writeAll() |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
64 |
.getOutput(Task.OutputKind.DIRECT); |
36526 | 65 |
|
66 |
if (!log.isEmpty()) { |
|
67 |
throw new Exception("unexpected output: " + log); |
|
68 |
} |
|
69 |
||
70 |
Path modulePath = base.resolve("module-path"); |
|
71 |
||
72 |
Files.createDirectories(modulePath); |
|
73 |
||
74 |
Path jar = modulePath.resolve("test-api-1.0.jar"); |
|
75 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
76 |
new JarTask(tb, jar) |
36526 | 77 |
.baseDir(legacyClasses) |
78 |
.files("api/Api.class") |
|
79 |
.run(); |
|
80 |
||
81 |
Path moduleSrc = base.resolve("module-src"); |
|
82 |
Path m1 = moduleSrc.resolve("m1"); |
|
83 |
||
84 |
Path classes = base.resolve("classes"); |
|
85 |
||
86 |
Files.createDirectories(classes); |
|
87 |
||
88 |
tb.writeJavaFiles(m1, |
|
89 |
"module m1 { requires test.api; }", |
|
90 |
"package impl; public class Impl { public void e(api.Api api) { api.actionPerformed(null); } }"); |
|
91 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
92 |
new JavacTask(tb) |
36526 | 93 |
.options("-modulesourcepath", moduleSrc.toString(), "-modulepath", modulePath.toString(), "-addmods", "java.desktop") |
94 |
.outdir(classes) |
|
95 |
.files(findJavaFiles(moduleSrc)) |
|
96 |
.run() |
|
97 |
.writeAll(); |
|
98 |
} |
|
99 |
||
100 |
@Test |
|
37758 | 101 |
public void testUnnamedModule(Path base) throws Exception { |
36526 | 102 |
Path legacySrc = base.resolve("legacy-src"); |
103 |
tb.writeJavaFiles(legacySrc, |
|
104 |
"package api; public abstract class Api { public void run(CharSequence str) { } private void run(base.Base base) { } }", |
|
105 |
"package base; public interface Base { public void run(); }"); |
|
106 |
Path legacyClasses = base.resolve("legacy-classes"); |
|
107 |
Files.createDirectories(legacyClasses); |
|
108 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
109 |
String log = new JavacTask(tb) |
36526 | 110 |
.options() |
111 |
.outdir(legacyClasses) |
|
112 |
.files(findJavaFiles(legacySrc)) |
|
113 |
.run() |
|
114 |
.writeAll() |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
115 |
.getOutput(Task.OutputKind.DIRECT); |
36526 | 116 |
|
117 |
if (!log.isEmpty()) { |
|
118 |
throw new Exception("unexpected output: " + log); |
|
119 |
} |
|
120 |
||
121 |
Path modulePath = base.resolve("module-path"); |
|
122 |
||
123 |
Files.createDirectories(modulePath); |
|
124 |
||
125 |
Path apiJar = modulePath.resolve("test-api-1.0.jar"); |
|
126 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
127 |
new JarTask(tb, apiJar) |
36526 | 128 |
.baseDir(legacyClasses) |
129 |
.files("api/Api.class") |
|
130 |
.run(); |
|
131 |
||
132 |
Path baseJar = base.resolve("base.jar"); |
|
133 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
134 |
new JarTask(tb, baseJar) |
36526 | 135 |
.baseDir(legacyClasses) |
136 |
.files("base/Base.class") |
|
137 |
.run(); |
|
138 |
||
139 |
Path moduleSrc = base.resolve("module-src"); |
|
140 |
Path m1 = moduleSrc.resolve("m1"); |
|
141 |
||
142 |
Path classes = base.resolve("classes"); |
|
143 |
||
144 |
Files.createDirectories(classes); |
|
145 |
||
146 |
tb.writeJavaFiles(m1, |
|
147 |
"module m1 { requires test.api; }", |
|
148 |
"package impl; public class Impl { public void e(api.Api api) { api.run(\"\"); } }"); |
|
149 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
150 |
new JavacTask(tb) |
36526 | 151 |
.options("-modulesourcepath", moduleSrc.toString(), "-modulepath", modulePath.toString(), "-classpath", baseJar.toString()) |
152 |
.outdir(classes) |
|
153 |
.files(findJavaFiles(moduleSrc)) |
|
154 |
.run() |
|
155 |
.writeAll(); |
|
156 |
} |
|
157 |
||
158 |
@Test |
|
37758 | 159 |
public void testModuleInfoFromClassFileDependsOnAutomatic(Path base) throws Exception { |
36526 | 160 |
Path automaticSrc = base.resolve("automaticSrc"); |
161 |
tb.writeJavaFiles(automaticSrc, "package api; public class Api {}"); |
|
162 |
Path automaticClasses = base.resolve("automaticClasses"); |
|
163 |
tb.createDirectories(automaticClasses); |
|
164 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
165 |
String automaticLog = new JavacTask(tb) |
36526 | 166 |
.outdir(automaticClasses) |
167 |
.files(findJavaFiles(automaticSrc)) |
|
168 |
.run() |
|
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 (!automaticLog.isEmpty()) |
|
173 |
throw new Exception("expected output not found: " + automaticLog); |
|
174 |
||
175 |
Path modulePath = base.resolve("module-path"); |
|
176 |
||
177 |
Files.createDirectories(modulePath); |
|
178 |
||
179 |
Path automaticJar = modulePath.resolve("automatic-1.0.jar"); |
|
180 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
181 |
new JarTask(tb, automaticJar) |
36526 | 182 |
.baseDir(automaticClasses) |
183 |
.files("api/Api.class") |
|
184 |
.run(); |
|
185 |
||
186 |
Path depSrc = base.resolve("depSrc"); |
|
187 |
Path depClasses = base.resolve("depClasses"); |
|
188 |
||
189 |
Files.createDirectories(depSrc); |
|
190 |
Files.createDirectories(depClasses); |
|
191 |
||
192 |
tb.writeJavaFiles(depSrc, |
|
193 |
"module m1 { requires public automatic; }", |
|
194 |
"package dep; public class Dep { api.Api api; }"); |
|
195 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
196 |
new JavacTask(tb) |
36526 | 197 |
.options("-modulepath", modulePath.toString()) |
198 |
.outdir(depClasses) |
|
199 |
.files(findJavaFiles(depSrc)) |
|
200 |
.run() |
|
201 |
.writeAll(); |
|
202 |
||
203 |
Path moduleJar = modulePath.resolve("m1.jar"); |
|
204 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
205 |
new JarTask(tb, moduleJar) |
36526 | 206 |
.baseDir(depClasses) |
207 |
.files("module-info.class", "dep/Dep.class") |
|
208 |
.run(); |
|
209 |
||
210 |
Path testSrc = base.resolve("testSrc"); |
|
211 |
Path testClasses = base.resolve("testClasses"); |
|
212 |
||
213 |
Files.createDirectories(testSrc); |
|
214 |
Files.createDirectories(testClasses); |
|
215 |
||
216 |
tb.writeJavaFiles(testSrc, |
|
217 |
"module m2 { requires automatic; }", |
|
218 |
"package test; public class Test { }"); |
|
219 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
220 |
new JavacTask(tb) |
36526 | 221 |
.options("-modulepath", modulePath.toString()) |
222 |
.outdir(testClasses) |
|
223 |
.files(findJavaFiles(testSrc)) |
|
224 |
.run() |
|
225 |
.writeAll(); |
|
226 |
} |
|
227 |
} |