Search in sources :

Example 6 with PluginId

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

the class ActionManagerImpl method error.

@NotNull
@Contract(pure = true)
private static RuntimeException error(@NotNull ActionStub stub, @NotNull Throwable original, @NotNull String template, @NotNull String className) {
    PluginId pluginId = stub.getPluginId();
    String text = MessageFormat.format(template, className);
    if (pluginId == null) {
        return new IllegalStateException(text);
    }
    return new PluginException(text, original, pluginId);
}
Also used : PluginException(com.intellij.diagnostic.PluginException) PluginId(com.intellij.openapi.extensions.PluginId) NotNull(org.jetbrains.annotations.NotNull) Contract(org.jetbrains.annotations.Contract)

Example 7 with PluginId

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

the class PluginInstaller method prepareToInstall.

private static boolean prepareToInstall(PluginNode pluginNode, List<PluginId> pluginIds, List<IdeaPluginDescriptor> allPlugins, Set<PluginNode> installedDependant, PluginManagerMain.PluginEnabler pluginEnabler, @NotNull ProgressIndicator indicator) throws IOException {
    installedDependant.add(pluginNode);
    // check for dependent plugins at first.
    if (pluginNode.getDepends() != null && pluginNode.getDepends().size() > 0) {
        // prepare plugins list for install
        final PluginId[] optionalDependentPluginIds = pluginNode.getOptionalDependentPluginIds();
        final List<PluginNode> depends = new ArrayList<>();
        final List<PluginNode> optionalDeps = new ArrayList<>();
        for (int i = 0; i < pluginNode.getDepends().size(); i++) {
            PluginId depPluginId = pluginNode.getDepends().get(i);
            if (PluginManager.isPluginInstalled(depPluginId) || PluginManagerCore.isModuleDependency(depPluginId) || InstalledPluginsState.getInstance().wasInstalled(depPluginId) || (pluginIds != null && pluginIds.contains(depPluginId))) {
                // ignore installed or installing plugins
                continue;
            }
            IdeaPluginDescriptor depPluginDescriptor = findPluginInRepo(depPluginId, allPlugins);
            PluginNode depPlugin;
            if (depPluginDescriptor instanceof PluginNode) {
                depPlugin = (PluginNode) depPluginDescriptor;
            } else {
                depPlugin = new PluginNode(depPluginId, depPluginId.getIdString(), "-1");
            }
            if (depPluginDescriptor != null) {
                if (ArrayUtil.indexOf(optionalDependentPluginIds, depPluginId) != -1) {
                    optionalDeps.add(depPlugin);
                } else {
                    depends.add(depPlugin);
                }
            }
        }
        if (depends.size() > 0) {
            // has something to install prior installing the plugin
            final boolean[] proceed = new boolean[1];
            try {
                GuiUtils.runOrInvokeAndWait(() -> {
                    String title = IdeBundle.message("plugin.manager.dependencies.detected.title");
                    String deps = StringUtil.join(depends, node -> node.getName(), ", ");
                    String message = IdeBundle.message("plugin.manager.dependencies.detected.message", depends.size(), deps);
                    proceed[0] = Messages.showYesNoDialog(message, title, Messages.getWarningIcon()) == Messages.YES;
                });
            } catch (Exception e) {
                return false;
            }
            if (!proceed[0] || !prepareToInstall(depends, allPlugins, installedDependant, pluginEnabler, indicator)) {
                return false;
            }
        }
        if (optionalDeps.size() > 0) {
            final boolean[] proceed = new boolean[1];
            try {
                GuiUtils.runOrInvokeAndWait(() -> {
                    String title = IdeBundle.message("plugin.manager.dependencies.detected.title");
                    String deps = StringUtil.join(optionalDeps, node -> node.getName(), ", ");
                    String message = IdeBundle.message("plugin.manager.optional.dependencies.detected.message", optionalDeps.size(), deps);
                    proceed[0] = Messages.showYesNoDialog(message, title, Messages.getWarningIcon()) == Messages.YES;
                });
            } catch (Exception e) {
                return false;
            }
            if (proceed[0] && !prepareToInstall(optionalDeps, allPlugins, installedDependant, pluginEnabler, indicator)) {
                return false;
            }
        }
    }
    Ref<IdeaPluginDescriptor> toDisable = Ref.create(null);
    Optional<PluginReplacement> replacement = StreamEx.of(PluginReplacement.EP_NAME.getExtensions()).findFirst(r -> r.getNewPluginId().equals(pluginNode.getPluginId().getIdString()));
    if (replacement.isPresent()) {
        PluginReplacement pluginReplacement = replacement.get();
        IdeaPluginDescriptor oldPlugin = PluginManager.getPlugin(pluginReplacement.getOldPluginDescriptor().getPluginId());
        if (oldPlugin == null) {
            LOG.warn("Plugin with id '" + pluginReplacement.getOldPluginDescriptor().getPluginId() + "' not found");
        } else if (!pluginEnabler.isDisabled(oldPlugin.getPluginId())) {
            ApplicationManager.getApplication().invokeAndWait(() -> {
                String title = IdeBundle.message("plugin.manager.obsolete.plugins.detected.title");
                String message = pluginReplacement.getReplacementMessage(oldPlugin, pluginNode);
                if (Messages.showYesNoDialog(message, title, Messages.getWarningIcon()) == Messages.YES) {
                    toDisable.set(oldPlugin);
                }
            });
        }
    }
    PluginDownloader downloader = PluginDownloader.createDownloader(pluginNode, pluginNode.getRepositoryName(), null);
    if (downloader.prepareToInstall(indicator)) {
        synchronized (ourLock) {
            downloader.install();
        }
        pluginNode.setStatus(PluginNode.STATUS_DOWNLOADED);
        if (!toDisable.isNull()) {
            pluginEnabler.disablePlugins(Collections.singleton(toDisable.get()));
        }
    } else {
        return false;
    }
    return true;
}
Also used : PluginId(com.intellij.openapi.extensions.PluginId) IOException(java.io.IOException) PluginDownloader(com.intellij.openapi.updateSettings.impl.PluginDownloader)

