use of com.thoughtworks.go.util.command.CommandLine in project gocd by gocd.
the class ProcessWrapperTest method shouldBeAbleToCompleteInput.
@Test
public void shouldBeAbleToCompleteInput() throws Exception {
String input1 = "SYSIN: Line 1!";
String input2 = "SYSIN: Line 2!";
CommandLine line = CommandLine.createCommandLine("ruby").withArgs(script("echo-all-input"));
ConsoleResult result = run(line, input1, input2);
assertThat(result.returnValue(), is(0));
assertThat(result.output(), contains("You said: " + input1));
assertThat(result.output(), contains("You said: " + input2));
assertThat(result.error().size(), is(0));
}
use of com.thoughtworks.go.util.command.CommandLine in project gocd by gocd.
the class ProcessWrapperTest method shouldSetGoServerVariablesIfTheyExist.
@Test
public void shouldSetGoServerVariablesIfTheyExist() {
System.setProperty("GO_DEPENDENCY_LABEL_PIPELINE_NAME", "999");
CommandLine line = CommandLine.createCommandLine("ruby").withArgs(script("dump-environment"));
ConsoleResult result = run(line);
assertThat("Errors: " + result.errorAsString(), result.returnValue(), is(0));
assertThat(result.output(), contains("GO_DEPENDENCY_LABEL_PIPELINE_NAME=999"));
}
use of com.thoughtworks.go.util.command.CommandLine 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.CommandLine in project gocd by gocd.
the class BaseCommandBuilder method build.
public void build(BuildLogElement buildLogElement, DefaultGoPublisher publisher, EnvironmentVariableContext environmentVariableContext, TaskExtension taskExtension) throws CruiseControlException {
final long startTime = System.currentTimeMillis();
if (!workingDir.isDirectory()) {
String message = "Working directory \"" + workingDir.getAbsolutePath() + "\" is not a directory!";
publisher.consumeLine(message);
setBuildError(buildLogElement, message);
throw new CruiseControlException(message);
}
ExecScript execScript = new ExecScript(errorString);
CommandLine commandLine = buildCommandLine();
// mimic Ant target/task logging
buildLogElement.setBuildLogHeader(command);
//TODO: Clean up this code and re-use the CommandLine code
try {
CompositeConsumer consumer = new CompositeConsumer(publisher, execScript);
commandLine.runScript(execScript, consumer, environmentVariableContext, null);
setBuildDuration(startTime, buildLogElement);
if (execScript.foundError()) {
// detected the error string in the command output
String message = "Build failed. Command " + this.command + " reported [" + errorString + "].";
setBuildError(buildLogElement, message);
buildLogElement.setTaskError();
throw new CruiseControlException(message);
} else if (execScript.getExitCode() != 0) {
String message = "return code is " + execScript.getExitCode();
setBuildError(buildLogElement, message);
throw new CruiseControlException(message);
}
} catch (CheckedCommandLineException ex) {
setBuildError(buildLogElement, "exec error");
setTaskError(buildLogElement, "Could not execute command: " + commandLine.toStringForDisplay());
throw ex;
}
}
use of com.thoughtworks.go.util.command.CommandLine in project gocd by gocd.
the class CommandBuilder method buildCommandLine.
protected CommandLine buildCommandLine() {
CommandLine command = null;
if (SystemUtil.isWindows()) {
command = CommandLine.createCommandLine("cmd").withWorkingDir(workingDir);
command.withArg("/c");
command.withArg(translateToWindowsPath(this.command));
} else {
command = CommandLine.createCommandLine(this.command).withWorkingDir(workingDir);
}
String[] argsArray = CommandLine.translateCommandLine(args);
for (int i = 0; i < argsArray.length; i++) {
String arg = argsArray[i];
command.withArg(arg);
}
return command;
}
Aggregations