com.intellij.execution.process.ProcessHandler Java Examples

The following examples show how to use com.intellij.execution.process.ProcessHandler. 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: FlutterAppManager.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Return the active (front most in the UI) Flutter app.
 * <p>
 * This could return null even if there is a running Flutter app, if the front-most
 * running process (focused in the Run or Debug view) is not a Flutter app instance.
 */
@Nullable
public FlutterApp getActiveApp() {
  RunContentManager mgr = getRunContentManager();
  if (mgr == null) {
    return null;
  }
  final RunContentDescriptor descriptor = mgr.getSelectedContent();
  if (descriptor == null) {
    return null;
  }

  final ProcessHandler process = descriptor.getProcessHandler();
  if (process == null) {
    return null;
  }

  final FlutterApp app = FlutterApp.fromProcess(process);
  return app != null && app.isConnected() ? app : null;
}
 
Example #2
Source File: SMTestRunnerConnectionUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
/**
 * @deprecated use {@link #initConsoleView(SMTRunnerConsoleView, String)} (to be removed in IDEA 16)
 */
@SuppressWarnings({"unused", "deprecation"})
public static void initConsoleView(@Nonnull final SMTRunnerConsoleView consoleView,
                                   @Nonnull final String testFrameworkName,
                                   @javax.annotation.Nullable final TestLocationProvider locator,
                                   final boolean idBasedTreeConstruction,
                                   @Nullable final TestProxyFilterProvider filterProvider) {
  consoleView.addAttachToProcessListener(new AttachToProcessListener() {
    @Override
    public void onAttachToProcess(@Nonnull ProcessHandler processHandler) {
      TestConsoleProperties properties = consoleView.getProperties();

      SMTestLocator testLocator = new CompositeTestLocationProvider(locator);

      TestProxyPrinterProvider printerProvider = null;
      if (filterProvider != null) {
        printerProvider = new TestProxyPrinterProvider(consoleView, filterProvider);
      }

      SMTestRunnerResultsForm resultsForm = consoleView.getResultsViewer();
      attachEventsProcessors(properties, resultsForm, resultsForm.getStatisticsPane(), processHandler, testFrameworkName, testLocator, idBasedTreeConstruction, printerProvider);
    }
  });
  consoleView.setHelpId("reference.runToolWindow.testResultsTab");
  consoleView.initUI();
}
 
Example #3
Source File: RemoteProcessSupport.java    From consulo with Apache License 2.0 6 votes vote down vote up
private boolean dropProcessInfo(Pair<Target, Parameters> key, @Nullable String errorMessage, @Nullable ProcessHandler handler) {
  Info info;
  synchronized (myProcMap) {
    info = myProcMap.get(key);
    if (info != null && (handler == null || info.handler == handler)) {
      myProcMap.remove(key);
      myProcMap.notifyAll();
    }
    else {
      // different processHandler
      info = null;
    }
  }
  if (info instanceof PendingInfo) {
    PendingInfo pendingInfo = (PendingInfo)info;
    if (pendingInfo.stderr.length() > 0 || pendingInfo.ref.isNull()) {
      if (errorMessage != null) pendingInfo.stderr.append(errorMessage);
      pendingInfo.ref.set(new RunningInfo(null, -1, pendingInfo.stderr.toString()));
    }
    synchronized (pendingInfo.ref) {
      pendingInfo.ref.notifyAll();
    }
  }
  return info != null;
}
 
Example #4
Source File: FlutterApp.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Nullable
public static FlutterApp firstFromProjectProcess(@NotNull Project project) {
  final List<RunContentDescriptor> runningProcesses =
    ExecutionManager.getInstance(project).getContentManager().getAllDescriptors();
  for (RunContentDescriptor descriptor : runningProcesses) {
    final ProcessHandler process = descriptor.getProcessHandler();
    if (process != null) {
      final FlutterApp app = FlutterApp.fromProcess(process);
      if (app != null) {
        return app;
      }
    }
  }

  return null;
}
 
Example #5
Source File: TestLaunchState.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@NotNull
@Override
protected ProcessHandler startProcess() throws ExecutionException {
  final RunMode mode = RunMode.fromEnv(getEnvironment());
  final FlutterCommandStartResult result = fields.run(getEnvironment().getProject(), mode);
  switch (result.status) {
    case OK:
      assert result.processHandler != null;
      return result.processHandler;
    case EXCEPTION:
      assert result.exception != null;
      throw new ExecutionException(FlutterBundle.message("flutter.command.exception.message" + result.exception.getMessage()));
    default:
      throw new ExecutionException("Unexpected state");
  }
}
 
