com.intellij.execution.ExecutionManager Java Examples

The following examples show how to use com.intellij.execution.ExecutionManager. 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: AnalyzeStacktraceUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
public static RunContentDescriptor addConsole(Project project, @Nullable ConsoleFactory consoleFactory, final String tabTitle, String text, @Nullable consulo.ui.image.Image icon) {
  final TextConsoleBuilder builder = TextConsoleBuilderFactory.getInstance().createBuilder(project);
  builder.filters(EP_NAME.getExtensions(project));
  final ConsoleView consoleView = builder.getConsole();

  final DefaultActionGroup toolbarActions = new DefaultActionGroup();
  JComponent consoleComponent = consoleFactory != null ? consoleFactory.createConsoleComponent(consoleView, toolbarActions) : new MyConsolePanel(consoleView, toolbarActions);
  final RunContentDescriptor descriptor = new RunContentDescriptor(consoleView, null, consoleComponent, tabTitle, icon) {
    @Override
    public boolean isContentReuseProhibited() {
      return true;
    }
  };

  final Executor executor = DefaultRunExecutor.getRunExecutorInstance();
  for (AnAction action : consoleView.createConsoleActions()) {
    toolbarActions.add(action);
  }
  final ConsoleViewImpl console = (ConsoleViewImpl)consoleView;
  ConsoleViewUtil.enableReplaceActionForConsoleViewEditor(console.getEditor());
  console.getEditor().getSettings().setCaretRowShown(true);
  toolbarActions.add(new AnnotateStackTraceAction(console.getEditor(), console.getHyperlinks()));
  ExecutionManager.getInstance(project).getContentManager().showRunContent(executor, descriptor);
  consoleView.allowHeavyFilters();
  if (consoleFactory == null) {
    printStacktrace(consoleView, text);
  }
  return descriptor;
}
 
Example #2
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 #3
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 #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: 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 #6
Source File: RunIdeConsoleAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
private static RunContentDescriptor createConsoleView(@Nonnull Project project, @Nonnull PsiFile psiFile) {
  ConsoleView consoleView = TextConsoleBuilderFactory.getInstance().createBuilder(project).getConsole();

  DefaultActionGroup toolbarActions = new DefaultActionGroup();
  JComponent panel = new JPanel(new BorderLayout());
  panel.add(consoleView.getComponent(), BorderLayout.CENTER);
  ActionToolbar toolbar = ActionManager.getInstance().createActionToolbar(ActionPlaces.UNKNOWN, toolbarActions, false);
  toolbar.setTargetComponent(consoleView.getComponent());
  panel.add(toolbar.getComponent(), BorderLayout.WEST);

  final RunContentDescriptor descriptor = new RunContentDescriptor(consoleView, null, panel, psiFile.getName()) {
    @Override
    public boolean isContentReuseProhibited() {
      return true;
    }
  };
  Executor executor = DefaultRunExecutor.getRunExecutorInstance();
  toolbarActions.addAll(consoleView.createConsoleActions());
  toolbarActions.add(new CloseAction(executor, descriptor, project));
  ExecutionManager.getInstance(project).getContentManager().showRunContent(executor, descriptor);

  return descriptor;
}
 
Example #7
Source File: JavaStatusChecker.java    From embeddedlinux-jvmdebugger-intellij with Apache License 2.0 6 votes vote down vote up
/**
 * Stops the applications via the descriptor of configuration.  This gets called when the application finishes on the client side without maniually closing it.
 *
 * @param javaExitCode
 */
