Search in sources :

Example 21 with Executor

use of com.intellij.execution.Executor in project intellij-community by JetBrains.

the class RemoteProcessSupport method startProcess.

private void startProcess(Target target, Parameters configuration, @NotNull Pair<Target, Parameters> key) {
    ProgramRunner runner = new DefaultProgramRunner() {

        @Override
        @NotNull
        public String getRunnerId() {
            return "MyRunner";
        }

        @Override
        public boolean canRun(@NotNull String executorId, @NotNull RunProfile profile) {
            return true;
        }
    };
    Executor executor = DefaultRunExecutor.getRunExecutorInstance();
    ProcessHandler processHandler;
    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), null);
        return;
    }
    processHandler.addProcessListener(getProcessListener(key));
    processHandler.startNotify();
}
Also used : DefaultRunExecutor(com.intellij.execution.executors.DefaultRunExecutor) Executor(com.intellij.execution.Executor) RunProfileState(com.intellij.execution.configurations.RunProfileState) DefaultProgramRunner(com.intellij.execution.runners.DefaultProgramRunner) ProcessHandler(com.intellij.execution.process.ProcessHandler) ExecutionResult(com.intellij.execution.ExecutionResult) RunProfile(com.intellij.execution.configurations.RunProfile) DefaultProgramRunner(com.intellij.execution.runners.DefaultProgramRunner) ProgramRunner(com.intellij.execution.runners.ProgramRunner) ExecutionException(com.intellij.execution.ExecutionException) NotNull(org.jetbrains.annotations.NotNull) ExecutionException(com.intellij.execution.ExecutionException)

Example 22 with Executor

use of com.intellij.execution.Executor in project intellij-community by JetBrains.

the class ShowRunningListAction method actionPerformed.

@Override
public void actionPerformed(final AnActionEvent e) {
    final Project project = e.getProject();
    if (project == null || project.isDisposed())
        return;
    final Ref<Pair<? extends JComponent, String>> stateRef = new Ref<>();
    final Ref<Balloon> balloonRef = new Ref<>();
    final Timer timer = UIUtil.createNamedTimer("runningLists", 250);
    ActionListener actionListener = new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            Balloon balloon = balloonRef.get();
            if (project.isDisposed() || (balloon != null && balloon.isDisposed())) {
                timer.stop();
                return;
            }
            ArrayList<Project> projects = new ArrayList<>(Arrays.asList(ProjectManager.getInstance().getOpenProjects()));
            //List should begin with current project
            projects.remove(project);
            projects.add(0, project);
            Pair<? extends JComponent, String> state = getCurrentState(projects);
            Pair<? extends JComponent, String> prevState = stateRef.get();
            if (prevState != null && prevState.getSecond().equals(state.getSecond()))
                return;
            stateRef.set(state);
            BalloonBuilder builder = JBPopupFactory.getInstance().createBalloonBuilder(state.getFirst());
            builder.setShowCallout(false).setTitle(ExecutionBundle.message("show.running.list.balloon.title")).setBlockClicksThroughBalloon(true).setDialogMode(true).setHideOnKeyOutside(false);
            IdeFrame frame = IdeFrame.KEY.getData(e.getDataContext());
            if (frame == null) {
                frame = WindowManagerEx.getInstanceEx().getFrame(project);
            }
            if (balloon != null) {
                balloon.hide();
            }
            builder.setClickHandler(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    if (e.getSource() instanceof MouseEvent) {
                        MouseEvent mouseEvent = (MouseEvent) e.getSource();
                        Component component = mouseEvent.getComponent();
                        component = SwingUtilities.getDeepestComponentAt(component, mouseEvent.getX(), mouseEvent.getY());
                        Object value = ((JComponent) component).getClientProperty(KEY);
                        if (value instanceof Trinity) {
                            Project aProject = (Project) ((Trinity) value).first;
                            JFrame aFrame = WindowManager.getInstance().getFrame(aProject);
                            if (aFrame != null && !aFrame.isActive()) {
                                IdeFocusManager.getGlobalInstance().doWhenFocusSettlesDown(() -> {
                                    IdeFocusManager.getGlobalInstance().requestFocus(aFrame, true);
                                });
                            }
                            ExecutionManagerImpl.getInstance(aProject).getContentManager().toFrontRunContent((Executor) ((Trinity) value).second, (RunContentDescriptor) ((Trinity) value).third);
                        }
                    }
                }
            }, false);
            balloon = builder.createBalloon();
            balloonRef.set(balloon);
            JComponent component = frame.getComponent();
            RelativePoint point = new RelativePoint(component, new Point(component.getWidth(), 0));
            balloon.show(point, Balloon.Position.below);
        }
    };
    timer.addActionListener(actionListener);
    timer.setInitialDelay(0);
    timer.start();
}
Also used : Trinity(com.intellij.openapi.util.Trinity) ActionEvent(java.awt.event.ActionEvent) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) ArrayList(java.util.ArrayList) Balloon(com.intellij.openapi.ui.popup.Balloon) RelativePoint(com.intellij.ui.awt.RelativePoint) IdeFrame(com.intellij.openapi.wm.IdeFrame) BalloonBuilder(com.intellij.openapi.ui.popup.BalloonBuilder) Executor(com.intellij.execution.Executor) Pair(com.intellij.openapi.util.Pair) MouseEvent(java.awt.event.MouseEvent) RunContentDescriptor(com.intellij.execution.ui.RunContentDescriptor) RelativePoint(com.intellij.ui.awt.RelativePoint) Project(com.intellij.openapi.project.Project) Ref(com.intellij.openapi.util.Ref) ActionListener(java.awt.event.ActionListener)

