private void startHandlingStreams() {
    final ProcessListener processListener =
        new ProcessListener() {
          public void startNotified(final ProcessEvent event) {
            // do nothing
          }

          public void processTerminated(final ProcessEvent event) {
            final int exitCode = event.getExitCode();
            try {
              setExitCode(exitCode);
              SvnCommand.this.processTerminated(exitCode);
            } finally {
              listeners().processTerminated(exitCode);
            }
          }

          public void processWillTerminate(
              final ProcessEvent event, final boolean willBeDestroyed) {
            // do nothing
          }

          public void onTextAvailable(final ProcessEvent event, final Key outputType) {
            SvnCommand.this.onTextAvailable(event.getText(), outputType);
          }
        };

    outputAdapter = new CapturingProcessAdapter();
    myHandler.addProcessListener(outputAdapter);
    myHandler.addProcessListener(processListener);
    myHandler.startNotify();
  }
  @NotNull
  @Override
  protected OSProcessHandler startProcess() throws ExecutionException {

    if (processHandler != null && !processHandler.isProcessTerminated()) {
      log.debug("existing running process found");

      processHandler.addProcessListener(
          new ProcessListener() {
            @Override
            public void startNotified(ProcessEvent event) {}

            @Override
            public void processTerminated(ProcessEvent event) {
              log.debug("existing process terminated");
            }

            @Override
            public void processWillTerminate(ProcessEvent event, boolean willBeDestroyed) {}

            @Override
            public void onTextAvailable(ProcessEvent event, Key outputType) {}
          });

      processHandler.destroyProcess();
    }

    processHandler =
        JavaCommandLineStateUtil.startProcess(createCommandLine(), true); // ansiColoringEnabled());

    return processHandler;
  }
Example #3
0
  public void launch(final MPSMakeCallback callback) {
    if (!isValid()) {
      throw new IllegalStateException("Unable to launch without validation");
    }

    GeneralCommandLine gcl = new GeneralCommandLine(myCommandLine);
    gcl.setWorkDirectory(myProject.getBaseDir().getPath());
    final TextEventProcessor tep =
        new TextEventProcessor(myProject, "MPS") {
          @Override
          public void reportWrittenFile(String file) {
            LOG.debug("written file: " + file);
            callback.fileWritten(file);
          }

          @Override
          public void reportDeletedFile(String file) {
            LOG.debug("deleted file: " + file);
            callback.fileDeleted(file);
          }

          @Override
          public void error(String text) {
            LOG.debug("error: " + text);
            callback.error(text);
          }

          @Override
          public void info(String text) {
            LOG.info("info: " + text);
            callback.info(text);
          }
        };
    try {
      OSProcessHandler processHandler =
          new OSProcessHandler(gcl.createProcess(), myCommandLine.get(0));
      processHandler.addProcessListener(
          new ProcessAdapter() {
            @Override
            public void onTextAvailable(ProcessEvent event, Key outputType) {
              if (outputType == ProcessOutputTypes.STDERR) {
                tep.processStderr(event.getText());
              } else if (outputType == ProcessOutputTypes.STDOUT) {
                tep.processStdout(event.getText());
              }
            }
          });
      processHandler.startNotify();

      processHandler.waitFor();
      if (processHandler.getProcess().exitValue() != 0) {
        callback.error("External process returned non-zero");
      }

    } catch (ExecutionException e) {
      LOG.debug(e);
      callback.error("Error running process: " + e.getMessage());
    }
  }
  public void attachTaskToProcess(final OSProcessHandler handler) {
    handler.addProcessListener(
        new ProcessAdapter() {
          @Override
          public void processTerminated(final ProcessEvent event) {
            handler.removeProcessListener(this);
            ensureFinished();
          }

          @Override
          public void startNotified(final ProcessEvent event) {
            startSearch();
          }
        });
  }