Example #6
Source File: GaugeCommandLineState.java    From Intellij-Plugin with Apache License 2.0 6 votes vote down vote up
@NotNull
@Override
public ExecutionResult execute(@NotNull Executor executor, @NotNull ProgramRunner runner) throws ExecutionException {
    addProjectClasspath();
    if (GaugeVersion.isGreaterOrEqual(GaugeRunConfiguration.TEST_RUNNER_SUPPORT_VERSION, false)
            && GaugeSettingsService.getSettings().useIntelliJTestRunner()) {
        ProcessHandler handler = startProcess();
        GaugeConsoleProperties properties = new GaugeConsoleProperties(config, "Gauge", executor, handler);
        ConsoleView console = SMTestRunnerConnectionUtil.createAndAttachConsole("Gauge", handler, properties);
        DefaultExecutionResult result = new DefaultExecutionResult(console, handler, createActions(console, handler));
        if (ActionManager.getInstance().getAction("RerunFailedTests") != null) {
            AbstractRerunFailedTestsAction action = properties.createRerunFailedTestsAction(console);
            if (action != null) {
                action.setModelProvider(((SMTRunnerConsoleView) console)::getResultsViewer);
                result.setRestartActions(action);
            }
        }
        return result;
    }
    return super.execute(executor, runner);
}
 
Example #7
Source File: ExecutionManagerImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
@Override
public ProcessHandler[] getRunningProcesses() {
  if (myContentManager == null) return EMPTY_PROCESS_HANDLERS;
  List<ProcessHandler> handlers = null;
  for (RunContentDescriptor descriptor : getContentManager().getAllDescriptors()) {
    ProcessHandler processHandler = descriptor.getProcessHandler();
    if (processHandler != null) {
      if (handlers == null) {
        handlers = new SmartList<>();
      }
      handlers.add(processHandler);
    }
  }
  return handlers == null ? EMPTY_PROCESS_HANDLERS : handlers.toArray(new ProcessHandler[handlers.size()]);
}
 
Example #8
Source File: EOFAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
@RequiredUIAccess
@Override
public void actionPerformed(@Nonnull AnActionEvent e) {
  RunContentDescriptor descriptor = StopAction.getRecentlyStartedContentDescriptor(e.getDataContext());
  ProcessHandler activeProcessHandler = descriptor != null ? descriptor.getProcessHandler() : null;
  if (activeProcessHandler == null || activeProcessHandler.isProcessTerminated()) return;

  try {
    OutputStream input = activeProcessHandler.getProcessInput();
    if (input != null) {
      ConsoleView console = e.getData(LangDataKeys.CONSOLE_VIEW);
      if (console != null) {
        console.print("^D\n", ConsoleViewContentType.SYSTEM_OUTPUT);
      }
      input.close();
    }
  }
  catch (IOException ignored) {
  }
}
 
Example #9
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 #10
Source File: LaunchState.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Returns the currently running app for the given RunConfig, if any.
 */
@Nullable
public static ProcessHandler getRunningAppProcess(RunConfig config) {
  final Project project = config.getProject();
  final List<RunContentDescriptor> runningProcesses =
    ExecutionManager.getInstance(project).getContentManager().getAllDescriptors();

  for (RunContentDescriptor descriptor : runningProcesses) {
    final ProcessHandler process = descriptor.getProcessHandler();
    if (process != null && !process.isProcessTerminated() && process.getUserData(FLUTTER_RUN_CONFIG_KEY) == config) {
      return process;
    }
  }

  return null;
}
 
Example #11
Source File: AbstractAutoTestManager.java    From consulo with Apache License 2.0 6 votes vote down vote up
public void setAutoTestEnabled(@Nonnull RunContentDescriptor descriptor, @Nonnull ExecutionEnvironment environment, boolean enabled) {
  Content content = descriptor.getAttachedContent();
  if (content != null) {
    if (enabled) {
      myEnabledRunProfiles.add(environment.getRunProfile());
      myWatcher.activate();
    }
    else {
      myEnabledRunProfiles.remove(environment.getRunProfile());
      if (!hasEnabledAutoTests()) {
        myWatcher.deactivate();
      }
      ProcessHandler processHandler = descriptor.getProcessHandler();
      if (processHandler != null) {
        clearRestarterListener(processHandler);
      }
    }
  }
}
 
