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

The following examples show how to use com.intellij.execution.process.ProcessHandler#startNotify() . 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: 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 2
Source File: XDebuggerManagerImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
@Override
public XDebugSession startSessionAndShowTab(@Nonnull String sessionName,
                                            Image icon,
                                            @Nullable RunContentDescriptor contentToReuse,
                                            boolean showToolWindowOnSuspendOnly,
                                            @Nonnull XDebugProcessStarter starter) throws ExecutionException {
  XDebugSessionImpl session = startSession(contentToReuse, starter, new XDebugSessionImpl(null, this, sessionName, icon, showToolWindowOnSuspendOnly, contentToReuse));

  if (!showToolWindowOnSuspendOnly) {
    session.showSessionTab();
  }
  ProcessHandler handler = session.getDebugProcess().getProcessHandler();
  handler.startNotify();
  return session;
}
 
Example 3
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 4
Source File: RNConsoleImpl.java    From react-native-console with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private void processConsole(ProcessHandler processHandler) {
    attachToProcess(processHandler);
    processHandler.startNotify();// If not call this, the command content will not be shown
}
 
Example 5
Source File: RNTerminalExecutionConsoleImpl.java    From react-native-console with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private void processConsole(ProcessHandler processHandler) {
    attachToProcess(processHandler);
    processHandler.startNotify();// If not call this, the command content will not be shown
}
 
Example 6
Source File: RNUtil.java    From react-native-console with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private static void processConsole(Project project, ProcessHandler processHandler) {
        ConsoleView consoleView = TextConsoleBuilderFactory.getInstance().createBuilder(project).getConsole();
        consoleView.clear();
        consoleView.attachToProcess(processHandler);
        processHandler.startNotify();

        ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(project);
        ToolWindow toolWindow;
        toolWindow = toolWindowManager.getToolWindow(TOOL_ID);

        // if already exist tool window then show it
        if (toolWindow != null) {
            toolWindow.show(null);// TODO add more tabs here?
            return;
        }

        toolWindow = toolWindowManager.registerToolWindow(TOOL_ID, true, ToolWindowAnchor.BOTTOM);
        toolWindow.setTitle("Android....");
        toolWindow.setStripeTitle("Android Console");
        toolWindow.setShowStripeButton(true);
        toolWindow.setIcon(PluginIcons.ICON_TOOL_WINDOW);

        JPanel panel = new JPanel((LayoutManager) new BorderLayout());
        panel.add((Component) consoleView.getComponent(), "Center");

        // Create toolbars
        DefaultActionGroup toolbarActions = new DefaultActionGroup();
        AnAction[]
                consoleActions = consoleView.createConsoleActions();// 必须在 consoleView.getComponent() 调用后组件真正初始化之后调用
        toolbarActions.addAll((AnAction[]) Arrays.copyOf(consoleActions, consoleActions.length));
        toolbarActions.add((AnAction) new StopProcessAction("Stop process", "Stop process", processHandler));
//        toolbarActions.add((AnAction) new CloseAction(defaultExecutor, runDescriptor, project));


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

        ContentImpl consoleContent = new ContentImpl(panel, "Build", false);
        consoleContent.setManager(toolWindow.getContentManager());

        toolbarActions.add(new CloseTabAction(consoleContent));

//        addAdditionalConsoleEditorActions(consoleView, consoleContent);
//        consoleComponent.setActions();
        toolWindow.getContentManager().addContent(consoleContent);
        toolWindow.getContentManager().addContent(new ContentImpl(new JButton("Test"), "Build2", false));
        toolWindow.show(null);
    }
 
Example 7
Source File: ExternalExec.java    From idea-gitignore with MIT License 4 votes vote down vote up
/**
 * Runs {@link IgnoreLanguage} executable with the given command and current working directory.
 *
 * @param language  current language
 * @param command   to call
 * @param directory current working directory
 * @param parser    {@link ExecutionOutputParser} implementation
 * @param <T>       return type
 * @return result of the call
 */
@Nullable
private static <T> ArrayList<T> run(@NotNull IgnoreLanguage language,
                                    @NotNull String command,
                                    @Nullable VirtualFile directory,
                                    @Nullable final ExecutionOutputParser<T> parser) {
    final String bin = bin(language);
    if (bin == null) {
        return null;
    }

    try {
        final String cmd = bin + " " + command;
        final File workingDirectory = directory != null ? new File(directory.getPath()) : null;
        final Process process = Runtime.getRuntime().exec(cmd, null, workingDirectory);

        ProcessHandler handler = new BaseOSProcessHandler(process, StringUtil.join(cmd, " "), null) {
            @NotNull
            @Override
            public Future<?> executeTask(@NotNull Runnable task) {
                return SharedThreadPool.getInstance().submit(task);
            }

            @Override
            public void notifyTextAvailable(@NotNull String text, @NotNull Key outputType) {
                if (parser != null) {
                    parser.onTextAvailable(text, outputType);
                }
            }
        };

        handler.startNotify();
        if (!handler.waitFor(DEFAULT_TIMEOUT)) {
            return null;
        }
        if (parser != null) {
            parser.notifyFinished(process.exitValue());
            if (parser.isErrorsReported()) {
                return null;
            }
            return parser.getOutput();
        }
    } catch (IOException ignored) {
    }

    return null;
}