25 * @test
26 * @library /lib/testlibrary
27 * @modules jdk.jlink/jdk.tools.jmod
28 * jdk.compiler
29 * @build jdk.testlibrary.FileUtils CompilerUtils
30 * @run testng JmodTest
31 * @summary Basic test for jmod
32 */
33
34 import java.io.*;
35 import java.lang.module.ModuleDescriptor;
36 import java.lang.reflect.Method;
37 import java.nio.file.*;
38 import java.util.*;
39 import java.util.function.Consumer;
40 import java.util.regex.Pattern;
41 import java.util.stream.Stream;
42 import jdk.testlibrary.FileUtils;
43 import org.testng.annotations.BeforeTest;
44 import org.testng.annotations.Test;
45 import static java.lang.module.ModuleDescriptor.Version;
46 import static java.nio.charset.StandardCharsets.UTF_8;
47 import static java.util.stream.Collectors.toSet;
48 import static org.testng.Assert.*;
49
50 public class JmodTest {
51
52 static final String TEST_SRC = System.getProperty("test.src", ".");
53 static final Path SRC_DIR = Paths.get(TEST_SRC, "src");
54 static final Path EXPLODED_DIR = Paths.get("build");
55 static final Path MODS_DIR = Paths.get("jmods");
56
57 static final String CLASSES_PREFIX = "classes/";
58 static final String CMDS_PREFIX = "bin/";
59 static final String LIBS_PREFIX = "native/";
60 static final String CONFIGS_PREFIX = "conf/";
61
62 @BeforeTest
63 public void buildExplodedModules() throws IOException {
64 if (Files.exists(EXPLODED_DIR))
266
267 jmod("describe",
268 MODS_DIR.resolve("describeFoo.jmod").toString())
269 .assertSuccess()
270 .resultChecker(r -> {
271 // Expect similar output: "foo, requires mandated java.base
272 // exports jdk.test.foo, conceals jdk.test.foo.internal"
273 Pattern p = Pattern.compile("\\s+foo\\s+requires\\s+mandated\\s+java.base");
274 assertTrue(p.matcher(r.output).find(),
275 "Expecting to find \"foo, requires java.base\"" +
276 "in output, but did not: [" + r.output + "]");
277 p = Pattern.compile(
278 "exports\\s+jdk.test.foo\\s+conceals\\s+jdk.test.foo.internal");
279 assertTrue(p.matcher(r.output).find(),
280 "Expecting to find \"exports ..., conceals ...\"" +
281 "in output, but did not: [" + r.output + "]");
282 });
283 }
284
285 @Test
286 public void testVersion() {
287 jmod("--version")
288 .assertSuccess()
289 .resultChecker(r -> {
290 assertContains(r.output, System.getProperty("java.version"));
291 });
292 }
293
294 @Test
295 public void testHelp() {
296 jmod("--help")
297 .assertSuccess()
298 .resultChecker(r ->
299 assertTrue(r.output.startsWith("Usage: jmod"), "Help not printed")
300 );
301 }
302
303 @Test
304 public void testTmpFileAlreadyExists() throws IOException {
305 // Implementation detail: jmod tool creates <jmod-file>.tmp
|
25 * @test
26 * @library /lib/testlibrary
27 * @modules jdk.jlink/jdk.tools.jmod
28 * jdk.compiler
29 * @build jdk.testlibrary.FileUtils CompilerUtils
30 * @run testng JmodTest
31 * @summary Basic test for jmod
32 */
33
34 import java.io.*;
35 import java.lang.module.ModuleDescriptor;
36 import java.lang.reflect.Method;
37 import java.nio.file.*;
38 import java.util.*;
39 import java.util.function.Consumer;
40 import java.util.regex.Pattern;
41 import java.util.stream.Stream;
42 import jdk.testlibrary.FileUtils;
43 import org.testng.annotations.BeforeTest;
44 import org.testng.annotations.Test;
45
46 import static java.io.File.pathSeparator;
47 import static java.lang.module.ModuleDescriptor.Version;
48 import static java.nio.charset.StandardCharsets.UTF_8;
49 import static java.util.stream.Collectors.toSet;
50 import static org.testng.Assert.*;
51
52 public class JmodTest {
53
54 static final String TEST_SRC = System.getProperty("test.src", ".");
55 static final Path SRC_DIR = Paths.get(TEST_SRC, "src");
56 static final Path EXPLODED_DIR = Paths.get("build");
57 static final Path MODS_DIR = Paths.get("jmods");
58
59 static final String CLASSES_PREFIX = "classes/";
60 static final String CMDS_PREFIX = "bin/";
61 static final String LIBS_PREFIX = "native/";
62 static final String CONFIGS_PREFIX = "conf/";
63
64 @BeforeTest
65 public void buildExplodedModules() throws IOException {
66 if (Files.exists(EXPLODED_DIR))
268
269 jmod("describe",
270 MODS_DIR.resolve("describeFoo.jmod").toString())
271 .assertSuccess()
272 .resultChecker(r -> {
273 // Expect similar output: "foo, requires mandated java.base
274 // exports jdk.test.foo, conceals jdk.test.foo.internal"
275 Pattern p = Pattern.compile("\\s+foo\\s+requires\\s+mandated\\s+java.base");
276 assertTrue(p.matcher(r.output).find(),
277 "Expecting to find \"foo, requires java.base\"" +
278 "in output, but did not: [" + r.output + "]");
279 p = Pattern.compile(
280 "exports\\s+jdk.test.foo\\s+conceals\\s+jdk.test.foo.internal");
281 assertTrue(p.matcher(r.output).find(),
282 "Expecting to find \"exports ..., conceals ...\"" +
283 "in output, but did not: [" + r.output + "]");
284 });
285 }
286
287 @Test
288 public void testDuplicateEntries() throws IOException {
289 Path jmod = MODS_DIR.resolve("testDuplicates.jmod");
290 FileUtils.deleteFileIfExistsWithRetry(jmod);
291 String cp = EXPLODED_DIR.resolve("foo").resolve("classes").toString();
292 Path lp = EXPLODED_DIR.resolve("foo").resolve("lib");
293
294 jmod("create",
295 "--class-path", cp + pathSeparator + cp,
296 jmod.toString())
297 .assertSuccess()
298 .resultChecker(r ->
299 assertContains(r.output, "Warning: ignoring duplicate entry")
300 );
301
302 FileUtils.deleteFileIfExistsWithRetry(jmod);
303 jmod("create",
304 "--class-path", cp,
305 "--libs", lp.toString() + pathSeparator + lp.toString(),
306 jmod.toString())
307 .assertSuccess()
308 .resultChecker(r ->
309 assertContains(r.output, "Warning: ignoring duplicate entry")
310 );
311 }
312
313 @Test
314 public void testIgnoreModuleInfoInOtherSections() throws IOException {
315 Path jmod = MODS_DIR.resolve("testIgnoreModuleInfoInOtherSections.jmod");
316 FileUtils.deleteFileIfExistsWithRetry(jmod);
317 String cp = EXPLODED_DIR.resolve("foo").resolve("classes").toString();
318
319 jmod("create",
320 "--class-path", cp,
321 "--libs", cp,
322 jmod.toString())
323 .assertSuccess()
324 .resultChecker(r ->
325 assertContains(r.output, "Warning: ignoring entry")
326 );
327
328 FileUtils.deleteFileIfExistsWithRetry(jmod);
329 jmod("create",
330 "--class-path", cp,
331 "--cmds", cp,
332 jmod.toString())
333 .assertSuccess()
334 .resultChecker(r ->
335 assertContains(r.output, "Warning: ignoring entry")
336 );
337 }
338
339 @Test
340 public void testVersion() {
341 jmod("--version")
342 .assertSuccess()
343 .resultChecker(r -> {
344 assertContains(r.output, System.getProperty("java.version"));
345 });
346 }
347
348 @Test
349 public void testHelp() {
350 jmod("--help")
351 .assertSuccess()
352 .resultChecker(r ->
353 assertTrue(r.output.startsWith("Usage: jmod"), "Help not printed")
354 );
355 }
356
357 @Test
358 public void testTmpFileAlreadyExists() throws IOException {
359 // Implementation detail: jmod tool creates <jmod-file>.tmp
|