author | gadams |
Tue, 09 Jan 2018 13:58:30 -0500 | |
changeset 48629 | a58c1924e037 |
parent 47216 | 71c04702a3d5 |
child 48699 | f4e628259d1b |
permissions | -rw-r--r-- |
36511 | 1 |
/** |
45286
cd809e28c082
8180887: move FileUtils to top level testlibrary
iignatyev
parents:
45004
diff
changeset
|
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 |
|
43067
3f011a470ce2
8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents:
42922
diff
changeset
|
26 |
* @bug 8142968 8166568 8166286 8170618 8168149 |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41916
diff
changeset
|
27 |
* @summary Basic test for jmod |
45393 | 28 |
* @library /test/lib |
41484
834b7539ada3
8164689: Retrofit jar, jlink, jmod as a ToolProvider
mchung
parents:
39882
diff
changeset
|
29 |
* @modules jdk.compiler |
834b7539ada3
8164689: Retrofit jar, jlink, jmod as a ToolProvider
mchung
parents:
39882
diff
changeset
|
30 |
* jdk.jlink |
45393 | 31 |
* @build jdk.test.lib.compiler.CompilerUtils |
45467
99c87a16a8e4
8181761: add explicit @build actions for jdk.test.lib classes in all :tier2 tests
iignatyev
parents:
45393
diff
changeset
|
32 |
* jdk.test.lib.util.FileUtils |
99c87a16a8e4
8181761: add explicit @build actions for jdk.test.lib classes in all :tier2 tests
iignatyev
parents:
45393
diff
changeset
|
33 |
* jdk.test.lib.Platform |
43192
0c05ac48a30b
8172870: test/tools/jmod/JmodTest.java fails on windows with AccessDeniedException
mchung
parents:
43109
diff
changeset
|
34 |
* @run testng/othervm -Djava.io.tmpdir=. JmodTest |
36511 | 35 |
*/ |
36 |
||
37 |
import java.io.*; |
|
38 |
import java.lang.module.ModuleDescriptor; |
|
39 |
import java.lang.reflect.Method; |
|
40 |
import java.nio.file.*; |
|
41 |
import java.util.*; |
|
42 |
import java.util.function.Consumer; |
|
43 |
import java.util.regex.Pattern; |
|
41484
834b7539ada3
8164689: Retrofit jar, jlink, jmod as a ToolProvider
mchung
parents:
39882
diff
changeset
|
44 |
import java.util.spi.ToolProvider; |
36511 | 45 |
import java.util.stream.Stream; |
45393 | 46 |
import jdk.test.lib.compiler.CompilerUtils; |
45286
cd809e28c082
8180887: move FileUtils to top level testlibrary
iignatyev
parents:
45004
diff
changeset
|
47 |
import jdk.test.lib.util.FileUtils; |
36511 | 48 |
import org.testng.annotations.BeforeTest; |
49 |
import org.testng.annotations.Test; |
|
39882
2a5433a2eca5
8134779: (jmod) ZipException is thrown if there are duplicate resources
chegar
parents:
36511
diff
changeset
|
50 |
|
2a5433a2eca5
8134779: (jmod) ZipException is thrown if there are duplicate resources
chegar
parents:
36511
diff
changeset
|
51 |
import static java.io.File.pathSeparator; |
36511 | 52 |
import static java.lang.module.ModuleDescriptor.Version; |
53 |
import static java.nio.charset.StandardCharsets.UTF_8; |
|
54 |
import static java.util.stream.Collectors.toSet; |
|
55 |
import static org.testng.Assert.*; |
|
56 |
||
57 |
public class JmodTest { |
|
58 |
||
41484
834b7539ada3
8164689: Retrofit jar, jlink, jmod as a ToolProvider
mchung
parents:
39882
diff
changeset
|
59 |
static final ToolProvider JMOD_TOOL = ToolProvider.findFirst("jmod") |
834b7539ada3
8164689: Retrofit jar, jlink, jmod as a ToolProvider
mchung
parents:
39882
diff
changeset
|
60 |
.orElseThrow(() -> |
834b7539ada3
8164689: Retrofit jar, jlink, jmod as a ToolProvider
mchung
parents:
39882
diff
changeset
|
61 |
new RuntimeException("jmod tool not found") |
834b7539ada3
8164689: Retrofit jar, jlink, jmod as a ToolProvider
mchung
parents:
39882
diff
changeset
|
62 |
); |
834b7539ada3
8164689: Retrofit jar, jlink, jmod as a ToolProvider
mchung
parents:
39882
diff
changeset
|
63 |
|
36511 | 64 |
static final String TEST_SRC = System.getProperty("test.src", "."); |
65 |
static final Path SRC_DIR = Paths.get(TEST_SRC, "src"); |
|
66 |
static final Path EXPLODED_DIR = Paths.get("build"); |
|
67 |
static final Path MODS_DIR = Paths.get("jmods"); |
|
68 |
||
69 |
static final String CLASSES_PREFIX = "classes/"; |
|
70 |
static final String CMDS_PREFIX = "bin/"; |
|
43729
21db38703675
8174739: Rename JMOD section name for native libraries from native to lib
mchung
parents:
43242
diff
changeset
|
71 |
static final String LIBS_PREFIX = "lib/"; |
36511 | 72 |
static final String CONFIGS_PREFIX = "conf/"; |
73 |
||
74 |
@BeforeTest |
|
75 |
public void buildExplodedModules() throws IOException { |
|
76 |
if (Files.exists(EXPLODED_DIR)) |
|
77 |
FileUtils.deleteFileTreeWithRetry(EXPLODED_DIR); |
|
78 |
||
79 |
for (String name : new String[] { "foo"/*, "bar", "baz"*/ } ) { |
|
80 |
Path dir = EXPLODED_DIR.resolve(name); |
|
81 |
assertTrue(compileModule(name, dir.resolve("classes"))); |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41916
diff
changeset
|
82 |
copyResource(SRC_DIR.resolve("foo"), |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41916
diff
changeset
|
83 |
dir.resolve("classes"), |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41916
diff
changeset
|
84 |
"jdk/test/foo/resources/foo.properties"); |
36511 | 85 |
createCmds(dir.resolve("bin")); |
86 |
createLibs(dir.resolve("lib")); |
|
87 |
createConfigs(dir.resolve("conf")); |
|
88 |
} |
|
89 |
||
90 |
if (Files.exists(MODS_DIR)) |
|
91 |
FileUtils.deleteFileTreeWithRetry(MODS_DIR); |
|
92 |
Files.createDirectories(MODS_DIR); |
|
93 |
} |
|
94 |
||
41916 | 95 |
// JDK-8166286 - jmod fails on symlink to directory |
96 |
@Test |
|
97 |
public void testSymlinks() throws IOException { |
|
98 |
Path apaDir = EXPLODED_DIR.resolve("apa"); |
|
99 |
Path classesDir = EXPLODED_DIR.resolve("apa").resolve("classes"); |
|
100 |
assertTrue(compileModule("apa", classesDir)); |
|
101 |
Path libDir = apaDir.resolve("lib"); |
|
102 |
createFiles(libDir, List.of("foo/bar/libfoo.so")); |
|
103 |
try { |
|
104 |
Path link = Files.createSymbolicLink( |
|
105 |
libDir.resolve("baz"), libDir.resolve("foo").toAbsolutePath()); |
|
106 |
assertTrue(Files.exists(link)); |
|
107 |
} catch (UnsupportedOperationException uoe) { |
|
108 |
// OS does not support symlinks. Nothing to test! |
|
109 |
return; |
|
110 |
} |
|
111 |
||
112 |
Path jmod = MODS_DIR.resolve("apa.jmod"); |
|
113 |
jmod("create", |
|
114 |
"--libs=", libDir.toString(), |
|
115 |
"--class-path", classesDir.toString(), |
|
116 |
jmod.toString()) |
|
117 |
.assertSuccess(); |
|
118 |
} |
|
119 |
||
42922
9111fb672357
8170618: jmod should validate if any exported or open package is missing
sundar
parents:
42703
diff
changeset
|
120 |
// JDK-8170618 - jmod should validate if any exported or open package is missing |
9111fb672357
8170618: jmod should validate if any exported or open package is missing
sundar
parents:
42703
diff
changeset
|
121 |
@Test |
9111fb672357
8170618: jmod should validate if any exported or open package is missing
sundar
parents:
42703
diff
changeset
|
122 |
public void testMissingPackages() throws IOException { |
9111fb672357
8170618: jmod should validate if any exported or open package is missing
sundar
parents:
42703
diff
changeset
|
123 |
Path apaDir = EXPLODED_DIR.resolve("apa"); |
9111fb672357
8170618: jmod should validate if any exported or open package is missing
sundar
parents:
42703
diff
changeset
|
124 |
Path classesDir = EXPLODED_DIR.resolve("apa").resolve("classes"); |
9111fb672357
8170618: jmod should validate if any exported or open package is missing
sundar
parents:
42703
diff
changeset
|
125 |
if (Files.exists(classesDir)) |
9111fb672357
8170618: jmod should validate if any exported or open package is missing
sundar
parents:
42703
diff
changeset
|
126 |
FileUtils.deleteFileTreeWithRetry(classesDir); |
9111fb672357
8170618: jmod should validate if any exported or open package is missing
sundar
parents:
42703
diff
changeset
|
127 |
assertTrue(compileModule("apa", classesDir)); |
9111fb672357
8170618: jmod should validate if any exported or open package is missing
sundar
parents:
42703
diff
changeset
|
128 |
FileUtils.deleteFileTreeWithRetry(classesDir.resolve("jdk")); |
9111fb672357
8170618: jmod should validate if any exported or open package is missing
sundar
parents:
42703
diff
changeset
|
129 |
Path jmod = MODS_DIR.resolve("apa.jmod"); |
9111fb672357
8170618: jmod should validate if any exported or open package is missing
sundar
parents:
42703
diff
changeset
|
130 |
jmod("create", |
9111fb672357
8170618: jmod should validate if any exported or open package is missing
sundar
parents:
42703
diff
changeset
|
131 |
"--class-path", classesDir.toString(), |
9111fb672357
8170618: jmod should validate if any exported or open package is missing
sundar
parents:
42703
diff
changeset
|
132 |
jmod.toString()) |
9111fb672357
8170618: jmod should validate if any exported or open package is missing
sundar
parents:
42703
diff
changeset
|
133 |
.assertFailure() |
9111fb672357
8170618: jmod should validate if any exported or open package is missing
sundar
parents:
42703
diff
changeset
|
134 |
.resultChecker(r -> { |
9111fb672357
8170618: jmod should validate if any exported or open package is missing
sundar
parents:
42703
diff
changeset
|
135 |
assertContains(r.output, "Packages that are exported or open in apa are not present: [jdk.test.apa]"); |
9111fb672357
8170618: jmod should validate if any exported or open package is missing
sundar
parents:
42703
diff
changeset
|
136 |
}); |
9111fb672357
8170618: jmod should validate if any exported or open package is missing
sundar
parents:
42703
diff
changeset
|
137 |
if (Files.exists(classesDir)) |
9111fb672357
8170618: jmod should validate if any exported or open package is missing
sundar
parents:
42703
diff
changeset
|
138 |
FileUtils.deleteFileTreeWithRetry(classesDir); |
9111fb672357
8170618: jmod should validate if any exported or open package is missing
sundar
parents:
42703
diff
changeset
|
139 |
} |
9111fb672357
8170618: jmod should validate if any exported or open package is missing
sundar
parents:
42703
diff
changeset
|
140 |
|
36511 | 141 |
@Test |
142 |
public void testList() throws IOException { |
|
143 |
String cp = EXPLODED_DIR.resolve("foo").resolve("classes").toString(); |
|
144 |
jmod("create", |
|
145 |
"--class-path", cp, |
|
146 |
MODS_DIR.resolve("foo.jmod").toString()) |
|
147 |
.assertSuccess(); |
|
148 |
||
149 |
jmod("list", |
|
150 |
MODS_DIR.resolve("foo.jmod").toString()) |
|
151 |
.assertSuccess() |
|
152 |
.resultChecker(r -> { |
|
153 |
// asserts dependent on the exact contents of foo |
|
154 |
assertContains(r.output, CLASSES_PREFIX + "module-info.class"); |
|
155 |
assertContains(r.output, CLASSES_PREFIX + "jdk/test/foo/Foo.class"); |
|
156 |
assertContains(r.output, CLASSES_PREFIX + "jdk/test/foo/internal/Message.class"); |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41916
diff
changeset
|
157 |
assertContains(r.output, CLASSES_PREFIX + "jdk/test/foo/resources/foo.properties"); |
36511 | 158 |
}); |
159 |
} |
|
160 |
||
161 |
@Test |
|
42468 | 162 |
public void testExtractCWD() throws IOException { |
163 |
Path cp = EXPLODED_DIR.resolve("foo").resolve("classes"); |
|
164 |
jmod("create", |
|
165 |
"--class-path", cp.toString(), |
|
166 |
MODS_DIR.resolve("fooExtractCWD.jmod").toString()) |
|
167 |
.assertSuccess(); |
|
168 |
||
169 |
jmod("extract", |
|
170 |
MODS_DIR.resolve("fooExtractCWD.jmod").toString()) |
|
171 |
.assertSuccess() |
|
172 |
.resultChecker(r -> { |
|
173 |
// module-info should exist, but jmod will have added its Packages attr. |
|
174 |
assertTrue(Files.exists(Paths.get("classes/module-info.class"))); |
|
175 |
assertSameContent(cp.resolve("jdk/test/foo/Foo.class"), |
|
176 |
Paths.get("classes/jdk/test/foo/Foo.class")); |
|
177 |
assertSameContent(cp.resolve("jdk/test/foo/internal/Message.class"), |
|
178 |
Paths.get("classes/jdk/test/foo/internal/Message.class")); |
|
179 |
assertSameContent(cp.resolve("jdk/test/foo/resources/foo.properties"), |
|
180 |
Paths.get("classes/jdk/test/foo/resources/foo.properties")); |
|
181 |
}); |
|
182 |
} |
|
183 |
||
184 |
@Test |
|
185 |
public void testExtractDir() throws IOException { |
|
186 |
if (Files.exists(Paths.get("extractTestDir"))) |
|
187 |
FileUtils.deleteFileTreeWithRetry(Paths.get("extractTestDir")); |
|
188 |
Path cp = EXPLODED_DIR.resolve("foo").resolve("classes"); |
|
189 |
Path bp = EXPLODED_DIR.resolve("foo").resolve("bin"); |
|
190 |
Path lp = EXPLODED_DIR.resolve("foo").resolve("lib"); |
|
191 |
Path cf = EXPLODED_DIR.resolve("foo").resolve("conf"); |
|
192 |
||
193 |
jmod("create", |
|
194 |
"--conf", cf.toString(), |
|
195 |
"--cmds", bp.toString(), |
|
196 |
"--libs", lp.toString(), |
|
197 |
"--class-path", cp.toString(), |
|
198 |
MODS_DIR.resolve("fooExtractDir.jmod").toString()) |
|
199 |
.assertSuccess(); |
|
200 |
||
201 |
jmod("extract", |
|
202 |
"--dir", "extractTestDir", |
|
203 |
MODS_DIR.resolve("fooExtractDir.jmod").toString()) |
|
204 |
.assertSuccess(); |
|
205 |
||
206 |
jmod("extract", |
|
207 |
"--dir", "extractTestDir", |
|
208 |
MODS_DIR.resolve("fooExtractDir.jmod").toString()) |
|
209 |
.assertSuccess() |
|
210 |
.resultChecker(r -> { |
|
211 |
// check a sample of the extracted files |
|
212 |
Path p = Paths.get("extractTestDir"); |
|
213 |
assertTrue(Files.exists(p.resolve("classes/module-info.class"))); |
|
214 |
assertSameContent(cp.resolve("jdk/test/foo/Foo.class"), |
|
215 |
p.resolve("classes/jdk/test/foo/Foo.class")); |
|
216 |
assertSameContent(bp.resolve("first"), |
|
217 |
p.resolve(CMDS_PREFIX).resolve("first")); |
|
218 |
assertSameContent(lp.resolve("first.so"), |
|
219 |
p.resolve(LIBS_PREFIX).resolve("second.so")); |
|
220 |
assertSameContent(cf.resolve("second.cfg"), |
|
221 |
p.resolve(CONFIGS_PREFIX).resolve("second.cfg")); |
|
222 |
}); |
|
223 |
} |
|
224 |
||
225 |
@Test |
|
36511 | 226 |
public void testMainClass() throws IOException { |
227 |
Path jmod = MODS_DIR.resolve("fooMainClass.jmod"); |
|
228 |
FileUtils.deleteFileIfExistsWithRetry(jmod); |
|
229 |
String cp = EXPLODED_DIR.resolve("foo").resolve("classes").toString(); |
|
230 |
||
231 |
jmod("create", |
|
232 |
"--class-path", cp, |
|
233 |
"--main-class", "jdk.test.foo.Foo", |
|
234 |
jmod.toString()) |
|
235 |
.assertSuccess() |
|
236 |
.resultChecker(r -> { |
|
237 |
Optional<String> omc = getModuleDescriptor(jmod).mainClass(); |
|
238 |
assertTrue(omc.isPresent()); |
|
239 |
assertEquals(omc.get(), "jdk.test.foo.Foo"); |
|
240 |
}); |
|
241 |
} |
|
242 |
||
243 |
@Test |
|
244 |
public void testModuleVersion() throws IOException { |
|
245 |
Path jmod = MODS_DIR.resolve("fooVersion.jmod"); |
|
246 |
FileUtils.deleteFileIfExistsWithRetry(jmod); |
|
247 |
String cp = EXPLODED_DIR.resolve("foo").resolve("classes").toString(); |
|
248 |
||
249 |
jmod("create", |
|
250 |
"--class-path", cp, |
|
251 |
"--module-version", "5.4.3", |
|
252 |
jmod.toString()) |
|
253 |
.assertSuccess() |
|
254 |
.resultChecker(r -> { |
|
255 |
Optional<Version> ov = getModuleDescriptor(jmod).version(); |
|
256 |
assertTrue(ov.isPresent()); |
|
257 |
assertEquals(ov.get().toString(), "5.4.3"); |
|
258 |
}); |
|
259 |
} |
|
260 |
||
261 |
@Test |
|
262 |
public void testConfig() throws IOException { |
|
263 |
Path jmod = MODS_DIR.resolve("fooConfig.jmod"); |
|
264 |
FileUtils.deleteFileIfExistsWithRetry(jmod); |
|
265 |
Path cp = EXPLODED_DIR.resolve("foo").resolve("classes"); |
|
266 |
Path cf = EXPLODED_DIR.resolve("foo").resolve("conf"); |
|
267 |
||
268 |
jmod("create", |
|
269 |
"--class-path", cp.toString(), |
|
270 |
"--config", cf.toString(), |
|
271 |
jmod.toString()) |
|
272 |
.assertSuccess() |
|
273 |
.resultChecker(r -> { |
|
274 |
try (Stream<String> s1 = findFiles(cf).map(p -> CONFIGS_PREFIX + p); |
|
275 |
Stream<String> s2 = findFiles(cp).map(p -> CLASSES_PREFIX + p)) { |
|
276 |
Set<String> expectedFilenames = Stream.concat(s1, s2) |
|
277 |
.collect(toSet()); |
|
278 |
assertJmodContent(jmod, expectedFilenames); |
|
279 |
} |
|
280 |
}); |
|
281 |
} |
|
282 |
||
283 |
@Test |
|
284 |
public void testCmds() throws IOException { |
|
285 |
Path jmod = MODS_DIR.resolve("fooCmds.jmod"); |
|
286 |
FileUtils.deleteFileIfExistsWithRetry(jmod); |
|
287 |
Path cp = EXPLODED_DIR.resolve("foo").resolve("classes"); |
|
288 |
Path bp = EXPLODED_DIR.resolve("foo").resolve("bin"); |
|
289 |
||
290 |
jmod("create", |
|
291 |
"--cmds", bp.toString(), |
|
292 |
"--class-path", cp.toString(), |
|
293 |
jmod.toString()) |
|
294 |
.assertSuccess() |
|
295 |
.resultChecker(r -> { |
|
296 |
try (Stream<String> s1 = findFiles(bp).map(p -> CMDS_PREFIX + p); |
|
297 |
Stream<String> s2 = findFiles(cp).map(p -> CLASSES_PREFIX + p)) { |
|
298 |
Set<String> expectedFilenames = Stream.concat(s1,s2) |
|
299 |
.collect(toSet()); |
|
300 |
assertJmodContent(jmod, expectedFilenames); |
|
301 |
} |
|
302 |
}); |
|
303 |
} |
|
304 |
||
305 |
@Test |
|
306 |
public void testLibs() throws IOException { |
|
307 |
Path jmod = MODS_DIR.resolve("fooLibs.jmod"); |
|
308 |
FileUtils.deleteFileIfExistsWithRetry(jmod); |
|
309 |
Path cp = EXPLODED_DIR.resolve("foo").resolve("classes"); |
|
310 |
Path lp = EXPLODED_DIR.resolve("foo").resolve("lib"); |
|
311 |
||
312 |
jmod("create", |
|
313 |
"--libs=", lp.toString(), |
|
314 |
"--class-path", cp.toString(), |
|
315 |
jmod.toString()) |
|
316 |
.assertSuccess() |
|
317 |
.resultChecker(r -> { |
|
318 |
try (Stream<String> s1 = findFiles(lp).map(p -> LIBS_PREFIX + p); |
|
319 |
Stream<String> s2 = findFiles(cp).map(p -> CLASSES_PREFIX + p)) { |
|
320 |
Set<String> expectedFilenames = Stream.concat(s1,s2) |
|
321 |
.collect(toSet()); |
|
322 |
assertJmodContent(jmod, expectedFilenames); |
|
323 |
} |
|
324 |
}); |
|
325 |
} |
|
326 |
||
327 |
@Test |
|
328 |
public void testAll() throws IOException { |
|
329 |
Path jmod = MODS_DIR.resolve("fooAll.jmod"); |
|
330 |
FileUtils.deleteFileIfExistsWithRetry(jmod); |
|
331 |
Path cp = EXPLODED_DIR.resolve("foo").resolve("classes"); |
|
332 |
Path bp = EXPLODED_DIR.resolve("foo").resolve("bin"); |
|
333 |
Path lp = EXPLODED_DIR.resolve("foo").resolve("lib"); |
|
334 |
Path cf = EXPLODED_DIR.resolve("foo").resolve("conf"); |
|
335 |
||
336 |
jmod("create", |
|
337 |
"--conf", cf.toString(), |
|
338 |
"--cmds=", bp.toString(), |
|
339 |
"--libs=", lp.toString(), |
|
340 |
"--class-path", cp.toString(), |
|
341 |
jmod.toString()) |
|
342 |
.assertSuccess() |
|
343 |
.resultChecker(r -> { |
|
344 |
try (Stream<String> s1 = findFiles(lp).map(p -> LIBS_PREFIX + p); |
|
345 |
Stream<String> s2 = findFiles(cp).map(p -> CLASSES_PREFIX + p); |
|
346 |
Stream<String> s3 = findFiles(bp).map(p -> CMDS_PREFIX + p); |
|
347 |
Stream<String> s4 = findFiles(cf).map(p -> CONFIGS_PREFIX + p)) { |
|
348 |
Set<String> expectedFilenames = Stream.concat(Stream.concat(s1,s2), |
|
349 |
Stream.concat(s3, s4)) |
|
350 |
.collect(toSet()); |
|
351 |
assertJmodContent(jmod, expectedFilenames); |
|
352 |
} |
|
353 |
}); |
|
354 |
} |
|
355 |
||
356 |
@Test |
|
357 |
public void testExcludes() throws IOException { |
|
358 |
Path jmod = MODS_DIR.resolve("fooLibs.jmod"); |
|
359 |
FileUtils.deleteFileIfExistsWithRetry(jmod); |
|
360 |
Path cp = EXPLODED_DIR.resolve("foo").resolve("classes"); |
|
361 |
Path lp = EXPLODED_DIR.resolve("foo").resolve("lib"); |
|
362 |
||
363 |
jmod("create", |
|
364 |
"--libs=", lp.toString(), |
|
365 |
"--class-path", cp.toString(), |
|
366 |
"--exclude", "**internal**", |
|
367 |
"--exclude", "first.so", |
|
368 |
jmod.toString()) |
|
369 |
.assertSuccess() |
|
370 |
.resultChecker(r -> { |
|
371 |
Set<String> expectedFilenames = new HashSet<>(); |
|
372 |
expectedFilenames.add(CLASSES_PREFIX + "module-info.class"); |
|
373 |
expectedFilenames.add(CLASSES_PREFIX + "jdk/test/foo/Foo.class"); |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41916
diff
changeset
|
374 |
expectedFilenames.add(CLASSES_PREFIX + "jdk/test/foo/resources/foo.properties"); |
36511 | 375 |
expectedFilenames.add(LIBS_PREFIX + "second.so"); |
376 |
expectedFilenames.add(LIBS_PREFIX + "third/third.so"); |
|
377 |
assertJmodContent(jmod, expectedFilenames); |
|
378 |
||
379 |
Set<String> unexpectedFilenames = new HashSet<>(); |
|
380 |
unexpectedFilenames.add(CLASSES_PREFIX + "jdk/test/foo/internal/Message.class"); |
|
381 |
unexpectedFilenames.add(LIBS_PREFIX + "first.so"); |
|
382 |
assertJmodDoesNotContain(jmod, unexpectedFilenames); |
|
383 |
}); |
|
384 |
} |
|
385 |
||
386 |
@Test |
|
387 |
public void describe() throws IOException { |
|
388 |
String cp = EXPLODED_DIR.resolve("foo").resolve("classes").toString(); |
|
389 |
jmod("create", |
|
390 |
"--class-path", cp, |
|
391 |
MODS_DIR.resolve("describeFoo.jmod").toString()) |
|
392 |
.assertSuccess(); |
|
393 |
||
394 |
jmod("describe", |
|
395 |
MODS_DIR.resolve("describeFoo.jmod").toString()) |
|
396 |
.assertSuccess() |
|
397 |
.resultChecker(r -> { |
|
45004
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
43729
diff
changeset
|
398 |
// Expect similar output: "foo... exports jdk.test.foo ... |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
43729
diff
changeset
|
399 |
// ... requires java.base mandated... contains jdk.test.foo.internal" |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
43729
diff
changeset
|
400 |
Pattern p = Pattern.compile("foo\\s+exports\\s+jdk.test.foo"); |
36511 | 401 |
assertTrue(p.matcher(r.output).find(), |
45004
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
43729
diff
changeset
|
402 |
"Expecting to find \"foo... exports jdk.test.foo\"" + |
36511 | 403 |
"in output, but did not: [" + r.output + "]"); |
404 |
p = Pattern.compile( |
|
45004
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
43729
diff
changeset
|
405 |
"requires\\s+java.base\\s+mandated\\s+contains\\s+jdk.test.foo.internal"); |
36511 | 406 |
assertTrue(p.matcher(r.output).find(), |
45004
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
43729
diff
changeset
|
407 |
"Expecting to find \"requires java.base mandated..., " + |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
43729
diff
changeset
|
408 |
"contains jdk.test.foo.internal ...\"" + |
36511 | 409 |
"in output, but did not: [" + r.output + "]"); |
410 |
}); |
|
411 |
} |
|
412 |
||
413 |
@Test |
|
39882
2a5433a2eca5
8134779: (jmod) ZipException is thrown if there are duplicate resources
chegar
parents:
36511
diff
changeset
|
414 |
public void testDuplicateEntries() throws IOException { |
2a5433a2eca5
8134779: (jmod) ZipException is thrown if there are duplicate resources
chegar
parents:
36511
diff
changeset
|
415 |
Path jmod = MODS_DIR.resolve("testDuplicates.jmod"); |
2a5433a2eca5
8134779: (jmod) ZipException is thrown if there are duplicate resources
chegar
parents:
36511
diff
changeset
|
416 |
FileUtils.deleteFileIfExistsWithRetry(jmod); |
2a5433a2eca5
8134779: (jmod) ZipException is thrown if there are duplicate resources
chegar
parents:
36511
diff
changeset
|
417 |
String cp = EXPLODED_DIR.resolve("foo").resolve("classes").toString(); |
2a5433a2eca5
8134779: (jmod) ZipException is thrown if there are duplicate resources
chegar
parents:
36511
diff
changeset
|
418 |
Path lp = EXPLODED_DIR.resolve("foo").resolve("lib"); |
2a5433a2eca5
8134779: (jmod) ZipException is thrown if there are duplicate resources
chegar
parents:
36511
diff
changeset
|
419 |
|
2a5433a2eca5
8134779: (jmod) ZipException is thrown if there are duplicate resources
chegar
parents:
36511
diff
changeset
|
420 |
jmod("create", |
2a5433a2eca5
8134779: (jmod) ZipException is thrown if there are duplicate resources
chegar
parents:
36511
diff
changeset
|
421 |
"--class-path", cp + pathSeparator + cp, |
2a5433a2eca5
8134779: (jmod) ZipException is thrown if there are duplicate resources
chegar
parents:
36511
diff
changeset
|
422 |
jmod.toString()) |
2a5433a2eca5
8134779: (jmod) ZipException is thrown if there are duplicate resources
chegar
parents:
36511
diff
changeset
|
423 |
.assertSuccess() |
2a5433a2eca5
8134779: (jmod) ZipException is thrown if there are duplicate resources
chegar
parents:
36511
diff
changeset
|
424 |
.resultChecker(r -> |
2a5433a2eca5
8134779: (jmod) ZipException is thrown if there are duplicate resources
chegar
parents:
36511
diff
changeset
|
425 |
assertContains(r.output, "Warning: ignoring duplicate entry") |
2a5433a2eca5
8134779: (jmod) ZipException is thrown if there are duplicate resources
chegar
parents:
36511
diff
changeset
|
426 |
); |
2a5433a2eca5
8134779: (jmod) ZipException is thrown if there are duplicate resources
chegar
parents:
36511
diff
changeset
|
427 |
|
2a5433a2eca5
8134779: (jmod) ZipException is thrown if there are duplicate resources
chegar
parents:
36511
diff
changeset
|
428 |
FileUtils.deleteFileIfExistsWithRetry(jmod); |
2a5433a2eca5
8134779: (jmod) ZipException is thrown if there are duplicate resources
chegar
parents:
36511
diff
changeset
|
429 |
jmod("create", |
2a5433a2eca5
8134779: (jmod) ZipException is thrown if there are duplicate resources
chegar
parents:
36511
diff
changeset
|
430 |
"--class-path", cp, |
2a5433a2eca5
8134779: (jmod) ZipException is thrown if there are duplicate resources
chegar
parents:
36511
diff
changeset
|
431 |
"--libs", lp.toString() + pathSeparator + lp.toString(), |
2a5433a2eca5
8134779: (jmod) ZipException is thrown if there are duplicate resources
chegar
parents:
36511
diff
changeset
|
432 |
jmod.toString()) |
2a5433a2eca5
8134779: (jmod) ZipException is thrown if there are duplicate resources
chegar
parents:
36511
diff
changeset
|
433 |
.assertSuccess() |
2a5433a2eca5
8134779: (jmod) ZipException is thrown if there are duplicate resources
chegar
parents:
36511
diff
changeset
|
434 |
.resultChecker(r -> |
2a5433a2eca5
8134779: (jmod) ZipException is thrown if there are duplicate resources
chegar
parents:
36511
diff
changeset
|
435 |
assertContains(r.output, "Warning: ignoring duplicate entry") |
2a5433a2eca5
8134779: (jmod) ZipException is thrown if there are duplicate resources
chegar
parents:
36511
diff
changeset
|
436 |
); |
2a5433a2eca5
8134779: (jmod) ZipException is thrown if there are duplicate resources
chegar
parents:
36511
diff
changeset
|
437 |
} |
2a5433a2eca5
8134779: (jmod) ZipException is thrown if there are duplicate resources
chegar
parents:
36511
diff
changeset
|
438 |
|
2a5433a2eca5
8134779: (jmod) ZipException is thrown if there are duplicate resources
chegar
parents:
36511
diff
changeset
|
439 |
@Test |
2a5433a2eca5
8134779: (jmod) ZipException is thrown if there are duplicate resources
chegar
parents:
36511
diff
changeset
|
440 |
public void testIgnoreModuleInfoInOtherSections() throws IOException { |
2a5433a2eca5
8134779: (jmod) ZipException is thrown if there are duplicate resources
chegar
parents:
36511
diff
changeset
|
441 |
Path jmod = MODS_DIR.resolve("testIgnoreModuleInfoInOtherSections.jmod"); |
2a5433a2eca5
8134779: (jmod) ZipException is thrown if there are duplicate resources
chegar
parents:
36511
diff
changeset
|
442 |
FileUtils.deleteFileIfExistsWithRetry(jmod); |
2a5433a2eca5
8134779: (jmod) ZipException is thrown if there are duplicate resources
chegar
parents:
36511
diff
changeset
|
443 |
String cp = EXPLODED_DIR.resolve("foo").resolve("classes").toString(); |
2a5433a2eca5
8134779: (jmod) ZipException is thrown if there are duplicate resources
chegar
parents:
36511
diff
changeset
|
444 |
|
2a5433a2eca5
8134779: (jmod) ZipException is thrown if there are duplicate resources
chegar
parents:
36511
diff
changeset
|
445 |
jmod("create", |
2a5433a2eca5
8134779: (jmod) ZipException is thrown if there are duplicate resources
chegar
parents:
36511
diff
changeset
|
446 |
"--class-path", cp, |
2a5433a2eca5
8134779: (jmod) ZipException is thrown if there are duplicate resources
chegar
parents:
36511
diff
changeset
|
447 |
"--libs", cp, |
2a5433a2eca5
8134779: (jmod) ZipException is thrown if there are duplicate resources
chegar
parents:
36511
diff
changeset
|
448 |
jmod.toString()) |
2a5433a2eca5
8134779: (jmod) ZipException is thrown if there are duplicate resources
chegar
parents:
36511
diff
changeset
|
449 |
.assertSuccess() |
2a5433a2eca5
8134779: (jmod) ZipException is thrown if there are duplicate resources
chegar
parents:
36511
diff
changeset
|
450 |
.resultChecker(r -> |
2a5433a2eca5
8134779: (jmod) ZipException is thrown if there are duplicate resources
chegar
parents:
36511
diff
changeset
|
451 |
assertContains(r.output, "Warning: ignoring entry") |
2a5433a2eca5
8134779: (jmod) ZipException is thrown if there are duplicate resources
chegar
parents:
36511
diff
changeset
|
452 |
); |
2a5433a2eca5
8134779: (jmod) ZipException is thrown if there are duplicate resources
chegar
parents:
36511
diff
changeset
|
453 |
|
2a5433a2eca5
8134779: (jmod) ZipException is thrown if there are duplicate resources
chegar
parents:
36511
diff
changeset
|
454 |
FileUtils.deleteFileIfExistsWithRetry(jmod); |
2a5433a2eca5
8134779: (jmod) ZipException is thrown if there are duplicate resources
chegar
parents:
36511
diff
changeset
|
455 |
jmod("create", |
2a5433a2eca5
8134779: (jmod) ZipException is thrown if there are duplicate resources
chegar
parents:
36511
diff
changeset
|
456 |
"--class-path", cp, |
2a5433a2eca5
8134779: (jmod) ZipException is thrown if there are duplicate resources
chegar
parents:
36511
diff
changeset
|
457 |
"--cmds", cp, |
2a5433a2eca5
8134779: (jmod) ZipException is thrown if there are duplicate resources
chegar
parents:
36511
diff
changeset
|
458 |
jmod.toString()) |
2a5433a2eca5
8134779: (jmod) ZipException is thrown if there are duplicate resources
chegar
parents:
36511
diff
changeset
|
459 |
.assertSuccess() |
2a5433a2eca5
8134779: (jmod) ZipException is thrown if there are duplicate resources
chegar
parents:
36511
diff
changeset
|
460 |
.resultChecker(r -> |
2a5433a2eca5
8134779: (jmod) ZipException is thrown if there are duplicate resources
chegar
parents:
36511
diff
changeset
|
461 |
assertContains(r.output, "Warning: ignoring entry") |
2a5433a2eca5
8134779: (jmod) ZipException is thrown if there are duplicate resources
chegar
parents:
36511
diff
changeset
|
462 |
); |
2a5433a2eca5
8134779: (jmod) ZipException is thrown if there are duplicate resources
chegar
parents:
36511
diff
changeset
|
463 |
} |
2a5433a2eca5
8134779: (jmod) ZipException is thrown if there are duplicate resources
chegar
parents:
36511
diff
changeset
|
464 |
|
2a5433a2eca5
8134779: (jmod) ZipException is thrown if there are duplicate resources
chegar
parents:
36511
diff
changeset
|
465 |
@Test |
43067
3f011a470ce2
8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents:
42922
diff
changeset
|
466 |
public void testLastOneWins() throws IOException { |
3f011a470ce2
8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents:
42922
diff
changeset
|
467 |
Path workDir = Paths.get("lastOneWins"); |
3f011a470ce2
8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents:
42922
diff
changeset
|
468 |
if (Files.exists(workDir)) |
3f011a470ce2
8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents:
42922
diff
changeset
|
469 |
FileUtils.deleteFileTreeWithRetry(workDir); |
3f011a470ce2
8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents:
42922
diff
changeset
|
470 |
Files.createDirectory(workDir); |
3f011a470ce2
8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents:
42922
diff
changeset
|
471 |
Path jmod = MODS_DIR.resolve("lastOneWins.jmod"); |
3f011a470ce2
8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents:
42922
diff
changeset
|
472 |
FileUtils.deleteFileIfExistsWithRetry(jmod); |
3f011a470ce2
8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents:
42922
diff
changeset
|
473 |
Path cp = EXPLODED_DIR.resolve("foo").resolve("classes"); |
3f011a470ce2
8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents:
42922
diff
changeset
|
474 |
Path bp = EXPLODED_DIR.resolve("foo").resolve("bin"); |
3f011a470ce2
8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents:
42922
diff
changeset
|
475 |
Path lp = EXPLODED_DIR.resolve("foo").resolve("lib"); |
3f011a470ce2
8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents:
42922
diff
changeset
|
476 |
Path cf = EXPLODED_DIR.resolve("foo").resolve("conf"); |
3f011a470ce2
8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents:
42922
diff
changeset
|
477 |
|
3f011a470ce2
8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents:
42922
diff
changeset
|
478 |
Path shouldNotBeAdded = workDir.resolve("shouldNotBeAdded"); |
3f011a470ce2
8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents:
42922
diff
changeset
|
479 |
Files.createDirectory(shouldNotBeAdded); |
3f011a470ce2
8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents:
42922
diff
changeset
|
480 |
Files.write(shouldNotBeAdded.resolve("aFile"), "hello".getBytes(UTF_8)); |
3f011a470ce2
8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents:
42922
diff
changeset
|
481 |
|
3f011a470ce2
8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents:
42922
diff
changeset
|
482 |
// Pairs of options. For options with required arguments the last one |
3f011a470ce2
8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents:
42922
diff
changeset
|
483 |
// should win ( first should be effectively ignored, but may still be |
3f011a470ce2
8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents:
42922
diff
changeset
|
484 |
// validated ). |
3f011a470ce2
8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents:
42922
diff
changeset
|
485 |
jmod("create", |
3f011a470ce2
8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents:
42922
diff
changeset
|
486 |
"--conf", shouldNotBeAdded.toString(), |
3f011a470ce2
8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents:
42922
diff
changeset
|
487 |
"--conf", cf.toString(), |
3f011a470ce2
8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents:
42922
diff
changeset
|
488 |
"--cmds", shouldNotBeAdded.toString(), |
3f011a470ce2
8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents:
42922
diff
changeset
|
489 |
"--cmds", bp.toString(), |
3f011a470ce2
8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents:
42922
diff
changeset
|
490 |
"--libs", shouldNotBeAdded.toString(), |
3f011a470ce2
8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents:
42922
diff
changeset
|
491 |
"--libs", lp.toString(), |
3f011a470ce2
8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents:
42922
diff
changeset
|
492 |
"--class-path", shouldNotBeAdded.toString(), |
3f011a470ce2
8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents:
42922
diff
changeset
|
493 |
"--class-path", cp.toString(), |
3f011a470ce2
8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents:
42922
diff
changeset
|
494 |
"--main-class", "does.NotExist", |
3f011a470ce2
8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents:
42922
diff
changeset
|
495 |
"--main-class", "jdk.test.foo.Foo", |
3f011a470ce2
8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents:
42922
diff
changeset
|
496 |
"--module-version", "00001", |
3f011a470ce2
8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents:
42922
diff
changeset
|
497 |
"--module-version", "5.4.3", |
3f011a470ce2
8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents:
42922
diff
changeset
|
498 |
"--do-not-resolve-by-default", |
3f011a470ce2
8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents:
42922
diff
changeset
|
499 |
"--do-not-resolve-by-default", |
3f011a470ce2
8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents:
42922
diff
changeset
|
500 |
"--warn-if-resolved=incubating", |
3f011a470ce2
8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents:
42922
diff
changeset
|
501 |
"--warn-if-resolved=deprecated", |
3f011a470ce2
8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents:
42922
diff
changeset
|
502 |
MODS_DIR.resolve("lastOneWins.jmod").toString()) |
3f011a470ce2
8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents:
42922
diff
changeset
|
503 |
.assertSuccess() |
3f011a470ce2
8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents:
42922
diff
changeset
|
504 |
.resultChecker(r -> { |
3f011a470ce2
8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents:
42922
diff
changeset
|
505 |
ModuleDescriptor md = getModuleDescriptor(jmod); |
3f011a470ce2
8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents:
42922
diff
changeset
|
506 |
Optional<String> omc = md.mainClass(); |
3f011a470ce2
8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents:
42922
diff
changeset
|
507 |
assertTrue(omc.isPresent()); |
3f011a470ce2
8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents:
42922
diff
changeset
|
508 |
assertEquals(omc.get(), "jdk.test.foo.Foo"); |
3f011a470ce2
8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents:
42922
diff
changeset
|
509 |
Optional<Version> ov = md.version(); |
3f011a470ce2
8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents:
42922
diff
changeset
|
510 |
assertTrue(ov.isPresent()); |
3f011a470ce2
8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents:
42922
diff
changeset
|
511 |
assertEquals(ov.get().toString(), "5.4.3"); |
3f011a470ce2
8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents:
42922
diff
changeset
|
512 |
|
3f011a470ce2
8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents:
42922
diff
changeset
|
513 |
try (Stream<String> s1 = findFiles(lp).map(p -> LIBS_PREFIX + p); |
3f011a470ce2
8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents:
42922
diff
changeset
|
514 |
Stream<String> s2 = findFiles(cp).map(p -> CLASSES_PREFIX + p); |
3f011a470ce2
8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents:
42922
diff
changeset
|
515 |
Stream<String> s3 = findFiles(bp).map(p -> CMDS_PREFIX + p); |
3f011a470ce2
8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents:
42922
diff
changeset
|
516 |
Stream<String> s4 = findFiles(cf).map(p -> CONFIGS_PREFIX + p)) { |
3f011a470ce2
8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents:
42922
diff
changeset
|
517 |
Set<String> expectedFilenames = Stream.concat(Stream.concat(s1,s2), |
3f011a470ce2
8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents:
42922
diff
changeset
|
518 |
Stream.concat(s3, s4)) |
3f011a470ce2
8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents:
42922
diff
changeset
|
519 |
.collect(toSet()); |
3f011a470ce2
8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents:
42922
diff
changeset
|
520 |
assertJmodContent(jmod, expectedFilenames); |
3f011a470ce2
8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents:
42922
diff
changeset
|
521 |
} |
3f011a470ce2
8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents:
42922
diff
changeset
|
522 |
}); |
3f011a470ce2
8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents:
42922
diff
changeset
|
523 |
|
3f011a470ce2
8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents:
42922
diff
changeset
|
524 |
jmod("extract", |
3f011a470ce2
8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents:
42922
diff
changeset
|
525 |
"--dir", "blah", |
3f011a470ce2
8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents:
42922
diff
changeset
|
526 |
"--dir", "lastOneWinsExtractDir", |
3f011a470ce2
8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents:
42922
diff
changeset
|
527 |
jmod.toString()) |
3f011a470ce2
8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents:
42922
diff
changeset
|
528 |
.assertSuccess() |
3f011a470ce2
8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents:
42922
diff
changeset
|
529 |
.resultChecker(r -> { |
3f011a470ce2
8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents:
42922
diff
changeset
|
530 |
assertTrue(Files.exists(Paths.get("lastOneWinsExtractDir"))); |
3f011a470ce2
8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents:
42922
diff
changeset
|
531 |
assertTrue(Files.notExists(Paths.get("blah"))); |
3f011a470ce2
8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents:
42922
diff
changeset
|
532 |
}); |
3f011a470ce2
8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents:
42922
diff
changeset
|
533 |
} |
3f011a470ce2
8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents:
42922
diff
changeset
|
534 |
|
3f011a470ce2
8168149: Examine the behavior of jmod command-line options - repeating vs last one wins
chegar
parents:
42922
diff
changeset
|
535 |
@Test |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41916
diff
changeset
|
536 |
public void testPackagesAttribute() throws IOException { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41916
diff
changeset
|
537 |
Path jmod = MODS_DIR.resolve("foo.jmod"); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41916
diff
changeset
|
538 |
FileUtils.deleteFileIfExistsWithRetry(jmod); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41916
diff
changeset
|
539 |
String cp = EXPLODED_DIR.resolve("foo").resolve("classes").toString(); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41916
diff
changeset
|
540 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41916
diff
changeset
|
541 |
Set<String> expectedPackages = Set.of("jdk.test.foo", |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41916
diff
changeset
|
542 |
"jdk.test.foo.internal", |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41916
diff
changeset
|
543 |
"jdk.test.foo.resources"); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41916
diff
changeset
|
544 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41916
diff
changeset
|
545 |
jmod("create", |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41916
diff
changeset
|
546 |
"--class-path", cp, |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41916
diff
changeset
|
547 |
jmod.toString()) |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41916
diff
changeset
|
548 |
.assertSuccess() |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41916
diff
changeset
|
549 |
.resultChecker(r -> { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41916
diff
changeset
|
550 |
Set<String> pkgs = getModuleDescriptor(jmod).packages(); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41916
diff
changeset
|
551 |
assertEquals(pkgs, expectedPackages); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41916
diff
changeset
|
552 |
}); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41916
diff
changeset
|
553 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41916
diff
changeset
|
554 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41916
diff
changeset
|
555 |
@Test |
36511 | 556 |
public void testVersion() { |
557 |
jmod("--version") |
|
558 |
.assertSuccess() |
|
559 |
.resultChecker(r -> { |
|
560 |
assertContains(r.output, System.getProperty("java.version")); |
|
561 |
}); |
|
562 |
} |
|
563 |
||
564 |
@Test |
|
565 |
public void testHelp() { |
|
566 |
jmod("--help") |
|
567 |
.assertSuccess() |
|
42703
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42468
diff
changeset
|
568 |
.resultChecker(r -> { |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42468
diff
changeset
|
569 |
assertTrue(r.output.startsWith("Usage: jmod"), "Help not printed"); |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42468
diff
changeset
|
570 |
assertFalse(r.output.contains("--do-not-resolve-by-default")); |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42468
diff
changeset
|
571 |
assertFalse(r.output.contains("--warn-if-resolved")); |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42468
diff
changeset
|
572 |
}); |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42468
diff
changeset
|
573 |
} |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42468
diff
changeset
|
574 |
|
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42468
diff
changeset
|
575 |
@Test |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42468
diff
changeset
|
576 |
public void testHelpExtra() { |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42468
diff
changeset
|
577 |
jmod("--help-extra") |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42468
diff
changeset
|
578 |
.assertSuccess() |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42468
diff
changeset
|
579 |
.resultChecker(r -> { |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42468
diff
changeset
|
580 |
assertTrue(r.output.startsWith("Usage: jmod"), "Extra help not printed"); |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42468
diff
changeset
|
581 |
assertContains(r.output, "--do-not-resolve-by-default"); |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42468
diff
changeset
|
582 |
assertContains(r.output, "--warn-if-resolved"); |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42468
diff
changeset
|
583 |
}); |
36511 | 584 |
} |
585 |
||
586 |
@Test |
|
587 |
public void testTmpFileRemoved() throws IOException { |
|
588 |
// Implementation detail: jmod tool creates <jmod-file>.tmp |
|
589 |
// Ensure that it is removed in the event of a failure. |
|
590 |
// The failure in this case is a class in the unnamed package. |
|
591 |
||
43242 | 592 |
Path jmod = MODS_DIR.resolve("testTmpFileRemoved.jmod"); |
593 |
Path tmp = MODS_DIR.resolve(".testTmpFileRemoved.jmod.tmp"); |
|
36511 | 594 |
FileUtils.deleteFileIfExistsWithRetry(jmod); |
43242 | 595 |
FileUtils.deleteFileIfExistsWithRetry(tmp); |
36511 | 596 |
String cp = EXPLODED_DIR.resolve("foo").resolve("classes") + File.pathSeparator + |
597 |
EXPLODED_DIR.resolve("foo").resolve("classes") |
|
598 |
.resolve("jdk").resolve("test").resolve("foo").toString(); |
|
599 |
||
600 |
jmod("create", |
|
601 |
"--class-path", cp, |
|
602 |
jmod.toString()) |
|
43242 | 603 |
.assertFailure() |
604 |
.resultChecker(r -> { |
|
605 |
assertContains(r.output, "unnamed package"); |
|
606 |
assertTrue(Files.notExists(tmp), "Unexpected tmp file:" + tmp); |
|
607 |
}); |
|
43109 | 608 |
} |
609 |
||
36511 | 610 |
// --- |
611 |
||
612 |
static boolean compileModule(String name, Path dest) throws IOException { |
|
613 |
return CompilerUtils.compile(SRC_DIR.resolve(name), dest); |
|
614 |
} |
|
615 |
||
616 |
static void assertContains(String output, String subString) { |
|
617 |
if (output.contains(subString)) |
|
618 |
assertTrue(true); |
|
619 |
else |
|
620 |
assertTrue(false,"Expected to find [" + subString + "], in output [" |
|
621 |
+ output + "]" + "\n"); |
|
622 |
} |
|
623 |
||
624 |
static ModuleDescriptor getModuleDescriptor(Path jmod) { |
|
625 |
ClassLoader cl = ClassLoader.getSystemClassLoader(); |
|
626 |
try (FileSystem fs = FileSystems.newFileSystem(jmod, cl)) { |
|
627 |
String p = "/classes/module-info.class"; |
|
628 |
try (InputStream is = Files.newInputStream(fs.getPath(p))) { |
|
629 |
return ModuleDescriptor.read(is); |
|
630 |
} |
|
631 |
} catch (IOException ioe) { |
|
632 |
throw new UncheckedIOException(ioe); |
|
633 |
} |
|
634 |
} |
|
635 |
||
636 |
static Stream<String> findFiles(Path dir) { |
|
637 |
try { |
|
638 |
return Files.find(dir, Integer.MAX_VALUE, (p, a) -> a.isRegularFile()) |
|
639 |
.map(dir::relativize) |
|
640 |
.map(Path::toString) |
|
641 |
.map(p -> p.replace(File.separator, "/")); |
|
642 |
} catch (IOException x) { |
|
643 |
throw new UncheckedIOException(x); |
|
644 |
} |
|
645 |
} |
|
646 |
||
647 |
static Set<String> getJmodContent(Path jmod) { |
|
648 |
JmodResult r = jmod("list", jmod.toString()).assertSuccess(); |
|
649 |
return Stream.of(r.output.split("\r?\n")).collect(toSet()); |
|
650 |
} |
|
651 |
||
652 |
static void assertJmodContent(Path jmod, Set<String> expected) { |
|
653 |
Set<String> actual = getJmodContent(jmod); |
|
654 |
if (!Objects.equals(actual, expected)) { |
|
655 |
Set<String> unexpected = new HashSet<>(actual); |
|
656 |
unexpected.removeAll(expected); |
|
657 |
Set<String> notFound = new HashSet<>(expected); |
|
658 |
notFound.removeAll(actual); |
|
659 |
StringBuilder sb = new StringBuilder(); |
|
660 |
sb.append("Unexpected but found:\n"); |
|
661 |
unexpected.forEach(s -> sb.append("\t" + s + "\n")); |
|
662 |
sb.append("Expected but not found:\n"); |
|
663 |
notFound.forEach(s -> sb.append("\t" + s + "\n")); |
|
664 |
assertTrue(false, "Jmod content check failed.\n" + sb.toString()); |
|
665 |
} |
|
666 |
} |
|
667 |
||
668 |
static void assertJmodDoesNotContain(Path jmod, Set<String> unexpectedNames) { |
|
669 |
Set<String> actual = getJmodContent(jmod); |
|
670 |
Set<String> unexpected = new HashSet<>(); |
|
671 |
for (String name : unexpectedNames) { |
|
672 |
if (actual.contains(name)) |
|
673 |
unexpected.add(name); |
|
674 |
} |
|
675 |
if (!unexpected.isEmpty()) { |
|
676 |
StringBuilder sb = new StringBuilder(); |
|
677 |
for (String s : unexpected) |
|
678 |
sb.append("Unexpected but found: " + s + "\n"); |
|
679 |
sb.append("In :"); |
|
680 |
for (String s : actual) |
|
681 |
sb.append("\t" + s + "\n"); |
|
682 |
assertTrue(false, "Jmod content check failed.\n" + sb.toString()); |
|
683 |
} |
|
684 |
} |
|
685 |
||
42468 | 686 |
static void assertSameContent(Path p1, Path p2) { |
687 |
try { |
|
688 |
byte[] ba1 = Files.readAllBytes(p1); |
|
689 |
byte[] ba2 = Files.readAllBytes(p2); |
|
690 |
assertEquals(ba1, ba2); |
|
691 |
} catch (IOException x) { |
|
692 |
throw new UncheckedIOException(x); |
|
693 |
} |
|
694 |
} |
|
695 |
||
36511 | 696 |
static JmodResult jmod(String... args) { |
697 |
ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
|
698 |
PrintStream ps = new PrintStream(baos); |
|
699 |
System.out.println("jmod " + Arrays.asList(args)); |
|
41484
834b7539ada3
8164689: Retrofit jar, jlink, jmod as a ToolProvider
mchung
parents:
39882
diff
changeset
|
700 |
int ec = JMOD_TOOL.run(ps, ps, args); |
36511 | 701 |
return new JmodResult(ec, new String(baos.toByteArray(), UTF_8)); |
702 |
} |
|
703 |
||
704 |
static class JmodResult { |
|
705 |
final int exitCode; |
|
706 |
final String output; |
|
707 |
||
708 |
JmodResult(int exitValue, String output) { |
|
709 |
this.exitCode = exitValue; |
|
710 |
this.output = output; |
|
711 |
} |
|
712 |
JmodResult assertSuccess() { assertTrue(exitCode == 0, output); return this; } |
|
713 |
JmodResult assertFailure() { assertTrue(exitCode != 0, output); return this; } |
|
714 |
JmodResult resultChecker(Consumer<JmodResult> r) { r.accept(this); return this; } |
|
715 |
} |
|
716 |
||
717 |
static void createCmds(Path dir) throws IOException { |
|
718 |
List<String> files = Arrays.asList( |
|
719 |
"first", "second", "third" + File.separator + "third"); |
|
720 |
createFiles(dir, files); |
|
721 |
} |
|
722 |
||
723 |
static void createLibs(Path dir) throws IOException { |
|
724 |
List<String> files = Arrays.asList( |
|
725 |
"first.so", "second.so", "third" + File.separator + "third.so"); |
|
726 |
createFiles(dir, files); |
|
727 |
} |
|
728 |
||
729 |
static void createConfigs(Path dir) throws IOException { |
|
730 |
List<String> files = Arrays.asList( |
|
731 |
"first.cfg", "second.cfg", "third" + File.separator + "third.cfg"); |
|
732 |
createFiles(dir, files); |
|
733 |
} |
|
734 |
||
735 |
static void createFiles(Path dir, List<String> filenames) throws IOException { |
|
736 |
for (String name : filenames) { |
|
737 |
Path file = dir.resolve(name); |
|
738 |
Files.createDirectories(file.getParent()); |
|
739 |
Files.createFile(file); |
|
740 |
try (OutputStream os = Files.newOutputStream(file)) { |
|
741 |
os.write("blahblahblah".getBytes(UTF_8)); |
|
742 |
} |
|
743 |
} |
|
744 |
} |
|
745 |
||
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41916
diff
changeset
|
746 |
static void copyResource(Path srcDir, Path dir, String resource) throws IOException { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41916
diff
changeset
|
747 |
Path dest = dir.resolve(resource); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41916
diff
changeset
|
748 |
Files.deleteIfExists(dest); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41916
diff
changeset
|
749 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41916
diff
changeset
|
750 |
Files.createDirectories(dest.getParent()); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41916
diff
changeset
|
751 |
Files.copy(srcDir.resolve(resource), dest); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41916
diff
changeset
|
752 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41916
diff
changeset
|
753 |
|
36511 | 754 |
// Standalone entry point. |
755 |
public static void main(String[] args) throws Throwable { |
|
756 |
JmodTest test = new JmodTest(); |
|
757 |
test.buildExplodedModules(); |
|
758 |
for (Method m : JmodTest.class.getDeclaredMethods()) { |
|
759 |
if (m.getAnnotation(Test.class) != null) { |
|
760 |
System.out.println("Invoking " + m.getName()); |
|
761 |
m.invoke(test); |
|
762 |
} |
|
763 |
} |
|
764 |
} |
|
765 |
} |