Example 23 with Executor

use of com.intellij.execution.Executor in project intellij-community by JetBrains.

the class ShowRunningListAction method getCurrentState.

private static Pair<? extends JComponent, String> getCurrentState(@NotNull List<Project> projects) {
    NonOpaquePanel panel = new NonOpaquePanel(new GridLayout(0, 1, 10, 10));
    StringBuilder state = new StringBuilder();
    for (int i = 0; i < projects.size(); i++) {
        Project project = projects.get(i);
        final ExecutionManagerImpl executionManager = ExecutionManagerImpl.getInstance(project);
        List<RunContentDescriptor> runningDescriptors = executionManager.getRunningDescriptors(Condition.TRUE);
        if (!runningDescriptors.isEmpty() && projects.size() > 1) {
            state.append(project.getName());
            panel.add(new JLabel("<html><body><b>Project '" + project.getName() + "'</b></body></html>"));
        }
        for (RunContentDescriptor descriptor : runningDescriptors) {
            Set<Executor> executors = executionManager.getExecutors(descriptor);
            for (Executor executor : executors) {
                state.append(System.identityHashCode(descriptor.getAttachedContent())).append("@").append(System.identityHashCode(executor.getIcon())).append(";");
                ProcessHandler processHandler = descriptor.getProcessHandler();
                Icon icon = (processHandler instanceof KillableProcess && processHandler.isProcessTerminating()) ? AllIcons.Debugger.KillProcess : executor.getIcon();
                JLabel label = new JLabel("<html><body><a href=\"\">" + descriptor.getDisplayName() + "</a></body></html>", icon, SwingConstants.LEADING);
                label.setIconTextGap(JBUI.scale(2));
                label.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
                label.putClientProperty(KEY, Trinity.create(project, executor, descriptor));
                panel.add(label);
            }
        }
    }
    if (panel.getComponentCount() == 0) {
        panel.setBorder(JBUI.Borders.empty(10));
        panel.add(new JLabel(ExecutionBundle.message("show.running.list.balloon.nothing"), SwingConstants.CENTER));
    } else {
        panel.setBorder(JBUI.Borders.empty(10, 10, 0, 10));
        JLabel label = new JLabel(ExecutionBundle.message("show.running.list.balloon.hint"));
        label.setFont(JBUI.Fonts.miniFont());
        panel.add(label);
    }
    return Pair.create(panel, state.toString());
}
Also used : RunContentDescriptor(com.intellij.execution.ui.RunContentDescriptor) RelativePoint(com.intellij.ui.awt.RelativePoint) KillableProcess(com.intellij.execution.KillableProcess) NonOpaquePanel(com.intellij.ui.components.panels.NonOpaquePanel) Project(com.intellij.openapi.project.Project) Executor(com.intellij.execution.Executor) ProcessHandler(com.intellij.execution.process.ProcessHandler) LayeredIcon(com.intellij.ui.LayeredIcon) ExecutionManagerImpl(com.intellij.execution.impl.ExecutionManagerImpl)

Example 24 with Executor

use of com.intellij.execution.Executor in project intellij-community by JetBrains.

the class AbstractRerunFailedTestsAction method execute.

