Skip to content

Commit 78133b9

Browse files
author
duke
committed
Backport ce312b3ecbbacaf23f4b2893898ce8de8cd53daa
1 parent 22fef0a commit 78133b9

File tree

3 files changed

+24
-27
lines changed

3 files changed

+24
-27
lines changed

test/jdk/tools/jpackage/helpers/jdk/jpackage/test/HelloApp.java

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -351,16 +351,6 @@ public static final class AppOutputVerifier {
351351
this.outputFilePath = TKit.workDir().resolve(OUTPUT_FILENAME);
352352
this.params = new HashMap<>();
353353
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;
364354
}
365355

366356
public AppOutputVerifier saveOutput(boolean v) {
@@ -442,10 +432,7 @@ public Executor.Result execute(String... args) {
442432
if (launcherNoExit) {
443433
return getExecutor(args).executeWithoutExitCodeCheck();
444434
} else {
445-
final int attempts = 3;
446-
final int waitBetweenAttemptsSeconds = 5;
447-
return getExecutor(args).executeAndRepeatUntilExitCode(expectedExitCode, attempts,
448-
waitBetweenAttemptsSeconds);
435+
return HelloApp.execute(expectedExitCode, getExecutor(args));
449436
}
450437
}
451438

@@ -475,7 +462,6 @@ private Executor getExecutor(String...args) {
475462
}
476463

477464
private boolean launcherNoExit;
478-
private boolean removePath;
479465
private boolean saveOutput;
480466
private final Path launcherPath;
481467
private Path outputFilePath;
@@ -488,7 +474,22 @@ public static AppOutputVerifier assertApp(Path helloAppLauncher) {
488474
return new AppOutputVerifier(helloAppLauncher);
489475
}
490476

491-
public static Executor configureEnvironment(Executor executor) {
477+
public static Executor.Result configureAndExecute(int expectedExitCode, Executor executor) {
478+
return execute(expectedExitCode, configureEnvironment(executor));
479+
}
480+
481+
private static Executor.Result execute(int expectedExitCode, Executor executor) {
482+
if (TKit.isLinux()) {
483+
final int attempts = 3;
484+
final int waitBetweenAttemptsSeconds = 5;
485+
return executor.executeAndRepeatUntilExitCode(expectedExitCode, attempts,
486+
waitBetweenAttemptsSeconds);
487+
} else {
488+
return executor.execute(expectedExitCode);
489+
}
490+
}
491+
492+
private static Executor configureEnvironment(Executor executor) {
492493
if (CLEAR_JAVA_ENV_VARS) {
493494
executor.removeEnvVar("JAVA_TOOL_OPTIONS");
494495
executor.removeEnvVar("_JAVA_OPTIONS");

test/jdk/tools/jpackage/share/AppLauncherEnvTest.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
import jdk.jpackage.test.JPackageCommand;
3131
import jdk.jpackage.test.Annotations.Test;
3232
import jdk.jpackage.test.Executor;
33-
import static jdk.jpackage.test.HelloApp.configureEnvironment;
33+
import static jdk.jpackage.test.HelloApp.configureAndExecute;
3434
import jdk.jpackage.test.TKit;
3535

3636
/**
@@ -62,16 +62,12 @@ public static void test() throws Exception {
6262

6363
final String envVarName = envVarName();
6464

65-
final int attempts = 3;
66-
final int waitBetweenAttemptsSeconds = 5;
67-
List<String> output = configureEnvironment(new Executor())
65+
List<String> output = configureAndExecute(0, new Executor()
6866
.saveOutput()
6967
.setExecutable(cmd.appLauncherPath().toAbsolutePath())
7068
.addArguments("--print-env-var=" + envVarName)
7169
.addArguments("--print-sys-prop=" + testAddDirProp)
72-
.addArguments("--print-sys-prop=" + "java.library.path")
73-
.executeAndRepeatUntilExitCode(0, attempts,
74-
waitBetweenAttemptsSeconds).getOutput();
70+
.addArguments("--print-sys-prop=" + "java.library.path")).getOutput();
7571

7672
BiFunction<Integer, String, String> getValue = (idx, name) -> {
7773
return output.get(idx).substring((name + "=").length());

test/jdk/tools/jpackage/windows/WinChildProcessTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
import java.nio.file.Path;
4141

4242
import jdk.jpackage.test.JPackageCommand;
43-
import static jdk.jpackage.test.HelloApp.configureEnvironment;
43+
import static jdk.jpackage.test.HelloApp.configureAndExecute;
4444
import jdk.jpackage.test.Annotations.Test;
4545
import jdk.jpackage.test.Executor;
4646
import jdk.jpackage.test.TKit;
@@ -63,9 +63,9 @@ public static void test() {
6363

6464
// Start the third party application launcher and dump and save the
6565
// output of the application
66-
List<String> output = configureEnvironment(new Executor()).saveOutput().dumpOutput()
67-
.setExecutable(cmd.appLauncherPath().toAbsolutePath())
68-
.execute(0).getOutput();
66+
List<String> output = configureAndExecute(0, new Executor().saveOutput().dumpOutput()
67+
.setExecutable(cmd.appLauncherPath().toAbsolutePath()))
68+
.getOutput();
6969
String pidStr = output.get(0);
7070

7171
// parse child PID

0 commit comments

Comments
 (0)