diff --git a/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/HelloApp.java b/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/HelloApp.java index a004dd421c1..46aa2f1375f 100644 --- a/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/HelloApp.java +++ b/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/HelloApp.java @@ -351,16 +351,6 @@ public final class HelloApp { this.outputFilePath = TKit.workDir().resolve(OUTPUT_FILENAME); this.params = new HashMap<>(); this.defaultLauncherArgs = new ArrayList<>(); - - if (TKit.isWindows()) { - // When running app launchers on Windows, clear users environment (JDK-8254920) - removePath(true); - } - } - - public AppOutputVerifier removePath(boolean v) { - removePath = v; - return this; } public AppOutputVerifier saveOutput(boolean v) { @@ -442,10 +432,7 @@ public final class HelloApp { if (launcherNoExit) { return getExecutor(args).executeWithoutExitCodeCheck(); } else { - final int attempts = 3; - final int waitBetweenAttemptsSeconds = 5; - return getExecutor(args).executeAndRepeatUntilExitCode(expectedExitCode, attempts, - waitBetweenAttemptsSeconds); + return HelloApp.execute(expectedExitCode, getExecutor(args)); } } @@ -475,7 +462,6 @@ public final class HelloApp { } private boolean launcherNoExit; - private boolean removePath; private boolean saveOutput; private final Path launcherPath; private Path outputFilePath; @@ -488,7 +474,22 @@ public final class HelloApp { return new AppOutputVerifier(helloAppLauncher); } - public static Executor configureEnvironment(Executor executor) { + public static Executor.Result configureAndExecute(int expectedExitCode, Executor executor) { + return execute(expectedExitCode, configureEnvironment(executor)); + } + + private static Executor.Result execute(int expectedExitCode, Executor executor) { + if (TKit.isLinux()) { + final int attempts = 3; + final int waitBetweenAttemptsSeconds = 5; + return executor.executeAndRepeatUntilExitCode(expectedExitCode, attempts, + waitBetweenAttemptsSeconds); + } else { + return executor.execute(expectedExitCode); + } + } + + private static Executor configureEnvironment(Executor executor) { if (CLEAR_JAVA_ENV_VARS) { executor.removeEnvVar("JAVA_TOOL_OPTIONS"); executor.removeEnvVar("_JAVA_OPTIONS"); diff --git a/test/jdk/tools/jpackage/share/AppLauncherEnvTest.java b/test/jdk/tools/jpackage/share/AppLauncherEnvTest.java index 52016e6f4ab..772370b0f8c 100644 --- a/test/jdk/tools/jpackage/share/AppLauncherEnvTest.java +++ b/test/jdk/tools/jpackage/share/AppLauncherEnvTest.java @@ -30,7 +30,7 @@ import java.util.stream.Stream; import jdk.jpackage.test.JPackageCommand; import jdk.jpackage.test.Annotations.Test; import jdk.jpackage.test.Executor; -import static jdk.jpackage.test.HelloApp.configureEnvironment; +import static jdk.jpackage.test.HelloApp.configureAndExecute; import jdk.jpackage.test.TKit; /** @@ -62,16 +62,12 @@ public class AppLauncherEnvTest { final String envVarName = envVarName(); - final int attempts = 3; - final int waitBetweenAttemptsSeconds = 5; - List output = configureEnvironment(new Executor()) + List output = configureAndExecute(0, new Executor() .saveOutput() .setExecutable(cmd.appLauncherPath().toAbsolutePath()) .addArguments("--print-env-var=" + envVarName) .addArguments("--print-sys-prop=" + testAddDirProp) - .addArguments("--print-sys-prop=" + "java.library.path") - .executeAndRepeatUntilExitCode(0, attempts, - waitBetweenAttemptsSeconds).getOutput(); + .addArguments("--print-sys-prop=" + "java.library.path")).getOutput(); BiFunction getValue = (idx, name) -> { return output.get(idx).substring((name + "=").length()); diff --git a/test/jdk/tools/jpackage/windows/WinChildProcessTest.java b/test/jdk/tools/jpackage/windows/WinChildProcessTest.java index 5b0ff9b1f01..a83ef837331 100644 --- a/test/jdk/tools/jpackage/windows/WinChildProcessTest.java +++ b/test/jdk/tools/jpackage/windows/WinChildProcessTest.java @@ -40,7 +40,7 @@ import java.util.Optional; import java.nio.file.Path; import jdk.jpackage.test.JPackageCommand; -import static jdk.jpackage.test.HelloApp.configureEnvironment; +import static jdk.jpackage.test.HelloApp.configureAndExecute; import jdk.jpackage.test.Annotations.Test; import jdk.jpackage.test.Executor; import jdk.jpackage.test.TKit; @@ -63,9 +63,9 @@ public class WinChildProcessTest { // Start the third party application launcher and dump and save the // output of the application - List output = configureEnvironment(new Executor()).saveOutput().dumpOutput() - .setExecutable(cmd.appLauncherPath().toAbsolutePath()) - .execute(0).getOutput(); + List output = configureAndExecute(0, new Executor().saveOutput().dumpOutput() + .setExecutable(cmd.appLauncherPath().toAbsolutePath())) + .getOutput(); String pidStr = output.get(0); // parse child PID