Example 8 with PluginId

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

the class PluginManagerMain method loadPluginsFromHostInBackground.

/**
   * Start a new thread which downloads new list of plugins from the site in
   * the background and updates a list of plugins in the table.
   */
protected void loadPluginsFromHostInBackground() {
    setDownloadStatus(true);
    ApplicationManager.getApplication().executeOnPooledThread(() -> {
        final List<IdeaPluginDescriptor> list = ContainerUtil.newArrayList();
        final Map<String, String> errors = ContainerUtil.newLinkedHashMap();
        ProgressIndicator indicator = new EmptyProgressIndicator();
        List<String> hosts = RepositoryHelper.getPluginHosts();
        Set<PluginId> unique = ContainerUtil.newHashSet();
        for (String host : hosts) {
            try {
                if (host == null || acceptHost(host)) {
                    List<IdeaPluginDescriptor> plugins = RepositoryHelper.loadPlugins(host, indicator);
                    for (IdeaPluginDescriptor plugin : plugins) {
                        if (unique.add(plugin.getPluginId())) {
                            list.add(plugin);
                        }
                    }
                }
            } catch (FileNotFoundException e) {
                LOG.info(host, e);
            } catch (IOException e) {
                LOG.info(host, e);
                if (host != ApplicationInfoEx.getInstanceEx().getBuiltinPluginsUrl()) {
                    errors.put(host, String.format("'%s' for '%s'", e.getMessage(), host));
                }
            }
        }
        UIUtil.invokeLaterIfNeeded(() -> {
            setDownloadStatus(false);
            if (!list.isEmpty()) {
                InstalledPluginsState state = InstalledPluginsState.getInstance();
                for (IdeaPluginDescriptor descriptor : list) {
                    state.onDescriptorDownload(descriptor);
                }
                modifyPluginsList(list);
                propagateUpdates(list);
            }
            if (!errors.isEmpty()) {
                String message = IdeBundle.message("error.list.of.plugins.was.not.loaded", StringUtil.join(errors.keySet(), ", "), StringUtil.join(errors.values(), ",\n"));
                String title = IdeBundle.message("title.plugins");
                String ok = CommonBundle.message("button.retry"), cancel = CommonBundle.getCancelButtonText();
                if (Messages.showOkCancelDialog(message, title, ok, cancel, Messages.getErrorIcon()) == Messages.OK) {
                    loadPluginsFromHostInBackground();
                }
            }
        });
    });
}
Also used : EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) PluginId(com.intellij.openapi.extensions.PluginId)

Example 9 with PluginId

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

the class PluginManagerMain method suggestToEnableInstalledDependantPlugins.

