Skip to content

Commit 349e46a

Browse files
author
duke
committed
Backport 28f9e2d34a29499b25af902d15ebfd416ffe638e
1 parent bd1728a commit 349e46a

File tree

5 files changed

+81
-74
lines changed

5 files changed

+81
-74
lines changed

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

Lines changed: 47 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
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;

test/jdk/tools/jpackage/macosx/ArgumentsFilteringTest.java

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2020, 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
@@ -21,9 +21,6 @@
2121
* questions.
2222
*/
2323

24-
import java.nio.file.Path;
25-
import java.util.List;
26-
import java.util.ArrayList;
2724
import jdk.jpackage.test.JPackageCommand;
2825
import jdk.jpackage.test.HelloApp;
2926
import jdk.jpackage.test.Annotations.Test;
@@ -52,20 +49,22 @@ public class ArgumentsFilteringTest {
5249
public void test1() {
5350
JPackageCommand cmd = JPackageCommand.helloAppImage();
5451
cmd.executeAndAssertHelloAppImageCreated();
55-
Path launcherPath = cmd.appLauncherPath();
56-
HelloApp.assertApp(launcherPath)
57-
.executeAndVerifyOutput(false, List.of("-psn_1_1"),
58-
new ArrayList<>());
52+
var appVerifier = HelloApp.assertMainLauncher(cmd);
53+
if (appVerifier != null) {
54+
appVerifier.execute("-psn_1_1");
55+
appVerifier.verifyOutput();
56+
}
5957
}
6058

6159
@Test
6260
public void test2() {
6361
JPackageCommand cmd = JPackageCommand.helloAppImage()
6462
.addArguments("--arguments", "-psn_2_2");
6563
cmd.executeAndAssertHelloAppImageCreated();
66-
Path launcherPath = cmd.appLauncherPath();
67-
HelloApp.assertApp(launcherPath)
68-
.executeAndVerifyOutput(false, List.of("-psn_1_1"),
69-
List.of("-psn_2_2"));
64+
var appVerifier = HelloApp.assertMainLauncher(cmd);
65+
if (appVerifier != null) {
66+
appVerifier.execute("-psn_1_1");
67+
appVerifier.verifyOutput("-psn_2_2");
68+
}
7069
}
7170
}

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

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 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
@@ -24,7 +24,6 @@
2424
import java.nio.file.Path;
2525
import java.util.List;
2626
import jdk.jpackage.test.HelloApp;
27-
import jdk.jpackage.test.Functional.ThrowingConsumer;
2827
import jdk.jpackage.test.JPackageCommand;
2928
import jdk.jpackage.test.Annotations.BeforeEach;
3029
import jdk.jpackage.test.Annotations.Test;
@@ -64,27 +63,19 @@ public static void useJPackageToolProvider() {
6463
@Parameter("Goodbye")
6564
@Parameter("com.hello/com.hello.Hello")
6665
public static void testApp(String javaAppDesc) {
67-
testIt(javaAppDesc, null);
68-
}
69-
70-
private static void testIt(String javaAppDesc,
71-
ThrowingConsumer<JPackageCommand> initializer) {
72-
7366
JPackageCommand cmd = JPackageCommand.helloAppImage(javaAppDesc).addArguments(
7467
"--arguments", JPackageCommand.escapeAndJoin(TRICKY_ARGUMENTS));
75-
if (initializer != null) {
76-
ThrowingConsumer.toConsumer(initializer).accept(cmd);
77-
}
7868

7969
cmd.executeAndAssertImageCreated();
8070

81-
Path launcherPath = cmd.appLauncherPath();
82-
if (!cmd.isFakeRuntime(String.format(
83-
"Not running [%s] launcher", launcherPath))) {
84-
HelloApp.assertApp(launcherPath)
85-
.addDefaultArguments(TRICKY_ARGUMENTS)
86-
.executeAndVerifyOutput();
71+
if (!cmd.canRunLauncher("Not running the test")) {
72+
return;
8773
}
74+
75+
Path launcherPath = cmd.appLauncherPath();
76+
HelloApp.assertApp(launcherPath)
77+
.addDefaultArguments(TRICKY_ARGUMENTS)
78+
.executeAndVerifyOutput();
8879
}
8980

9081
private final static List<String> TRICKY_ARGUMENTS = List.of(

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, 2023, 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
@@ -233,13 +233,12 @@ public void test() throws IOException {
233233
cmd.executeAndAssertHelloAppImageCreated();
234234
} else {
235235
cmd.executeAndAssertImageCreated();
236-
if (!cmd.isFakeRuntime(String.format("Not running [%s]",
237-
cmd.appLauncherPath()))) {
238-
List<String> output = new Executor()
239-
.setDirectory(cmd.outputDir())
240-
.setExecutable(cmd.appLauncherPath())
241-
.dumpOutput().saveOutput()
242-
.execute(1).getOutput();
236+
var appVerifier = HelloApp.assertMainLauncher(cmd);
237+
if (appVerifier != null) {
238+
List<String> output = appVerifier
239+
.saveOutput(true)
240+
.expectedExitCode(1)
241+
.execute().getOutput();
243242
TKit.assertTextStream(String.format(
244243
"Error: Could not find or load main class %s",
245244
nonExistingMainClass)).apply(output.stream());

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2021, 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
@@ -26,7 +26,6 @@
2626
import java.nio.file.Files;
2727
import jdk.jpackage.test.HelloApp;
2828
import jdk.jpackage.test.TKit;
29-
import jdk.jpackage.test.Functional.ThrowingConsumer;
3029
import jdk.jpackage.test.JPackageCommand;
3130
import jdk.jpackage.test.Annotations.Test;
3231

@@ -50,11 +49,16 @@ public static void test() throws IOException {
5049

5150
cmd.executeAndAssertImageCreated();
5251

52+
if (!cmd.canRunLauncher("Not running the test")) {
53+
return;
54+
}
55+
56+
HelloApp.executeLauncherAndVerifyOutput(cmd);
57+
5358
Path launcherPath = cmd.appLauncherPath();
54-
HelloApp.assertApp(launcherPath).executeAndVerifyOutput();
5559

5660
String lp = launcherPath.toString();
57-
TKit.assertTrue(lp.endsWith(".exe"), "UNexpected launcher path: " + lp);
61+
TKit.assertTrue(lp.endsWith(".exe"), "Unexpected launcher path: " + lp);
5862

5963
Path newLauncherPath = Path.of(lp.replaceAll(".exe", ".anything"));
6064
Files.move(launcherPath, newLauncherPath);

0 commit comments

Comments
 (0)