Skip to content

Commit

Permalink
8284067: jpackage'd launcher reports non-zero exit codes with error p…
Browse files Browse the repository at this point in the history
…rompt

Reviewed-by: asemenyuk
Backport-of: b9cc3bc1bf61572f2813f057eea7326fd0c2bd14
  • Loading branch information
GoeLin committed Jul 25, 2022
1 parent de4792a commit c402838
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 9 deletions.
9 changes: 3 additions & 6 deletions 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
Expand All @@ -25,6 +25,7 @@

#include <io.h>
#include <fcntl.h>
#include <stdlib.h>
#include <windows.h>

#include "AppLauncher.h"
Expand Down Expand Up @@ -180,11 +181,7 @@ void launchApp() {
GetExitCodeProcess));
}

if (exitCode != 0) {
JP_THROW(tstrings::any() << "Child process exited with code "
<< exitCode);
}

exit(exitCode);
return;
}

Expand Down
2 changes: 2 additions & 0 deletions test/jdk/tools/jpackage/apps/Hello.java
Expand Up @@ -70,6 +70,8 @@ public static void main(String[] args) throws IOException, InterruptedException
lock.wait();
}
}

System.exit(Integer.getInteger("jpackage.test.exitCode", 0));
}

private static List<String> printArgs(String[] args) {
Expand Down
Expand Up @@ -370,6 +370,8 @@ public AppOutputVerifier addParam(String name, String value) {
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;
}
Expand Down Expand Up @@ -421,8 +423,8 @@ public void executeAndVerifyOutput(boolean removePath,
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);
}

Expand Down Expand Up @@ -468,6 +470,7 @@ private Executor getExecutor(String...args) {

private final Path launcherPath;
private Path outputFilePath;
private int expectedExitCode;
private final List<String> defaultLauncherArgs;
private final Map<String, String> params;
}
Expand Down
13 changes: 12 additions & 1 deletion 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
Expand Down Expand Up @@ -349,6 +349,17 @@ public void testAtFile() throws IOException {
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);
}
Expand Down

1 comment on commit c402838

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.