Java Code Examples for com.intellij.execution.process.ProcessHandler#addProcessListener()

The following examples show how to use com.intellij.execution.process.ProcessHandler#addProcessListener() . 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: DuneCompiler.java    From reasonml-idea-plugin with MIT License 6 votes vote down vote up
@Override
public void run(@NotNull VirtualFile file, @NotNull CliType cliType, @Nullable Compiler.ProcessTerminated onProcessTerminated) {
    if (!(cliType instanceof CliType.Dune)) {
        LOG.error("Invalid cliType for dune compiler. cliType = " + cliType);
        return;
    }
    CompilerProcess process = DuneProcess.getInstance(project);
    if (process.start()) {
        ProcessHandler duneHandler = process.recreate(cliType, onProcessTerminated);
        if (duneHandler != null) {
            ConsoleView console = getConsoleView();
            if (console != null) {
                console.attachToProcess(duneHandler);
                duneHandler.addProcessListener(new ProcessFinishedListener());
            }
            process.startNotify();
            ServiceManager.getService(project, InsightManager.class).downloadRincewindIfNeeded(file);
        } else {
            process.terminate();
        }
    }
}
 
Example 2
Source File: SkylarkDebugProcess.java    From intellij with Apache License 2.0 6 votes vote down vote up
@Override
public void sessionInitialized() {
  waitForConnection();
  ProcessHandler processHandler = getSession().getRunContentDescriptor().getProcessHandler();
  processHandler.addProcessListener(
      new ProcessAdapter() {
        @Override
        public void processWillTerminate(ProcessEvent event, boolean willBeDestroyed) {
          if (transport.isConnected()) {
            // unset breakpoints and resume all threads prior to stopping debugger, otherwise the
            // interrupt signal won't be properly handled
            clearBreakpoints();
            startStepping(null, Stepping.NONE);
          }
        }
      });
}
 
Example 3
Source File: ReactiveTfvcClientHost.java    From azure-devops-intellij with MIT License 6 votes vote down vote up
public static ReactiveTfvcClientHost create(Project project, Path clientPath) throws ExecutionException {
    SingleThreadScheduler scheduler = new SingleThreadScheduler(defineNestedLifetime(project), "ReactiveTfClient Scheduler");
    ReactiveClientConnection connection = new ReactiveClientConnection(scheduler);
    try {
        Path logDirectory = Paths.get(PathManager.getLogPath(), "ReactiveTfsClient");
        Path clientHomeDir = clientPath.getParent().getParent();
        GeneralCommandLine commandLine = ProcessHelper.patchPathEnvironmentVariable(
                getClientCommandLine(clientPath, connection.getPort(), logDirectory, clientHomeDir));
        ProcessHandler processHandler = new OSProcessHandler(commandLine);
        connection.getLifetime().onTerminationIfAlive(processHandler::destroyProcess);

        processHandler.addProcessListener(createProcessListener(connection));
        processHandler.startNotify();

        return new ReactiveTfvcClientHost(connection);
    } catch (Throwable t) {
        connection.terminate();
        throw t;
    }
}
 
Example 4
Source File: EsyCompiler.java    From reasonml-idea-plugin with MIT License 5 votes vote down vote up
@Override
public void run(@NotNull VirtualFile file, @NotNull CliType cliType, @Nullable ProcessTerminated onProcessTerminated) {
    if (!(cliType instanceof CliType.Esy)) {
        LOG.error("Invalid cliType for esy compiler. cliType = " + cliType);
        return;
    }
    EsyProcess process = EsyProcess.getInstance(m_project);
    ProcessHandler processHandler = process.recreate(cliType, onProcessTerminated);
    if (processHandler != null) {
        processHandler.addProcessListener(new ProcessFinishedListener());
        ConsoleView console = getConsoleView();
        console.attachToProcess(processHandler);
        process.startNotify();
    }
}
 
