From b9cc3bc1bf61572f2813f057eea7326fd0c2bd14 Mon Sep 17 00:00:00 2001 From: Alexey Semenyuk Date: Wed, 6 Apr 2022 11:49:36 +0000 Subject: [PATCH] 8284067: jpackage'd launcher reports non-zero exit codes with error prompt Reviewed-by: almatvee --- .../windows/native/applauncher/WinLauncher.cpp | 9 +++------ test/jdk/tools/jpackage/apps/Hello.java | 2 ++ .../helpers/jdk/jpackage/test/HelloApp.java | 7 +++++-- .../share/jdk/jpackage/tests/BasicTest.java | 13 ++++++++++++- 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/src/jdk.jpackage/windows/native/applauncher/WinLauncher.cpp b/src/jdk.jpackage/windows/native/applauncher/WinLauncher.cpp index 4e899d4b1d1..74fe6c315e5 100644 --- a/src/jdk.jpackage/windows/native/applauncher/WinLauncher.cpp +++ b/src/jdk.jpackage/windows/native/applauncher/WinLauncher.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020, 2022, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -25,6 +25,7 @@ #include #include +#include #include #include "AppLauncher.h" @@ -180,11 +181,7 @@ void launchApp() { GetExitCodeProcess)); } - if (exitCode != 0) { - JP_THROW(tstrings::any() << "Child process exited with code " - << exitCode); - } - + exit(exitCode); return; } diff --git a/test/jdk/tools/jpackage/apps/Hello.java b/test/jdk/tools/jpackage/apps/Hello.java index 000573c933f..0e23e1d1e4a 100644 --- a/test/jdk/tools/jpackage/apps/Hello.java +++ b/test/jdk/tools/jpackage/apps/Hello.java @@ -70,6 +70,8 @@ public class Hello implements OpenFilesHandler { lock.wait(); } } + + System.exit(Integer.getInteger("jpackage.test.exitCode", 0)); } private static List printArgs(String[] args) { 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 2d0d23dae26..7d5472fd5be 100644 --- a/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/HelloApp.java +++ b/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/HelloApp.java @@ -370,6 +370,8 @@ public final class HelloApp { params.put(name, value); } else if ("jpackage.test.appOutput".equals(name)) { outputFilePath = Path.of(value); + } else if ("jpackage.test.exitCode".equals(name)) { + expectedExitCode = Integer.parseInt(value); } return this; } @@ -421,8 +423,8 @@ public final class HelloApp { final int attempts = 3; final int waitBetweenAttemptsSeconds = 5; getExecutor(launcherArgs.toArray(new String[0])).dumpOutput().setRemovePath( - removePath).executeAndRepeatUntilExitCode(0, attempts, - waitBetweenAttemptsSeconds); + removePath).executeAndRepeatUntilExitCode(expectedExitCode, + attempts, waitBetweenAttemptsSeconds); verifyOutputFile(outputFilePath, appArgs, params); } @@ -468,6 +470,7 @@ public final class HelloApp { private final Path launcherPath; private Path outputFilePath; + private int expectedExitCode; private final List defaultLauncherArgs; private final Map params; } diff --git a/test/jdk/tools/jpackage/share/jdk/jpackage/tests/BasicTest.java b/test/jdk/tools/jpackage/share/jdk/jpackage/tests/BasicTest.java index cad0a3f3b73..b240b8a5bde 100644 --- a/test/jdk/tools/jpackage/share/jdk/jpackage/tests/BasicTest.java +++ b/test/jdk/tools/jpackage/share/jdk/jpackage/tests/BasicTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2019, 2022, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -349,6 +349,17 @@ public final class BasicTest { HelloApp.executeLauncherAndVerifyOutput(cmd); } + @Test + @Parameter("1") + @Parameter("123") + public void testExitCode(int exitCode) { + JPackageCommand cmd = JPackageCommand + .helloAppImage() + .addArguments("--java-options", String.format( + "-Djpackage.test.exitCode=%d", exitCode)); + cmd.executeAndAssertHelloAppImageCreated(); + } + private static Executor getJPackageToolProvider() { return getToolProvider(JavaTool.JPACKAGE); }