private void setUpProject() throws IOException { File tempDirectory = FileUtil.createTempDirectory(myName, ""); PlatformTestCase.synchronizeTempDirVfs(LocalFileSystem.getInstance().refreshAndFindFileByIoFile(tempDirectory)); myFilesToDelete.add(tempDirectory); String projectPath = FileUtil.toSystemIndependentName(tempDirectory.getPath()) + "/" + myName + ProjectFileType.DOT_DEFAULT_EXTENSION; ByteArrayOutputStream buffer = new ByteArrayOutputStream(); new Throwable(projectPath).printStackTrace(new PrintStream(buffer)); myProject = PlatformTestCase.createProject(projectPath, buffer.toString()); EdtTestUtil.runInEdtAndWait(new ThrowableRunnable<Throwable>() { @SuppressWarnings("TestOnlyProblems") @Override public void run() throws Throwable { ProjectManagerEx.getInstanceEx().openTestProject(myProject); for (ModuleFixtureBuilder moduleFixtureBuilder : myModuleFixtureBuilders) { moduleFixtureBuilder.getFixture().setUp(); } LightPlatformTestCase.clearUncommittedDocuments(myProject); ((FileTypeManagerImpl)FileTypeManager.getInstance()).drainReDetectQueue(); } }); }
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(); }
protected void setUpProject() throws Exception { myProjectManager = ProjectManagerEx.getInstanceEx(); assertNotNull("Cannot instantiate ProjectManager component", myProjectManager); File projectFile = getIprFile(); myProject = doCreateProject(projectFile); myProjectManager.openTestProject(myProject); LocalFileSystem.getInstance().refreshIoFiles(myFilesToDelete); setUpModule(); setUpJdk(); LightPlatformTestCase.clearUncommittedDocuments(getProject()); runStartupActivities(); ((FileTypeManagerImpl)FileTypeManager.getInstance()).drainReDetectQueue(); }
@Override protected void setUp() throws Exception { super.setUp(); initApplication(); registerExtension(FileTypeFactory.FILE_TYPE_FACTORY_EP, new InternalFileTypeFactory()); registerExtensionPoint(FileDocumentSynchronizationVetoer.EP_NAME, FileDocumentSynchronizationVetoer.class); getApplication().registerService(CommandProcessor.class, new MyMockCommandProcessor()); getApplication().registerService(CodeStyleFacade.class, new DefaultCodeStyleFacade()); getApplication().registerService(ProjectLocator.class, new DefaultProjectLocator()); MockEditorFactory editorFactory = new MockEditorFactory(); getApplication().registerService(EditorFactory.class, editorFactory); final LanguageFileType[] fileType = {null}; getApplication().addComponent(FileTypeManager.class, new FileTypeManagerImpl(null, new MockSchemesManagerFactory()) { @NotNull @Override public FileType getFileTypeByFileName(@NotNull String fileName) { return fileType[0]; } @NotNull @Override public FileType getFileTypeByFile(@NotNull VirtualFile file) { return fileType[0]; } @NotNull @Override public FileType getFileTypeByExtension(@NotNull String extension) { return fileType[0]; } }); fileType[0] = StdFileTypes.JAVA; getApplication().getComponent(FileTypeManager.class); final VirtualFileManager virtualFileManager = EasyMock.createMock(VirtualFileManager.class); final ProjectManager projectManager = EasyMock.createMock(ProjectManager.class); myDocumentManager = new MyMockFileDocumentManager(virtualFileManager, projectManager); getApplication().registerService(FileDocumentManager.class, myDocumentManager); getApplication().registerService(DataManager.class, new DataManagerImpl()); }
public static void setBuckFileType() { ApplicationManager.getApplication() .runWriteAction( new Runnable() { @Override public void run() { FileTypeManager fileTypeManager = FileTypeManagerImpl.getInstance(); FileType fileType = fileTypeManager.getFileTypeByFileName( BuckFileType.INSTANCE.getDefaultExtension()); // Remove all FileType associations for BUCK files that are not BuckFileType while (!(fileType instanceof BuckFileType || fileType instanceof UnknownFileType)) { List<FileNameMatcher> fileNameMatchers = fileTypeManager.getAssociations(fileType); for (FileNameMatcher fileNameMatcher : fileNameMatchers) { if (fileNameMatcher.accept(BuckFileType.INSTANCE.getDefaultExtension())) { fileTypeManager.removeAssociation(fileType, fileNameMatcher); } } fileType = fileTypeManager.getFileTypeByFileName( BuckFileType.INSTANCE.getDefaultExtension()); } // Use a simple BinaryFileStubBuilder, that doesn't offer stubbing BinaryFileStubBuilders.INSTANCE.addExplicitExtension( fileType, new BinaryFileStubBuilder() { @Override public boolean acceptsFile(VirtualFile virtualFile) { return false; } @Nullable @Override public Stub buildStubTree(FileContent fileContent) { return null; } @Override public int getStubVersion() { return 0; } }); } }); }