Esempio n. 1
0
  /** Run new Maven os process with given arguments and commands. */
  public void execute() {
    Process process = null;
    BufferedReader br = null;
    try {
      ProcessBuilder processBuilder = getProcessBuilder();
      processBuilder.redirectErrorStream(true);
      log.info("Starting process: " + processBuilder.command());

      process = processBuilder.start();

      // Read output
      br = new BufferedReader(new InputStreamReader(process.getInputStream()));
      String line;
      while ((line = br.readLine()) != null) {
        System.out.println(line);
      }

      process.waitFor();
    } catch (Exception e) {
      throw new RuntimeException(e);
    } finally {
      close(br);
      destroyProcess(process);
    }
  }
 private static void logCommand(final Context context, final ProcessBuilder builder) {
   final StringBuilder description = new StringBuilder("Running: ");
   for (final String arg : builder.command()) {
     description.append(arg).append(" ");
   }
   context.log(description.toString());
 }
Esempio n. 3
0
  private void spawnWorkerAndWait(Script myWhatToDo) {
    String currentClassPathString = System.getProperty("java.class.path");
    Set<File> classPaths = calculateClassPath(new File(System.getProperty("user.dir")));

    List<String> commandLine = new ArrayList<String>();
    commandLine.add(JavaEnvUtils.getJreExecutable("java"));
    commandLine.addAll(Arrays.asList(JVM_ARGS));
    StringBuilder sb = new StringBuilder();
    String pathSeparator = System.getProperty("path.separator");
    for (File cp : classPaths) {
      sb.append(pathSeparator);
      sb.append(cp.getAbsolutePath());
    }

    // copy ant libs
    for (String entry : currentClassPathString.split(pathSeparator)) {
      if (entry.indexOf("ant") >= 0) {
        sb.append(pathSeparator);
        sb.append(entry);
      }
    }

    commandLine.add("-classpath");
    commandLine.add(sb.toString());

    commandLine.add(MakeWorker.class.getCanonicalName());
    try {
      commandLine.add(myWhatToDo.dumpToTmpFile().getAbsolutePath());
    } catch (FileNotFoundException e) {
      throw new BuildException(e);
    }

    ProcessBuilder pb = new ProcessBuilder(JavaEnvUtils.getJreExecutable("java"));
    pb.command(commandLine);
    pb.directory(new File(System.getProperty("user.dir")));

    executeProcess(pb);
  }
Esempio n. 4
0
  public IdedClient() {
    boolean ok = false;
    try {
      ProcessBuilder builder = new ProcessBuilder();
      Paths paths = new Paths();
      builder.environment().put("RUST_HOME", paths.getRustHome().getPath());
      builder.command(paths.getIded().getPath());
      process = builder.start();

      stdoutReader = new Thread(new StdoutReader(process.getInputStream()));
      stderrReader = new Thread(new StderrReader(process.getErrorStream()));

      stdoutReader.start();
      stderrReader.start();

      ok = true;
    } catch (IOException e) {
      throw new RuntimeException(e);
    } finally {
      if (!ok) {
        close();
      }
    }
  }