void execute(@NotNull AnActionEvent e, @NotNull ExecutionEnvironment environment) {
    MyRunProfile profile = getRunProfile(environment);
    if (profile == null) {
        return;
    }
    final ExecutionEnvironmentBuilder environmentBuilder = new ExecutionEnvironmentBuilder(environment).runProfile(profile);
    final InputEvent event = e.getInputEvent();
    if (!(event instanceof MouseEvent) || !event.isShiftDown()) {
        performAction(environmentBuilder);
        return;
    }
    final LinkedHashMap<Executor, ProgramRunner> availableRunners = new LinkedHashMap<>();
    for (Executor ex : new Executor[] { DefaultRunExecutor.getRunExecutorInstance(), DefaultDebugExecutor.getDebugExecutorInstance() }) {
        final ProgramRunner runner = RunnerRegistry.getInstance().getRunner(ex.getId(), profile);
        if (runner != null) {
            availableRunners.put(ex, runner);
        }
    }
    if (availableRunners.isEmpty()) {
        LOG.error(environment.getExecutor().getActionName() + " is not available now");
    } else if (availableRunners.size() == 1) {
        //noinspection ConstantConditions
        performAction(environmentBuilder.runner(availableRunners.get(environment.getExecutor())));
    } else {
        final JBList list = new JBList(availableRunners.keySet());
        list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        list.setSelectedValue(environment.getExecutor(), true);
        list.setCellRenderer(new DefaultListCellRenderer() {

            @NotNull
            @Override
            public Component getListCellRendererComponent(@NotNull JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
                final Component component = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
                if (value instanceof Executor) {
                    setText(UIUtil.removeMnemonic(((Executor) value).getStartActionText()));
                    setIcon(((Executor) value).getIcon());
                }
                return component;
            }
        });
        //noinspection ConstantConditions
        JBPopupFactory.getInstance().createListPopupBuilder(list).setTitle("Restart Failed Tests").setMovable(false).setResizable(false).setRequestFocus(true).setItemChoosenCallback(() -> {
            final Object value = list.getSelectedValue();
            if (value instanceof Executor) {
                //noinspection ConstantConditions
                performAction(environmentBuilder.runner(availableRunners.get(value)).executor((Executor) value));
            }
        }).createPopup().showUnderneathOf(event.getComponent());
    }
}
Also used : MouseEvent(java.awt.event.MouseEvent) NotNull(org.jetbrains.annotations.NotNull) LinkedHashMap(java.util.LinkedHashMap) DefaultRunExecutor(com.intellij.execution.executors.DefaultRunExecutor) DefaultDebugExecutor(com.intellij.execution.executors.DefaultDebugExecutor) Executor(com.intellij.execution.Executor) JBList(com.intellij.ui.components.JBList) InputEvent(java.awt.event.InputEvent) ExecutionEnvironmentBuilder(com.intellij.execution.runners.ExecutionEnvironmentBuilder) ProgramRunner(com.intellij.execution.runners.ProgramRunner)

Example 25 with Executor

use of com.intellij.execution.Executor in project intellij-community by JetBrains.

the class RerunFailedTestsAction method getRunProfile.

@Override
protected MyRunProfile getRunProfile(@NotNull ExecutionEnvironment environment) {
    //noinspection ConstantConditions
    final JUnitConfiguration configuration = (JUnitConfiguration) myConsoleProperties.getConfiguration();
    final TestMethods testMethods = new TestMethods(configuration, environment, getFailedTests(configuration.getProject()));
    return new MyRunProfile(configuration) {

        @Override
        @NotNull
        public Module[] getModules() {
            return testMethods.getModulesToCompile();
        }

        @Override
        public RunProfileState getState(@NotNull Executor executor, @NotNull ExecutionEnvironment env) {
            testMethods.clear();
            return testMethods;
        }
    };
}
Also used : ExecutionEnvironment(com.intellij.execution.runners.ExecutionEnvironment) Executor(com.intellij.execution.Executor) JUnitConfiguration(com.intellij.execution.junit.JUnitConfiguration) TestMethods(com.intellij.execution.junit.TestMethods) Module(com.intellij.openapi.module.Module) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

Executor (com.intellij.execution.Executor)34 DefaultRunExecutor (com.intellij.execution.executors.DefaultRunExecutor)15 NotNull (org.jetbrains.annotations.NotNull)14 DefaultDebugExecutor (com.intellij.execution.executors.DefaultDebugExecutor)9 ProcessHandler (com.intellij.execution.process.ProcessHandler)9 RunContentDescriptor (com.intellij.execution.ui.RunContentDescriptor)9 Project (com.intellij.openapi.project.Project)9 ProgramRunner (com.intellij.execution.runners.ProgramRunner)8 ExecutionEnvironment (com.intellij.execution.runners.ExecutionEnvironment)7 RunnerAndConfigurationSettings (com.intellij.execution.RunnerAndConfigurationSettings)4 ConsoleView (com.intellij.execution.ui.ConsoleView)4 CloseAction (com.intellij.execution.ui.actions.CloseAction)4 Module (com.intellij.openapi.module.Module)4 File (java.io.File)4 DefaultExecutionResult (com.intellij.execution.DefaultExecutionResult)3 ExecutionException (com.intellij.execution.ExecutionException)3 GeneralCommandLine (com.intellij.execution.configurations.GeneralCommandLine)3 OSProcessHandler (com.intellij.execution.process.OSProcessHandler)3 ExecutionEnvironmentBuilder (com.intellij.execution.runners.ExecutionEnvironmentBuilder)3 AbstractTestProxy (com.intellij.execution.testframework.AbstractTestProxy)3