Search in sources :

Example 16 with PluginId

use of com.intellij.openapi.extensions.PluginId in project intellij-community by JetBrains.

the class InstalledPluginsTableModel method warnAboutMissedDependencies.

private void warnAboutMissedDependencies(final Boolean newVal, final IdeaPluginDescriptor... ideaPluginDescriptors) {
    final Set<PluginId> deps = new HashSet<>();
    final List<IdeaPluginDescriptor> descriptorsToCheckDependencies = new ArrayList<>();
    if (newVal) {
        Collections.addAll(descriptorsToCheckDependencies, ideaPluginDescriptors);
    } else {
        descriptorsToCheckDependencies.addAll(getAllPlugins());
        descriptorsToCheckDependencies.removeAll(Arrays.asList(ideaPluginDescriptors));
        for (Iterator<IdeaPluginDescriptor> iterator = descriptorsToCheckDependencies.iterator(); iterator.hasNext(); ) {
            IdeaPluginDescriptor descriptor = iterator.next();
            final Boolean enabled = myEnabled.get(descriptor.getPluginId());
            if (enabled == null || !enabled.booleanValue()) {
                iterator.remove();
            }
        }
    }
    for (final IdeaPluginDescriptor ideaPluginDescriptor : descriptorsToCheckDependencies) {
        PluginManagerCore.checkDependants(ideaPluginDescriptor, pluginId -> PluginManager.getPlugin(pluginId), pluginId -> {
            Boolean enabled = myEnabled.get(pluginId);
            if (enabled == null) {
                return false;
            }
            if (newVal && !enabled.booleanValue()) {
                deps.add(pluginId);
            }
            if (!newVal) {
                if (ideaPluginDescriptor instanceof IdeaPluginDescriptorImpl && ((IdeaPluginDescriptorImpl) ideaPluginDescriptor).isDeleted()) {
                    return true;
                }
                final PluginId pluginDescriptorId = ideaPluginDescriptor.getPluginId();
                for (IdeaPluginDescriptor descriptor : ideaPluginDescriptors) {
                    if (pluginId.equals(descriptor.getPluginId())) {
                        deps.add(pluginDescriptorId);
                        break;
                    }
                }
            }
            return true;
        });
    }
    if (!deps.isEmpty()) {
        final String listOfSelectedPlugins = StringUtil.join(ideaPluginDescriptors, pluginDescriptor -> pluginDescriptor.getName(), ", ");
        final Set<IdeaPluginDescriptor> pluginDependencies = new HashSet<>();
        final String listOfDependencies = StringUtil.join(deps, pluginId -> {
            final IdeaPluginDescriptor pluginDescriptor = PluginManager.getPlugin(pluginId);
            assert pluginDescriptor != null;
            pluginDependencies.add(pluginDescriptor);
            return pluginDescriptor.getName();
        }, "<br>");
        final String message = !newVal ? "<html>The following plugins <br>" + listOfDependencies + "<br>are enabled and depend" + (deps.size() == 1 ? "s" : "") + " on selected plugins. " + "<br>Would you like to disable them too?</html>" : "<html>The following plugins on which " + listOfSelectedPlugins + " depend" + (ideaPluginDescriptors.length == 1 ? "s" : "") + " are disabled:<br>" + listOfDependencies + "<br>Would you like to enable them?</html>";
        if (Messages.showOkCancelDialog(message, newVal ? "Enable Dependant Plugins" : "Disable Plugins with Dependency on this", Messages.getQuestionIcon()) == Messages.OK) {
            for (PluginId pluginId : deps) {
                myEnabled.put(pluginId, newVal);
            }
            updatePluginDependencies();
            hideNotApplicablePlugins(newVal, pluginDependencies.toArray(new IdeaPluginDescriptor[pluginDependencies.size()]));
        }
    }
}
Also used : PluginId(com.intellij.openapi.extensions.PluginId) HashSet(com.intellij.util.containers.hash.HashSet)

Example 17 with PluginId

use of com.intellij.openapi.extensions.PluginId in project intellij-community by JetBrains.

the class SelectPluginsStep method buildRequires.

private String buildRequires(final IdeaPluginDescriptor descriptor) {
    StringBuilder requiresBuffer = new StringBuilder();
    for (PluginId id : StartupWizardModel.getNonOptionalDependencies(descriptor)) {
        final IdeaPluginDescriptor dependent = findPlugin(id);
        if (dependent != null) {
            String name = getAbbreviatedName(dependent);
            if (requiresBuffer.length() == 0) {
                requiresBuffer.append("   (requires ");
            } else {
                requiresBuffer.append(", ");
            }
            requiresBuffer.append(name);
        }
    }
    List<IdeaPluginDescriptor> requiredBy = myModel.getDependentsOnEarlierPages(descriptor, false);
    if (requiredBy.size() > 0) {
        if (requiresBuffer.length() > 0) {
            requiresBuffer.append(", ");
        } else {
            requiresBuffer.append("   (");
        }
        requiresBuffer.append("required by ");
        requiresBuffer.append(StringUtil.join(requiredBy, ideaPluginDescriptor -> getAbbreviatedName(ideaPluginDescriptor), ", "));
    }
    if (requiresBuffer.length() > 0) {
        requiresBuffer.append(")");
    }
    return requiresBuffer.toString();
}
Also used : UIUtil(com.intellij.util.ui.UIUtil) ShowSettingsUtil(com.intellij.openapi.options.ShowSettingsUtil) StringUtil(com.intellij.openapi.util.text.StringUtil) WizardNavigationState(com.intellij.ui.wizard.WizardNavigationState) CollectionListModel(com.intellij.ui.CollectionListModel) ArrayList(java.util.ArrayList) java.awt(java.awt) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) java.awt.event(java.awt.event) WizardStep(com.intellij.ui.wizard.WizardStep) NotNull(org.jetbrains.annotations.NotNull) ListSelectionEvent(javax.swing.event.ListSelectionEvent) ListSelectionListener(javax.swing.event.ListSelectionListener) PluginId(com.intellij.openapi.extensions.PluginId) Collections(java.util.Collections) ClickListener(com.intellij.ui.ClickListener) IdeaPluginDescriptor(com.intellij.ide.plugins.IdeaPluginDescriptor) javax.swing(javax.swing) IdeaPluginDescriptor(com.intellij.ide.plugins.IdeaPluginDescriptor) PluginId(com.intellij.openapi.extensions.PluginId)

