当前位置: 首页>>代码示例>>Java>>正文


Java ProcessUtil.process方法代码示例

本文整理汇总了Java中org.eclipse.che.api.core.util.ProcessUtil.process方法的典型用法代码示例。如果您正苦于以下问题:Java ProcessUtil.process方法的具体用法?Java ProcessUtil.process怎么用?Java ProcessUtil.process使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.eclipse.che.api.core.util.ProcessUtil的用法示例。


在下文中一共展示了ProcessUtil.process方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: readMavenVersionInformation

import org.eclipse.che.api.core.util.ProcessUtil; //导入方法依赖的package包/类
private static void readMavenVersionInformation(LineConsumer cmdOutput) throws IOException {
  final CommandLine commandLine = new CommandLine(getMavenExecCommand()).add("-version");
  final ProcessBuilder processBuilder =
      new ProcessBuilder().command(commandLine.toShellCommand()).redirectErrorStream(true);
  final Process process = processBuilder.start();
  ProcessUtil.process(process, cmdOutput, LineConsumer.DEV_NULL);
}
 
开发者ID:eclipse,项目名称:che,代码行数:8,代码来源:MavenUtils.java

示例2: execute

import org.eclipse.che.api.core.util.ProcessUtil; //导入方法依赖的package包/类
public void execute(String[] commandLine, File workDir)
    throws TimeoutException, IOException, InterruptedException {
  ProcessBuilder pb =
      new ProcessBuilder(commandLine).redirectErrorStream(true).directory(workDir);

  eventService.publish(
      new ComposerOutputImpl(String.join(" ", commandLine), ComposerOutput.State.START));

  LineConsumer lineConsumer =
      new AbstractLineConsumer() {
        @Override
        public void writeLine(String line) throws IOException {
          eventService.publish(new ComposerOutputImpl(line, ComposerOutput.State.IN_PROGRESS));
        }
      };

  // process will be stopped after timeout
  Watchdog watcher = new Watchdog(10, TimeUnit.MINUTES);

  try {
    final Process process = pb.start();
    final ValueHolder<Boolean> isTimeoutExceeded = new ValueHolder<>(false);
    watcher.start(
        () -> {
          isTimeoutExceeded.set(true);
          ProcessUtil.kill(process);
        });
    // consume logs until process ends
    ProcessUtil.process(process, lineConsumer);
    process.waitFor();
    eventService.publish(new ComposerOutputImpl("Done", ComposerOutput.State.DONE));
    if (isTimeoutExceeded.get()) {
      LOG.error("Command time expired : command-line " + Arrays.toString(commandLine));
      eventService.publish(
          new ComposerOutputImpl(
              "Installing dependencies time expired", ComposerOutput.State.ERROR));
      throw new TimeoutException();
    } else if (process.exitValue() != 0) {
      LOG.error("Command failed : command-line " + Arrays.toString(commandLine));
      eventService.publish(new ComposerOutputImpl("Error occurred", ComposerOutput.State.ERROR));
      throw new IOException(
          "Process failed. Exit code "
              + process.exitValue()
              + " command-line : "
              + Arrays.toString(commandLine));
    }
  } finally {
    watcher.stop();
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:51,代码来源:ComposerCommandExecutor.java

示例3: execute

import org.eclipse.che.api.core.util.ProcessUtil; //导入方法依赖的package包/类
/**
 * Execute maven archetype command
 *
 * @param commandLine command to execution e.g. mvn archetype:generate
 *     -DarchetypeGroupId=<archetype-groupId> -DarchetypeArtifactId=<archetype-artifactId>
 *     -DarchetypeVersion=<archetype-version> -DgroupId=<my.groupid> -DartifactId=<my-artifactId>
 * @param workDir folder where command will execute in common use root dir of workspace
 * @throws TimeoutException
 * @throws IOException
 * @throws InterruptedException
 */
private void execute(String[] commandLine, File workDir)
    throws TimeoutException, IOException, InterruptedException {
  ProcessBuilder pb =
      new ProcessBuilder(commandLine).redirectErrorStream(true).directory(workDir);

  eventService.publish(
      new ArchetypeOutputImpl("Start Project generation", ArchetypeOutput.State.START));

  LineConsumer lineConsumer =
      new AbstractLineConsumer() {
        @Override
        public void writeLine(String line) throws IOException {
          eventService.publish(new ArchetypeOutputImpl(line, ArchetypeOutput.State.IN_PROGRESS));
        }
      };

  // process will be stopped after timeout
  Watchdog watcher = new Watchdog(60, TimeUnit.SECONDS);

  try {
    final Process process = pb.start();
    final ValueHolder<Boolean> isTimeoutExceeded = new ValueHolder<>(false);
    watcher.start(
        () -> {
          isTimeoutExceeded.set(true);
          ProcessUtil.kill(process);
        });
    // consume logs until process ends
    ProcessUtil.process(process, lineConsumer);
    process.waitFor();
    eventService.publish(new ArchetypeOutputImpl("Done", DONE));
    if (isTimeoutExceeded.get()) {
      LOG.error("Generation project time expired : command-line " + Arrays.toString(commandLine));
      eventService.publish(new ArchetypeOutputImpl("Generation project time expired", ERROR));
      throw new TimeoutException();
    } else if (process.exitValue() != 0) {
      LOG.error("Generation project fail : command-line " + Arrays.toString(commandLine));
      eventService.publish(new ArchetypeOutputImpl("Generation project occurs error", ERROR));
      throw new IOException(
          "Process failed. Exit code "
              + process.exitValue()
              + " command-line : "
              + Arrays.toString(commandLine));
    }
  } finally {
    watcher.stop();
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:60,代码来源:ArchetypeGenerator.java

示例4: suspend

import org.eclipse.che.api.core.util.ProcessUtil; //导入方法依赖的package包/类
public Location suspend(final String file, boolean isRemoteConnection)
    throws IOException, InterruptedException, DebuggerException {
  if (pid < 0) {
    throw new DebuggerException("Gdb process not found.");
  }

  if (isRemoteConnection) {
    Runtime.getRuntime().exec("kill -SIGINT " + pid).waitFor();
    sendCommand("signal SIGSTOP ");
  } else {
    final List<String> outputs = new ArrayList<>();
    final ProcessBuilder processBuilder =
        new ProcessBuilder().command("ps", "-o", "pid,cmd", "--ppid", String.valueOf(pid));
    final Process process = processBuilder.start();

    LineConsumer stdout =
        new AbstractLineConsumer() {
          @Override
          public void writeLine(String line) throws IOException {
            outputs.add(line);
          }
        };

    ProcessUtil.process(process, stdout);

    int processId = -1;
    for (String output : outputs) {
      try {
        final ProcessInfo processInfo = ProcessInfo.parse(output);
        if (file.equals(processInfo.getProcessName())) {
          processId = processInfo.getProcessId();
        }
      } catch (Exception e) {
        // we can't get info about current process, but we are trying to get info about another
        // processes
      }
    }

    if (processId == -1) {
      throw new DebuggerException(format("Process %s not found.", file));
    }
    Runtime.getRuntime().exec("kill -SIGINT " + processId).waitFor();
  }

  final GdbOutput gdbOutput = sendCommand("backtrace");
  final GdbBacktrace backtrace = GdbBacktrace.parse(gdbOutput);
  final Map<Integer, Location> frames = backtrace.getFrames();

  if (frames.containsKey(0)) {
    return frames.get(0);
  }
  throw new DebuggerException("Unable recognize current location for debugger session. ");
}
 
开发者ID:eclipse,项目名称:che,代码行数:54,代码来源:Gdb.java


注:本文中的org.eclipse.che.api.core.util.ProcessUtil.process方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。