private void startProcess(Target target, Parameters configuration, Pair<Target, Parameters> key) { ProgramRunner runner = new DefaultProgramRunner() { @NotNull public String getRunnerId() { return "MyRunner"; } public boolean canRun(@NotNull String executorId, @NotNull 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, ExceptionUtil.getUserStackTrace(e, LOG), processHandler); return; } processHandler.addProcessListener(getProcessListener(key)); processHandler.startNotify(); }
private void initConsoleUI(Process process) { // Init console view myConsoleView = createConsoleView(); myConsoleView.setBorder(new SideBorder(UIUtil.getBorderColor(), SideBorder.LEFT)); myProcessHandler = createProcessHandler(process, myProvider.getCommandLineString()); myConsoleExecuteActionHandler = createConsoleExecuteActionHandler(); ProcessTerminatedListener.attach(myProcessHandler); myProcessHandler.addProcessListener( new ProcessAdapter() { @Override public void processTerminated(ProcessEvent event) { finishConsole(); } }); // Attach to process myConsoleView.attachToProcess(myProcessHandler); // Runner creating final Executor defaultExecutor = ExecutorRegistry.getInstance().getExecutorById(DefaultRunExecutor.EXECUTOR_ID); final DefaultActionGroup toolbarActions = new DefaultActionGroup(); final ActionToolbar actionToolbar = ActionManager.getInstance() .createActionToolbar(ActionPlaces.UNKNOWN, toolbarActions, false); // Runner creating final JPanel panel = new JPanel(new BorderLayout()); panel.add(actionToolbar.getComponent(), BorderLayout.WEST); panel.add(myConsoleView.getComponent(), BorderLayout.CENTER); actionToolbar.setTargetComponent(panel); final RunContentDescriptor contentDescriptor = new RunContentDescriptor( myConsoleView, myProcessHandler, panel, constructConsoleTitle(myConsoleTitle)); // tool bar actions final List<AnAction> actions = fillToolBarActions(toolbarActions, defaultExecutor, contentDescriptor); registerActionShortcuts(actions, getLanguageConsole().getConsoleEditor().getComponent()); registerActionShortcuts(actions, panel); panel.updateUI(); showConsole(defaultExecutor, contentDescriptor); // Run myProcessHandler.startNotify(); }