Skip to content

Commit

Permalink
Merge pull request #80 from gnodet/issue-36
Browse files Browse the repository at this point in the history
Replace the jpm library with the jdk ProcessHandle interface, #36
  • Loading branch information
ppalaga committed Oct 2, 2020
2 parents b99ba8a + 98ba2e2 commit 8b90534
Show file tree
Hide file tree
Showing 11 changed files with 23 additions and 494 deletions.
Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -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<Message> serializer;
Expand Down Expand Up @@ -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<String> 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();
Expand All @@ -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(
Expand Down
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -158,9 +156,7 @@ public ExecutionResult execute(ClientOutput output, List<String> 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 {
Expand Down
60 changes: 0 additions & 60 deletions client/src/main/java/org/jboss/fuse/mvnd/jpm/Process.java

This file was deleted.

157 changes: 0 additions & 157 deletions client/src/main/java/org/jboss/fuse/mvnd/jpm/ProcessImpl.java

This file was deleted.

0 comments on commit 8b90534

Please sign in to comment.