Search in sources :

Example 21 with MultiMap

use of com.intellij.util.containers.MultiMap in project intellij-community by JetBrains.

the class PluginsAdvertiser method runActivity.

@Override
public void runActivity(@NotNull Project project) {
    if (!UpdateSettings.getInstance().isCheckNeeded()) {
        return;
    }
    final UnknownFeaturesCollector collectorSuggester = UnknownFeaturesCollector.getInstance(project);
    final Set<UnknownFeature> unknownFeatures = collectorSuggester.getUnknownFeatures();
    final KnownExtensions extensions = loadExtensions();
    if (extensions != null && unknownFeatures.isEmpty()) {
        return;
    }
    final Application application = ApplicationManager.getApplication();
    if (application.isUnitTestMode() || application.isHeadlessEnvironment()) {
        return;
    }
    //noinspection SSBasedInspection
    SwingUtilities.invokeLater(() -> application.executeOnPooledThread(new Runnable() {

        private final Set<PluginDownloader> myPlugins = new HashSet<>();

        private List<IdeaPluginDescriptor> myAllPlugins;

        private final Map<Plugin, IdeaPluginDescriptor> myDisabledPlugins = new HashMap<>();

        private List<String> myBundledPlugin;

        private final MultiMap<String, UnknownFeature> myFeatures = new MultiMap<>();

        @Override
        public void run() {
            if (project.isDisposed()) {
                return;
            }
            try {
                myAllPlugins = RepositoryHelper.loadPluginsFromAllRepositories(null);
                if (project.isDisposed()) {
                    return;
                }
                if (extensions == null) {
                    loadSupportedExtensions(myAllPlugins);
                    if (project.isDisposed())
                        return;
                    EditorNotifications.getInstance(project).updateAllNotifications();
                }
                final Map<String, Plugin> ids = new HashMap<>();
                for (UnknownFeature feature : unknownFeatures) {
                    ProgressManager.checkCanceled();
                    final List<Plugin> pluginId = retrieve(feature);
                    if (pluginId != null) {
                        for (Plugin plugin : pluginId) {
                            ids.put(plugin.myPluginId, plugin);
                            myFeatures.putValue(plugin.myPluginId, feature);
                        }
                    }
                }
                final List<String> disabledPlugins = PluginManagerCore.getDisabledPlugins();
                //include disabled plugins
                for (String id : ids.keySet()) {
                    Plugin plugin = ids.get(id);
                    if (disabledPlugins.contains(id)) {
                        final IdeaPluginDescriptor pluginDescriptor = PluginManager.getPlugin(PluginId.getId(id));
                        if (pluginDescriptor != null) {
                            myDisabledPlugins.put(plugin, pluginDescriptor);
                        }
                    }
                }
                myBundledPlugin = hasBundledPluginToInstall(ids.values());
                for (IdeaPluginDescriptor loadedPlugin : myAllPlugins) {
                    final PluginId pluginId = loadedPlugin.getPluginId();
                    if (ids.containsKey(pluginId.getIdString()) && !disabledPlugins.contains(pluginId.getIdString()) && !PluginManagerCore.isBrokenPlugin(loadedPlugin)) {
                        myPlugins.add(PluginDownloader.createDownloader(loadedPlugin));
                    }
                }
                ApplicationManager.getApplication().invokeLater(this::onSuccess, ModalityState.NON_MODAL);
            } catch (Exception e) {
                LOG.info(e);
            }
        }

        private void onSuccess() {
            String message = null;
            if (!myPlugins.isEmpty() || !myDisabledPlugins.isEmpty()) {
                message = getAddressedMessagePresentation();
                if (!myDisabledPlugins.isEmpty()) {
                    message += "<a href=\"enable\">Enable plugins...</a><br>";
                } else {
                    message += "<a href=\"configure\">Configure plugins...</a><br>";
                }
                message += "<a href=\"ignore\">Ignore Unknown Features</a>";
            } else if (myBundledPlugin != null && !PropertiesComponent.getInstance().isTrueValue(IGNORE_ULTIMATE_EDITION)) {
                message = "Features covered by " + IDEA_ULTIMATE_EDITION + " (" + StringUtil.join(myBundledPlugin, ", ") + ") are detected.<br>" + "<a href=\"open\">" + CHECK_ULTIMATE_EDITION_TITLE + "</a><br>" + "<a href=\"ignoreUltimate\">" + ULTIMATE_EDITION_SUGGESTION + "</a>";
            }
            if (message != null) {
                final ConfigurePluginsListener notificationListener = new ConfigurePluginsListener(unknownFeatures, project, myAllPlugins, myPlugins, myDisabledPlugins);
                NOTIFICATION_GROUP.createNotification(DISPLAY_ID, message, NotificationType.INFORMATION, notificationListener).notify(project);
            }
        }

        @NotNull
        private String getAddressedMessagePresentation() {
            final MultiMap<String, String> addressedFeatures = MultiMap.createSet();
            final Set<String> ids = new LinkedHashSet<>();
            for (PluginDownloader plugin : myPlugins) {
                ids.add(plugin.getPluginId());
            }
            for (Plugin plugin : myDisabledPlugins.keySet()) {
                ids.add(plugin.myPluginId);
            }
            for (String id : ids) {
                for (UnknownFeature feature : myFeatures.get(id)) {
                    addressedFeatures.putValue(feature.getFeatureDisplayName(), feature.getImplementationName());
                }
            }
            final String addressedFeaturesPresentation = StringUtil.join(addressedFeatures.entrySet(), entry -> entry.getKey() + "[" + StringUtil.join(entry.getValue(), ", ") + "]", ", ");
            final int addressedFeaturesNumber = addressedFeatures.keySet().size();
            final int pluginsNumber = ids.size();
            return StringUtil.pluralize("Plugin", pluginsNumber) + " supporting " + StringUtil.pluralize("feature", addressedFeaturesNumber) + " (" + addressedFeaturesPresentation + ") " + (pluginsNumber == 1 ? "is" : "are") + " currently " + (myPlugins.isEmpty() ? "disabled" : "not installed") + ".<br>";
        }
    }));
}
Also used : PluginId(com.intellij.openapi.extensions.PluginId) MultiMap(com.intellij.util.containers.MultiMap) PluginDownloader(com.intellij.openapi.updateSettings.impl.PluginDownloader) IOException(java.io.IOException) MultiMap(com.intellij.util.containers.MultiMap)

