use of com.thoughtworks.go.util.command.CommandLineException in project gocd by gocd.
the class ProcessWrapperTest method shouldThrowExceptionWhenExecutableDoesNotExist.
@Test
public void shouldThrowExceptionWhenExecutableDoesNotExist() throws IOException {
CommandLine line = CommandLine.createCommandLine("doesnotexist");
try {
ProcessOutputStreamConsumer outputStreamConsumer = inMemoryConsumer();
line.execute(outputStreamConsumer, new EnvironmentVariableContext(), null);
fail("Expected exception");
} catch (CommandLineException e) {
assertThat(e.getMessage(), containsString("Make sure this command can execute manually."));
assertThat(e.getMessage(), containsString("doesnotexist"));
assertThat(e.getResult(), notNullValue());
}
}
use of com.thoughtworks.go.util.command.CommandLineException in project gocd by gocd.
the class GarageServiceTest method shouldFailWhenGitIsNotFoundInPath.
@Test
public void shouldFailWhenGitIsNotFoundInPath() throws Exception {
HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
CommandLine commandLine = mock(CommandLine.class);
GarageService spy = spy(garageService);
doReturn(commandLine).when(spy).getGit();
doReturn(commandLine).when(commandLine).withArg(anyString());
doReturn(commandLine).when(commandLine).withWorkingDir(any(File.class));
when(commandLine.run(any(InMemoryStreamConsumer.class), eq(GarageService.PROCESS_TAG))).thenThrow(new CommandLineException("failed to execute git"));
spy.gc(result);
assertThat(result.isSuccessful(), is(false));
assertThat(result.hasMessage(), is(true));
verify(spy, times(1)).getGit();
}
use of com.thoughtworks.go.util.command.CommandLineException in project gocd by gocd.
the class ProcessManager method startProcess.
Process startProcess(ProcessBuilder processBuilder, String commandLineForDisplay) {
Process process;
try {
LOG.debug("[Command Line] START command {}", commandLineForDisplay);
process = processBuilder.start();
LOG.debug("[Command Line] END command {}", commandLineForDisplay);
} catch (IOException e) {
LOG.error("[Command Line] Failed executing [{}]", commandLineForDisplay);
LOG.error("[Command Line] Agent's Environment Variables: {}", System.getenv());
throw new CommandLineException(String.format("Error while executing [%s] \n Make sure this command can execute manually.", commandLineForDisplay), e);
}
return process;
}
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, String... input) {
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, input));
} 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("[Command Line] {}. Path: {}", 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();
}
use of com.thoughtworks.go.util.command.CommandLineException in project gocd by gocd.
the class P4Fixture method stopP4d.
private void stopP4d(P4Client p4) {
try {
p4.admin("stop");
ConsoleResult consoleResult = p4.checkConnection();
while (!consoleResult.failed()) {
try {
// Wait for the server to shutdown
Thread.sleep(100);
} catch (InterruptedException ignored) {
}
}
} catch (CommandLineException expected) {
// Stopping p4d on windows returns the following failure:
if (expected.getResult().errorAsString().contains("WSAECONNRESET") || expected.getResult().errorAsString().contains("WSAECONNREFUSED")) {
return;
}
if (expected.getResult().errorAsString().contains("Connection refused") || expected.getResult().errorAsString().contains("Connection reset")) {
return;
}
throw expected;
}
}
Aggregations