Example #12
Source File: FlutterApp.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@NotNull
public static List<FlutterApp> allFromProjectProcess(@NotNull Project project) {
  final List<FlutterApp> allRunningApps = new ArrayList<>();
  final List<RunContentDescriptor> runningProcesses =
    ExecutionManager.getInstance(project).getContentManager().getAllDescriptors();
  for (RunContentDescriptor descriptor : runningProcesses) {
    final ProcessHandler process = descriptor.getProcessHandler();
    if (process != null) {
      final FlutterApp app = FlutterApp.fromProcess(process);
      if (app != null) {
        allRunningApps.add(app);
      }
    }
  }

  return allRunningApps;
}
 
Example #13
Source File: FreeRunConfiguration.java    From react-native-console with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@NotNull
private ProcessHandler createProcessHandler(GeneralCommandLine commandLine) throws ExecutionException {
    return new KillableProcessHandler(commandLine) {
        @NotNull
        @Override
        protected BaseOutputReader.Options readerOptions() {
            return new BaseOutputReader.Options() {
                @Override
                public BaseDataReader.SleepingPolicy policy() {
                    return BaseDataReader.SleepingPolicy.BLOCKING;
                }

                @Override
                public boolean splitToLines() {
                    return false;
                }

                @Override
                public boolean withSeparators() {
                    return true;
                }
            };
        }
    };
}
 
Example #14
Source File: FreeRunConfiguration.java    From react-native-console with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private ExecutionResult buildExecutionResult() throws ExecutionException {
    GeneralCommandLine commandLine = createDefaultCommandLine();
    ProcessHandler processHandler = createProcessHandler(commandLine);
    ProcessTerminatedListener.attach(processHandler);
    ConsoleView console = new TerminalExecutionConsole(getProject(), processHandler);

    console.print(
        "Welcome to React Native Console, now please click one button on top toolbar to start.\n",
        ConsoleViewContentType.SYSTEM_OUTPUT);
    console.attachToProcess(processHandler);

    console.print(
        "Give a Star or Suggestion:\n",
        ConsoleViewContentType.NORMAL_OUTPUT);


    processHandler.destroyProcess();
    return new DefaultExecutionResult(console, processHandler);
}
 
Example #15
Source File: RunnerUtil.java    From react-native-console with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public static final ConsoleView showHelperProcessRunContent(String header, OSProcessHandler runHandler, Project project, Executor defaultExecutor) {
        ProcessTerminatedListener.attach(runHandler);

        ConsoleViewImpl consoleView = new ConsoleViewImpl(project, true);
        DefaultActionGroup toolbarActions = new DefaultActionGroup();

        JPanel panel = new JPanel((LayoutManager) new BorderLayout());
        panel.add((Component) consoleView.getComponent(), "Center");
        ActionToolbar toolbar = ActionManager.getInstance().createActionToolbar("unknown", (ActionGroup) toolbarActions, false);
        toolbar.setTargetComponent(consoleView.getComponent());
        panel.add((Component) toolbar.getComponent(), "West");

        RunContentDescriptor runDescriptor = new RunContentDescriptor((ExecutionConsole) consoleView,
                (ProcessHandler) runHandler, (JComponent) panel, header, AllIcons.RunConfigurations.Application);
        AnAction[]
                consoleActions = consoleView.createConsoleActions();
        toolbarActions.addAll((AnAction[]) Arrays.copyOf(consoleActions, consoleActions.length));
        toolbarActions.add((AnAction) new StopProcessAction("Stop process", "Stop process", (ProcessHandler) runHandler));
        toolbarActions.add((AnAction) new CloseAction(defaultExecutor, runDescriptor, project));

        consoleView.attachToProcess((ProcessHandler) runHandler);
//        ExecutionManager.getInstance(environment.getProject()).getContentManager().showRunContent(environment.getExecutor(), runDescriptor);
        showConsole(project, defaultExecutor, runDescriptor);
        return (ConsoleView) consoleView;
    }
 
Example #16
Source File: ExecutionManagerImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
public static void stopProcess(@Nullable ProcessHandler processHandler) {
  if (processHandler == null) {
    return;
  }

  processHandler.putUserData(ProcessHandler.TERMINATION_REQUESTED, Boolean.TRUE);

  if (processHandler instanceof KillableProcess && processHandler.isProcessTerminating()) {
    // process termination was requested, but it's still alive
    // in this case 'force quit' will be performed
    ((KillableProcess)processHandler).killProcess();
    return;
  }

  if (!processHandler.isProcessTerminated()) {
    if (processHandler.detachIsDefault()) {
      processHandler.detachProcess();
    }
    else {
      processHandler.destroyProcess();
    }
  }
}
 