Example 5
Source File: PromptConsoleView.java    From reasonml-idea-plugin with MIT License 5 votes vote down vote up
@Override
public void attachToProcess(@NotNull ProcessHandler processHandler) {
    super.attachToProcess(processHandler);

    processHandler.addProcessListener(new ProcessAdapter() {
        @Override
        public void processTerminated(@NotNull ProcessEvent event) {
            ApplicationManager.getApplication().invokeLater(() -> ApplicationManager.getApplication().runWriteAction(m_promptConsole::disablePrompt));
        }
    });
}
 
Example 6
Source File: FlutterLog.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void listenToProcess(@NotNull ProcessHandler processHandler, @NotNull Disposable parent) {
  processHandler.addProcessListener(new ProcessAdapter() {
    @Override
    public void onTextAvailable(@NotNull ProcessEvent event, @NotNull Key outputType) {
      onEntry(logEntryParser.parseDaemonEvent(event, outputType));
    }
  }, parent);
}
 
Example 7
Source File: FlutterLog.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void listenToProcess(@NotNull ProcessHandler processHandler, @NotNull Disposable parent) {
  processHandler.addProcessListener(new ProcessAdapter() {
    @Override
    public void onTextAvailable(@NotNull ProcessEvent event, @NotNull Key outputType) {
      onEntry(logEntryParser.parseDaemonEvent(event, outputType));
    }
  }, parent);
}
 
Example 8
Source File: CoverageDataManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void attachToProcess(@Nonnull final ProcessHandler handler, @Nonnull final RunConfigurationBase configuration, final RunnerSettings runnerSettings) {
  handler.addProcessListener(new ProcessAdapter() {
    @Override
    public void processTerminated(final ProcessEvent event) {
      processGatheredCoverage(configuration, runnerSettings);
    }
  });
}
 
Example 9
Source File: RemoteProcessSupport.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void startProcess(Target target, Parameters configuration, Pair<Target, Parameters> key) {
  ProgramRunner runner = new DefaultProgramRunner() {
    @Override
    @Nonnull
    public String getRunnerId() {
      return "MyRunner";
    }

    @Override
    public boolean canRun(@Nonnull String executorId, @Nonnull RunProfile profile) {
      return true;
    }
  };
  Executor executor = DefaultRunExecutor.getRunExecutorInstance();
  ProcessHandler processHandler = null;
  try {
    RunProfileState state = getRunProfileState(target, configuration, executor);
    ExecutionResult result = state.execute(executor, runner);
    //noinspection ConstantConditions
    processHandler = result.getProcessHandler();
  }
  catch (Exception e) {
    dropProcessInfo(key, e instanceof ExecutionException? e.getMessage() : ExceptionUtil.getUserStackTrace(e, LOG), processHandler);
    return;
  }
  processHandler.addProcessListener(getProcessListener(key));
  processHandler.startNotify();
}
 
Example 10
Source File: LogConsoleBase.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void attachStopLogConsoleTrackingListener(final ProcessHandler process) {
  if (process != null) {
    final ProcessAdapter stopListener = new ProcessAdapter() {
      @Override
      public void processTerminated(final ProcessEvent event) {
        process.removeProcessListener(this);
        stopRunning(true);
      }
    };
    process.addProcessListener(stopListener);
  }
}
 
Example 11
Source File: FlutterApp.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Creates a process that will launch the flutter app.
 * <p>
 * (Assumes we are launching it in --machine mode.)
 */