Example #5
0
  private static void runOutOfProcess(
      CompileContext compileContext, VirtualFile outputDir, File kotlinHome, File scriptFile) {
    final SimpleJavaParameters params = new SimpleJavaParameters();
    params.setJdk(new SimpleJavaSdkType().createJdk("tmp", SystemProperties.getJavaHome()));
    params.setMainClass("org.jetbrains.jet.cli.KotlinCompiler");
    params.getProgramParametersList().add("-module", scriptFile.getAbsolutePath());
    params.getProgramParametersList().add("-output", path(outputDir));
    params.getProgramParametersList().add("-tags");

    for (File jar : kompilerClasspath(kotlinHome, compileContext)) {
      params.getClassPath().add(jar);
    }

    params.getVMParametersList().addParametersString("-Djava.awt.headless=true -Xmx512m");
    //        params.getVMParametersList().addParametersString("-agentlib:yjpagent=sampling");

    Sdk sdk = params.getJdk();

    final GeneralCommandLine commandLine =
        JdkUtil.setupJVMCommandLine(
            ((JavaSdkType) sdk.getSdkType()).getVMExecutablePath(sdk), params, false);

    compileContext.addMessage(
        INFORMATION, "Invoking out-of-process compiler with arguments: " + commandLine, "", -1, -1);

    try {
      final OSProcessHandler processHandler =
          new OSProcessHandler(commandLine.createProcess(), commandLine.getCommandLineString()) {
            @Override
            public Charset getCharset() {
              return commandLine.getCharset();
            }
          };

      ProcessAdapter processListener = createProcessListener(compileContext);
      processHandler.addProcessListener(processListener);

      processHandler.startNotify();
      processHandler.waitFor();
    } catch (Exception e) {
      compileContext.addMessage(ERROR, "[Internal Error] " + e.getLocalizedMessage(), "", -1, -1);
      return;
    }
  }
  private JsonObject parseDubConfiguration() {
    try {
      String baseDir = project.getBaseDir().getCanonicalPath();
      GeneralCommandLine commandLine = new GeneralCommandLine();
      commandLine.setWorkDirectory(new File(baseDir));
      commandLine.setExePath(dubBinaryPath);
      ParametersList parametersList = commandLine.getParametersList();
      parametersList.addParametersString("describe");

      OSProcessHandler process =
          new OSProcessHandler(
              commandLine.createProcess(), commandLine.getPreparedCommandLine(Platform.current()));

      final StringBuilder builder = new StringBuilder();
      process.addProcessListener(
          new ProcessAdapter() {
            @Override
            public void onTextAvailable(ProcessEvent event, Key outputType) {
              builder.append(event.getText());
            }
          });

      process.startNotify();
      process.waitFor();

      // remove the warning line at the top if it exists
      String json =
          builder
              .toString()
              .replaceAll("WARNING.+", "")
              .trim()
              .replaceFirst(commandLine.getPreparedCommandLine(Platform.current()), "");

      // process output of dub describe into jsonObject
      return new JsonParser().parse(json).getAsJsonObject();

    } catch (ExecutionException ex) {
      ex.printStackTrace();
    }
    return null;
  }
