Search in sources :

Example 1 with CompositeConsumer

use of com.thoughtworks.go.util.command.CompositeConsumer 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;
    }
}
Also used : CompositeConsumer(com.thoughtworks.go.util.command.CompositeConsumer) CheckedCommandLineException(com.thoughtworks.go.util.command.CheckedCommandLineException) CommandLine(com.thoughtworks.go.util.command.CommandLine) ExecScript(com.thoughtworks.go.util.command.ExecScript) CruiseControlException(com.thoughtworks.go.util.command.CruiseControlException)

Aggregations

CheckedCommandLineException (com.thoughtworks.go.util.command.CheckedCommandLineException)1 CommandLine (com.thoughtworks.go.util.command.CommandLine)1 CompositeConsumer (com.thoughtworks.go.util.command.CompositeConsumer)1 CruiseControlException (com.thoughtworks.go.util.command.CruiseControlException)1 ExecScript (com.thoughtworks.go.util.command.ExecScript)1