Search in sources :

Example 41 with AccessToken

use of com.intellij.openapi.application.AccessToken in project go-lang-idea-plugin by go-lang-plugin-org.

the class GoProjectModelConverterProvider method convertSdks.

private static void convertSdks() {
    ProjectJdkTable sdkTable = ProjectJdkTable.getInstance();
    Collection<String> globalGoPathUrls = ContainerUtil.newLinkedHashSet();
    Collection<Sdk> sdksToDelete = ContainerUtil.newArrayList();
    Collection<Sdk> sdksToAdd = ContainerUtil.newArrayList();
    GoSdkType sdkType = GoSdkType.getInstance();
    for (Sdk sdk : sdkTable.getAllJdks()) {
        String sdkTypeName = sdk.getSdkType().getName();
        if (isGoSdkType(sdkTypeName)) {
            sdksToDelete.add(sdk);
            String sdkHome = sdkType.adjustSelectedSdkHome(sdk.getHomePath());
            if (sdkType.isValidSdkHome(sdkHome)) {
                ProjectJdkImpl newSdk = new ProjectJdkImpl(sdk.getName(), sdkType, sdkHome, sdkType.getVersionString(sdkHome));
                sdkType.setupSdkPaths(newSdk);
                sdksToAdd.add(newSdk);
                for (String classesRoot : sdk.getRootProvider().getUrls(OrderRootType.CLASSES)) {
                    if (!classesRoot.equals(sdk.getHomePath())) {
                        globalGoPathUrls.add(classesRoot);
                    }
                }
            }
        }
    }
    for (VirtualFile file : GoSdkUtil.getGoPathsRootsFromEnvironment()) {
        globalGoPathUrls.remove(file.getUrl());
    }
    AccessToken l = WriteAction.start();
    try {
        for (Sdk sdk : sdksToDelete) {
            sdkTable.removeJdk(sdk);
        }
        for (Sdk sdk : sdksToAdd) {
            sdkTable.addJdk(sdk);
        }
        globalGoPathUrls.addAll(GoApplicationLibrariesService.getInstance().getLibraryRootUrls());
        GoApplicationLibrariesService.getInstance().setLibraryRootUrls(globalGoPathUrls);
    } finally {
        l.finish();
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ProjectJdkTable(com.intellij.openapi.projectRoots.ProjectJdkTable) AccessToken(com.intellij.openapi.application.AccessToken) ProjectJdkImpl(com.intellij.openapi.projectRoots.impl.ProjectJdkImpl) Sdk(com.intellij.openapi.projectRoots.Sdk) GoSdkType(com.goide.sdk.GoSdkType)

Example 42 with AccessToken

use of com.intellij.openapi.application.AccessToken in project android by JetBrains.

the class ProjectStructureConfigurable method reset.

@Override
public void reset() {
    AccessToken token = HeavyProcessLatch.INSTANCE.processStarted("Resetting Project Structure");
    try {
        mySdksConfigurable.reset();
        Configurable toSelect = null;
        for (Configurable each : myConfigurables) {
            if (myUiState.lastEditedConfigurable != null && myUiState.lastEditedConfigurable.equals(each.getDisplayName())) {
                toSelect = each;
            }
            if (each instanceof MasterDetailsComponent) {
                ((MasterDetailsComponent) each).setHistory(myHistory);
            }
            each.reset();
        }
        myHistory.clear();
        if (toSelect == null && !myConfigurables.isEmpty()) {
            toSelect = myConfigurables.get(0);
        }
        removeSelected();
        navigateTo(toSelect != null ? createPlaceFor(toSelect) : null, false);
        if (myUiState.proportion > 0) {
            mySplitter.setProportion(myUiState.proportion);
        }
    } finally {
        token.finish();
    }
}
Also used : AccessToken(com.intellij.openapi.application.AccessToken) MasterDetailsComponent(com.intellij.openapi.ui.MasterDetailsComponent) IdeSdksConfigurable(com.android.tools.idea.gradle.structure.IdeSdksConfigurable)

Example 43 with AccessToken

use of com.intellij.openapi.application.AccessToken in project android by JetBrains.

the class AndroidProjectStructureConfigurable method reset.

@Override
public void reset() {
    // Need this to ensure VFS operations will not block because of storage flushing and other maintenance IO tasks run in background.
    AccessToken token = HeavyProcessLatch.INSTANCE.processStarted("Resetting project structure");
    try {
        for (Configurable configurable : myConfigurables) {
            configurable.reset();
        }
        if (myUiInitialized) {
            validateState();
            // Prepare module entries but don't add them until after developer services
            ModuleManager moduleManager = ModuleManager.getInstance(myProject);
            Module[] modules = moduleManager.getModules();
            Arrays.sort(modules, ModuleTypeComparator.INSTANCE);
            List<AndroidModuleConfigurable> moduleConfigurables = Lists.newArrayList();
            for (Module module : modules) {
                AndroidModuleConfigurable configurable = addModule(module);
                if (configurable != null) {
                    moduleConfigurables.add(configurable);
                }
            }
            // Populate the "Developer Services" section
            removeServices();
            if (Projects.isBuildWithGradle(myProject)) {
                DefaultComboBoxModel moduleList = new DefaultComboBoxModel();
                for (AndroidModuleConfigurable moduleConfigurable : moduleConfigurables) {
                    // Collect only Android modules
                    if (AndroidFacet.getInstance(moduleConfigurable.getModule()) != null) {
                        moduleList.addElement(moduleConfigurable.getModule());
                    }
                }
                if (!myProject.isDefault() && moduleList.getSize() > 0) {
                    // into that event.
                    for (int i = 0; i < moduleList.getSize(); i++) {
                        Module module = (Module) moduleList.getElementAt(i);
                        for (DeveloperService service : DeveloperServices.getAll(module)) {
                            service.getContext().restore();
                        }
                    }
                    Module module = (Module) moduleList.getSelectedItem();
                    Set<ServiceCategory> categories = Sets.newHashSet();
                    for (DeveloperService s : DeveloperServices.getAll(module)) {
                        if (!s.getContext().hiddenFromStructureDialog().get()) {
                            categories.add(s.getCategory());
                        }
                    }
                    ArrayList<ServiceCategory> categoriesSorted = Lists.newArrayList(categories);
                    Collections.sort(categoriesSorted);
                    for (ServiceCategory category : categoriesSorted) {
                        myConfigurables.add(new ServiceCategoryConfigurable(moduleList, category));
                    }
                }
            }
            // Populate the "Modules" section.
            removeModules();
            Module toSelect = null;
            for (Module module : modules) {
                AndroidModuleConfigurable configurable = addModule(module);
                if (configurable != null) {
                    myConfigurables.add(configurable);
                    if (configurable.getDisplayName().equals(myUiState.lastSelectedConfigurable)) {
                        toSelect = module;
                    }
                }
            }
            if (myUiState.proportion > 0) {
                mySplitter.setProportion(myUiState.proportion);
            }
            mySidePanel.reset();
            if (toSelect != null) {
                mySidePanel.select(toSelect);
            } else {
                mySidePanel.selectSdk();
            }
        }
    } finally {
        token.finish();
    }
}
Also used : ServiceCategory(com.android.tools.idea.structure.services.ServiceCategory) ServiceCategoryConfigurable(com.android.tools.idea.structure.services.view.ServiceCategoryConfigurable) AndroidModuleConfigurable(com.android.tools.idea.gradle.structure.editors.AndroidModuleConfigurable) AndroidModuleConfigurable(com.android.tools.idea.gradle.structure.editors.AndroidModuleConfigurable) ServiceCategoryConfigurable(com.android.tools.idea.structure.services.view.ServiceCategoryConfigurable) AndroidProjectConfigurable(com.android.tools.idea.gradle.structure.editors.AndroidProjectConfigurable) ModuleManager(com.intellij.openapi.module.ModuleManager) DeveloperService(com.android.tools.idea.structure.services.DeveloperService) AccessToken(com.intellij.openapi.application.AccessToken) Module(com.intellij.openapi.module.Module)

Example 44 with AccessToken

use of com.intellij.openapi.application.AccessToken in project android by JetBrains.

the class CaptureService method deleteBackingFile.

/**
   * Deletes the file associated with this capture.
   */
private void deleteBackingFile(@NotNull CaptureHandle captureHandle, @Nullable Capture capture) {
    boolean deleted = false;
    if (capture != null) {
        AccessToken token = WriteAction.start();
        try {
            capture.getFile().delete(this);
            deleted = true;
        } catch (Exception ignored) {
        } finally {
            token.finish();
        }
    }
    if (!deleted) {
        //noinspection ResultOfMethodCallIgnored
        captureHandle.getFile().delete();
    }
}
Also used : AccessToken(com.intellij.openapi.application.AccessToken) IOException(java.io.IOException)

Example 45 with AccessToken

use of com.intellij.openapi.application.AccessToken in project intellij-plugins by JetBrains.

the class LibraryManager method registerModule.

@NotNull
public ProjectComponentReferenceCounter registerModule(@NotNull final Module module, ProblemsHolder problemsHolder, boolean collectLocalStyleHolders) throws InitException {
    final Project project = module.getProject();
    final StringRegistry.StringWriter stringWriter = new StringRegistry.StringWriter(16384);
    stringWriter.startChange();
    final AssetCounter assetCounter = new AssetCounter();
    final LibraryCollector libraryCollector = new LibraryCollector(this, new LibraryStyleInfoCollector(assetCounter, problemsHolder, module, stringWriter), module);
    final Client client;
    try {
        final AccessToken token = ReadAction.start();
        try {
            libraryCollector.collect(module);
        } finally {
            token.finish();
        }
        client = Client.getInstance();
        if (stringWriter.hasChanges()) {
            client.updateStringRegistry(stringWriter);
        } else {
            stringWriter.commit();
        }
    } catch (Throwable e) {
        stringWriter.rollback();
        throw new InitException(e, "error.collect.libraries");
    }
    assert !libraryCollector.sdkLibraries.isEmpty();
    final FlexLibrarySet flexLibrarySet = getOrCreateFlexLibrarySet(libraryCollector, assetCounter);
    final InfoMap<Project, ProjectInfo> registeredProjects = client.getRegisteredProjects();
    ProjectInfo info = registeredProjects.getNullableInfo(project);
    if (info == null) {
        info = new ProjectInfo(project);
        registeredProjects.add(info);
        client.openProject(project);
        DesignerApplicationManager.getInstance().projectRegistered(project);
    }
    LibrarySet librarySet;
    if (libraryCollector.externalLibraries.isEmpty()) {
        librarySet = null;
    } else {
        final String key = createKey(libraryCollector.externalLibraries, false);
        librarySet = librarySets.get(key);
        if (librarySet == null) {
            final SortResult sortResult = sortLibraries(new LibrarySorter(), libraryCollector, flexLibrarySet.contains, key, false);
            librarySet = new LibrarySet(sortResult.id, flexLibrarySet, sortResult.libraries);
            registerLibrarySet(key, librarySet);
        }
    }
    final ModuleInfo moduleInfo = new ModuleInfo(module, librarySet == null ? flexLibrarySet : librarySet, ModuleInfoUtil.isApp(module));
    final ProjectComponentReferenceCounter projectComponentReferenceCounter = new ProjectComponentReferenceCounter();
    if (collectLocalStyleHolders) {
        // client.registerModule finalize it
        stringWriter.startChange();
        try {
            moduleInfo.setLocalStyleHolders(ModuleInfoUtil.collectLocalStyle(moduleInfo, libraryCollector.getFlexSdkVersion(), stringWriter, problemsHolder, projectComponentReferenceCounter, assetCounter));
        } catch (Throwable e) {
            stringWriter.rollback();
            throw new InitException(e, "error.collect.local.style.holders");
        }
    }
    client.registerModule(project, moduleInfo, stringWriter);
    client.fillAssetClassPoolIfNeed(flexLibrarySet);
    module.getMessageBus().connect(moduleInfo).subscribe(ProjectTopics.PROJECT_ROOTS, new ModuleRootListener() {

        @Override
        public void rootsChanged(ModuleRootEvent event) {
            new Notification(FlashUIDesignerBundle.message("plugin.name"), FlashUIDesignerBundle.message("plugin.name"), "Please reopen your project to update on library changes.", NotificationType.WARNING).notify(project);
        }
    });
    return projectComponentReferenceCounter;
}
Also used : ModuleRootListener(com.intellij.openapi.roots.ModuleRootListener) Notification(com.intellij.notification.Notification) StringRegistry(com.intellij.flex.uiDesigner.io.StringRegistry) ProjectComponentReferenceCounter(com.intellij.flex.uiDesigner.mxml.ProjectComponentReferenceCounter) Project(com.intellij.openapi.project.Project) AccessToken(com.intellij.openapi.application.AccessToken) ModuleRootEvent(com.intellij.openapi.roots.ModuleRootEvent) SortResult(com.intellij.flex.uiDesigner.libraries.LibrarySorter.SortResult) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

AccessToken (com.intellij.openapi.application.AccessToken)97 VirtualFile (com.intellij.openapi.vfs.VirtualFile)28 Nullable (org.jetbrains.annotations.Nullable)15 Module (com.intellij.openapi.module.Module)13 Project (com.intellij.openapi.project.Project)12 Document (com.intellij.openapi.editor.Document)10 GitRepository (git4idea.repo.GitRepository)9 ArrayList (java.util.ArrayList)9 PsiElement (com.intellij.psi.PsiElement)7 NotNull (org.jetbrains.annotations.NotNull)6 File (java.io.File)5 IOException (java.io.IOException)5 ModifiableRootModel (com.intellij.openapi.roots.ModifiableRootModel)4 PsiFile (com.intellij.psi.PsiFile)4 List (java.util.List)4 HgCommandResult (org.zmlx.hg4idea.execution.HgCommandResult)4 ReadAction (com.intellij.openapi.application.ReadAction)3 CompileContext (com.intellij.openapi.compiler.CompileContext)3 CompileTask (com.intellij.openapi.compiler.CompileTask)3 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)3