Search in sources :

Example 11 with ExecAction

use of org.gradle.process.internal.ExecAction in project gradle by gradle.

the class CommandLineToolVersionLocator method getVswhereOutput.

private String getVswhereOutput(File vswhereBinary, List<String> args) {
    ExecAction exec = execActionFactory.newExecAction();
    exec.args(args);
    exec.executable(vswhereBinary.getAbsolutePath());
    exec.setWorkingDir(vswhereBinary.getParentFile());
    StreamByteBuffer buffer = new StreamByteBuffer();
    exec.setStandardOutput(buffer.getOutputStream());
    exec.setErrorOutput(NullOutputStream.INSTANCE);
    exec.setIgnoreExitValue(true);
    ExecResult result = exec.execute();
    int exitValue = result.getExitValue();
    if (exitValue == 0) {
        return buffer.readAsString("UTF-8");
    } else {
        LOGGER.debug("vswhere.exe returned a non-zero exit value ({}) - ignoring", result.getExitValue());
        return null;
    }
}
Also used : ExecAction(org.gradle.process.internal.ExecAction) StreamByteBuffer(org.gradle.internal.io.StreamByteBuffer) ExecResult(org.gradle.process.ExecResult)

Example 12 with ExecAction

use of org.gradle.process.internal.ExecAction in project gradle by gradle.

the class DefaultCommandLineToolInvocationWorker method execute.

@Override
public void execute(CommandLineToolInvocation invocation, BuildOperationContext context) {
    BuildOperationDescriptor description = invocation.description().build();
    ExecAction toolExec = execActionFactory.newExecAction();
    toolExec.executable(executable);
    if (invocation.getWorkDirectory() != null) {
        GFileUtils.mkdirs(invocation.getWorkDirectory());
        toolExec.workingDir(invocation.getWorkDirectory());
    }
    toolExec.args(invocation.getArgs());
    if (!invocation.getPath().isEmpty()) {
        String pathVar = OperatingSystem.current().getPathVar();
        String toolPath = Joiner.on(File.pathSeparator).join(invocation.getPath());
        toolPath = toolPath + File.pathSeparator + System.getenv(pathVar);
        toolExec.environment(pathVar, toolPath);
        if (OperatingSystem.current().isWindows() && toolExec.getEnvironment().containsKey(pathVar.toUpperCase())) {
            toolExec.getEnvironment().remove(pathVar.toUpperCase());
        }
    }
    toolExec.environment(invocation.getEnvironment());
    StreamByteBuffer errOutput = new StreamByteBuffer();
    StreamByteBuffer stdOutput = new StreamByteBuffer();
    toolExec.setErrorOutput(errOutput.getOutputStream());
    toolExec.setStandardOutput(stdOutput.getOutputStream());
    try {
        toolExec.execute();
        invocation.getLogger().operationSuccess(description.getDisplayName(), combineOutput(stdOutput, errOutput));
    } catch (ExecException e) {
        invocation.getLogger().operationFailed(description.getDisplayName(), combineOutput(stdOutput, errOutput));
        throw new CommandLineToolInvocationFailure(invocation, String.format("%s failed while %s.", name, description.getDisplayName()));
    }
}
Also used : ExecAction(org.gradle.process.internal.ExecAction) BuildOperationDescriptor(org.gradle.internal.operations.BuildOperationDescriptor) ExecException(org.gradle.process.internal.ExecException) StreamByteBuffer(org.gradle.internal.io.StreamByteBuffer)

Aggregations

ExecAction (org.gradle.process.internal.ExecAction)12 StreamByteBuffer (org.gradle.internal.io.StreamByteBuffer)5 ExecResult (org.gradle.process.ExecResult)3 ExecException (org.gradle.process.internal.ExecException)3 File (java.io.File)2 GradleException (org.gradle.api.GradleException)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 List (java.util.List)1 Action (org.gradle.api.Action)1 JavadocExecHandleBuilder (org.gradle.external.javadoc.internal.JavadocExecHandleBuilder)1 BuildOperationDescriptor (org.gradle.internal.operations.BuildOperationDescriptor)1 MeasuredOperation (org.gradle.performance.measure.MeasuredOperation)1 MeasuredOperationList (org.gradle.performance.results.MeasuredOperationList)1 JavaExecAction (org.gradle.process.internal.JavaExecAction)1