Example #17
Source File: FlutterApp.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Nullable
public static FlutterApp firstFromProjectProcess(@NotNull Project project) {
  final List<RunContentDescriptor> runningProcesses =
    ExecutionManager.getInstance(project).getContentManager().getAllDescriptors();
  for (RunContentDescriptor descriptor : runningProcesses) {
    final ProcessHandler process = descriptor.getProcessHandler();
    if (process != null) {
      final FlutterApp app = FlutterApp.fromProcess(process);
      if (app != null) {
        return app;
      }
    }
  }

  return null;
}
 
Example #18
Source File: ServerConnectionManager.java    From aem-ide-tooling-4-intellij with Apache License 2.0 6 votes vote down vote up
public void stopDebugConnection(@NotNull DataContext dataContext) {
    ProcessHandler processHandler = getHandler(dataContext);
    if(processHandler instanceof KillableProcess && processHandler.isProcessTerminating()) {
        ((KillableProcess) processHandler).killProcess();
        return;
    }

    ServerConfiguration serverConfiguration = selectionHandler.getCurrentConfiguration();
    if(serverConfiguration != null) {
        serverConfiguration.setServerStatus(ServerConfiguration.ServerStatus.disconnecting);
    }
    if(processHandler != null) {
        if(processHandler.detachIsDefault()) {
            processHandler.detachProcess();
        } else {
            processHandler.destroyProcess();
        }
    }
    if(serverConfiguration != null) {
        serverConfiguration.setServerStatus(ServerConfiguration.ServerStatus.disconnected);
    }
}
 
Example #19
Source File: BuckCommandHandler.java    From Buck-IntelliJ-Plugin with Apache License 2.0 5 votes vote down vote up
/**
 * Start the buck process.
 */
@Nullable
protected Process startProcess() throws ExecutionException {
  synchronized (mProcessStateLock) {
    final ProcessHandler processHandler = createProcess(mCommandLine);
    mHandler = (OSProcessHandler) processHandler;
    return mHandler.getProcess();
  }
}
 
Example #20
Source File: ReplGenericState.java    From reasonml-idea-plugin with MIT License 5 votes vote down vote up
@Nullable
@Override
public ExecutionResult execute(Executor executor, @NotNull ProgramRunner runner) throws ExecutionException {
    ProcessHandler processHandler = startProcess();
    if (processHandler == null) {
        return null;
    }

    PromptConsoleView consoleView = new PromptConsoleView(m_environment.getProject(), true, true);
    consoleView.attachToProcess(processHandler);

    return new DefaultExecutionResult(consoleView, processHandler);
}
 
Example #21
Source File: RunContentManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
private RunContentDescriptor getDescriptorBy(ProcessHandler handler, Executor runnerInfo) {
  List<Content> contents = new ArrayList<>();
  ContainerUtil.addAll(contents, getContentManagerForRunner(runnerInfo, null).getContents());
  ContainerUtil.addAll(contents, myToolwindowIdToContentManagerMap.get(RunDashboardManager.getInstance(myProject).getToolWindowId()).getContents());
  for (Content content : contents) {
    RunContentDescriptor runContentDescriptor = getRunContentDescriptorByContent(content);
    assert runContentDescriptor != null;
    if (runContentDescriptor.getProcessHandler() == handler) {
      return runContentDescriptor;
    }
  }
  return null;
}
 
Example #22
Source File: ExecutionManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public List<RunContentDescriptor> getRunningDescriptors(@Nonnull Condition<RunnerAndConfigurationSettings> condition) {
  List<RunContentDescriptor> result = new SmartList<>();
  for (Trinity<RunContentDescriptor, RunnerAndConfigurationSettings, Executor> trinity : myRunningConfigurations) {
    if (condition.value(trinity.getSecond())) {
      ProcessHandler processHandler = trinity.getFirst().getProcessHandler();
      if (processHandler != null /*&& !processHandler.isProcessTerminating()*/ && !processHandler.isProcessTerminated()) {
        result.add(trinity.getFirst());
      }
    }
  }
  return result;
}
 
