@@ -294,34 +294,8 @@ public JPackageCommand setInputToEmptyDirectory() {
294294
295295 public JPackageCommand setFakeRuntime () {
296296 verifyMutable ();
297-
298- ThrowingConsumer <Path , IOException > createBulkFile = path -> {
299- Files .createDirectories (path .getParent ());
300- try (FileOutputStream out = new FileOutputStream (path .toFile ())) {
301- byte [] bytes = new byte [4 * 1024 ];
302- new SecureRandom ().nextBytes (bytes );
303- out .write (bytes );
304- }
305- };
306-
307297 addPrerequisiteAction (cmd -> {
308- Path fakeRuntimeDir = TKit .createTempDirectory ("fake_runtime" );
309-
310- TKit .trace (String .format ("Init fake runtime in [%s] directory" ,
311- fakeRuntimeDir ));
312-
313- if (TKit .isOSX ()) {
314- // Make MacAppImageBuilder happy
315- createBulkFile .accept (fakeRuntimeDir .resolve (Path .of (
316- "lib/jli/libjli.dylib" )));
317- }
318-
319- // Make sure fake runtime takes some disk space.
320- // Package bundles with 0KB size are unexpected and considered
321- // an error by PackageTest.
322- createBulkFile .accept (fakeRuntimeDir .resolve (Path .of ("lib" , "bulk" )));
323-
324- cmd .setArgumentValue ("--runtime-image" , fakeRuntimeDir );
298+ cmd .setArgumentValue ("--runtime-image" , createInputRuntimeImage (RuntimeImageType .RUNTIME_TYPE_FAKE ));
325299 });
326300
327301 return this ;
@@ -390,24 +364,77 @@ public static JPackageCommand helloAppImage(JavaAppDesc javaAppDesc) {
390364 return cmd ;
391365 }
392366
367+ public enum RuntimeImageType {
368+
369+ /**
370+ * Runtime suitable for running the default "Hello" test app.
371+ */
372+ RUNTIME_TYPE_HELLO_APP ,
373+
374+ /**
375+ * Fake runtime.
376+ */
377+ RUNTIME_TYPE_FAKE ,
378+
379+ ;
380+ }
381+
393382 public static Path createInputRuntimeImage () {
383+ return createInputRuntimeImage (RuntimeImageType .RUNTIME_TYPE_HELLO_APP );
384+ }
385+
386+ public static Path createInputRuntimeImage (RuntimeImageType role ) {
387+ Objects .requireNonNull (role );
394388
395389 final Path runtimeImageDir ;
390+ switch (role ) {
391+
392+ case RUNTIME_TYPE_FAKE -> {
393+ Consumer <Path > createBulkFile = ThrowingConsumer .toConsumer (path -> {
394+ Files .createDirectories (path .getParent ());
395+ try (FileOutputStream out = new FileOutputStream (path .toFile ())) {
396+ byte [] bytes = new byte [4 * 1024 ];
397+ new SecureRandom ().nextBytes (bytes );
398+ out .write (bytes );
399+ }
400+ });
396401
397- if (JPackageCommand .DEFAULT_RUNTIME_IMAGE != null ) {
398- runtimeImageDir = JPackageCommand .DEFAULT_RUNTIME_IMAGE ;
399- } else {
400- runtimeImageDir = TKit .createTempDirectory ("runtime-image" ).resolve ("data" );
401-
402- new Executor ().setToolProvider (JavaTool .JLINK )
403- .dumpOutput ()
404- .addArguments (
405- "--output" , runtimeImageDir .toString (),
406- "--add-modules" , "java.desktop" ,
407- "--strip-debug" ,
408- "--no-header-files" ,
409- "--no-man-pages" )
410- .execute ();
402+ runtimeImageDir = TKit .createTempDirectory ("fake_runtime" );
403+
404+ TKit .trace (String .format ("Init fake runtime in [%s] directory" , runtimeImageDir ));
405+
406+ if (TKit .isOSX ()) {
407+ // Make MacAppImageBuilder happy
408+ createBulkFile .accept (runtimeImageDir .resolve (Path .of ("lib/jli/libjli.dylib" )));
409+ }
410+
411+ // Make sure fake runtime takes some disk space.
412+ // Package bundles with 0KB size are unexpected and considered
413+ // an error by PackageTest.
414+ createBulkFile .accept (runtimeImageDir .resolve (Path .of ("lib" , "bulk" )));
415+ }
416+
417+ case RUNTIME_TYPE_HELLO_APP -> {
418+ if (JPackageCommand .DEFAULT_RUNTIME_IMAGE != null && !isFakeRuntime (DEFAULT_RUNTIME_IMAGE )) {
419+ runtimeImageDir = JPackageCommand .DEFAULT_RUNTIME_IMAGE ;
420+ } else {
421+ runtimeImageDir = TKit .createTempDirectory ("runtime-image" ).resolve ("data" );
422+
423+ new Executor ().setToolProvider (JavaTool .JLINK )
424+ .dumpOutput ()
425+ .addArguments (
426+ "--output" , runtimeImageDir .toString (),
427+ "--add-modules" , "java.desktop" ,
428+ "--strip-debug" ,
429+ "--no-header-files" ,
430+ "--no-man-pages" )
431+ .execute ();
432+ }
433+ }
434+
435+ default -> {
436+ throw ExceptionBox .reachedUnreachable ();
437+ }
411438 }
412439
413440 return runtimeImageDir ;
0 commit comments