Search in sources :

Example 1 with StartupManagerImpl

use of com.intellij.ide.startup.impl.StartupManagerImpl in project intellij-community by JetBrains.

the class ProjectManagerImpl method openProject.

@Override
public boolean openProject(@NotNull final Project project) {
    if (isLight(project)) {
        ((ProjectImpl) project).setTemporarilyDisposed(false);
        boolean isInitialized = StartupManagerEx.getInstanceEx(project).startupActivityPassed();
        if (isInitialized) {
            addToOpened(project);
            // events already fired
            return true;
        }
    }
    for (Project p : getOpenProjects()) {
        if (ProjectUtil.isSameProject(project.getProjectFilePath(), p)) {
            GuiUtils.invokeLaterIfNeeded(() -> ProjectUtil.focusProjectWindow(p, false), ModalityState.NON_MODAL);
            return false;
        }
    }
    if (!addToOpened(project)) {
        return false;
    }
    Runnable process = () -> {
        TransactionGuard.getInstance().submitTransactionAndWait(() -> fireProjectOpened(project));
        StartupManagerImpl startupManager = (StartupManagerImpl) StartupManager.getInstance(project);
        startupManager.runStartupActivities();
        // Startup activities (e.g. the one in FileBasedIndexProjectHandler) have scheduled dumb mode to begin "later"
        // Now we schedule-and-wait to the same event queue to guarantee that the dumb mode really begins now:
        // Post-startup activities should not ever see unindexed and at the same time non-dumb state
        TransactionGuard.getInstance().submitTransactionAndWait(startupManager::startCacheUpdate);
        startupManager.runPostStartupActivitiesFromExtensions();
        GuiUtils.invokeLaterIfNeeded(() -> {
            if (!project.isDisposed()) {
                startupManager.runPostStartupActivities();
                Application application = ApplicationManager.getApplication();
                if (!(application.isHeadlessEnvironment() || application.isUnitTestMode())) {
                    StorageUtilKt.checkUnknownMacros(project, true);
                }
            }
            if (ApplicationManager.getApplication().isActive()) {
                JFrame projectFrame = WindowManager.getInstance().getFrame(project);
                if (projectFrame != null) {
                    IdeFocusManager.getInstance(project).requestFocus(projectFrame, true);
                }
            }
        }, ModalityState.NON_MODAL);
    };
    ProgressIndicator indicator = myProgressManager.getProgressIndicator();
    if (indicator != null) {
        indicator.setText("Preparing workspace...");
        process.run();
        return true;
    }
    boolean ok = myProgressManager.runProcessWithProgressSynchronously(process, ProjectBundle.message("project.load.progress"), canCancelProjectLoading(), project);
    if (!ok) {
        closeProject(project, false, false, true);
        notifyProjectOpenFailed();
        return false;
    }
    return true;
}
Also used : StartupManagerImpl(com.intellij.ide.startup.impl.StartupManagerImpl) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator)

Example 2 with StartupManagerImpl

use of com.intellij.ide.startup.impl.StartupManagerImpl in project intellij-community by JetBrains.