public void stopApplication(@NotNull int javaExitCode) {
    final RunManagerImpl runManager = (RunManagerImpl) RunManager.getInstance(project);
    final Collection<RunnerAndConfigurationSettings> allConfigurations = runManager.getSortedConfigurations();
    List<RunContentDescriptor> allDescriptors = ExecutionManager.getInstance(project).getContentManager().getAllDescriptors();
    boolean exitMsgDisplay = false;
    for (RunnerAndConfigurationSettings runConfiguration : allConfigurations) {
        if (runConfiguration.getConfiguration().getFactory().getType() instanceof EmbeddedLinuxJVMConfigurationType) {
            for (RunContentDescriptor descriptor : allDescriptors) {
                if (runConfiguration.getName().equals(descriptor.getDisplayName())) {
                    try {
                        if (!exitMsgDisplay) {
                            consoleView.print(EmbeddedLinuxJVMBundle.message("exit.code.message", javaExitCode), ConsoleViewContentType.SYSTEM_OUTPUT);
                            exitMsgDisplay = true;
                        }
                        descriptor.setProcessHandler(null);
                    } catch (Exception e) {

                    }
                }
            }

        }

    }
}
 
Example #8
Source File: StopAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
private static List<RunContentDescriptor> getActiveStoppableDescriptors(final DataContext dataContext) {
  final Project project = dataContext.getData(CommonDataKeys.PROJECT);
  if (project == null) {
    return Collections.emptyList();
  }
  final List<RunContentDescriptor> runningProcesses = ExecutionManager.getInstance(project).getContentManager().getAllDescriptors();
  if (runningProcesses.isEmpty()) {
    return Collections.emptyList();
  }
  final List<RunContentDescriptor> activeDescriptors = new ArrayList<>();
  for (RunContentDescriptor descriptor : runningProcesses) {
    if (canBeStopped(descriptor)) {
      activeDescriptors.add(descriptor);
    }
  }
  return activeDescriptors;
}
 
Example #9
Source File: CloseAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void actionPerformed(AnActionEvent e) {
  final RunContentDescriptor contentDescriptor = getContentDescriptor();
  if (contentDescriptor == null) {
    return;
  }
  final boolean removedOk = ExecutionManager.getInstance(myProject).getContentManager().removeRunContent(getExecutor(), contentDescriptor);
  if (removedOk) {
    myContentDescriptor = null;
    myExecutor = null;
  }
}
 
Example #10
Source File: RunContentBuilder.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void contentAdded(Collection<ConsoleViewContentType> types) {
  if (myProject.isDisposed() || myUi.isDisposed())
    return;
  for (ConsoleViewContentType type : types) {
    if ((type == ConsoleViewContentType.NORMAL_OUTPUT) && myRunConfigurationBase.isShowConsoleOnStdOut()
        || (type == ConsoleViewContentType.ERROR_OUTPUT) && myRunConfigurationBase.isShowConsoleOnStdErr()) {
      ExecutionManager.getInstance(myProject).getContentManager().toFrontRunContent(myExecutor, myRunContentDescriptor);
      myUi.selectAndFocus(myUi.findContent(ExecutionConsole.CONSOLE_CONTENT_ID), false, false);
      return;
    }
  }
}
 
Example #11
Source File: FakeRerunAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
protected ExecutionEnvironment getEnvironment(@Nonnull AnActionEvent event) {
  ExecutionEnvironment environment = event.getData(LangDataKeys.EXECUTION_ENVIRONMENT);
  if (environment == null) {
    Project project = event.getProject();
    RunContentDescriptor contentDescriptor = project == null ? null : ExecutionManager.getInstance(project).getContentManager().getSelectedContent();
    if (contentDescriptor != null) {
      JComponent component = contentDescriptor.getComponent();
      if (component != null) {
        environment = DataManager.getInstance().getDataContext(component).getData(LangDataKeys.EXECUTION_ENVIRONMENT);
      }
    }
  }
  return environment;
}
 
Example #12
Source File: StopAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
static RunContentDescriptor getRecentlyStartedContentDescriptor(@Nonnull DataContext dataContext) {
  final RunContentDescriptor contentDescriptor = dataContext.getData(LangDataKeys.RUN_CONTENT_DESCRIPTOR);
  if (contentDescriptor != null) {
    // toolwindow case
    return contentDescriptor;
  }
  else {
    // main menu toolbar
    final Project project = dataContext.getData(CommonDataKeys.PROJECT);
    return project == null ? null : ExecutionManager.getInstance(project).getContentManager().getSelectedContent();
  }
}
 
