Java Code Examples for com.intellij.execution.process.ProcessOutput#isTimeout()

The following examples show how to use com.intellij.execution.process.ProcessOutput#isTimeout() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NoSqlConfigurable.java    From nosql4idea with Apache License 2.0 5 votes vote down vote up
public ProcessOutput checkShellPath(DatabaseVendor databaseVendor, String shellPath) throws ExecutionException, TimeoutException {
    if (isBlank(shellPath)) {
        return null;
    }

    GeneralCommandLine commandLine = new GeneralCommandLine();
    commandLine.setExePath(shellPath);
    if (testParameter != null) {
        commandLine.addParameter(testParameter);
    }
    CapturingProcessHandler handler = new CapturingProcessHandler(commandLine.createProcess(), CharsetToolkit.getDefaultSystemCharset());
    ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
    ProcessOutput result = indicator == null ?
            handler.runProcess(TIMEOUT_MS) :
            handler.runProcessWithProgressIndicator(indicator);
    if (result.isTimeout()) {
        throw new TimeoutException("Couldn't check " + databaseVendor.name + " CLI executable - stopped by timeout.");
    } else if (result.isCancelled()) {
        throw new ProcessCanceledException();
    } else if (result.getExitCode() != 0 || !result.getStderr().isEmpty()) {
        throw new ExecutionException(String.format("Errors while executing %s. exitCode=%s errors: %s",
                commandLine.toString(),
                result.getExitCode(),
                result.getStderr()));
    }
    return result;
}
 
Example 2
Source File: Executor.java    From consulo with Apache License 2.0 5 votes vote down vote up
protected static String run(List<String> params) {
  final ProcessBuilder builder = new ProcessBuilder().command(params);
  builder.directory(ourCurrentDir());
  builder.redirectErrorStream(true);
  Process clientProcess;
  try {
    clientProcess = builder.start();
  }
  catch (IOException e) {
    throw new RuntimeException(e);
  }

  CapturingProcessHandler handler = new CapturingProcessHandler(clientProcess, CharsetToolkit.getDefaultSystemCharset(), StringUtil.join(params, " "));
  ProcessOutput result = handler.runProcess(30*1000);
  if (result.isTimeout()) {
    throw new RuntimeException("Timeout waiting for the command execution. Command: " + StringUtil.join(params, " "));
  }

  if (result.getExitCode() != 0) {
    log("{" + result.getExitCode() + "}");
  }
  String stdout = result.getStdout().trim();
  if (!StringUtil.isEmptyOrSpaces(stdout)) {
    log(stdout.trim());
  }
  return stdout;
}
 
Example 3
Source File: ExecutableValidator.java    From consulo with Apache License 2.0 5 votes vote down vote up
protected static boolean doCheckExecutable(@Nonnull String executable, @Nonnull List<String> processParameters) {
  try {
    GeneralCommandLine commandLine = new GeneralCommandLine();
    commandLine.setExePath(executable);
    commandLine.addParameters(processParameters);
    commandLine.setCharset(CharsetToolkit.getDefaultSystemCharset());
    CapturingProcessHandler handler = new CapturingProcessHandler(commandLine);
    ProcessOutput result = handler.runProcess(TIMEOUT_MS);
    boolean timeout = result.isTimeout();
    int exitCode = result.getExitCode();
    String stderr = result.getStderr();
    if (timeout) {
      LOG.warn("Validation of " + executable + " failed with a timeout");
    }
    if (exitCode != 0) {
      LOG.warn("Validation of " + executable + " failed with a non-zero exit code: " + exitCode);
    }
    if (!stderr.isEmpty()) {
      LOG.warn("Validation of " + executable + " failed with a non-empty error output: " + stderr);
    }
    return !timeout && exitCode == 0 && stderr.isEmpty();
  }
  catch (Throwable t) {
    LOG.warn(t);
    return false;
  }
}
 
Example 4
Source File: TestClientRunner.java    From consulo with Apache License 2.0 4 votes vote down vote up
public ProcessOutput runClient(@Nonnull String exeName, @javax.annotation.Nullable String stdin, @javax.annotation.Nullable final File workingDir, String... commandLine) throws IOException {
  final List<String> arguments = new ArrayList<String>();

  final File client = new File(myClientBinaryPath, SystemInfo.isWindows ? exeName + ".exe" : exeName);
  if (client.exists()) {
    arguments.add(client.toString());
  }
  else {
    // assume client is in path
    arguments.add(exeName);
  }
  Collections.addAll(arguments, commandLine);

  if (myTraceClient) {
    LOG.info("*** running:\n" + arguments);
    if (StringUtil.isNotEmpty(stdin)) {
      LOG.info("*** stdin:\n" + stdin);
    }
  }

  final ProcessBuilder builder = new ProcessBuilder().command(arguments);
  if (workingDir != null) {
    builder.directory(workingDir);
  }
  if (myClientEnvironment != null) {
    builder.environment().putAll(myClientEnvironment);
  }
  final Process clientProcess = builder.start();

  if (stdin != null) {
    final OutputStream outputStream = clientProcess.getOutputStream();
    try {
      final byte[] bytes = stdin.getBytes();
      outputStream.write(bytes);
    }
    finally {
      outputStream.close();
    }
  }

  final CapturingProcessHandler handler =
          new CapturingProcessHandler(clientProcess, CharsetToolkit.getDefaultSystemCharset(), StringUtil.join(arguments, " "));
  final ProcessOutput result = handler.runProcess(100 * 1000, false);
  if (myTraceClient || result.isTimeout()) {
    LOG.debug("*** result: " + result.getExitCode());
    final String out = result.getStdout().trim();
    if (out.length() > 0) {
      LOG.debug("*** output:\n" + out);
    }
    final String err = result.getStderr().trim();
    if (err.length() > 0) {
      LOG.debug("*** error:\n" + err);
    }
  }

  if (result.isTimeout()) {
    String processList = LogUtil.getProcessList();
    handler.destroyProcess();
    throw new RuntimeException("Timeout waiting for VCS client to finish execution:\n" + processList);
  }

  return result;
}