cache already checked plugins (IDEA-124828)

This commit is contained in:
Anna Kozlova
2014-05-16 21:57:29 +04:00
parent 0f9f39d977
commit 3326c46adf
2 changed files with 20 additions and 123 deletions
@@ -554,123 +554,6 @@ public class InstalledPluginsTableModel extends PluginTableModel {
}
}
private class InstalledPluginsTableRenderer extends DefaultTableCellRenderer {
private JLabel myNameLabel = new JLabel();
private JLabel myBundledLabel = new JLabel();
private JPanel myPanel = new JPanel(new BorderLayout());
private final IdeaPluginDescriptor myPluginDescriptor;
public InstalledPluginsTableRenderer(IdeaPluginDescriptor pluginDescriptor) {
myPluginDescriptor = pluginDescriptor;
myNameLabel.setFont(PluginManagerColumnInfo.getNameFont());
myBundledLabel.setFont(UIUtil.getLabelFont(UIUtil.FontSize.SMALL));
myPanel.setBorder(BorderFactory.createEmptyBorder(1, 0, 1, 1));
myNameLabel.setOpaque(true);
myPanel.add(myNameLabel, BorderLayout.WEST);
myPanel.add(myBundledLabel, BorderLayout.EAST);
}
@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(JBColor.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(JBColor.RED);
}
}
return myPanel;
}
}
private class MyPluginManagerColumnInfo extends PluginManagerColumnInfo {
public MyPluginManagerColumnInfo() {
super(PluginManagerColumnInfo.COLUMN_NAME, InstalledPluginsTableModel.this);
@@ -72,6 +72,8 @@ import java.util.concurrent.TimeoutException;
public final class UpdateChecker {
private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.updateSettings.impl.UpdateChecker");
private static final Map<String, String> ourUpdatedPlugins = new HashMap<String, String>();
public enum DownloadPatchResult {
SUCCESS, FAILED, CANCELED
}
@@ -243,10 +245,13 @@ public final class UpdateChecker {
final IdeaPluginDescriptor installedPlugin = toUpdate.get(idString);
if (installedPlugin == null) {
prepareToInstall(downloaded, loadedPlugin, indicator, buildNumber);
} else if (StringUtil.compareVersionNumbers(loadedPlugin.getVersion(), installedPlugin.getVersion()) > 0) {
updateSettings.myOutdatedPlugins.add(idString);
if (!disabledPlugins.contains(idString)) {
prepareToInstall(downloaded, loadedPlugin, indicator, buildNumber);
} else {
final String newVersion = loadedPlugin.getVersion();
if (StringUtil.compareVersionNumbers(newVersion, installedPlugin.getVersion()) > 0) {
updateSettings.myOutdatedPlugins.add(idString);
if (isReadyToUpdate(idString, newVersion) && !disabledPlugins.contains(idString)) {
prepareToInstall(downloaded, loadedPlugin, indicator, buildNumber);
}
}
}
}
@@ -266,6 +271,11 @@ public final class UpdateChecker {
return downloaded.isEmpty() ? null : downloaded.values();
}
private static boolean isReadyToUpdate(String idString, String newVersion) {
final String oldVersion = ourUpdatedPlugins.put(idString, newVersion);
return oldVersion == null || StringUtil.compareVersionNumbers(newVersion, oldVersion) > 0;
}
private static void prepareToInstall(Map<PluginId, PluginDownloader> downloaded,
IdeaPluginDescriptor loadedPlugin,
@Nullable ProgressIndicator indicator,
@@ -386,8 +396,12 @@ public final class UpdateChecker {
progressIndicator.setText2(finalPluginUrl);
}
final PluginDownloader downloader = new PluginDownloader(pluginId, finalPluginUrl, pluginVersion);
if (downloader.prepareToInstall(progressIndicator, buildNumber)) {
downloaded.put(PluginId.getId(pluginId), downloader);
final IdeaPluginDescriptor loadedPlugin = PluginManager.getPlugin(PluginId.getId(pluginId));
if (loadedPlugin == null || pluginVersion == null ||
StringUtil.compareVersionNumbers(pluginVersion, loadedPlugin.getVersion()) > 0) {
if (isReadyToUpdate(pluginId, pluginVersion) && downloader.prepareToInstall(progressIndicator, buildNumber)) {
downloaded.put(PluginId.getId(pluginId), downloader);
}
}
}
catch (IOException e) {