11/*
2- * Copyright (c) 2019, 2022 , Oracle and/or its affiliates. All rights reserved.
2+ * Copyright (c) 2019, 2024 , Oracle and/or its affiliates. All rights reserved.
33 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44 *
55 * This code is free software; you can redistribute it and/or modify it
@@ -311,20 +311,23 @@ public static Path createBundle(JavaAppDesc appDesc, Path outputDir) {
311311
312312 public static void executeLauncherAndVerifyOutput (JPackageCommand cmd ,
313313 String ... args ) {
314- AppOutputVerifier av = getVerifier (cmd , args );
314+ AppOutputVerifier av = assertMainLauncher (cmd , args );
315315 if (av != null ) {
316- // when running app launchers, clear users environment
317- av .executeAndVerifyOutput (true , args );
316+ av .executeAndVerifyOutput (args );
318317 }
319318 }
320319
321320 public static Executor .Result executeLauncher (JPackageCommand cmd ,
322321 String ... args ) {
323- AppOutputVerifier av = getVerifier (cmd , args );
324- return av .executeOnly (true , args );
322+ AppOutputVerifier av = assertMainLauncher (cmd , args );
323+ if (av != null ) {
324+ return av .saveOutput (true ).execute (args );
325+ } else {
326+ return null ;
327+ }
325328 }
326329
327- private static AppOutputVerifier getVerifier (JPackageCommand cmd ,
330+ public static AppOutputVerifier assertMainLauncher (JPackageCommand cmd ,
328331 String ... args ) {
329332 final Path launcherPath = cmd .appLauncherPath ();
330333 if (!cmd .canRunLauncher (String .format ("Not running [%s] launcher" ,
@@ -348,6 +351,26 @@ public static final class AppOutputVerifier {
348351 this .outputFilePath = TKit .workDir ().resolve (OUTPUT_FILENAME );
349352 this .params = new HashMap <>();
350353 this .defaultLauncherArgs = new ArrayList <>();
354+
355+ if (TKit .isWindows ()) {
356+ // When running app launchers on Windows, clear users environment (JDK-8254920)
357+ removePath (true );
358+ }
359+ }
360+
361+ public AppOutputVerifier removePath (boolean v ) {
362+ removePath = v ;
363+ return this ;
364+ }
365+
366+ public AppOutputVerifier saveOutput (boolean v ) {
367+ saveOutput = v ;
368+ return this ;
369+ }
370+
371+ public AppOutputVerifier expectedExitCode (int v ) {
372+ expectedExitCode = v ;
373+ return this ;
351374 }
352375
353376 public AppOutputVerifier addDefaultArguments (String ... v ) {
@@ -366,6 +389,8 @@ public AppOutputVerifier addParam(String name, String value) {
366389 outputFilePath = Path .of (value );
367390 } else if ("jpackage.test.exitCode" .equals (name )) {
368391 expectedExitCode = Integer .parseInt (value );
392+ } else if ("jpackage.test.noexit" .equals (name )) {
393+ launcherNoExit = Boolean .parseBoolean (value );
369394 }
370395 return this ;
371396 }
@@ -409,36 +434,19 @@ public void verifyOutput(String... args) {
409434 }
410435
411436 public void executeAndVerifyOutput (String ... args ) {
412- executeAndVerifyOutput (false , args );
413- }
414-
415- public void executeAndVerifyOutput (boolean removePath ,
416- List <String > launcherArgs , List <String > appArgs ) {
417- final int attempts = 3 ;
418- final int waitBetweenAttemptsSeconds = 5 ;
419- getExecutor (launcherArgs .toArray (new String [0 ])).dumpOutput ().setRemovePath (
420- removePath ).executeAndRepeatUntilExitCode (expectedExitCode ,
421- attempts , waitBetweenAttemptsSeconds );
422- verifyOutputFile (outputFilePath , appArgs , params );
437+ execute (args );
438+ verifyOutput (args );
423439 }
424440
425- public void executeAndVerifyOutput (boolean removePath , String ... args ) {
426- final List <String > launcherArgs = List .of (args );
427- final List <String > appArgs ;
428- if (launcherArgs .isEmpty ()) {
429- appArgs = defaultLauncherArgs ;
441+ public Executor .Result execute (String ... args ) {
442+ if (launcherNoExit ) {
443+ return getExecutor (args ).executeWithoutExitCodeCheck ();
430444 } else {
431- appArgs = launcherArgs ;
445+ final int attempts = 3 ;
446+ final int waitBetweenAttemptsSeconds = 5 ;
447+ return getExecutor (args ).executeAndRepeatUntilExitCode (expectedExitCode , attempts ,
448+ waitBetweenAttemptsSeconds );
432449 }
433-
434- executeAndVerifyOutput (removePath , launcherArgs , appArgs );
435- }
436-
437- public Executor .Result executeOnly (boolean removePath , String ...args ) {
438- return getExecutor (args )
439- .saveOutput ()
440- .setRemovePath (removePath )
441- .executeWithoutExitCodeCheck ();
442450 }
443451
444452 private Executor getExecutor (String ...args ) {
@@ -458,10 +466,16 @@ private Executor getExecutor(String...args) {
458466 final List <String > launcherArgs = List .of (args );
459467 return new Executor ()
460468 .setDirectory (outputFile .getParent ())
469+ .saveOutput (saveOutput )
470+ .dumpOutput ()
471+ .setRemovePath (removePath )
461472 .setExecutable (executablePath )
462473 .addArguments (launcherArgs );
463474 }
464475
476+ private boolean launcherNoExit ;
477+ private boolean removePath ;
478+ private boolean saveOutput ;
465479 private final Path launcherPath ;
466480 private Path outputFilePath ;
467481 private int expectedExitCode ;
0 commit comments