use of com.thoughtworks.go.util.command.CommandLineException in project gocd by gocd.
the class ExecCommandExecutor method executeCommandLine.
private int executeCommandLine(final BuildSession buildSession, final CommandLine commandLine) {
final AtomicInteger exitCode = new AtomicInteger(-1);
final CountDownLatch canceledOrDone = new CountDownLatch(1);
buildSession.submitRunnable(new Runnable() {
@Override
public void run() {
try {
exitCode.set(commandLine.run(buildSession.processOutputStreamConsumer(), null));
} catch (CommandLineException e) {
LOG.error("Command failed", e);
String message = format("Error happened while attempting to execute '%s'. \nPlease make sure [%s] can be executed on this agent.\n", commandLine.toStringForDisplay(), commandLine.getExecutable());
String path = System.getenv("PATH");
buildSession.println(message);
buildSession.println(format("[Debug Information] Environment variable PATH: %s", path));
LOG.error(format("[Command Line] %s. Path: %s", message, path));
} finally {
canceledOrDone.countDown();
}
}
});
Future<?> cancelMonitor = buildSession.submitRunnable(new Runnable() {
@Override
public void run() {
try {
buildSession.waitUntilCanceled();
} catch (InterruptedException e) {
// ignore
} finally {
canceledOrDone.countDown();
}
}
});
try {
canceledOrDone.await();
} catch (InterruptedException e) {
LOG.error("Building thread interrupted", e);
}
cancelMonitor.cancel(true);
return exitCode.get();
}
Aggregations