305 if (moduleName != null) { |
305 if (moduleName != null) { |
306 // Build module jar. |
306 // Build module jar. |
307 cmd.executePrerequisiteActions(); |
307 cmd.executePrerequisiteActions(); |
308 } |
308 } |
309 |
309 |
310 TKit.withTempDirectory("runtime", runtimeDir -> { |
310 TKit.withTempDirectory("runtime", tempDir -> { |
311 TKit.deleteDirectoryRecursive(runtimeDir, String.format( |
311 final Path runtimeDir = tempDir.resolve("data"); |
312 "Delete [%s] output directory for jlink command", runtimeDir)); |
312 |
|
313 // List of modules required for test app. |
|
314 final var modules = new String[] { |
|
315 "java.base", |
|
316 "java.desktop" |
|
317 }; |
|
318 |
313 Executor jlink = getToolProvider(JavaTool.JLINK) |
319 Executor jlink = getToolProvider(JavaTool.JLINK) |
314 .saveOutput(false) |
320 .saveOutput(false) |
315 .addArguments( |
321 .addArguments( |
316 "--add-modules", "java.base", |
322 "--add-modules", String.join(",", modules), |
317 "--output", runtimeDir.toString(), |
323 "--output", runtimeDir.toString(), |
318 "--strip-debug", |
324 "--strip-debug", |
319 "--no-header-files", |
325 "--no-header-files", |
320 "--no-man-pages"); |
326 "--no-man-pages"); |
321 |
327 |
327 |
333 |
328 jlink.execute().assertExitCodeIsZero(); |
334 jlink.execute().assertExitCodeIsZero(); |
329 |
335 |
330 cmd.addArguments("--runtime-image", runtimeDir); |
336 cmd.addArguments("--runtime-image", runtimeDir); |
331 cmd.executeAndAssertHelloAppImageCreated(); |
337 cmd.executeAndAssertHelloAppImageCreated(); |
332 |
|
333 final Path appImageRuntimePath = cmd.appRuntimeDirectory(); |
|
334 |
|
335 // |
|
336 // This is an overkill to list modules in jlink output as we have |
|
337 // already verified that Java app is functional and thus app's runtime |
|
338 // is likely to be OK, but let's double check. |
|
339 // |
|
340 // Filter out all first strings with whitespace. They are java |
|
341 // launcher output like `Picked up ...` unrelated to module names. |
|
342 // |
|
343 Pattern whitespaceChar = Pattern.compile("\\s"); |
|
344 List<String> moduleList = new Executor().dumpOutput().setExecutable( |
|
345 appImageRuntimePath.resolve( |
|
346 JPackageCommand.relativePathInRuntime(JavaTool.JAVA))).addArguments( |
|
347 "--list-modules").executeAndGetOutput().stream().dropWhile( |
|
348 s -> whitespaceChar.matcher(s).find()).sorted().collect( |
|
349 Collectors.toList()); |
|
350 |
|
351 List<String> expectedModules = new ArrayList<>(); |
|
352 expectedModules.add(String.format("java.base@%s", |
|
353 System.getProperty("java.version"))); |
|
354 if (moduleName != null) { |
|
355 expectedModules.add(moduleName); |
|
356 } |
|
357 expectedModules = expectedModules.stream().sorted().collect( |
|
358 Collectors.toList()); |
|
359 |
|
360 TKit.assertStringListEquals(expectedModules, moduleList, |
|
361 String.format( |
|
362 "Check modules in application image runtime directory at [%s]", |
|
363 appImageRuntimePath)); |
|
364 }); |
338 }); |
365 } |
339 } |
366 |
340 |
367 private static Executor getJPackageToolProvider() { |
341 private static Executor getJPackageToolProvider() { |
368 return getToolProvider(JavaTool.JPACKAGE); |
342 return getToolProvider(JavaTool.JPACKAGE); |