Search in sources :

Example 1 with ExecAction

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

the class GradleVsMavenBuildExperimentRunner method createMavenInvocation.

private ExecAction createMavenInvocation(MavenInvocationSpec buildSpec) {
    ExecAction execAction = execActionFactory.newExecAction();
    execAction.setWorkingDir(buildSpec.getWorkingDirectory());
    execAction.executable(buildSpec.getInstallation().getMvn());
    execAction.args(buildSpec.getArgs());
    execAction.args(buildSpec.getTasksToRun());
    execAction.environment("MAVEN_OPTS", Joiner.on(' ').join(Iterables.concat(buildSpec.getMavenOpts(), buildSpec.getJvmOpts())));
    return execAction;
}
Also used : ExecAction(org.gradle.process.internal.ExecAction)

Example 2 with ExecAction

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

the class GccVersionDeterminer method transform.

private String transform(File gccBinary, List<String> args) {
    ExecAction exec = execActionFactory.newExecAction();
    exec.executable(gccBinary.getAbsolutePath());
    exec.setWorkingDir(gccBinary.getParentFile());
    exec.args(args);
    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();
    } else {
        return null;
    }
}
Also used : ExecAction(org.gradle.process.internal.ExecAction) StreamByteBuffer(org.gradle.internal.io.StreamByteBuffer) ExecResult(org.gradle.process.ExecResult)

Example 3 with ExecAction

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

the class DefaultFileOperations method exec.

public ExecResult exec(Action<? super ExecSpec> action) {
    ExecAction execAction = instantiator.newInstance(DefaultExecAction.class, fileResolver);
    action.execute(execAction);
    return execAction.execute();
}
Also used : JavaExecAction(org.gradle.process.internal.JavaExecAction) DefaultExecAction(org.gradle.process.internal.DefaultExecAction) DefaultJavaExecAction(org.gradle.process.internal.DefaultJavaExecAction) ExecAction(org.gradle.process.internal.ExecAction)

Example 4 with ExecAction

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

the class JavadocGenerator method execute.

@Override
public WorkResult execute(JavadocSpec spec) {
    JavadocExecHandleBuilder javadocExecHandleBuilder = new JavadocExecHandleBuilder(execActionFactory);
    javadocExecHandleBuilder.setExecutable(spec.getExecutable());
    javadocExecHandleBuilder.execDirectory(spec.getWorkingDir()).options(spec.getOptions()).optionsFile(spec.getOptionsFile());
    ExecAction execAction = javadocExecHandleBuilder.getExecHandle();
    if (spec.isIgnoreFailures()) {
        execAction.setIgnoreExitValue(true);
    }
    try {
        execAction.execute();
    } catch (ExecException e) {
        LOG.info("Problems generating Javadoc." + "\n  Command line issued: " + execAction.getCommandLine() + "\n  Generated Javadoc options file has following contents:\n------\n{}------", GFileUtils.readFileQuietly(spec.getOptionsFile()));
        throw new GradleException(String.format("Javadoc generation failed. Generated Javadoc options file (useful for troubleshooting): '%s'", spec.getOptionsFile()), e);
    }
    return new SimpleWorkResult(true);
}
Also used : ExecAction(org.gradle.process.internal.ExecAction) JavadocExecHandleBuilder(org.gradle.external.javadoc.internal.JavadocExecHandleBuilder) ExecException(org.gradle.process.internal.ExecException) GradleException(org.gradle.api.GradleException) SimpleWorkResult(org.gradle.api.internal.tasks.SimpleWorkResult)

Example 5 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) {
    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(invocation.getDescription(), combineOutput(stdOutput, errOutput));
    } catch (ExecException e) {
        invocation.getLogger().operationFailed(invocation.getDescription(), combineOutput(stdOutput, errOutput));
        throw new CommandLineToolInvocationFailure(invocation, String.format("%s failed while %s.", name, invocation.getDescription()));
    }
}
Also used : ExecAction(org.gradle.process.internal.ExecAction) ExecException(org.gradle.process.internal.ExecException) StreamByteBuffer(org.gradle.internal.io.StreamByteBuffer)

Aggregations

ExecAction (org.gradle.process.internal.ExecAction)7 GradleException (org.gradle.api.GradleException)2 StreamByteBuffer (org.gradle.internal.io.StreamByteBuffer)2 ExecException (org.gradle.process.internal.ExecException)2 File (java.io.File)1 IOException (java.io.IOException)1 Action (org.gradle.api.Action)1 SimpleWorkResult (org.gradle.api.internal.tasks.SimpleWorkResult)1 JavadocExecHandleBuilder (org.gradle.external.javadoc.internal.JavadocExecHandleBuilder)1 MeasuredOperation (org.gradle.performance.measure.MeasuredOperation)1 ExecResult (org.gradle.process.ExecResult)1 DefaultExecAction (org.gradle.process.internal.DefaultExecAction)1 DefaultJavaExecAction (org.gradle.process.internal.DefaultJavaExecAction)1 JavaExecAction (org.gradle.process.internal.JavaExecAction)1