Example 22 with MultiMap

use of com.intellij.util.containers.MultiMap in project intellij-community by JetBrains.

the class VcsCommittedListsZipperAdapter method groupLocations.

public Pair<List<RepositoryLocationGroup>, List<RepositoryLocation>> groupLocations(final List<RepositoryLocation> in) {
    final List<RepositoryLocationGroup> groups = new ArrayList<>();
    final List<RepositoryLocation> singles = new ArrayList<>();
    final MultiMap<Object, RepositoryLocation> map = new MultiMap<>();
    for (RepositoryLocation location : in) {
        final Object key = myGroupCreator.createKey(location);
        map.putValue(key, location);
    }
    final Set<Object> keys = map.keySet();
    for (Object key : keys) {
        final Collection<RepositoryLocation> locations = map.get(key);
        if (locations.size() == 1) {
            singles.addAll(locations);
        } else {
            final RepositoryLocationGroup group = myGroupCreator.createGroup(key, locations);
            groups.add(group);
        }
    }
    return Pair.create(groups, singles);
}
Also used : MultiMap(com.intellij.util.containers.MultiMap) ArrayList(java.util.ArrayList) RepositoryLocation(com.intellij.openapi.vcs.RepositoryLocation)

Example 23 with MultiMap

use of com.intellij.util.containers.MultiMap in project intellij-community by JetBrains.

the class AbstractDataGetter method preLoadCommitData.

@NotNull
public TIntObjectHashMap<T> preLoadCommitData(@NotNull TIntHashSet commits) throws VcsException {
    TIntObjectHashMap<T> result = new TIntObjectHashMap<>();
    final MultiMap<VirtualFile, String> rootsAndHashes = MultiMap.create();
    commits.forEach(commit -> {
        CommitId commitId = myStorage.getCommitId(commit);
        if (commitId != null) {
            rootsAndHashes.putValue(commitId.getRoot(), commitId.getHash().asString());
        }
        return true;
    });
    for (Map.Entry<VirtualFile, Collection<String>> entry : rootsAndHashes.entrySet()) {
        VcsLogProvider logProvider = myLogProviders.get(entry.getKey());
        if (logProvider != null) {
            List<? extends T> details = readDetails(logProvider, entry.getKey(), ContainerUtil.newArrayList(entry.getValue()));
            for (T data : details) {
                int index = myStorage.getCommitIndex(data.getId(), data.getRoot());
                result.put(index, data);
            }
            saveInCache(result);
        } else {
            LOG.error("No log provider for root " + entry.getKey().getPath() + ". All known log providers " + myLogProviders);
        }
    }
    return result;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) CommitId(com.intellij.vcs.log.CommitId) VcsLogProvider(com.intellij.vcs.log.VcsLogProvider) TIntObjectHashMap(gnu.trove.TIntObjectHashMap) Collection(java.util.Collection) Map(java.util.Map) TIntObjectHashMap(gnu.trove.TIntObjectHashMap) MultiMap(com.intellij.util.containers.MultiMap) TIntIntHashMap(gnu.trove.TIntIntHashMap) NotNull(org.jetbrains.annotations.NotNull)