Example #13
Source File: XDebuggerManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void removeSession(@Nonnull final XDebugSessionImpl session) {
  XDebugSessionTab sessionTab = session.getSessionTab();
  mySessions.remove(session.getDebugProcess().getProcessHandler());
  if (sessionTab != null &&
      !myProject.isDisposed() &&
      !ApplicationManager.getApplication().isUnitTestMode() &&
      XDebuggerSettingManagerImpl.getInstanceImpl().getGeneralSettings().isHideDebuggerOnProcessTermination()) {
    ExecutionManager.getInstance(myProject).getContentManager().hideRunContent(DefaultDebugExecutor.getDebugExecutorInstance(), sessionTab.getRunContentDescriptor());
  }
  if (myActiveSession.compareAndSet(session, null)) {
    onActiveSessionChanged();
  }
}
 
Example #14
Source File: DebuggerSessionTabBase.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void select() {
  if (ApplicationManager.getApplication().isUnitTestMode()) return;

  UIUtil.invokeLaterIfNeeded(() -> {
    if (myRunContentDescriptor != null) {
      RunContentManager manager = ExecutionManager.getInstance(myProject).getContentManager();
      ToolWindow toolWindow = manager.getToolWindowByDescriptor(myRunContentDescriptor);
      Content content = myRunContentDescriptor.getAttachedContent();
      if (toolWindow == null || content == null) return;
      manager.selectRunContent(myRunContentDescriptor);
    }
  });
}
 
Example #15
Source File: XDebugSessionTab.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void toFront(boolean focus, @Nullable final Runnable onShowCallback) {
  if (ApplicationManager.getApplication().isUnitTestMode()) return;

  ApplicationManager.getApplication().invokeLater(() -> {
    if (myRunContentDescriptor != null) {
      RunContentManager manager = ExecutionManager.getInstance(myProject).getContentManager();
      ToolWindow toolWindow = manager.getToolWindowByDescriptor(myRunContentDescriptor);
      if (toolWindow != null) {
        if (!toolWindow.isVisible()) {
          toolWindow.show(() -> {
            if (onShowCallback != null) {
              onShowCallback.run();
            }
            myRebuildWatchesRunnable.run();
          });
        }
        manager.selectRunContent(myRunContentDescriptor);
      }
    }
  });

  if (focus) {
    ApplicationManager.getApplication().invokeLater(() -> {
      boolean focusWnd = XDebuggerSettingManagerImpl.getInstanceImpl().getGeneralSettings().isMayBringFrameToFrontOnBreakpoint();
      ProjectUtil.focusProjectWindow(myProject, focusWnd);
      if (!focusWnd) {
        AppIcon.getInstance().requestAttention(myProject, true);
      }
    });
  }
}
 
Example #16
Source File: AsyncProgramRunner.java    From consulo with Apache License 2.0 5 votes vote down vote up
protected static void startRunProfile(ExecutionEnvironment environment,
                                      RunProfileState state,
                                      ProgramRunner.Callback callback,
                                      @javax.annotation.Nullable RunProfileStarter starter) {

  ThrowableComputable<AsyncResult<RunContentDescriptor>, ExecutionException> func = () -> {
    AsyncResult<RunContentDescriptor> promise = starter == null ? AsyncResult.done(null) : starter.executeAsync(state, environment);
    return promise.doWhenDone(it -> BaseProgramRunner.postProcess(environment, it, callback));
  };

  ExecutionManager.getInstance(environment.getProject()).startRunProfile(runProfileStarter(func), state, environment);
}
 
