@Override public void update(AnActionEvent e) { Presentation presentation = e.getPresentation(); IdeaPluginDescriptor[] selection = getPluginTable().getSelectedObjects(); boolean enabled = (selection != null); if (enabled) { for (IdeaPluginDescriptor descr : selection) { presentation.setText(IdeBundle.message("action.download.and.install.plugin")); presentation.setDescription(IdeBundle.message("action.download.and.install.plugin")); enabled &= !ourInstallingNodes.contains(descr); if (descr instanceof PluginNode) { enabled &= !PluginManagerColumnInfo.isDownloaded((PluginNode) descr); if (((PluginNode) descr).getStatus() == PluginNode.STATUS_INSTALLED) { presentation.setText(IdeBundle.message("action.update.plugin")); presentation.setDescription(IdeBundle.message("action.update.plugin")); enabled &= ourState.hasNewerVersion(descr.getPluginId()); } } else if (descr instanceof IdeaPluginDescriptorImpl) { presentation.setText(IdeBundle.message("action.update.plugin")); presentation.setDescription(IdeBundle.message("action.update.plugin")); PluginId id = descr.getPluginId(); enabled = enabled && ourState.hasNewerVersion(id); } } } presentation.setEnabled(enabled); }
private static boolean isPluginInRepo( PluginId depPluginId, List<IdeaPluginDescriptor> allPlugins) { for (IdeaPluginDescriptor plugin : allPlugins) { if (plugin.getPluginId().equals(depPluginId)) { return true; } } return false; }
public void enableRows(IdeaPluginDescriptor[] ideaPluginDescriptors, Boolean value) { for (IdeaPluginDescriptor ideaPluginDescriptor : ideaPluginDescriptors) { final PluginId currentPluginId = ideaPluginDescriptor.getPluginId(); final Boolean enabled = myEnabled.get(currentPluginId) == null ? Boolean.FALSE : value; myEnabled.put(currentPluginId, enabled); } updatePluginDependencies(); warnAboutMissedDependencies(value, ideaPluginDescriptors); hideNotApplicablePlugins(value, ideaPluginDescriptors); }
@Nullable public static IdeaPluginDescriptor getPlugin(PluginId id) { final IdeaPluginDescriptor[] plugins = getPlugins(); for (final IdeaPluginDescriptor plugin : plugins) { if (Comparing.equal(id, plugin.getPluginId())) { return plugin; } } return null; }
private static void updateExistingPluginInfo( IdeaPluginDescriptor descr, IdeaPluginDescriptor existing) { int state = StringUtil.compareVersionNumbers(descr.getVersion(), existing.getVersion()); final PluginId pluginId = existing.getPluginId(); final String idString = pluginId.getIdString(); final JDOMExternalizableStringList installedPlugins = PluginManagerUISettings.getInstance().getInstalledPlugins(); if (!installedPlugins.contains(idString) && !((IdeaPluginDescriptorImpl) existing).isDeleted()) { installedPlugins.add(idString); } final PluginManagerUISettings updateSettings = PluginManagerUISettings.getInstance(); if (state > 0 && !PluginManager.isIncompatible(descr) && !updatedPlugins.contains(descr.getPluginId())) { NewVersions2Plugins.put(pluginId, 1); if (!updateSettings.myOutdatedPlugins.contains(idString)) { updateSettings.myOutdatedPlugins.add(idString); } final IdeaPluginDescriptorImpl plugin = (IdeaPluginDescriptorImpl) existing; plugin.setDownloadsCount(descr.getDownloads()); plugin.setVendor(descr.getVendor()); plugin.setVendorEmail(descr.getVendorEmail()); plugin.setVendorUrl(descr.getVendorUrl()); plugin.setUrl(descr.getUrl()); } else { updateSettings.myOutdatedPlugins.remove(idString); if (NewVersions2Plugins.remove(pluginId) != null) { updatedPlugins.add(pluginId); } } }
public static void prepareToUninstall(PluginId pluginId) throws IOException { synchronized (PluginManager.lock) { if (PluginManager.isPluginInstalled(pluginId)) { // add command to delete the 'action script' file IdeaPluginDescriptor pluginDescriptor = PluginManager.getPlugin(pluginId); StartupActionScriptManager.ActionCommand deleteOld = new StartupActionScriptManager.DeleteCommand(pluginDescriptor.getPath()); StartupActionScriptManager.addActionCommand(deleteOld); } } }
public ArrayList<IdeaPluginDescriptorImpl> dependent(IdeaPluginDescriptorImpl plugin) { ArrayList<IdeaPluginDescriptorImpl> list = new ArrayList<IdeaPluginDescriptorImpl>(); for (IdeaPluginDescriptor any : getAllPlugins()) { if (any instanceof IdeaPluginDescriptorImpl) { PluginId[] dep = any.getDependentPluginIds(); for (PluginId id : dep) { if (id == plugin.getPluginId()) { list.add((IdeaPluginDescriptorImpl) any); break; } } } } return list; }
public static void updateExistingPlugin( IdeaPluginDescriptor descriptor, IdeaPluginDescriptor existing) { if (existing != null) { updateExistingPluginInfo(descriptor, existing); updatedPlugins.add(existing.getPluginId()); } }
public void setValue(final IdeaPluginDescriptor ideaPluginDescriptor, Boolean value) { final PluginId currentPluginId = ideaPluginDescriptor.getPluginId(); final Boolean enabled = myEnabled.get(currentPluginId) == null ? Boolean.FALSE : value; myEnabled.put(currentPluginId, enabled); updatePluginDependencies(); warnAboutMissedDependencies(enabled, ideaPluginDescriptor); hideNotApplicablePlugins(value, ideaPluginDescriptor); }
private void updatePluginDependencies() { myDependentToRequiredListMap.clear(); final int rowCount = getRowCount(); for (int i = 0; i < rowCount; i++) { final IdeaPluginDescriptor descriptor = getObjectAt(i); final PluginId pluginId = descriptor.getPluginId(); myDependentToRequiredListMap.remove(pluginId); if (descriptor instanceof IdeaPluginDescriptorImpl && ((IdeaPluginDescriptorImpl) descriptor).isDeleted()) continue; final Boolean enabled = myEnabled.get(pluginId); if (enabled == null || enabled.booleanValue()) { PluginManager.checkDependants( descriptor, new Function<PluginId, IdeaPluginDescriptor>() { @Nullable public IdeaPluginDescriptor fun(final PluginId pluginId) { return PluginManager.getPlugin(pluginId); } }, new Condition<PluginId>() { public boolean value(final PluginId dependantPluginId) { final Boolean enabled = myEnabled.get(dependantPluginId); if (enabled == null || !enabled.booleanValue()) { Set<PluginId> required = myDependentToRequiredListMap.get(pluginId); if (required == null) { required = new HashSet<PluginId>(); myDependentToRequiredListMap.put(pluginId, required); } required.add(dependantPluginId); // return false; } return true; } }); if (enabled == null && !myDependentToRequiredListMap.containsKey(pluginId) && !PluginManager.isIncompatible(descriptor)) { myEnabled.put(pluginId, true); } } } }
@Override public boolean isPluginDescriptorAccepted(IdeaPluginDescriptor descriptor) { if (myEnabledFilter != ENABLED_DISABLED) { final boolean enabled = isEnabled(descriptor.getPluginId()); if (enabled && myEnabledFilter == DISABLED) return false; if (!enabled && myEnabledFilter == ENABLED) return false; } return true; }
private void setEnabled(IdeaPluginDescriptor ideaPluginDescriptor, final boolean enabled) { final Collection<String> disabledPlugins = PluginManager.getDisabledPlugins(); final PluginId pluginId = ideaPluginDescriptor.getPluginId(); if (!enabled && !disabledPlugins.contains(pluginId.toString())) { myEnabled.put(pluginId, null); } else { myEnabled.put(pluginId, enabled); } }
public void appendOrUpdateDescriptor(IdeaPluginDescriptor descriptor) { final PluginId descrId = descriptor.getPluginId(); final IdeaPluginDescriptor existing = PluginManager.getPlugin(descrId); if (existing != null) { updateExistingPlugin(descriptor, existing); } else { myInstalled.add(descriptor); view.add(descriptor); setEnabled(descriptor, true); fireTableDataChanged(); } }
private boolean installSelected(PluginTable pluginTable) { IdeaPluginDescriptor[] selection = pluginTable.getSelectedObjects(); if (selection != null) { boolean enabled = true; for (IdeaPluginDescriptor descr : selection) { if (descr instanceof PluginNode) { enabled &= !PluginManagerColumnInfo.isDownloaded((PluginNode) descr); if (((PluginNode) descr).getStatus() == PluginNode.STATUS_INSTALLED) { enabled &= InstalledPluginsTableModel.hasNewerVersion(descr.getPluginId()); } } else if (descr instanceof IdeaPluginDescriptorImpl) { PluginId id = descr.getPluginId(); enabled &= InstalledPluginsTableModel.hasNewerVersion(id); } } if (enabled) { new ActionInstallPlugin(this, installed).install(); } return true; } return false; }
public void updatePluginsList(List<IdeaPluginDescriptor> list) { // For each downloadable plugin we need to know whether its counterpart // is already installed, and if yes compare the difference in versions: // availability of newer versions will be indicated separately. for (IdeaPluginDescriptor descr : list) { PluginId descrId = descr.getPluginId(); IdeaPluginDescriptor existing = PluginManager.getPlugin(descrId); if (existing != null) { if (descr instanceof PluginNode) { updateExistingPluginInfo(descr, existing); } else { view.add(descr); setEnabled(descr); } } } for (IdeaPluginDescriptor descriptor : myInstalled) { if (!view.contains(descriptor)) { view.add(descriptor); } } fireTableDataChanged(); }
@Override public Component getTableCellRendererComponent( JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { final Component orig = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); if (myPluginDescriptor != null) { myNameLabel.setText(myPluginDescriptor.getName()); final PluginId pluginId = myPluginDescriptor.getPluginId(); final String idString = pluginId.getIdString(); if (myPluginDescriptor.isBundled()) { myBundledLabel.setText("Bundled"); } else { final String host = myPlugin2host.get(idString); if (host != null) { String presentableUrl = VfsUtil.urlToPath(host); final int idx = presentableUrl.indexOf('/'); if (idx > -1) { presentableUrl = presentableUrl.substring(0, idx); } myBundledLabel.setText("From " + presentableUrl); } else { if (PluginManagerUISettings.getInstance().getInstalledPlugins().contains(idString)) { myBundledLabel.setText("From repository"); } else { myBundledLabel.setText("Custom"); } } } if (myPluginDescriptor instanceof IdeaPluginDescriptorImpl && ((IdeaPluginDescriptorImpl) myPluginDescriptor).isDeleted()) { myNameLabel.setIcon(AllIcons.Actions.Clean); } else if (hasNewerVersion(pluginId)) { myNameLabel.setIcon(AllIcons.Nodes.Pluginobsolete); myPanel.setToolTipText("Newer version of the plugin is available"); } else { myNameLabel.setIcon(AllIcons.Nodes.Plugin); } final Color fg = orig.getForeground(); final Color bg = orig.getBackground(); final Color grayedFg = isSelected ? fg : Color.GRAY; myPanel.setBackground(bg); myNameLabel.setBackground(bg); myBundledLabel.setBackground(bg); myNameLabel.setForeground(fg); final boolean wasUpdated = wasUpdated(pluginId); if (wasUpdated || PluginManager.getPlugin(pluginId) == null) { if (!isSelected) { myNameLabel.setForeground(FileStatus.COLOR_ADDED); } if (wasUpdated) { myPanel.setToolTipText( "Plugin was updated to the newest version. Changes will be available after restart"); } else { myPanel.setToolTipText("Plugin will be activated after restart."); } } myBundledLabel.setForeground(grayedFg); final Set<PluginId> required = myDependentToRequiredListMap.get(pluginId); if (required != null && required.size() > 0) { myNameLabel.setForeground(Color.RED); final StringBuilder s = new StringBuilder(); if (myEnabled.get(pluginId) == null) { s.append("Plugin was not loaded.\n"); } if (required.contains(PluginId.getId("com.intellij.modules.ultimate"))) { s.append("The plugin requires IntelliJ IDEA Ultimate"); } else { s.append("Required plugin").append(required.size() == 1 ? " \"" : "s \""); s.append( StringUtil.join( required, new Function<PluginId, String>() { @Override public String fun(final PluginId id) { final IdeaPluginDescriptor plugin = PluginManager.getPlugin(id); return plugin == null ? id.getIdString() : plugin.getName(); } }, ",")); s.append(required.size() == 1 ? "\" is not enabled!" : "\" are not enabled!"); } myPanel.setToolTipText(s.toString()); } if (PluginManager.isIncompatible(myPluginDescriptor)) { myPanel.setToolTipText( IdeBundle.message( "plugin.manager.incompatible.tooltip.warning", ApplicationNamesInfo.getInstance().getFullProductName())); myNameLabel.setForeground(Color.red); } } return myPanel; }
private void warnAboutMissedDependencies( final Boolean newVal, final IdeaPluginDescriptor... ideaPluginDescriptors) { final Set<PluginId> deps = new HashSet<PluginId>(); final List<IdeaPluginDescriptor> descriptorsToCheckDependencies = new ArrayList<IdeaPluginDescriptor>(); if (newVal) { Collections.addAll(descriptorsToCheckDependencies, ideaPluginDescriptors); } else { descriptorsToCheckDependencies.addAll(view); descriptorsToCheckDependencies.addAll(filtered); 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) { PluginManager.checkDependants( ideaPluginDescriptor, new Function<PluginId, IdeaPluginDescriptor>() { @Nullable public IdeaPluginDescriptor fun(final PluginId pluginId) { return PluginManager.getPlugin(pluginId); } }, new Condition<PluginId>() { public boolean value(final PluginId pluginId) { Boolean enabled = myEnabled.get(pluginId); if (enabled == null) { return false; } if (newVal && !enabled.booleanValue()) { deps.add(pluginId); } if (!newVal) { 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, new Function<IdeaPluginDescriptor, String>() { @Override public String fun(IdeaPluginDescriptor pluginDescriptor) { return pluginDescriptor.getName(); } }, ", "); final Set<IdeaPluginDescriptor> pluginDependencies = new HashSet<IdeaPluginDescriptor>(); final String listOfDependencies = StringUtil.join( deps, new Function<PluginId, String>() { public String fun(final PluginId 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()) == DialogWrapper.OK_EXIT_CODE) { for (PluginId pluginId : deps) { myEnabled.put(pluginId, newVal); } updatePluginDependencies(); hideNotApplicablePlugins( newVal, pluginDependencies.toArray(new IdeaPluginDescriptor[pluginDependencies.size()])); } } }
public void install(@Nullable final Runnable onSuccess, boolean confirmed) { IdeaPluginDescriptor[] selection = getPluginTable().getSelectedObjects(); if (confirmed || userConfirm(selection)) { final List<PluginNode> list = new ArrayList<PluginNode>(); for (IdeaPluginDescriptor descr : selection) { PluginNode pluginNode = null; if (descr instanceof PluginNode) { pluginNode = (PluginNode) descr; } else if (descr instanceof IdeaPluginDescriptorImpl) { PluginId pluginId = descr.getPluginId(); pluginNode = new PluginNode(pluginId); pluginNode.setName(descr.getName()); pluginNode.setDepends( Arrays.asList(descr.getDependentPluginIds()), descr.getOptionalDependentPluginIds()); pluginNode.setSize("-1"); pluginNode.setRepositoryName(PluginInstaller.UNKNOWN_HOST_MARKER); } if (pluginNode != null) { list.add(pluginNode); ourInstallingNodes.add(pluginNode); } } final InstalledPluginsTableModel installedModel = (InstalledPluginsTableModel) myInstalled.getPluginsModel(); final Set<IdeaPluginDescriptor> disabled = new HashSet<IdeaPluginDescriptor>(); final Set<IdeaPluginDescriptor> disabledDependants = new HashSet<IdeaPluginDescriptor>(); for (PluginNode node : list) { final PluginId pluginId = node.getPluginId(); if (installedModel.isDisabled(pluginId)) { disabled.add(node); } final List<PluginId> depends = node.getDepends(); if (depends != null) { final Set<PluginId> optionalDeps = new HashSet<PluginId>(Arrays.asList(node.getOptionalDependentPluginIds())); for (PluginId dependantId : depends) { if (optionalDeps.contains(dependantId)) continue; final IdeaPluginDescriptor pluginDescriptor = PluginManager.getPlugin(dependantId); if (pluginDescriptor != null && installedModel.isDisabled(dependantId)) { disabledDependants.add(pluginDescriptor); } } } } if (suggestToEnableInstalledPlugins(installedModel, disabled, disabledDependants, list)) { myInstalled.setRequireShutdown(true); } try { Runnable onInstallRunnable = new Runnable() { @Override public void run() { for (PluginNode node : list) { installedModel.appendOrUpdateDescriptor(node); } if (!myInstalled.isDisposed()) { getPluginTable().updateUI(); myInstalled.setRequireShutdown(true); } else { boolean needToRestart = false; for (PluginNode node : list) { final IdeaPluginDescriptor pluginDescriptor = PluginManager.getPlugin(node.getPluginId()); if (pluginDescriptor == null || pluginDescriptor.isEnabled()) { needToRestart = true; break; } } if (needToRestart) { PluginManagerMain.notifyPluginsUpdated(null); } } if (onSuccess != null) { onSuccess.run(); } } }; Runnable cleanupRunnable = new Runnable() { @Override public void run() { ourInstallingNodes.removeAll(list); } }; PluginManagerMain.downloadPlugins( list, myHost.getPluginsModel().getAllPlugins(), onInstallRunnable, cleanupRunnable); } catch (final IOException e1) { ourInstallingNodes.removeAll(list); PluginManagerMain.LOG.error(e1); //noinspection SSBasedInspection SwingUtilities.invokeLater( new Runnable() { @Override public void run() { IOExceptionDialog.showErrorDialog( IdeBundle.message("action.download.and.install.plugin"), IdeBundle.message("error.plugin.download.failed")); } }); } } }
public Boolean valueOf(IdeaPluginDescriptor ideaPluginDescriptor) { return myEnabled.get(ideaPluginDescriptor.getPluginId()); }
private void setEnabled(IdeaPluginDescriptor ideaPluginDescriptor) { setEnabled(ideaPluginDescriptor, ideaPluginDescriptor.isEnabled()); }