use of com.thoughtworks.go.util.command.ExecScript 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;
}
}
Aggregations