Example 24 with MultiMap

use of com.intellij.util.containers.MultiMap in project intellij-community by JetBrains.

the class SimpleRefGroup method buildGroups.

public static void buildGroups(@NotNull MultiMap<VcsRefType, VcsRef> groupedRefs, boolean compact, boolean showTagNames, @NotNull List<RefGroup> result) {
    if (groupedRefs.isEmpty())
        return;
    if (compact) {
        VcsRef firstRef = ObjectUtils.assertNotNull(ContainerUtil.getFirstItem(groupedRefs.values()));
        RefGroup group = ContainerUtil.getFirstItem(result);
        if (group == null) {
            result.add(new SimpleRefGroup(firstRef.getType().isBranch() || showTagNames ? firstRef.getName() : "", ContainerUtil.newArrayList(groupedRefs.values())));
        } else {
            group.getRefs().addAll(groupedRefs.values());
        }
    } else {
        for (Map.Entry<VcsRefType, Collection<VcsRef>> entry : groupedRefs.entrySet()) {
            if (entry.getKey().isBranch()) {
                for (VcsRef ref : entry.getValue()) {
                    result.add(new SimpleRefGroup(ref.getName(), ContainerUtil.newArrayList(ref)));
                }
            } else {
                result.add(new SimpleRefGroup(showTagNames ? ObjectUtils.notNull(ContainerUtil.getFirstItem(entry.getValue())).getName() : "", ContainerUtil.newArrayList(entry.getValue())));
            }
        }
    }
}
Also used : VcsRefType(com.intellij.vcs.log.VcsRefType) VcsRef(com.intellij.vcs.log.VcsRef) MultiMap(com.intellij.util.containers.MultiMap) RefGroup(com.intellij.vcs.log.RefGroup)

Example 25 with MultiMap

use of com.intellij.util.containers.MultiMap in project intellij-community by JetBrains.

the class VcsLogRepoSizeCollector method groupRootsByVcs.

@NotNull
private static MultiMap<VcsKey, VirtualFile> groupRootsByVcs(@NotNull Map<VirtualFile, VcsLogProvider> providers) {
    MultiMap<VcsKey, VirtualFile> result = MultiMap.create();
    for (Map.Entry<VirtualFile, VcsLogProvider> entry : providers.entrySet()) {
        VirtualFile root = entry.getKey();
        VcsKey vcs = entry.getValue().getSupportedVcs();
        result.putValue(vcs, root);
    }
    return result;
}
Also used : VcsKey(com.intellij.openapi.vcs.VcsKey) VirtualFile(com.intellij.openapi.vfs.VirtualFile) VcsLogProvider(com.intellij.vcs.log.VcsLogProvider) Map(java.util.Map) MultiMap(com.intellij.util.containers.MultiMap) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

MultiMap (com.intellij.util.containers.MultiMap)141 NotNull (org.jetbrains.annotations.NotNull)38 UsageInfo (com.intellij.usageView.UsageInfo)26 VirtualFile (com.intellij.openapi.vfs.VirtualFile)25 Project (com.intellij.openapi.project.Project)19 PsiElement (com.intellij.psi.PsiElement)18 Collection (java.util.Collection)17 ConflictsDialog (com.intellij.refactoring.ui.ConflictsDialog)16 Nullable (org.jetbrains.annotations.Nullable)16 Map (java.util.Map)15 Module (com.intellij.openapi.module.Module)11 File (java.io.File)11 ArrayList (java.util.ArrayList)11 ContainerUtil (com.intellij.util.containers.ContainerUtil)10 HashSet (com.intellij.util.containers.HashSet)10 THashSet (gnu.trove.THashSet)9 java.util (java.util)9 Pair (com.intellij.openapi.util.Pair)8 com.intellij.psi (com.intellij.psi)8 HashSet (java.util.HashSet)8