Example #23
Source File: XDebugSessionImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void stop() {
  ProcessHandler processHandler = myDebugProcess == null ? null : myDebugProcess.getProcessHandler();
  if (processHandler == null || processHandler.isProcessTerminated() || processHandler.isProcessTerminating()) return;

  if (processHandler.detachIsDefault()) {
    processHandler.detachProcess();
  }
  else {
    processHandler.destroyProcess();
  }
}
 
Example #24
Source File: LaunchState.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
protected @NotNull
ProcessHandler startProcess() throws ExecutionException {
  // This can happen if there isn't a custom runner defined in plugin.xml.
  // The runner should extend LaunchState.Runner (below).
  throw new ExecutionException("need to implement LaunchState.Runner for " + runConfig.getClass());
}
 
Example #25
Source File: ConsoleViewImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
public ConsoleViewImpl(@Nonnull final Project project, @Nonnull GlobalSearchScope searchScope, boolean viewer, boolean usePredefinedMessageFilter) {
  this(project, searchScope, viewer, new ConsoleState.NotStartedStated() {
    @Nonnull
    @Override
    public ConsoleState attachTo(@Nonnull ConsoleViewImpl console, ProcessHandler processHandler) {
      return new ConsoleViewRunningState(console, processHandler, this, true, true);
    }
  }, usePredefinedMessageFilter);
}
 
Example #26
Source File: OpenFLRunningState.java    From intellij-haxe with Apache License 2.0 5 votes vote down vote up
@NotNull
@Override
protected ProcessHandler startProcess() throws ExecutionException {
  final HaxeModuleSettings settings = HaxeModuleSettings.getInstance(module);
  final Sdk sdk = ModuleRootManager.getInstance(module).getSdk();
  assert sdk != null;

  HaxeCommandLine commandLine = getCommandForOpenFL(sdk, settings);

  return new ColoredProcessHandler(commandLine.createProcess(), commandLine.getCommandLineString());
}
 
Example #27
Source File: StopProcessAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static void stopProcess(@Nonnull ProcessHandler processHandler) {
  if (processHandler instanceof KillableProcess && processHandler.isProcessTerminating()) {
    // process termination was requested, but it's still alive
    // in this case 'force quit' will be performed
    ((KillableProcess)processHandler).killProcess();
    return;
  }

  if (processHandler.detachIsDefault()) {
    processHandler.detachProcess();
  }
  else {
    processHandler.destroyProcess();
  }
}
 
Example #28
Source File: AbstractAutoTestManager.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static void clearRestarterListener(@Nonnull ProcessHandler processHandler) {
  ProcessListener restarterListener = ON_TERMINATION_RESTARTER_KEY.get(processHandler, null);
  if (restarterListener != null) {
    processHandler.removeProcessListener(restarterListener);
    ON_TERMINATION_RESTARTER_KEY.set(processHandler, null);
  }
}
 
Example #29
Source File: GaugeOutputToGeneralTestEventsProcessor.java    From Intellij-Plugin with Apache License 2.0 5 votes vote down vote up
GaugeOutputToGeneralTestEventsProcessor(@NotNull String testFrameworkName, @NotNull TestConsoleProperties consoleProperties, ProcessHandler handler) {
    super(testFrameworkName, consoleProperties);
    this.handler = handler;
    TestsCache cache = new TestsCache();
    processors = Arrays.asList(
            new SuiteEventProcessor(this, cache),
            new SpecEventProcessor(this, cache),
            new ScenarioEventProcessor(this, cache),
            new NotificationEventProcessor(this, cache),
            new StandardOutputEventProcessor(this, cache)
    );
    unexpectedEndProcessor = new UnexpectedEndProcessor(this, cache);
}
 
Example #30
Source File: ServerConnectionManager.java    From aem-ide-tooling-4-intellij with Apache License 2.0 5 votes vote down vote up
@Nullable
private ProcessHandler getHandler(@NotNull DataContext dataContext) {
    final RunContentDescriptor contentDescriptor = LangDataKeys.RUN_CONTENT_DESCRIPTOR.getData(dataContext);
    if(contentDescriptor != null) {
        // toolwindow case
        return contentDescriptor.getProcessHandler();
    } else {
        // main menu toolbar
        final Project project = CommonDataKeys.PROJECT.getData(dataContext);
        final RunContentDescriptor selectedContent =
            project == null ? null : ExecutionManager.getInstance(project).getContentManager().getSelectedContent();
        return selectedContent == null ? null : selectedContent.getProcessHandler();
    }
}