Example #7
0
 @Nullable
 private static String executeZipAlign(String zipAlignPath, File source, File destination) {
   GeneralCommandLine commandLine = new GeneralCommandLine();
   commandLine.setExePath(zipAlignPath);
   commandLine.addParameters("-f", "4", source.getAbsolutePath(), destination.getAbsolutePath());
   OSProcessHandler handler;
   try {
     handler = new OSProcessHandler(commandLine.createProcess(), "");
   } catch (ExecutionException e) {
     return e.getMessage();
   }
   final StringBuilder builder = new StringBuilder();
   handler.addProcessListener(
       new ProcessAdapter() {
         @Override
         public void onTextAvailable(ProcessEvent event, Key outputType) {
           builder.append(event.getText());
         }
       });
   handler.startNotify();
   handler.waitFor();
   int exitCode = handler.getProcess().exitValue();
   return exitCode != 0 ? builder.toString() : null;
 }
  protected ExecutionResult startSMRunner(Executor executor) throws ExecutionException {
    if (!isSmRunnerUsed()) {
      return null;
    }
    getJavaParameters()
        .getVMParametersList()
        .addProperty("idea." + getFrameworkId() + ".sm_runner");

    final RunnerSettings runnerSettings = getRunnerSettings();

    final SMTRunnerConsoleProperties testConsoleProperties =
        getConfiguration().createTestConsoleProperties(executor);
    testConsoleProperties.setIfUndefined(TestConsoleProperties.HIDE_PASSED_TESTS, false);

    final BaseTestsOutputConsoleView consoleView =
        SMTestRunnerConnectionUtil.createConsole(getFrameworkName(), testConsoleProperties);
    final SMTestRunnerResultsForm viewer = ((SMTRunnerConsoleView) consoleView).getResultsViewer();
    Disposer.register(getConfiguration().getProject(), consoleView);

    final OSProcessHandler handler = createHandler(executor);
    consoleView.attachToProcess(handler);
    handler.addProcessListener(
        new ProcessAdapter() {
          @Override
          public void startNotified(ProcessEvent event) {
            if (getConfiguration().isSaveOutputToFile()) {
              viewer.getRoot().setOutputFilePath(getConfiguration().getOutputFilePath());
            }
          }

          @Override
          public void processTerminated(ProcessEvent event) {
            Runnable runnable =
                new Runnable() {
                  public void run() {
                    viewer.getRoot().flush();
                    deleteTempFiles();
                    clear();
                  }
                };
            UIUtil.invokeLaterIfNeeded(runnable);
            handler.removeProcessListener(this);
          }
        });

    AbstractRerunFailedTestsAction rerunFailedTestsAction =
        testConsoleProperties.createRerunFailedTestsAction(consoleView);
    LOG.assertTrue(rerunFailedTestsAction != null);
    rerunFailedTestsAction.setModelProvider(
        new Getter<TestFrameworkRunningModel>() {
          @Override
          public TestFrameworkRunningModel get() {
            return viewer;
          }
        });

    final DefaultExecutionResult result = new DefaultExecutionResult(consoleView, handler);
    result.setRestartActions(rerunFailedTestsAction);

    JavaRunConfigurationExtensionManager.getInstance()
        .attachExtensionsToProcess(getConfiguration(), handler, runnerSettings);
    return result;
  }
  private void executeTest(String className, String testMethodName, String dunitPath) {
    String testPath = className + "." + testMethodName;
    final String workingDirectory = project.getBasePath();
    //            final String testFile = configuration.getDFile().getCanonicalPath();

    final String dubPath = ToolKey.DUB_KEY.getPath(project);
    if (dubPath == null || dubPath.isEmpty()) {
      Notifications.Bus.notify(
          new Notification(
              "Dunit Test Runner",
              "Dub path must be specified",
              "Dub executable path is empty"
                  + "<br/><a href='configureDLanguageTools'>Configure</a>",
              NotificationType.WARNING,
              new DToolsNotificationListener(project)),
          project);
      return;
    }

    GeneralCommandLine commandLine = new GeneralCommandLine();
    commandLine.setWorkDirectory(workingDirectory);
    commandLine.setExePath(dubPath);
    ParametersList parametersList = commandLine.getParametersList();
    parametersList.addParametersString("--");
    parametersList.addParametersString("-v");
    parametersList.addParametersString("--filter");
    parametersList.addParametersString(testPath + "$"); // regex to locate exact test

    final StringBuilder builder = new StringBuilder();
    try {
      OSProcessHandler process = new OSProcessHandler(commandLine.createProcess());
      process.addProcessListener(
          new ProcessAdapter() {
            @Override
            public void onTextAvailable(ProcessEvent event, Key outputType) {
              builder.append(event.getText());
            }
          });

      process.startNotify();
      process.waitFor();

    } catch (ExecutionException e) {
      e.printStackTrace();
    }

    String result = builder.toString();
    // call either finished(success) or failed
    String successPatternString = ".*OK:.*";
    Pattern successPattern = Pattern.compile(successPatternString);
    Matcher successMatcher = successPattern.matcher(result);

    if (successMatcher.find()) {
      testFinished(className, testMethodName, 0);
      testStdOut(className, testMethodName, result);
    } else if (result.contains("FAILURE:")) {
      testFailed(className, testMethodName, 0, "Failed", result);
    } else if (result.contains("SKIP:")) {
      testIgnored(className, testMethodName);
      testStdOut(className, testMethodName, result);
    } else {
      testFailed(className, testMethodName, 0, "Failed for unknown reasons", result);
    }
  }