@NotNull
public static FlutterApp start(@NotNull ExecutionEnvironment env,
                               @NotNull Project project,
                               @Nullable Module module,
                               @NotNull RunMode mode,
                               @NotNull FlutterDevice device,
                               @NotNull GeneralCommandLine command,
                               @Nullable String analyticsStart,
                               @Nullable String analyticsStop)
  throws ExecutionException {
  LOG.info(analyticsStart + " " + project.getName() + " (" + mode.mode() + ")");
  LOG.info(command.toString());

  final ProcessHandler process = new MostlySilentOsProcessHandler(command);
  Disposer.register(project, process::destroyProcess);

  // Send analytics for the start and stop events.
  if (analyticsStart != null) {
    FlutterInitializer.sendAnalyticsAction(analyticsStart);
  }

  final DaemonApi api = new DaemonApi(process);
  final FlutterApp app = new FlutterApp(project, module, mode, device, process, env, api, command);

  process.addProcessListener(new ProcessAdapter() {
    @Override
    public void processTerminated(@NotNull ProcessEvent event) {
      LOG.info(analyticsStop + " " + project.getName() + " (" + mode.mode() + ")");
      if (analyticsStop != null) {
        FlutterInitializer.sendAnalyticsAction(analyticsStop);
      }

      // Send analytics about whether this session used the reload workflow, the restart workflow, or neither.
      final String workflowType = app.reloadCount > 0 ? "reload" : (app.restartCount > 0 ? "restart" : "none");
      FlutterInitializer.getAnalytics().sendEvent("workflow", workflowType);

      // Send the ratio of reloads to restarts.
      int reloadfraction = 0;
      if ((app.reloadCount + app.restartCount) > 0) {
        final double fraction = (app.reloadCount * 100.0) / (app.reloadCount + app.restartCount);
        reloadfraction = (int)Math.round(fraction);
      }
      FlutterInitializer.getAnalytics().sendEventMetric("workflow", "reloadFraction", reloadfraction);

      Disposer.dispose(app);
    }
  });

  api.listen(process, new FlutterAppDaemonEventListener(app, project));

  return app;
}
 
Example 12
Source File: FlutterApp.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Creates a process that will launch the flutter app.
 * <p>
 * (Assumes we are launching it in --machine mode.)
 */
@NotNull
public static FlutterApp start(@NotNull ExecutionEnvironment env,
                               @NotNull Project project,
                               @Nullable Module module,
                               @NotNull RunMode mode,
                               @NotNull FlutterDevice device,
                               @NotNull GeneralCommandLine command,
                               @Nullable String analyticsStart,
                               @Nullable String analyticsStop)
  throws ExecutionException {
  LOG.info(analyticsStart + " " + project.getName() + " (" + mode.mode() + ")");
  LOG.info(command.toString());

  final ProcessHandler process = new MostlySilentOsProcessHandler(command);
  Disposer.register(project, process::destroyProcess);

  // Send analytics for the start and stop events.
  if (analyticsStart != null) {
    FlutterInitializer.sendAnalyticsAction(analyticsStart);
  }

  final DaemonApi api = new DaemonApi(process);
  final FlutterApp app = new FlutterApp(project, module, mode, device, process, env, api, command);

  process.addProcessListener(new ProcessAdapter() {
    @Override
    public void processTerminated(@NotNull ProcessEvent event) {
      LOG.info(analyticsStop + " " + project.getName() + " (" + mode.mode() + ")");
      if (analyticsStop != null) {
        FlutterInitializer.sendAnalyticsAction(analyticsStop);
      }

      // Send analytics about whether this session used the reload workflow, the restart workflow, or neither.
      final String workflowType = app.reloadCount > 0 ? "reload" : (app.restartCount > 0 ? "restart" : "none");
      FlutterInitializer.getAnalytics().sendEvent("workflow", workflowType);

      // Send the ratio of reloads to restarts.
      int reloadfraction = 0;
      if ((app.reloadCount + app.restartCount) > 0) {
        final double fraction = (app.reloadCount * 100.0) / (app.reloadCount + app.restartCount);
        reloadfraction = (int)Math.round(fraction);
      }
      FlutterInitializer.getAnalytics().sendEventMetric("workflow", "reloadFraction", reloadfraction);

      Disposer.dispose(app);
    }
  });

  api.listen(process, new FlutterAppDaemonEventListener(app, project));

  return app;
}