Search in sources :

Example 1 with SimpleProcessListener

use of com.facebook.buck.util.SimpleProcessListener in project buck by facebook.

the class SwiftStdlibStep method execute.

@Override
public StepExecutionResult execute(ExecutionContext context) throws InterruptedException {
    ListeningProcessExecutor executor = new ListeningProcessExecutor();
    ProcessExecutorParams params = makeProcessExecutorParams();
    SimpleProcessListener listener = new SimpleProcessListener();
    // TODO(ryu2): parse output as needed
    try {
        LOG.debug("%s", command);
        ListeningProcessExecutor.LaunchedProcess process = executor.launchProcess(params, listener);
        int result = executor.waitForProcess(process);
        if (result != 0) {
            LOG.error("Error running %s: %s", getDescription(context), listener.getStderr());
            return StepExecutionResult.of(result);
        }
    } catch (IOException e) {
        LOG.error(e, "Could not execute command %s", command);
        return StepExecutionResult.ERROR;
    }
    // Copy from temp to destinationDirectory if we wrote files.
    if (Files.notExists(temp)) {
        return StepExecutionResult.SUCCESS;
    }
    try (DirectoryStream<Path> dirStream = Files.newDirectoryStream(temp)) {
        if (dirStream.iterator().hasNext()) {
            Files.createDirectories(destinationDirectory);
            MoreFiles.copyRecursively(temp, destinationDirectory);
        }
    } catch (IOException e) {
        LOG.error(e, "Could not copy to %s", destinationDirectory);
        return StepExecutionResult.ERROR;
    }
    return StepExecutionResult.SUCCESS;
}
Also used : Path(java.nio.file.Path) ProcessExecutorParams(com.facebook.buck.util.ProcessExecutorParams) SimpleProcessListener(com.facebook.buck.util.SimpleProcessListener) ListeningProcessExecutor(com.facebook.buck.util.ListeningProcessExecutor) IOException(java.io.IOException)

Example 2 with SimpleProcessListener

use of com.facebook.buck.util.SimpleProcessListener in project buck by facebook.

the class SwiftCompileStep method execute.

@Override
public StepExecutionResult execute(ExecutionContext context) throws InterruptedException {
    ListeningProcessExecutor executor = new ListeningProcessExecutor();
    ProcessExecutorParams params = makeProcessExecutorParams();
    SimpleProcessListener listener = new SimpleProcessListener();
    // TODO(ryu2): parse the output, print build failure errors, etc.
    try {
        LOG.debug("%s", compilerCommand);
        ListeningProcessExecutor.LaunchedProcess process = executor.launchProcess(params, listener);
        int result = executor.waitForProcess(process);
        if (result != 0) {
            LOG.error("Error running %s: %s", getDescription(context), listener.getStderr());
        }
        return StepExecutionResult.of(result);
    } catch (IOException e) {
        LOG.error(e, "Could not execute command %s", compilerCommand);
        return StepExecutionResult.ERROR;
    }
}
Also used : ProcessExecutorParams(com.facebook.buck.util.ProcessExecutorParams) SimpleProcessListener(com.facebook.buck.util.SimpleProcessListener) ListeningProcessExecutor(com.facebook.buck.util.ListeningProcessExecutor) IOException(java.io.IOException)

Example 3 with SimpleProcessListener

use of com.facebook.buck.util.SimpleProcessListener in project buck by facebook.

the class MacNetworkConfiguration method runNetworkSetupCommand.

/**
   * Naive `networksetup` invocation; returns non-empty string of stdout if all went well.
   */
private static String runNetworkSetupCommand(String subCommand, String argument) throws InterruptedException {
    ListeningProcessExecutor executor = new ListeningProcessExecutor();
    SimpleProcessListener listener = new SimpleProcessListener();
    ProcessExecutorParams params = ProcessExecutorParams.builder().addCommand("networksetup").addCommand(String.format("-%s", subCommand)).addCommand(argument).build();
    ListeningProcessExecutor.LaunchedProcess process = null;
    try {
        process = executor.launchProcess(params, listener);
        if (executor.waitForProcess(process, COMMAND_TIMEOUT_MS, TimeUnit.MILLISECONDS) != 0) {
            return "";
        }
        return listener.getStdout();
    } catch (IOException e) {
        LOG.debug(e, "Exception while running networksetup command");
        return "";
    } finally {
        if (process != null) {
            executor.destroyProcess(process, /* force */
            true);
        }
    }
}
Also used : ProcessExecutorParams(com.facebook.buck.util.ProcessExecutorParams) SimpleProcessListener(com.facebook.buck.util.SimpleProcessListener) ListeningProcessExecutor(com.facebook.buck.util.ListeningProcessExecutor) IOException(java.io.IOException)

Aggregations

ListeningProcessExecutor (com.facebook.buck.util.ListeningProcessExecutor)3 ProcessExecutorParams (com.facebook.buck.util.ProcessExecutorParams)3 SimpleProcessListener (com.facebook.buck.util.SimpleProcessListener)3 IOException (java.io.IOException)3 Path (java.nio.file.Path)1