Search in sources :

Example 6 with ExecAction

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

the class AbstractLocator method find.

public File find() {
    synchronized (this) {
        if (cachedLocation == null) {
            ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
            ExecAction execAction = execActionFactory.newExecAction();
            execAction.executable("xcrun");
            execAction.workingDir(System.getProperty("user.dir"));
            execAction.args(getXcrunFlags());
            execAction.setStandardOutput(outputStream);
            execAction.execute().assertNormalExitValue();
            cachedLocation = new File(outputStream.toString().replace("\n", ""));
        }
        return cachedLocation;
    }
}
Also used : ExecAction(org.gradle.process.internal.ExecAction) ByteArrayOutputStream(java.io.ByteArrayOutputStream) File(java.io.File)

Example 7 with ExecAction

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

the class AbstractMetadataProvider method runCompiler.

private Pair<String, String> runCompiler(File gccBinary, List<String> args) {
    ExecAction exec = execActionFactory.newExecAction();
    exec.executable(gccBinary.getAbsolutePath());
    exec.setWorkingDir(gccBinary.getParentFile());
    exec.args(args);
    StreamByteBuffer buffer = new StreamByteBuffer();
    StreamByteBuffer errorBuffer = new StreamByteBuffer();
    exec.setStandardOutput(buffer.getOutputStream());
    exec.setErrorOutput(errorBuffer.getOutputStream());
    exec.setIgnoreExitValue(true);
    ExecResult result = exec.execute();
    int exitValue = result.getExitValue();
    if (exitValue == 0) {
        return Pair.of(buffer.readAsString(), errorBuffer.readAsString());
    } else {
        return null;
    }
}
Also used : ExecAction(org.gradle.process.internal.ExecAction) StreamByteBuffer(org.gradle.internal.io.StreamByteBuffer) ExecResult(org.gradle.process.ExecResult)

Example 8 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)

Example 9 with ExecAction

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

the class JavadocExecHandleBuilder method getExecHandle.

public ExecAction getExecHandle() {
    try {
        options.write(optionsFile);
    } catch (IOException e) {
        throw new GradleException("Failed to store javadoc options.", e);
    }
    ExecAction execAction = execActionFactory.newExecAction();
    execAction.workingDir(execDirectory);
    execAction.executable(GUtil.elvis(executable, Jvm.current().getJavadocExecutable()));
    execAction.args("@" + optionsFile.getAbsolutePath());
    options.contributeCommandLineOptions(execAction);
    return execAction;
}
Also used : ExecAction(org.gradle.process.internal.ExecAction) GradleException(org.gradle.api.GradleException) IOException(java.io.IOException)

Example 10 with ExecAction

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

the class GradleVsMavenBuildExperimentRunner method runMavenExperiment.

private void runMavenExperiment(MeasuredOperationList results, final MavenBuildExperimentSpec experiment, final MavenInvocationSpec buildSpec) {
    File projectDir = buildSpec.getWorkingDirectory();
    performMeasurements(new InvocationExecutorProvider() {

        public Action<MeasuredOperation> runner(final BuildExperimentInvocationInfo invocationInfo, final InvocationCustomizer invocationCustomizer) {
            return new Action<MeasuredOperation>() {

                @Override
                public void execute(MeasuredOperation measuredOperation) {
                    System.out.println("Run Maven using JVM opts: " + Iterables.concat(buildSpec.getMavenOpts(), buildSpec.getJvmOpts()));
                    List<String> cleanTasks = buildSpec.getCleanTasks();
                    if (!cleanTasks.isEmpty()) {
                        System.out.println("Cleaning up by running Maven tasks: " + Joiner.on(" ").join(buildSpec.getCleanTasks()));
                        ExecAction clean = createMavenInvocation(buildSpec, cleanTasks);
                        executeWithFileLogging(experiment, clean);
                    }
                    MavenInvocationSpec invocation = invocationCustomizer.customize(invocationInfo, buildSpec);
                    final ExecAction run = createMavenInvocation(invocation, invocation.getTasksToRun());
                    System.out.println("Measuring Maven tasks: " + Joiner.on(" ").join(buildSpec.getTasksToRun()));
                    DurationMeasurementImpl.measure(measuredOperation, new Runnable() {

                        @Override
                        public void run() {
                            executeWithFileLogging(experiment, run);
                        }
                    });
                }
            };
        }
    }, experiment, results, projectDir);
}
Also used : Action(org.gradle.api.Action) ExecAction(org.gradle.process.internal.ExecAction) ExecAction(org.gradle.process.internal.ExecAction) List(java.util.List) MeasuredOperationList(org.gradle.performance.results.MeasuredOperationList) File(java.io.File) MeasuredOperation(org.gradle.performance.measure.MeasuredOperation)

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