public PyModuleListener(MessageBus messageBus) { messageBus.connect().subscribe(ProjectTopics.MODULES, new ModuleAdapter() { @Override public void beforeModuleRemoved(@NotNull Project project, @NotNull Module module) { final RunManagerEx runManager = RunManagerEx.getInstanceEx(project); final Collection<RunnerAndConfigurationSettings> configurations = new ArrayList<RunnerAndConfigurationSettings>(runManager.getSortedConfigurations()); for (RunnerAndConfigurationSettings configuration : configurations) { if (configuration.getConfiguration() instanceof AbstractPythonRunConfiguration) { final Module configModule = ((AbstractPythonRunConfiguration)configuration.getConfiguration()).getModule(); if (configModule == module) { runManager.removeConfiguration(configuration); } } } } }); }
public static void doSetup(@NotNull LightProjectDescriptor descriptor, @NotNull LocalInspectionTool[] localInspectionTools, @NotNull Disposable parentDisposable) throws Exception { assertNull("Previous test " + ourTestCase + " hasn't called tearDown(). Probably overridden without super call.", ourTestCase); IdeaLogger.ourErrorsOccurred = null; ApplicationManager.getApplication().assertIsDispatchThread(); boolean reusedProject = true; if (ourProject == null || ourProjectDescriptor == null || !ourProjectDescriptor.equals(descriptor)) { initProject(descriptor); reusedProject = false; } ProjectManagerEx projectManagerEx = ProjectManagerEx.getInstanceEx(); projectManagerEx.openTestProject(ourProject); if (reusedProject) { DumbService.getInstance(ourProject).queueTask(new UnindexedFilesUpdater(ourProject, false)); } MessageBusConnection connection = ourProject.getMessageBus().connect(parentDisposable); connection.subscribe(ProjectTopics.MODULES, new ModuleAdapter() { @Override public void moduleAdded(@NotNull Project project, @NotNull Module module) { fail("Adding modules is not permitted in LightIdeaTestCase."); } }); clearUncommittedDocuments(getProject()); CodeInsightTestFixtureImpl.configureInspections(localInspectionTools, getProject(), Collections.<String>emptyList(), parentDisposable); assertFalse(getPsiManager().isDisposed()); Boolean passed = null; try { passed = StartupManagerEx.getInstanceEx(getProject()).startupActivityPassed(); } catch (Exception ignored) { } assertTrue("open: " + getProject().isOpen() + "; disposed:" + getProject().isDisposed() + "; startup passed:" + passed + "; all open projects: " + Arrays.asList(ProjectManager.getInstance().getOpenProjects()), getProject().isInitialized()); CodeStyleSettingsManager.getInstance(getProject()).setTemporarySettings(new CodeStyleSettings()); final FileDocumentManager manager = FileDocumentManager.getInstance(); if (manager instanceof FileDocumentManagerImpl) { Document[] unsavedDocuments = manager.getUnsavedDocuments(); manager.saveAllDocuments(); ApplicationManager.getApplication().runWriteAction(new Runnable() { @Override public void run() { ((FileDocumentManagerImpl)manager).dropAllUnsavedDocuments(); } }); assertEmpty("There are unsaved documents", Arrays.asList(unsavedDocuments)); } UIUtil.dispatchAllInvocationEvents(); // startup activities ((FileTypeManagerImpl)FileTypeManager.getInstance()).drainReDetectQueue(); }