From 98ba2e20e3c48f98e1bcb464c7982a143cf605f7 Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Fri, 2 Oct 2020 10:30:27 +0200 Subject: [PATCH] Replace the jpm library with the jdk ProcessHandle interface, #36 --- .../fuse/mvnd/client/DaemonConnector.java | 25 ++- .../jboss/fuse/mvnd/client/DefaultClient.java | 6 +- .../java/org/jboss/fuse/mvnd/jpm/Process.java | 60 ------- .../org/jboss/fuse/mvnd/jpm/ProcessImpl.java | 157 ------------------ .../org/jboss/fuse/mvnd/jpm/ScriptUtils.java | 142 ---------------- .../org/jboss/fuse/mvnd/jpm/unix/start.sh | 29 ---- .../jboss/fuse/mvnd/jpm/windows/destroy.vbs | 27 --- .../jboss/fuse/mvnd/jpm/windows/running.vbs | 26 --- .../org/jboss/fuse/mvnd/jpm/windows/start.vbs | 34 ---- .../org/jboss/fuse/mvnd/daemon/Server.java | 5 + .../jboss/fuse/mvnd/junit/TestRegistry.java | 6 +- 11 files changed, 23 insertions(+), 494 deletions(-) delete mode 100644 client/src/main/java/org/jboss/fuse/mvnd/jpm/Process.java delete mode 100644 client/src/main/java/org/jboss/fuse/mvnd/jpm/ProcessImpl.java delete mode 100644 client/src/main/java/org/jboss/fuse/mvnd/jpm/ScriptUtils.java delete mode 100644 client/src/main/resources/org/jboss/fuse/mvnd/jpm/unix/start.sh delete mode 100644 client/src/main/resources/org/jboss/fuse/mvnd/jpm/windows/destroy.vbs delete mode 100644 client/src/main/resources/org/jboss/fuse/mvnd/jpm/windows/running.vbs delete mode 100644 client/src/main/resources/org/jboss/fuse/mvnd/jpm/windows/start.vbs diff --git a/client/src/main/java/org/jboss/fuse/mvnd/client/DaemonConnector.java b/client/src/main/java/org/jboss/fuse/mvnd/client/DaemonConnector.java index e214a65c8..cbd914ef3 100644 --- a/client/src/main/java/org/jboss/fuse/mvnd/client/DaemonConnector.java +++ b/client/src/main/java/org/jboss/fuse/mvnd/client/DaemonConnector.java @@ -25,6 +25,7 @@ import java.util.Collections; import java.util.LinkedList; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.Optional; import java.util.UUID; @@ -44,8 +45,6 @@ import org.jboss.fuse.mvnd.common.Message; import org.jboss.fuse.mvnd.common.Serializer; import org.jboss.fuse.mvnd.common.ServerMain; -import org.jboss.fuse.mvnd.jpm.Process; -import org.jboss.fuse.mvnd.jpm.ScriptUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -64,6 +63,8 @@ public class DaemonConnector { private static final Logger LOGGER = LoggerFactory.getLogger(DaemonConnector.class); + private static final boolean IS_WINDOWS = System.getProperty("os.name").toLowerCase(Locale.ROOT).contains("win"); + private final DaemonRegistry registry; private final ClientLayout layout; private final Serializer serializer; @@ -252,17 +253,17 @@ private String startDaemon() { String command = ""; try { String classpath = findCommonJar(mavenHome).toString(); - final String java = ScriptUtils.isWindows() ? "bin\\java.exe" : "bin/java"; + final String java = IS_WINDOWS ? "bin\\java.exe" : "bin/java"; List args = new ArrayList<>(); - args.add("\"" + layout.javaHome().resolve(java) + "\""); + args.add(layout.javaHome().resolve(java).toString()); args.add("-classpath"); - args.add("\"" + classpath + "\""); + args.add(classpath); if (Environment.DAEMON_DEBUG.systemProperty().orDefault(() -> "false").asBoolean()) { args.add("-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=8000"); } - args.add("-Dmvnd.home=\"" + mavenHome + "\""); - args.add("-Dmvnd.java.home=\"" + layout.javaHome().toString() + "\""); - args.add("-Dlogback.configurationFile=\"" + layout.getLogbackConfigurationPath() + "\""); + args.add("-Dmvnd.home=" + mavenHome); + args.add("-Dmvnd.java.home=" + layout.javaHome().toString()); + args.add("-Dlogback.configurationFile=" + layout.getLogbackConfigurationPath()); args.add("-Ddaemon.uid=" + uid); args.add("-Xmx4g"); final String timeout = Environment.DAEMON_IDLE_TIMEOUT.systemProperty().asString(); @@ -274,7 +275,13 @@ private String startDaemon() { command = String.join(" ", args); LOGGER.debug("Starting daemon process: uid = {}, workingDir = {}, daemonArgs: {}", uid, workingDir, command); - Process.create(workingDir.toFile(), command); + ProcessBuilder.Redirect redirect = ProcessBuilder.Redirect.appendTo(layout.daemonLog("output").toFile()); + new ProcessBuilder() + .directory(workingDir.toFile()) + .command(args) + .redirectOutput(redirect) + .redirectError(redirect) + .start(); return uid; } catch (Exception e) { throw new DaemonException.StartException( diff --git a/client/src/main/java/org/jboss/fuse/mvnd/client/DefaultClient.java b/client/src/main/java/org/jboss/fuse/mvnd/client/DefaultClient.java index 085583467..905cf5bbc 100644 --- a/client/src/main/java/org/jboss/fuse/mvnd/client/DefaultClient.java +++ b/client/src/main/java/org/jboss/fuse/mvnd/client/DefaultClient.java @@ -15,7 +15,6 @@ */ package org.jboss.fuse.mvnd.client; -import java.io.IOException; import java.nio.file.Path; import java.nio.file.Paths; import java.time.Instant; @@ -37,7 +36,6 @@ import org.jboss.fuse.mvnd.common.Message.BuildException; import org.jboss.fuse.mvnd.common.Message.BuildMessage; import org.jboss.fuse.mvnd.common.Message.MessageSerializer; -import org.jboss.fuse.mvnd.jpm.ProcessImpl; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -158,9 +156,7 @@ public ExecutionResult execute(ClientOutput output, List argv) { output.accept("Stopping " + dis.length + " running daemons"); for (DaemonInfo di : dis) { try { - new ProcessImpl(di.getPid()).destroy(); - } catch (IOException t) { - System.out.println("Daemon " + di.getUid() + ": " + t.getMessage()); + ProcessHandle.of(di.getPid()).ifPresent(ProcessHandle::destroyForcibly); } catch (Exception t) { System.out.println("Daemon " + di.getUid() + ": " + t); } finally { diff --git a/client/src/main/java/org/jboss/fuse/mvnd/jpm/Process.java b/client/src/main/java/org/jboss/fuse/mvnd/jpm/Process.java deleted file mode 100644 index fe00db7e9..000000000 --- a/client/src/main/java/org/jboss/fuse/mvnd/jpm/Process.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jboss.fuse.mvnd.jpm; - -import java.io.File; -import java.io.IOException; -import java.io.Serializable; - -/** - * Interface representing a process - * - * File origin: https://github.com/apache/karaf/blob/karaf-4.2.6/util/src/main/java/org/apache/karaf/jpm/Process.java - */ -public interface Process extends Serializable { - - /** - * Retrieves the PID of the process - * - * @return the pid - */ - int getPid(); - - /** - * Check if this process is still running - * - * @return true if the process is running - * @throws IOException if an error occurs - */ - boolean isRunning() throws IOException; - - /** - * Destroy the process. - * - * @throws IOException If an error occurs. - */ - void destroy() throws IOException; - - static Process create(File dir, String command) throws IOException { - return ProcessImpl.create(dir, command); - } - - static Process attach(int pid) throws IOException { - return ProcessImpl.attach(pid); - } - -} diff --git a/client/src/main/java/org/jboss/fuse/mvnd/jpm/ProcessImpl.java b/client/src/main/java/org/jboss/fuse/mvnd/jpm/ProcessImpl.java deleted file mode 100644 index e4b107b24..000000000 --- a/client/src/main/java/org/jboss/fuse/mvnd/jpm/ProcessImpl.java +++ /dev/null @@ -1,157 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jboss.fuse.mvnd.jpm; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.InterruptedIOException; -import java.util.HashMap; -import java.util.Map; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * File origin: - * https://github.com/apache/karaf/blob/karaf-4.2.6/util/src/main/java/org/apache/karaf/jpm/impl/ProcessImpl.java - */ -public class ProcessImpl implements Process { - - /** - * - */ - private static final long serialVersionUID = -8140632422386086507L; - - private static final Logger LOG = LoggerFactory.getLogger(ProcessImpl.class); - - private int pid; - //private File input; - //private File output; - //private File error; - - public ProcessImpl(int pid/*, File input, File output, File error*/) { - this.pid = pid; - //this.input = input; - //this.output = output; - //this.error = error; - } - - public int getPid() { - return pid; - } - - public boolean isRunning() throws IOException { - if (ScriptUtils.isWindows()) { - Map props = new HashMap<>(); - props.put("${pid}", Integer.toString(pid)); - int ret = ScriptUtils.execute("running", props); - return ret == 0; - } else { - try { - java.lang.Process process = new java.lang.ProcessBuilder("ps", "-p", Integer.toString(pid)).start(); - BufferedReader r = new BufferedReader(new InputStreamReader(process.getInputStream())); - r.readLine(); // skip headers - String s = r.readLine(); - boolean running = s != null && s.length() > 0; - process.waitFor(); - return running; - } catch (InterruptedException e) { - throw new InterruptedIOException(); - } - } - } - - public void destroy() throws IOException { - int ret; - if (ScriptUtils.isWindows()) { - Map props = new HashMap<>(); - props.put("${pid}", Integer.toString(pid)); - ret = ScriptUtils.execute("destroy", props); - } else { - ret = ScriptUtils.executeProcess(new java.lang.ProcessBuilder("kill", "-9", Integer.toString(pid))); - } - if (ret != 0) { - throw new IOException("Unable to destroy process, it may already be terminated"); - } - } - - /* - public OutputStream getInputStream() throws FileNotFoundException { - return new FileOutputStream(input); - } - - public InputStream getOutputStream() throws FileNotFoundException { - return new FileInputStream(output); - } - - public InputStream getErrorStream() throws FileNotFoundException { - return new FileInputStream(error); - } - */ - - public int waitFor() throws InterruptedException { - return 0; - } - - public int exitValue() { - return 0; - } - - public static Process create(File dir, String command) throws IOException { - //File input = File.createTempFile("jpm.", ".input"); - //File output = File.createTempFile("jpm.", ".output"); - //File error = File.createTempFile("jpm.", ".error"); - final File pidFile = File.createTempFile("jpm.", ".pid"); - try { - Map props = new HashMap<>(); - //props.put("${in.file}", input.getCanonicalPath()); - //props.put("${out.file}", output.getCanonicalPath()); - //props.put("${err.file}", error.getCanonicalPath()); - props.put("${pid.file}", pidFile.getCanonicalPath()); - props.put("${dir}", dir != null ? dir.getCanonicalPath() : ""); - if (ScriptUtils.isWindows()) { - command = command.replaceAll("\"", "\"\""); - } - props.put("${command}", command); - int ret = ScriptUtils.execute("start", props); - if (ret != 0) { - throw new IOException("Unable to create process (error code: " + ret + ")"); - } - int pid = readPid(pidFile); - LOG.debug("Read server pid {} from {}", pid, pidFile); - return new ProcessImpl(pid/*, input, output, error*/); - } finally { - pidFile.delete(); - } - } - - public static Process attach(int pid) throws IOException { - return new ProcessImpl(pid); - } - - private static int readPid(File pidFile) throws IOException { - try (InputStream is = new FileInputStream(pidFile)) { - BufferedReader r = new BufferedReader(new InputStreamReader(is)); - String pidString = r.readLine(); - return Integer.parseInt(pidString); - } - } - -} diff --git a/client/src/main/java/org/jboss/fuse/mvnd/jpm/ScriptUtils.java b/client/src/main/java/org/jboss/fuse/mvnd/jpm/ScriptUtils.java deleted file mode 100644 index e13cd041b..000000000 --- a/client/src/main/java/org/jboss/fuse/mvnd/jpm/ScriptUtils.java +++ /dev/null @@ -1,142 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jboss.fuse.mvnd.jpm; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.InterruptedIOException; -import java.io.OutputStream; -import java.io.PrintStream; -import java.util.Locale; -import java.util.Map; -import java.util.Scanner; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * File origin: - * https://github.com/apache/karaf/blob/karaf-4.2.6/util/src/main/java/org/apache/karaf/jpm/impl/ScriptUtils.java - */ -public class ScriptUtils { - - private static final Logger LOG = LoggerFactory.getLogger(ScriptUtils.class); - - public static int execute(String name, Map props) throws IOException { - final File script = File.createTempFile("jpm.", ".script"); - - try { - if (isWindows()) { - String res = "windows/" + name + ".vbs"; - ScriptUtils.copyFilteredResource(res, script, props); - return executeProcess(new java.lang.ProcessBuilder("cscript", - "/NOLOGO", - "//E:vbs", - script.getCanonicalPath())); - } else { - String res = "unix/" + name + ".sh"; - ScriptUtils.copyFilteredResource(res, script, props); - return executeProcess(new java.lang.ProcessBuilder("/bin/sh", - script.getCanonicalPath())); - } - } finally { - script.delete(); - } - } - - public static int executeProcess(java.lang.ProcessBuilder builder) throws IOException { - builder.inheritIO(); - try { - java.lang.Process process = builder.start(); - return process.waitFor(); - } catch (InterruptedException e) { - throw new InterruptedIOException(); - } - } - - public static void copyFilteredResource(String resource, File outFile, Map props) throws IOException { - LOG.trace("Writing a script to {}", outFile); - InputStream is = null; - try { - is = ScriptUtils.class.getResourceAsStream(resource); - // Read it line at a time so that we can use the platform line ending when we write it out. - PrintStream out = new PrintStream(new FileOutputStream(outFile)); - try { - Scanner scanner = new Scanner(is); - while (scanner.hasNextLine()) { - String line = scanner.nextLine(); - line = filter(line, props); - LOG.trace("Script line {}", line); - out.println(line); - } - scanner.close(); - } finally { - safeClose(out); - } - } finally { - safeClose(is); - } - } - - private static void safeClose(InputStream is) throws IOException { - if (is == null) { - return; - } - try { - is.close(); - } catch (Throwable ignore) { - } - } - - private static void safeClose(OutputStream is) throws IOException { - if (is == null) { - return; - } - try { - is.close(); - } catch (Throwable ignore) { - } - } - - private static String filter(String line, Map props) { - for (Map.Entry i : props.entrySet()) { - int p1 = line.indexOf(i.getKey()); - if (p1 >= 0) { - String l1 = line.substring(0, p1); - String l2 = line.substring(p1 + i.getKey().length()); - line = l1 + i.getValue() + l2; - } - } - return line; - } - - private static final boolean windows; - - static { - windows = System.getProperty("os.name").toLowerCase(Locale.ROOT).startsWith("windows"); - } - - public static boolean isWindows() { - return windows; - } - - public static String getJavaCommandPath() throws IOException { - return new File(System.getProperty("java.home"), isWindows() ? "bin\\java.exe" : "bin/java").getCanonicalPath(); - } - -} diff --git a/client/src/main/resources/org/jboss/fuse/mvnd/jpm/unix/start.sh b/client/src/main/resources/org/jboss/fuse/mvnd/jpm/unix/start.sh deleted file mode 100644 index 6ec0f77e2..000000000 --- a/client/src/main/resources/org/jboss/fuse/mvnd/jpm/unix/start.sh +++ /dev/null @@ -1,29 +0,0 @@ -#!/bin/sh -################################################################################ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -################################################################################ - -#exec 1>${out.file} -#exec 2>${err.file} -exec 1>/dev/null -exec 2>/dev/null -if [ "x${dir}" != "x" ]; then - cd "${dir}" -fi -nohup ${command} & -echo $! > "${pid.file}" diff --git a/client/src/main/resources/org/jboss/fuse/mvnd/jpm/windows/destroy.vbs b/client/src/main/resources/org/jboss/fuse/mvnd/jpm/windows/destroy.vbs deleted file mode 100644 index abd60ebba..000000000 --- a/client/src/main/resources/org/jboss/fuse/mvnd/jpm/windows/destroy.vbs +++ /dev/null @@ -1,27 +0,0 @@ -'=============================================================================== -' -' Licensed to the Apache Software Foundation (ASF) under one or more -' contributor license agreements. See the NOTICE file distributed with -' this work for additional information regarding copyright ownership. -' The ASF licenses this file to You under the Apache License, Version 2.0 -' (the "License"); you may not use this file except in compliance with -' the License. You may obtain a copy of the License at -' -' http://www.apache.org/licenses/LICENSE-2.0 -' -' Unless required by applicable law or agreed to in writing, software -' distributed under the License is distributed on an "AS IS" BASIS, -' WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -' See the License for the specific language governing permissions and -' limitations under the License. -' -'=============================================================================== - -Set objWMIService = GetObject("winmgmts:\\.\root\cimv2") -Set colProcessList = objWMIService.ExecQuery("Select * from Win32_Process Where ProcessId = ${pid}") -intRetVal = 1 -For Each objProcess in colProcessList - objProcess.Terminate() - intRetVal = 0 -Next -WScript.Quit(intRetVal) diff --git a/client/src/main/resources/org/jboss/fuse/mvnd/jpm/windows/running.vbs b/client/src/main/resources/org/jboss/fuse/mvnd/jpm/windows/running.vbs deleted file mode 100644 index 32c65c5f0..000000000 --- a/client/src/main/resources/org/jboss/fuse/mvnd/jpm/windows/running.vbs +++ /dev/null @@ -1,26 +0,0 @@ -'=============================================================================== -' -' Licensed to the Apache Software Foundation (ASF) under one or more -' contributor license agreements. See the NOTICE file distributed with -' this work for additional information regarding copyright ownership. -' The ASF licenses this file to You under the Apache License, Version 2.0 -' (the "License"); you may not use this file except in compliance with -' the License. You may obtain a copy of the License at -' -' http://www.apache.org/licenses/LICENSE-2.0 -' -' Unless required by applicable law or agreed to in writing, software -' distributed under the License is distributed on an "AS IS" BASIS, -' WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -' See the License for the specific language governing permissions and -' limitations under the License. -' -'=============================================================================== - -Set objWMIService = GetObject("winmgmts:\\.\root\cimv2") -Set colProcessList = objWMIService.ExecQuery("Select * from Win32_Process Where ProcessId = ${pid}") -intRetVal = 1 -For Each objProcess in colProcessList - intRetVal = 0 -Next -WScript.Quit(intRetVal) diff --git a/client/src/main/resources/org/jboss/fuse/mvnd/jpm/windows/start.vbs b/client/src/main/resources/org/jboss/fuse/mvnd/jpm/windows/start.vbs deleted file mode 100644 index 6004c86c4..000000000 --- a/client/src/main/resources/org/jboss/fuse/mvnd/jpm/windows/start.vbs +++ /dev/null @@ -1,34 +0,0 @@ -'=============================================================================== -' -' Licensed to the Apache Software Foundation (ASF) under one or more -' contributor license agreements. See the NOTICE file distributed with -' this work for additional information regarding copyright ownership. -' The ASF licenses this file to You under the Apache License, Version 2.0 -' (the "License"); you may not use this file except in compliance with -' the License. You may obtain a copy of the License at -' -' http://www.apache.org/licenses/LICENSE-2.0 -' -' Unless required by applicable law or agreed to in writing, software -' distributed under the License is distributed on an "AS IS" BASIS, -' WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -' See the License for the specific language governing permissions and -' limitations under the License. -' -'=============================================================================== - -Set objWMIService = GetObject("winmgmts:\\.\root\cimv2") -Set objConfig = objWMIService.Get("Win32_ProcessStartup").SpawnInstance_ -objConfig.ShowWindow = SW_HIDE -objConfig.CreateFlags = 8 -If Len("${dir}") > 0 Then - intReturn = objWMIService.Get("Win32_Process").Create("${command}", "${dir}", objConfig, intProcessID) -Else - intReturn = objWMIService.Get("Win32_Process").Create("${command}", Null, objConfig, intProcessID) -End If -If intReturn = 0 Then - Set objOutputFile = CreateObject("Scripting.fileSystemObject").CreateTextFile("${pid.file}", TRUE) - objOutputFile.WriteLine(intProcessID) - objOutputFile.Close -End If -WScript.Quit(intReturn) diff --git a/daemon/src/main/java/org/jboss/fuse/mvnd/daemon/Server.java b/daemon/src/main/java/org/jboss/fuse/mvnd/daemon/Server.java index 28389152b..a81452728 100644 --- a/daemon/src/main/java/org/jboss/fuse/mvnd/daemon/Server.java +++ b/daemon/src/main/java/org/jboss/fuse/mvnd/daemon/Server.java @@ -494,6 +494,11 @@ public long getLastBusy() { return info.getLastBusy(); } + @Override + public String toString() { + return info.toString(); + } + private static class DaemonLoggingSpy extends AbstractLoggingSpy { private final PriorityBlockingQueue queue; diff --git a/integration-tests/src/test/java/org/jboss/fuse/mvnd/junit/TestRegistry.java b/integration-tests/src/test/java/org/jboss/fuse/mvnd/junit/TestRegistry.java index 42a987a59..3bc304f9b 100644 --- a/integration-tests/src/test/java/org/jboss/fuse/mvnd/junit/TestRegistry.java +++ b/integration-tests/src/test/java/org/jboss/fuse/mvnd/junit/TestRegistry.java @@ -15,14 +15,12 @@ */ package org.jboss.fuse.mvnd.junit; -import java.io.IOException; import java.nio.file.Path; import java.util.List; import org.assertj.core.api.Assertions; import org.jboss.fuse.mvnd.common.DaemonInfo; import org.jboss.fuse.mvnd.common.DaemonRegistry; import org.jboss.fuse.mvnd.common.DaemonState; -import org.jboss.fuse.mvnd.jpm.ProcessImpl; public class TestRegistry extends DaemonRegistry { @@ -40,9 +38,7 @@ public void killAll() { while (!(daemons = getAll()).isEmpty()) { for (DaemonInfo di : daemons) { try { - new ProcessImpl(di.getPid()).destroy(); - } catch (IOException t) { - System.out.println("Daemon " + di.getUid() + ": " + t.getMessage()); + ProcessHandle.of(di.getPid()).ifPresent(ProcessHandle::destroyForcibly); } catch (Exception t) { System.out.println("Daemon " + di.getUid() + ": " + t); } finally {