public static boolean suggestToEnableInstalledDependantPlugins(PluginEnabler pluginEnabler, List<PluginNode> list) {
    final Set<IdeaPluginDescriptor> disabled = new HashSet<>();
    final Set<IdeaPluginDescriptor> disabledDependants = new HashSet<>();
    for (PluginNode node : list) {
        final PluginId pluginId = node.getPluginId();
        if (pluginEnabler.isDisabled(pluginId)) {
            disabled.add(node);
        }
        final List<PluginId> depends = node.getDepends();
        if (depends != null) {
            final Set<PluginId> optionalDeps = new HashSet<>(Arrays.asList(node.getOptionalDependentPluginIds()));
            for (PluginId dependantId : depends) {
                if (optionalDeps.contains(dependantId))
                    continue;
                final IdeaPluginDescriptor pluginDescriptor = PluginManager.getPlugin(dependantId);
                if (pluginDescriptor != null && pluginEnabler.isDisabled(dependantId)) {
                    disabledDependants.add(pluginDescriptor);
                }
            }
        }
    }
    if (!disabled.isEmpty() || !disabledDependants.isEmpty()) {
        String message = "";
        if (disabled.size() == 1) {
            message += "Updated plugin '" + disabled.iterator().next().getName() + "' is disabled.";
        } else if (!disabled.isEmpty()) {
            message += "Updated plugins " + StringUtil.join(disabled, pluginDescriptor -> pluginDescriptor.getName(), ", ") + " are disabled.";
        }
        if (!disabledDependants.isEmpty()) {
            message += "<br>";
            message += "Updated plugin" + (list.size() > 1 ? "s depend " : " depends ") + "on disabled";
            if (disabledDependants.size() == 1) {
                message += " plugin '" + disabledDependants.iterator().next().getName() + "'.";
            } else {
                message += " plugins " + StringUtil.join(disabledDependants, pluginDescriptor -> pluginDescriptor.getName(), ", ") + ".";
            }
        }
        message += " Disabled plugins " + (disabled.isEmpty() ? "and plugins which depend on disabled " : "") + "won't be activated after restart.";
        int result;
        if (!disabled.isEmpty() && !disabledDependants.isEmpty()) {
            result = Messages.showYesNoCancelDialog(XmlStringUtil.wrapInHtml(message), CommonBundle.getWarningTitle(), "Enable all", "Enable updated plugin" + (disabled.size() > 1 ? "s" : ""), CommonBundle.getCancelButtonText(), Messages.getQuestionIcon());
            if (result == Messages.CANCEL)
                return false;
        } else {
            message += "<br>Would you like to enable ";
            if (!disabled.isEmpty()) {
                message += "updated plugin" + (disabled.size() > 1 ? "s" : "");
            } else {
                //noinspection SpellCheckingInspection
                message += "plugin dependenc" + (disabledDependants.size() > 1 ? "ies" : "y");
            }
            message += "?";
            result = Messages.showYesNoDialog(XmlStringUtil.wrapInHtml(message), CommonBundle.getWarningTitle(), Messages.getQuestionIcon());
            if (result == Messages.NO)
                return false;
        }
        if (result == Messages.YES) {
            disabled.addAll(disabledDependants);
            pluginEnabler.enablePlugins(disabled);
        } else if (result == Messages.NO && !disabled.isEmpty()) {
            pluginEnabler.enablePlugins(disabled);
        }
        return true;
    }
    return false;
}
Also used : UIUtil(com.intellij.util.ui.UIUtil) StyleSheet(javax.swing.text.html.StyleSheet) AllIcons(com.intellij.icons.AllIcons) URL(java.net.URL) JBLabel(com.intellij.ui.components.JBLabel) ApplicationEx(com.intellij.openapi.application.ex.ApplicationEx) Border(javax.swing.border.Border) SortByStatusAction(com.intellij.ide.plugins.sorters.SortByStatusAction) Task(com.intellij.openapi.progress.Task) JBUI(com.intellij.util.ui.JBUI) ApplicationNamesInfo(com.intellij.openapi.application.ApplicationNamesInfo) SearchableOptionsRegistrar(com.intellij.ide.ui.search.SearchableOptionsRegistrar) Messages(com.intellij.openapi.ui.Messages) ApplicationInfoEx(com.intellij.openapi.application.ex.ApplicationInfoEx) Logger(com.intellij.openapi.diagnostic.Logger) ProgressManager(com.intellij.openapi.progress.ProgressManager) BrowserUtil(com.intellij.ide.BrowserUtil) com.intellij.ui(com.intellij.ui) Collectors(java.util.stream.Collectors) NotificationListener(com.intellij.notification.NotificationListener) FileNotFoundException(java.io.FileNotFoundException) SearchUtil(com.intellij.ide.ui.search.SearchUtil) NotificationType(com.intellij.notification.NotificationType) JBScrollPane(com.intellij.ui.components.JBScrollPane) SpeedSearchSupply(com.intellij.ui.speedSearch.SpeedSearchSupply) IdeBundle(com.intellij.ide.IdeBundle) Notification(com.intellij.notification.Notification) EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) Nullable(org.jetbrains.annotations.Nullable) HTMLDocument(javax.swing.text.html.HTMLDocument) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) UpdateChecker(com.intellij.openapi.updateSettings.impl.UpdateChecker) List(java.util.List) ApplicationManager(com.intellij.openapi.application.ApplicationManager) XmlStringUtil(com.intellij.xml.util.XmlStringUtil) CustomLineBorder(com.intellij.ui.border.CustomLineBorder) NotNull(org.jetbrains.annotations.NotNull) PluginId(com.intellij.openapi.extensions.PluginId) java.util(java.util) BorderUIResource(javax.swing.plaf.BorderUIResource) NonNls(org.jetbrains.annotations.NonNls) ContainerUtil(com.intellij.util.containers.ContainerUtil) UiNotifyConnector(com.intellij.util.ui.update.UiNotifyConnector) HTMLEditorKit(javax.swing.text.html.HTMLEditorKit) CommonBundle(com.intellij.CommonBundle) Project(com.intellij.openapi.project.Project) DataManager(com.intellij.ide.DataManager) StringUtil.isEmptyOrSpaces(com.intellij.openapi.util.text.StringUtil.isEmptyOrSpaces) StringUtil(com.intellij.openapi.util.text.StringUtil) HTMLFrameHyperlinkEvent(javax.swing.text.html.HTMLFrameHyperlinkEvent) javax.swing.event(javax.swing.event) IOException(java.io.IOException) Disposable(com.intellij.openapi.Disposable) MouseEvent(java.awt.event.MouseEvent) java.awt(java.awt) com.intellij.openapi.actionSystem(com.intellij.openapi.actionSystem) DumbAwareAction(com.intellij.openapi.project.DumbAwareAction) JBPopupFactory(com.intellij.openapi.ui.popup.JBPopupFactory) ApplicationManagerEx(com.intellij.openapi.application.ex.ApplicationManagerEx) javax.swing(javax.swing) PluginId(com.intellij.openapi.extensions.PluginId)