the class ParsingTestCase method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    initApplication();
    ComponentAdapter component = getApplication().getPicoContainer().getComponentAdapter(ProgressManager.class.getName());
    if (component == null) {
        getApplication().getPicoContainer().registerComponent(new AbstractComponentAdapter(ProgressManager.class.getName(), Object.class) {

            @Override
            public Object getComponentInstance(PicoContainer container) throws PicoInitializationException, PicoIntrospectionException {
                return new ProgressManagerImpl();
            }

            @Override
            public void verify(PicoContainer container) throws PicoIntrospectionException {
            }
        });
    }
    Extensions.registerAreaClass("IDEA_PROJECT", null);
    myProject = new MockProjectEx(getTestRootDisposable());
    myPsiManager = new MockPsiManager(myProject);
    myFileFactory = new PsiFileFactoryImpl(myPsiManager);
    MutablePicoContainer appContainer = getApplication().getPicoContainer();
    registerComponentInstance(appContainer, MessageBus.class, getApplication().getMessageBus());
    registerComponentInstance(appContainer, SchemeManagerFactory.class, new MockSchemeManagerFactory());
    final MockEditorFactory editorFactory = new MockEditorFactory();
    registerComponentInstance(appContainer, EditorFactory.class, editorFactory);
    registerComponentInstance(appContainer, FileDocumentManager.class, new MockFileDocumentManagerImpl(charSequence -> editorFactory.createDocument(charSequence), FileDocumentManagerImpl.HARD_REF_TO_DOCUMENT_KEY));
    registerComponentInstance(appContainer, PsiDocumentManager.class, new MockPsiDocumentManager());
    registerApplicationService(PsiBuilderFactory.class, new PsiBuilderFactoryImpl());
    registerApplicationService(DefaultASTFactory.class, new DefaultASTFactoryImpl());
    registerApplicationService(ReferenceProvidersRegistry.class, new ReferenceProvidersRegistryImpl());
    myProject.registerService(CachedValuesManager.class, new CachedValuesManagerImpl(myProject, new PsiCachedValuesFactory(myPsiManager)));
    myProject.registerService(PsiManager.class, myPsiManager);
    myProject.registerService(StartupManager.class, new StartupManagerImpl(myProject));
    registerExtensionPoint(FileTypeFactory.FILE_TYPE_FACTORY_EP, FileTypeFactory.class);
    registerExtensionPoint(MetaLanguage.EP_NAME, MetaLanguage.class);
    for (ParserDefinition definition : myDefinitions) {
        addExplicitExtension(LanguageParserDefinitions.INSTANCE, definition.getFileNodeType().getLanguage(), definition);
    }
    if (myDefinitions.length > 0) {
        configureFromParserDefinition(myDefinitions[0], myFileExt);
    }
    // That's for reparse routines
    final PomModelImpl pomModel = new PomModelImpl(myProject);
    myProject.registerService(PomModel.class, pomModel);
    new TreeAspect(pomModel);
}
Also used : CharsetToolkit(com.intellij.openapi.vfs.CharsetToolkit) AbstractComponentAdapter(org.picocontainer.defaults.AbstractComponentAdapter) ReferenceProvidersRegistryImpl(com.intellij.psi.impl.source.resolve.reference.ReferenceProvidersRegistryImpl) NonNls(org.jetbrains.annotations.NonNls) ProgressManagerImpl(com.intellij.openapi.progress.impl.ProgressManagerImpl) org.picocontainer(org.picocontainer) BlockSupportImpl(com.intellij.psi.impl.source.text.BlockSupportImpl) PathManagerEx(com.intellij.openapi.application.ex.PathManagerEx) StartupManagerImpl(com.intellij.ide.startup.impl.StartupManagerImpl) PsiCachedValuesFactory(com.intellij.psi.impl.PsiCachedValuesFactory) com.intellij.lang(com.intellij.lang) StartupManager(com.intellij.openapi.startup.StartupManager) PomModel(com.intellij.pom.PomModel) Disposer(com.intellij.openapi.util.Disposer) ReferenceProvidersRegistry(com.intellij.psi.impl.source.resolve.reference.ReferenceProvidersRegistry) FileUtil(com.intellij.openapi.util.io.FileUtil) TestCase(junit.framework.TestCase) DebugUtil(com.intellij.psi.impl.DebugUtil) PsiFileFactoryImpl(com.intellij.psi.impl.PsiFileFactoryImpl) DiffLog(com.intellij.psi.impl.source.text.DiffLog) Extensions(com.intellij.openapi.extensions.Extensions) ProgressManager(com.intellij.openapi.progress.ProgressManager) FileTypeManager(com.intellij.openapi.fileTypes.FileTypeManager) LoadTextUtil(com.intellij.openapi.fileEditor.impl.LoadTextUtil) FileTypeFactory(com.intellij.openapi.fileTypes.FileTypeFactory) SchemeManagerFactory(com.intellij.openapi.options.SchemeManagerFactory) CachedValuesManagerImpl(com.intellij.util.CachedValuesManagerImpl) Set(java.util.Set) PsiBuilderFactoryImpl(com.intellij.lang.impl.PsiBuilderFactoryImpl) FileDocumentManager(com.intellij.openapi.fileEditor.FileDocumentManager) IOException(java.io.IOException) TextRange(com.intellij.openapi.util.TextRange) FileDocumentManagerImpl(com.intellij.openapi.fileEditor.impl.FileDocumentManagerImpl) Disposable(com.intellij.openapi.Disposable) File(java.io.File) CachedValuesManager(com.intellij.psi.util.CachedValuesManager) ExtensionPointName(com.intellij.openapi.extensions.ExtensionPointName) EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) PomModelImpl(com.intellij.pom.core.impl.PomModelImpl) EditorFactory(com.intellij.openapi.editor.EditorFactory) com.intellij.mock(com.intellij.mock) com.intellij.psi(com.intellij.psi) NotNull(org.jetbrains.annotations.NotNull) TreeAspect(com.intellij.pom.tree.TreeAspect) MessageBus(com.intellij.util.messages.MessageBus) StartupManagerImpl(com.intellij.ide.startup.impl.StartupManagerImpl) TreeAspect(com.intellij.pom.tree.TreeAspect) AbstractComponentAdapter(org.picocontainer.defaults.AbstractComponentAdapter) ProgressManagerImpl(com.intellij.openapi.progress.impl.ProgressManagerImpl) CachedValuesManagerImpl(com.intellij.util.CachedValuesManagerImpl) PsiBuilderFactoryImpl(com.intellij.lang.impl.PsiBuilderFactoryImpl) PsiCachedValuesFactory(com.intellij.psi.impl.PsiCachedValuesFactory) PomModelImpl(com.intellij.pom.core.impl.PomModelImpl) AbstractComponentAdapter(org.picocontainer.defaults.AbstractComponentAdapter) ProgressManager(com.intellij.openapi.progress.ProgressManager) ReferenceProvidersRegistryImpl(com.intellij.psi.impl.source.resolve.reference.ReferenceProvidersRegistryImpl) PsiFileFactoryImpl(com.intellij.psi.impl.PsiFileFactoryImpl)

