Skip to content

Commit

Permalink
Fail fast if the daemon can not be started, fixes #162
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet committed Nov 2, 2020
1 parent 5b5eab4 commit a95ac9e
Showing 1 changed file with 6 additions and 7 deletions.
Expand Up @@ -222,7 +222,8 @@ private DaemonClientConnection findConnection(List<DaemonInfo> compatibleDaemons
}

public DaemonClientConnection startDaemon(DaemonCompatibilitySpec constraint) {
final String daemon = startDaemon();
final String daemon = UUID.randomUUID().toString();
final Process process = startDaemon(daemon);
LOGGER.debug("Started Maven daemon {}", daemon);
long start = System.currentTimeMillis();
do {
Expand All @@ -235,14 +236,12 @@ public DaemonClientConnection startDaemon(DaemonCompatibilitySpec constraint) {
} catch (InterruptedException e) {
throw new DaemonException.InterruptedException(e);
}
} while (System.currentTimeMillis() - start < DEFAULT_CONNECT_TIMEOUT);
} while (process.isAlive() && System.currentTimeMillis() - start < DEFAULT_CONNECT_TIMEOUT);
DaemonDiagnostics diag = new DaemonDiagnostics(daemon, layout);
throw new DaemonException.ConnectException("Timeout waiting to connect to the Maven daemon.\n" + diag.describe());
}

private String startDaemon() {

final String uid = UUID.randomUUID().toString();
private Process startDaemon(String uid) {
final Path mavenHome = layout.mavenHome();
final Path workingDir = layout.userDir();
String command = "";
Expand Down Expand Up @@ -272,13 +271,13 @@ private String startDaemon() {

LOGGER.debug("Starting daemon process: uid = {}, workingDir = {}, daemonArgs: {}", uid, workingDir, command);
ProcessBuilder.Redirect redirect = ProcessBuilder.Redirect.appendTo(layout.daemonOutLog(uid).toFile());
new ProcessBuilder()
Process process = new ProcessBuilder()
.directory(workingDir.toFile())
.command(args)
.redirectOutput(redirect)
.redirectError(redirect)
.start();
return uid;
return process;
} catch (Exception e) {
throw new DaemonException.StartException(
String.format("Error starting daemon: uid = %s, workingDir = %s, daemonArgs: %s",
Expand Down

0 comments on commit a95ac9e

Please sign in to comment.