Skip to content

Commit 8acea07

Browse files
author
duke
committed
Backport 936b23953044d0c9a8ea558208c3cd503895144a
1 parent 73d6539 commit 8acea07

File tree

2 files changed

+129
-0
lines changed

2 files changed

+129
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
import java.io.File;
25+
import java.io.IOException;
26+
import java.nio.file.Path;
27+
28+
public class ChildProcessAppLauncher {
29+
public static void main(String[] args) throws IOException, InterruptedException {
30+
if (args.length == 1 && "noexit".equals(args[0])) {
31+
var lock = new Object();
32+
synchronized (lock) {
33+
lock.wait();
34+
}
35+
} else {
36+
var childPath = System.getProperty("jpackage.app-path"); // get the path to the current jpackage app launcher
37+
ProcessBuilder processBuilder = new ProcessBuilder(childPath, "noexit"); //ChildProcessAppLauncher acts as third party app
38+
Process process = processBuilder.start();
39+
System.out.println("Child id=" + process.pid());
40+
}
41+
}
42+
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/*
2+
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
/* @test
25+
* @bug 8325203
26+
* @summary Test that Jpackage windows executable application kills the launched 3rd party application
27+
* when System.exit(0) is invoked along with terminating java program.
28+
* @library ../helpers
29+
* @library /test/lib
30+
* @requires os.family == "windows"
31+
* @build WinChildProcessTest
32+
* @build jdk.jpackage.test.*
33+
* @build WinChildProcessTest
34+
* @modules jdk.jpackage/jdk.jpackage.internal
35+
* @run main/othervm -Xmx512m jdk.jpackage.test.Main
36+
* --jpt-run=WinChildProcessTest
37+
*
38+
*/
39+
40+
import java.util.List;
41+
import java.util.Optional;
42+
43+
import java.nio.file.Path;
44+
45+
import jdk.jpackage.test.JPackageCommand;
46+
import jdk.jpackage.test.Annotations.Test;
47+
import jdk.jpackage.test.Executor;
48+
import jdk.jpackage.test.TKit;
49+
50+
public class WinChildProcessTest {
51+
private static final Path TEST_APP_JAVA = TKit.TEST_SRC_ROOT
52+
.resolve("apps/ChildProcessAppLauncher.java");
53+
54+
@Test
55+
public static void test() throws Throwable {
56+
long childPid = 0;
57+
try {
58+
JPackageCommand cmd = JPackageCommand
59+
.helloAppImage(TEST_APP_JAVA + "*Hello");
60+
61+
// Create the image of the third party application launcher
62+
cmd.executeAndAssertImageCreated();
63+
64+
// Start the third party application launcher and dump and save the
65+
// output of the application
66+
List<String> output = new Executor().saveOutput().dumpOutput()
67+
.setExecutable(cmd.appLauncherPath().toAbsolutePath())
68+
.execute(0).getOutput();
69+
String pidStr = output.get(0);
70+
71+
// parse child PID
72+
childPid = Long.parseLong(pidStr.split("=", 2)[1]);
73+
74+
// Check whether the termination of third party application launcher
75+
// also terminating the launched third party application
76+
// If third party application is not terminated the test is
77+
// successful else failure
78+
Optional<ProcessHandle> processHandle = ProcessHandle.of(childPid);
79+
boolean isAlive = processHandle.isPresent()
80+
&& processHandle.get().isAlive();
81+
TKit.assertTrue(isAlive, "Check is child process is alive");
82+
} finally {
83+
// Kill only a specific child instance
84+
Runtime.getRuntime().exec("taskkill /F /PID " + childPid);
85+
}
86+
}
87+
}

0 commit comments

Comments
 (0)