Example 10 with PluginId

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

the class InstalledPluginsManagerMain method checkInstalledPluginDependencies.

private static void checkInstalledPluginDependencies(@NotNull InstalledPluginsTableModel model, @NotNull IdeaPluginDescriptorImpl pluginDescriptor, @Nullable Component parent) {
    final Set<PluginId> notInstalled = new HashSet<>();
    final Set<PluginId> disabledIds = new HashSet<>();
    final PluginId[] dependentPluginIds = pluginDescriptor.getDependentPluginIds();
    final PluginId[] optionalDependentPluginIds = pluginDescriptor.getOptionalDependentPluginIds();
    for (PluginId id : dependentPluginIds) {
        if (ArrayUtilRt.find(optionalDependentPluginIds, id) > -1)
            continue;
        final boolean disabled = model.isDisabled(id);
        final boolean enabled = model.isEnabled(id);
        if (!enabled && !disabled && !PluginManagerCore.isModuleDependency(id)) {
            notInstalled.add(id);
        } else if (disabled) {
            disabledIds.add(id);
        }
    }
    if (!notInstalled.isEmpty()) {
        String deps = StringUtil.join(notInstalled, id -> id.toString(), ", ");
        String message = "Plugin " + pluginDescriptor.getName() + " depends on unknown plugin" + (notInstalled.size() > 1 ? "s " : " ") + deps;
        MessagesEx.showWarningDialog(parent, message, CommonBundle.getWarningTitle());
    }
    if (!disabledIds.isEmpty()) {
        final Set<IdeaPluginDescriptor> dependencies = new HashSet<>();
        for (IdeaPluginDescriptor ideaPluginDescriptor : model.getAllPlugins()) {
            if (disabledIds.contains(ideaPluginDescriptor.getPluginId())) {
                dependencies.add(ideaPluginDescriptor);
            }
        }
        String part = "disabled plugin" + (dependencies.size() > 1 ? "s " : " ");
        String deps = StringUtil.join(dependencies, descriptor -> descriptor.getName(), ", ");
        String message = "Plugin " + pluginDescriptor.getName() + " depends on " + part + deps + ". Enable " + part.trim() + "?";
        if (MessagesEx.showOkCancelDialog(parent, message, CommonBundle.getWarningTitle(), Messages.getWarningIcon()) == Messages.OK) {
            model.enableRows(dependencies.toArray(new IdeaPluginDescriptor[dependencies.size()]), Boolean.TRUE);
        }
    }
}
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