Example 3 with StartupManagerImpl

use of com.intellij.ide.startup.impl.StartupManagerImpl in project android by JetBrains.

the class GradleFilePsiMerger method mergeGradleFiles.

/**
   * Merges the given source build.gradle content into the given destination build.gradle content,
   * and resolves and dynamic Gradle dependencies into specific versions. If a support library
   * filter is provided, the support libraries will be limited to match that filter. This is
   * typically set to the compileSdkVersion, such that you don't end up mixing and matching
   * compileSdkVersions and support libraries from different versions, which is not supported.
   */
public static String mergeGradleFiles(@NotNull String source, @NotNull String dest, @Nullable Project project, @Nullable final String supportLibVersionFilter) {
    source = source.replace("\r", "");
    dest = dest.replace("\r", "");
    final Project project2;
    boolean projectNeedsCleanup = false;
    if (project != null && !project.isDefault()) {
        project2 = project;
    } else {
        project2 = ((ProjectManagerImpl) ProjectManager.getInstance()).newProject("MergingOnly", "", false, true);
        assert project2 != null;
        ((StartupManagerImpl) StartupManager.getInstance(project2)).runStartupActivities();
        projectNeedsCleanup = true;
    }
    final GroovyFile templateBuildFile = (GroovyFile) PsiFileFactory.getInstance(project2).createFileFromText(SdkConstants.FN_BUILD_GRADLE, GroovyFileType.GROOVY_FILE_TYPE, source);
    final GroovyFile existingBuildFile = (GroovyFile) PsiFileFactory.getInstance(project2).createFileFromText(SdkConstants.FN_BUILD_GRADLE, GroovyFileType.GROOVY_FILE_TYPE, dest);
    String result = (new WriteCommandAction<String>(project2, "Merge Gradle Files", existingBuildFile) {

        @Override
        protected void run(@NotNull Result<String> result) throws Throwable {
            mergePsi(templateBuildFile, existingBuildFile, project2, supportLibVersionFilter);
            PsiElement formatted = CodeStyleManager.getInstance(project2).reformat(existingBuildFile);
            result.setResult(formatted.getText());
        }
    }).execute().getResultObject();
    if (projectNeedsCleanup) {
        ApplicationManager.getApplication().runWriteAction(() -> {
            Disposer.dispose(project2);
        });
    }
    return result;
}
Also used : Project(com.intellij.openapi.project.Project) StartupManagerImpl(com.intellij.ide.startup.impl.StartupManagerImpl) GroovyFile(org.jetbrains.plugins.groovy.lang.psi.GroovyFile) PsiElement(com.intellij.psi.PsiElement)

Example 4 with StartupManagerImpl

use of com.intellij.ide.startup.impl.StartupManagerImpl in project intellij-community by JetBrains.