Example #17
Source File: RerunFailedTestsAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static boolean getAction(@Nonnull AnActionEvent e, boolean execute) {
  Project project = e.getProject();
  if (project == null) {
    return false;
  }

  RunContentDescriptor contentDescriptor = ExecutionManager.getInstance(project).getContentManager().getSelectedContent();
  if (contentDescriptor == null) {
    return false;
  }

  JComponent component = contentDescriptor.getComponent();
  if (component == null) {
    return false;
  }

  ExecutionEnvironment environment = DataManager.getInstance().getDataContext(component).getData(LangDataKeys.EXECUTION_ENVIRONMENT);
  if (environment == null) {
    return false;
  }

  AnAction[] actions = contentDescriptor.getRestartActions();
  if (actions.length == 0) {
    return false;
  }

  for (AnAction action : actions) {
    if (action instanceof AbstractRerunFailedTestsAction) {
      if (execute) {
        ((AbstractRerunFailedTestsAction)action).execute(e, environment);
      }
      return true;
    }
  }
  return false;
}
 
Example #18
Source File: AbstractAutoTestManager.java    From consulo with Apache License 2.0 5 votes vote down vote up
protected void restartAllAutoTests(int modificationStamp) {
  RunContentManager contentManager = ExecutionManager.getInstance(myProject).getContentManager();
  boolean active = false;
  for (RunContentDescriptor descriptor : contentManager.getAllDescriptors()) {
    if (isAutoTestEnabledForDescriptor(descriptor)) {
      restartAutoTest(descriptor, modificationStamp, myWatcher);
      active = true;
    }
  }
  if (!active) {
    myWatcher.deactivate();
  }
}
 
Example #19
Source File: AbstractAutoTestManager.java    From consulo with Apache License 2.0 5 votes vote down vote up
private boolean hasEnabledAutoTests() {
  RunContentManager contentManager = ExecutionManager.getInstance(myProject).getContentManager();
  for (RunContentDescriptor descriptor : contentManager.getAllDescriptors()) {
    if (isAutoTestEnabledForDescriptor(descriptor)) {
      return true;
    }
  }
  return false;
}
 
Example #20
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();
    }
}
 
Example #21
Source File: FlutterAppManager.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Nullable
private RunContentManager getRunContentManager() {
  // Creating a RunContentManager causes a blank window to appear, so don't create it here.
  // See https://github.com/flutter/flutter-intellij/issues/4217
  if (ServiceManager.getServiceIfCreated(project, RunContentManager.class) == null) {
    return null;
  }
  return ExecutionManager.getInstance(project).getContentManager();
}
 
Example #22
Source File: FlutterAppManager.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Nullable
private RunContentManager getRunContentManager() {
  // Creating a RunContentManager causes a blank window to appear, so don't create it here.
  // See https://github.com/flutter/flutter-intellij/issues/4217
  if (ServiceManager.getServiceIfCreated(project, RunContentManager.class) == null) {
    return null;
  }
  return ExecutionManager.getInstance(project).getContentManager();
}
 
Example #23
Source File: XDebugSessionImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
public void showSessionTab() {
  RunContentDescriptor descriptor = getRunContentDescriptor();
  ExecutionManager.getInstance(getProject()).getContentManager()
          .showRunContent(DefaultDebugExecutor.getDebugExecutorInstance(), descriptor);
}
 
Example #24
Source File: RunnerUtil.java    From react-native-console with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public static void showConsole(Project project, Executor defaultExecutor, @NotNull RunContentDescriptor contentDescriptor) {
    // Show in run toolwindow
    ExecutionManager.getInstance(project).getContentManager().showRunContent(defaultExecutor, contentDescriptor);
}
 
Example #25
Source File: ExecutionChecker.java    From droidtestrec with Apache License 2.0 4 votes vote down vote up
public ExecutionChecker(ExecutionManager executionManager, String runConfigName, TestListener testListener) {
    this.executionManager = executionManager;
    this.runConfigName = runConfigName;
    this.testListener = testListener;
}
 
