author | shurailine |
Fri, 16 Mar 2018 03:15:35 -0700 | |
changeset 49258 | be0ec3cc0c2a |
parent 47216 | 71c04702a3d5 |
child 51675 | b487c1e914d0 |
permissions | -rw-r--r-- |
36511 | 1 |
/* |
45393 | 2 |
* Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved. |
36511 | 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 |
|
45393 | 26 |
* @library /lib/testlibrary /test/lib |
36511 | 27 |
* @modules jdk.compiler |
49258
be0ec3cc0c2a
8199616: Fix @module declarations in tier1 tests
shurailine
parents:
47216
diff
changeset
|
28 |
* java.scripting |
be0ec3cc0c2a
8199616: Fix @module declarations in tier1 tests
shurailine
parents:
47216
diff
changeset
|
29 |
* jdk.zipfs |
45393 | 30 |
* @build RunWithAutomaticModules jdk.test.lib.compiler.CompilerUtils JarUtils |
36511 | 31 |
* jdk.testlibrary.ProcessTools |
32 |
* @run testng RunWithAutomaticModules |
|
33 |
* @summary Runs tests that make use of automatic modules |
|
34 |
*/ |
|
35 |
||
36 |
import java.nio.file.Files; |
|
37 |
import java.nio.file.Path; |
|
38 |
import java.nio.file.Paths; |
|
39 |
||
45393 | 40 |
import jdk.test.lib.compiler.CompilerUtils; |
36511 | 41 |
import static jdk.testlibrary.ProcessTools.*; |
42 |
||
43 |
import org.testng.annotations.Test; |
|
44 |
import static org.testng.Assert.*; |
|
45 |
||
46 |
@Test |
|
47 |
public class RunWithAutomaticModules { |
|
48 |
||
49 |
private static final String TEST_SRC = System.getProperty("test.src"); |
|
50 |
||
51 |
private static final Path SRC_DIR = Paths.get(TEST_SRC, "src"); |
|
52 |
private static final Path CLASSES_DIR = Paths.get("classes"); |
|
53 |
private static final Path MODS_DIR = Paths.get("mods"); |
|
54 |
||
55 |
/** |
|
56 |
* Basic test that consists of 3 modules: |
|
57 |
* |
|
58 |
* basictest - the test itself |
|
59 |
* httpserver - a JAR file (automatic module) with a dummy HTTP server |
|
60 |
* logging - a JAR file (automatic module) with a dummy logging library |
|
61 |
* |
|
62 |
* The test runs the dummy HTTP server and checks that has the expected |
|
63 |
* reads and exported packages. |
|
64 |
* |
|
65 |
* The HTTP server uses the logging library. |
|
66 |
*/ |
|
67 |
||
68 |
public void testBasic() throws Exception { |
|
69 |
boolean compiled; |
|
70 |
||
71 |
Path loggingSrc = SRC_DIR.resolve("logging"); |
|
72 |
Path loggingClasses = CLASSES_DIR.resolve("logging"); |
|
73 |
||
74 |
Path httpServerSrc = SRC_DIR.resolve("httpserver"); |
|
75 |
Path httpServerClasses = CLASSES_DIR.resolve("httpserver"); |
|
76 |
||
77 |
String testModule = "basictest"; |
|
78 |
String mainClass = "test.Main"; |
|
79 |
||
80 |
||
81 |
// compile + create mods/logging-1.0.jar |
|
82 |
||
83 |
compiled = CompilerUtils.compile(loggingSrc, loggingClasses); |
|
84 |
assertTrue(compiled); |
|
85 |
||
86 |
JarUtils.createJarFile(MODS_DIR.resolve("logging-1.0.jar"), |
|
87 |
loggingClasses); |
|
88 |
||
89 |
||
90 |
// compile + create mods/httpserver-9.0.0.jar |
|
91 |
||
92 |
compiled = CompilerUtils.compile(httpServerSrc, |
|
93 |
httpServerClasses, |
|
94 |
"-cp", loggingClasses.toString()); |
|
95 |
assertTrue(compiled); |
|
96 |
||
97 |
JarUtils.createJarFile(MODS_DIR.resolve("httpserver-9.0.0.jar"), |
|
98 |
httpServerClasses); |
|
99 |
||
100 |
||
101 |
// compile basictest to mods/basictest |
|
102 |
||
103 |
compiled = CompilerUtils |
|
104 |
.compile(SRC_DIR.resolve(testModule), |
|
105 |
MODS_DIR.resolve(testModule), |
|
40261
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
36511
diff
changeset
|
106 |
"--module-path", MODS_DIR.toString()); |
36511 | 107 |
assertTrue(compiled); |
108 |
||
109 |
||
40261
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
36511
diff
changeset
|
110 |
// launch the test. Need --add-mdoules because nothing explicitly depends on logging |
36511 | 111 |
|
112 |
int exitValue |
|
40261
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
36511
diff
changeset
|
113 |
= executeTestJava("--module-path", MODS_DIR.toString(), |
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
36511
diff
changeset
|
114 |
"--add-modules", "logging", |
36511 | 115 |
"-m", testModule + "/" + mainClass) |
116 |
.outputTo(System.out) |
|
117 |
.errorTo(System.out) |
|
118 |
.getExitValue(); |
|
119 |
||
120 |
assertTrue(exitValue == 0); |
|
121 |
} |
|
122 |
||
123 |
||
124 |
||
125 |
/** |
|
126 |
* Test using a JAR file with a service provider as an automatic module. |
|
127 |
* |
|
128 |
* The consists of 2 modules: |
|
129 |
* |
|
130 |
* sptest - the test itself |
|
131 |
* bananascript - a JAR file (automatic module) with a dummy ScriptEngineFactory |
|
132 |
* |
|
133 |
* The test uses ServiceLoader to locate and load ScriptEngineFactory |
|
134 |
* implementations. It checks that bananascript is located. |
|
135 |
*/ |
|
136 |
||
137 |
public void testServiceProvider() throws Exception { |
|
138 |
boolean compiled; |
|
139 |
||
140 |
Path providerSrc = SRC_DIR.resolve("bananascript"); |
|
141 |
Path providerClasses = CLASSES_DIR.resolve("bananascript"); |
|
142 |
||
143 |
String testModule = "sptest"; |
|
144 |
String mainClass = "test.Main"; |
|
145 |
||
146 |
||
147 |
// create mods/bananascript-0.9.jar |
|
148 |
||
149 |
compiled = CompilerUtils.compile(providerSrc, providerClasses); |
|
150 |
assertTrue(compiled); |
|
151 |
||
152 |
String config = "META-INF/services/javax.script.ScriptEngineFactory"; |
|
153 |
Path services = providerClasses.resolve(config).getParent(); |
|
154 |
Files.createDirectories(services); |
|
155 |
Files.copy(providerSrc.resolve(config), providerClasses.resolve(config)); |
|
156 |
||
157 |
JarUtils.createJarFile(MODS_DIR.resolve("bananascript-0.9.jar"), providerClasses); |
|
158 |
||
159 |
||
160 |
// compile sptest to mods/sptest |
|
161 |
||
162 |
compiled = CompilerUtils |
|
163 |
.compile(SRC_DIR.resolve(testModule), |
|
164 |
MODS_DIR.resolve(testModule), |
|
40261
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
36511
diff
changeset
|
165 |
"--module-path", MODS_DIR.toString()); |
36511 | 166 |
|
167 |
assertTrue(compiled); |
|
168 |
||
169 |
||
170 |
// launch the test |
|
171 |
||
172 |
int exitValue |
|
40261
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
36511
diff
changeset
|
173 |
= executeTestJava("--module-path", MODS_DIR.toString(), |
36511 | 174 |
"-m", testModule + "/" + mainClass) |
175 |
.outputTo(System.out) |
|
176 |
.errorTo(System.out) |
|
177 |
.getExitValue(); |
|
178 |
||
179 |
assertTrue(exitValue == 0); |
|
180 |
||
181 |
} |
|
182 |
||
183 |
} |