Example 18 with PluginId

use of com.intellij.openapi.extensions.PluginId 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 19 with PluginId

use of com.intellij.openapi.extensions.PluginId in project intellij-community by JetBrains.

the class UpdatePluginsFromCustomRepositoryTest method testOnlyCompatiblePluginsAreChecked.

@Test
public void testOnlyCompatiblePluginsAreChecked() throws Exception {
    Map<PluginId, PluginDownloader> toUpdate = new LinkedHashMap<>();
    IdeaPluginDescriptor[] descriptors = new IdeaPluginDescriptor[] { loadDescriptor("plugin1.xml"), loadDescriptor("plugin2.xml") };
    BuildNumber currentBuildNumber = BuildNumber.fromString("IU-142.100");
    for (IdeaPluginDescriptor descriptor : descriptors) {
        PluginDownloader downloader = PluginDownloader.createDownloader(descriptor, null, currentBuildNumber);
        UpdateChecker.checkAndPrepareToInstall(downloader, new InstalledPluginsState(), toUpdate, new ArrayList<>(), null);
    }
    assertEquals("Found: " + toUpdate.size(), 1, toUpdate.size());
    PluginDownloader downloader = toUpdate.values().iterator().next();
    assertNotNull(downloader);
    assertEquals("0.1", downloader.getPluginVersion());
}
Also used : PluginDownloader(com.intellij.openapi.updateSettings.impl.PluginDownloader) InstalledPluginsState(com.intellij.ide.plugins.InstalledPluginsState) BuildNumber(com.intellij.openapi.util.BuildNumber) IdeaPluginDescriptor(com.intellij.ide.plugins.IdeaPluginDescriptor) PluginId(com.intellij.openapi.extensions.PluginId) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 20 with PluginId

use of com.intellij.openapi.extensions.PluginId in project intellij-community by JetBrains.

the class IdeErrorsDialog method updateInfoLabel.

private void updateInfoLabel(AbstractMessage message) {
    if (message == null) {
        myInfoLabel.setText("");
        return;
    }
    final Throwable throwable = message.getThrowable();
    if (throwable instanceof MessagePool.TooManyErrorsException) {
        myInfoLabel.setText("");
        return;
    }
    StringBuilder text = new StringBuilder();
    PluginId pluginId = findPluginId(throwable);
    if (pluginId == null) {
        if (throwable instanceof AbstractMethodError) {
            text.append(DiagnosticBundle.message("error.list.message.blame.unknown.plugin"));
        } else {
            text.append(DiagnosticBundle.message("error.list.message.blame.core", ApplicationNamesInfo.getInstance().getProductName()));
        }
    } else {
        text.append(DiagnosticBundle.message("error.list.message.blame.plugin", PluginManager.getPlugin(pluginId).getName()));
    }
    text.append(" ").append(DiagnosticBundle.message("error.list.message.info", DateFormatUtil.formatPrettyDateTime(message.getDate()), myMergedMessages.get(myIndex).size()));
    String url = null;
    if (message.isSubmitted()) {
        SubmittedReportInfo info = message.getSubmissionInfo();
        url = info.getURL();
        appendSubmissionInformation(info, text);
        text.append(". ");
    } else if (message.isSubmitting()) {
        text.append(" Submitting...");
    } else if (!message.isRead()) {
        text.append(" ").append(DiagnosticBundle.message("error.list.message.unread"));
    }
    myInfoLabel.setHtmlText(XmlStringUtil.wrapInHtml(text));
    myInfoLabel.setHyperlinkTarget(url);
}
Also used : PluginId(com.intellij.openapi.extensions.PluginId)

Aggregations

PluginId (com.intellij.openapi.extensions.PluginId)54 IdeaPluginDescriptor (com.intellij.ide.plugins.IdeaPluginDescriptor)25 NotNull (org.jetbrains.annotations.NotNull)10 IOException (java.io.IOException)8 IdeaLoggingEvent (com.intellij.openapi.diagnostic.IdeaLoggingEvent)6 Project (com.intellij.openapi.project.Project)6 Nullable (org.jetbrains.annotations.Nullable)6 SubmittedReportInfo (com.intellij.openapi.diagnostic.SubmittedReportInfo)5 PluginException (com.intellij.diagnostic.PluginException)4 DataContext (com.intellij.openapi.actionSystem.DataContext)4 NonNls (org.jetbrains.annotations.NonNls)4 ErrorBean (com.intellij.errorreport.bean.ErrorBean)3 EmptyProgressIndicator (com.intellij.openapi.progress.EmptyProgressIndicator)3 PluginDownloader (com.intellij.openapi.updateSettings.impl.PluginDownloader)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 File (java.io.File)3 AbstractMessage (com.intellij.diagnostic.AbstractMessage)2 LogMessageEx (com.intellij.diagnostic.LogMessageEx)2 CantRunException (com.intellij.execution.CantRunException)2 DataManager (com.intellij.ide.DataManager)2