the class UnindexedFilesUpdater method updateUnindexedFiles.

private void updateUnindexedFiles(ProgressIndicator indicator) {
    PerformanceWatcher.Snapshot snapshot = PerformanceWatcher.takeSnapshot();
    PushedFilePropertiesUpdater.getInstance(myProject).pushAllPropertiesNow();
    boolean trackResponsiveness = !ApplicationManager.getApplication().isUnitTestMode();
    if (trackResponsiveness)
        snapshot.logResponsivenessSinceCreation("Pushing properties");
    indicator.setIndeterminate(true);
    indicator.setText(IdeBundle.message("progress.indexing.scanning"));
    myIndex.clearIndicesIfNecessary();
    CollectingContentIterator finder = myIndex.createContentIterator(indicator);
    snapshot = PerformanceWatcher.takeSnapshot();
    myIndex.iterateIndexableFilesConcurrently(finder, myProject, indicator);
    myIndex.filesUpdateEnumerationFinished();
    if (trackResponsiveness)
        snapshot.logResponsivenessSinceCreation("Indexable file iteration");
    List<VirtualFile> files = finder.getFiles();
    if (!ApplicationManager.getApplication().isUnitTestMode()) {
        // full VFS refresh makes sense only after it's loaded, i.e. after scanning files to index is finished
        ((StartupManagerImpl) StartupManager.getInstance(myProject)).scheduleInitialVfsRefresh();
    }
    if (files.isEmpty()) {
        return;
    }
    snapshot = PerformanceWatcher.takeSnapshot();
    if (trackResponsiveness)
        LOG.info("Unindexed files update started: " + files.size() + " files to update");
    indicator.setIndeterminate(false);
    indicator.setText(IdeBundle.message("progress.indexing.updating"));
    indexFiles(indicator, files);
    if (trackResponsiveness)
        snapshot.logResponsivenessSinceCreation("Unindexed files update");
}
Also used : PerformanceWatcher(com.intellij.diagnostic.PerformanceWatcher) VirtualFile(com.intellij.openapi.vfs.VirtualFile) StartupManagerImpl(com.intellij.ide.startup.impl.StartupManagerImpl) CollectingContentIterator(com.intellij.openapi.roots.CollectingContentIterator)

Example 5 with StartupManagerImpl

use of com.intellij.ide.startup.impl.StartupManagerImpl in project intellij-community by JetBrains.

the class PlatformTestCase method runStartupActivities.

protected void runStartupActivities() {
    final StartupManagerImpl startupManager = (StartupManagerImpl) StartupManager.getInstance(myProject);
    startupManager.runStartupActivities();
    startupManager.startCacheUpdate();
    startupManager.runPostStartupActivities();
}
Also used : StartupManagerImpl(com.intellij.ide.startup.impl.StartupManagerImpl)

Aggregations

StartupManagerImpl (com.intellij.ide.startup.impl.StartupManagerImpl)8 DaemonCodeAnalyzerImpl (com.intellij.codeInsight.daemon.impl.DaemonCodeAnalyzerImpl)2 Project (com.intellij.openapi.project.Project)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 LocalInspectionTool (com.intellij.codeInspection.LocalInspectionTool)1 PerformanceWatcher (com.intellij.diagnostic.PerformanceWatcher)1 com.intellij.lang (com.intellij.lang)1 PsiBuilderFactoryImpl (com.intellij.lang.impl.PsiBuilderFactoryImpl)1 com.intellij.mock (com.intellij.mock)1 Disposable (com.intellij.openapi.Disposable)1 PathManagerEx (com.intellij.openapi.application.ex.PathManagerEx)1 EditorFactory (com.intellij.openapi.editor.EditorFactory)1 ExtensionPointName (com.intellij.openapi.extensions.ExtensionPointName)1 Extensions (com.intellij.openapi.extensions.Extensions)1 FileDocumentManager (com.intellij.openapi.fileEditor.FileDocumentManager)1 FileDocumentManagerImpl (com.intellij.openapi.fileEditor.impl.FileDocumentManagerImpl)1 LoadTextUtil (com.intellij.openapi.fileEditor.impl.LoadTextUtil)1 FileTypeFactory (com.intellij.openapi.fileTypes.FileTypeFactory)1 FileTypeManager (com.intellij.openapi.fileTypes.FileTypeManager)1 Module (com.intellij.openapi.module.Module)1