コード例 #1
0
ファイル: Maven.java プロジェクト: christophd/jellycastle
  /** 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);
    }
  }
コード例 #2
0
 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());
 }
コード例 #3
0
ファイル: MpsMakeHelper.java プロジェクト: lilongthinker/MPS
  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);
  }