Example #26
Source File: RunIdeConsoleAction.java    From consulo with Apache License 2.0 4 votes vote down vote up
private static void selectContent(RunContentDescriptor descriptor) {
  Executor executor = DefaultRunExecutor.getRunExecutorInstance();
  ConsoleViewImpl consoleView = ObjectUtils.assertNotNull((ConsoleViewImpl)descriptor.getExecutionConsole());
  ExecutionManager.getInstance(consoleView.getProject()).getContentManager().toFrontRunContent(executor, descriptor);
}
 
Example #27
Source File: AbstractConsoleRunnerWithHistory.java    From consulo with Apache License 2.0 4 votes vote down vote up
protected void showConsole(Executor defaultExecutor, @Nonnull RunContentDescriptor contentDescriptor) {
  // Show in run toolwindow
  ExecutionManager.getInstance(myProject).getContentManager().showRunContent(defaultExecutor, contentDescriptor);
}
 
Example #28
Source File: LogviewFactory.java    From logviewer with Apache License 2.0 4 votes vote down vote up
@Override
public void createToolWindowContent(@NotNull final Project project, @NotNull final ToolWindow toolWindow) {

    final File adb = AndroidSdkUtils.getAdb(project);
    ExecutionManager.getInstance(project).getContentManager();

    RunnerLayoutUi layoutUi = RunnerLayoutUi.Factory.getInstance(project).create("LogViewer", TOOL_WINDOW_ID, "Logview Tools", project);

    toolWindow.setIcon(LogviewerPluginIcons.TOOL_ICON);
    toolWindow.setAvailable(true, null);
    toolWindow.setToHideOnEmptyContent(true);
    toolWindow.setTitle(TOOL_WINDOW_ID);


    DeviceContext deviceContext = new DeviceContext();

    Content logcatContent = createLogcatContent(layoutUi, project, deviceContext);
    final LogView logcatView = logcatContent.getUserData(LOG_VIEW_KEY);
    layoutUi.addContent(logcatContent, 0, PlaceInGrid.center, false);

    final JBLoadingPanel loadingPanel = new JBLoadingPanel(new BorderLayout(), project);
    loadingPanel.add(layoutUi.getComponent(), BorderLayout.CENTER);

    final ContentManager contentManager = toolWindow.getContentManager();
    Content c = contentManager.getFactory().createContent(loadingPanel, "", true);
    c.putUserData(LOG_VIEW_KEY, logcatView);
    contentManager.addContent(c);
    ApplicationManager.getApplication().invokeLater(new Runnable() {
        @Override
        public void run() {
            logcatView.activate();
        }
    }, project.getDisposed());


    if (adb != null) {
        loadingPanel.setLoadingText("Initializing ADB");
        loadingPanel.startLoading();

        //ListenableFuture<AndroidDebugBridge> future = AdbService.getInstance().getDebugBridge(adb);
        ListenableFuture<AndroidDebugBridge> future = AdbBridgeFactory.getAdb(adb);
        Futures.addCallback(future, new FutureCallback<AndroidDebugBridge>() {
            @Override
            public void onSuccess(@Nullable AndroidDebugBridge bridge) {
                Logger.getInstance(LogviewFactory.class).info("Successfully obtained debug bridge");
                loadingPanel.stopLoading();
            }

            @Override
            public void onFailure(@NotNull Throwable t) {
                loadingPanel.stopLoading();
                Logger.getInstance(LogviewFactory.class).info("Unable to obtain debug bridge", t);
                String msg;
                if (t.getMessage() != null) {
                    msg = t.getMessage();
                } else {
                    msg = String.format("Unable to establish a connection to adb",
                            ApplicationNamesInfo.getInstance().getProductName(), adb.getAbsolutePath());
                }
                Messages.showErrorDialog(msg, "ADB Connection Error");
            }
        }, EdtExecutor.INSTANCE);
    } else {
        logcatView.showHint("No adb connection!.\n\nDrag and drop log files to view them.");
    }
}