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