mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-10-01 17:03:12 +07:00
update checker: download plugin on actual update if since/until is available
This commit is contained in:
+4
@@ -93,6 +93,10 @@ public class PluginDownloader {
|
||||
}
|
||||
|
||||
public boolean prepareToInstall(@Nullable ProgressIndicator pi, @Nullable BuildNumber forBuildNumber) throws IOException {
|
||||
if (myFile != null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
IdeaPluginDescriptor descriptor = null;
|
||||
if (!Boolean.getBoolean(StartupActionScriptManager.STARTUP_WIZARD_MODE) && PluginManager.isPluginInstalled(PluginId.getId(myPluginId))) {
|
||||
//store old plugins file
|
||||
|
||||
+43
-13
@@ -16,9 +16,13 @@
|
||||
package com.intellij.openapi.updateSettings.impl;
|
||||
|
||||
import com.intellij.ide.IdeBundle;
|
||||
import com.intellij.ide.plugins.PluginManagerConfigurable;
|
||||
import com.intellij.openapi.ui.Messages;
|
||||
import com.intellij.ide.plugins.PluginManagerMain;
|
||||
import com.intellij.openapi.progress.ProgressIndicator;
|
||||
import com.intellij.openapi.progress.ProgressManager;
|
||||
import com.intellij.openapi.progress.Task;
|
||||
import com.intellij.openapi.util.Ref;
|
||||
import com.intellij.ui.TableUtil;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
@@ -61,20 +65,46 @@ class PluginUpdateInfoDialog extends AbstractUpdateDialog {
|
||||
|
||||
@Override
|
||||
protected void doOKAction() {
|
||||
if (downloadPlugins() && toRestart()) {
|
||||
restart();
|
||||
}
|
||||
|
||||
super.doOKAction();
|
||||
final Ref<Boolean> result = new Ref<>();
|
||||
Runnable runnable = new Runnable() {
|
||||
public void run() {
|
||||
UpdateChecker.saveDisabledToUpdatePlugins();
|
||||
result.set(UpdateChecker.install(myUploadedPlugins));
|
||||
}
|
||||
};
|
||||
|
||||
final String progressTitle = "Download plugins...";
|
||||
if (downloadModal()) {
|
||||
ProgressManager.getInstance().runProcessWithProgressSynchronously(runnable, progressTitle, true, null);
|
||||
} else {
|
||||
ProgressManager.getInstance().run(new Task.Backgroundable(null, progressTitle, true) {
|
||||
@Override
|
||||
public void run(@NotNull ProgressIndicator indicator) {
|
||||
runnable.run();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess() {
|
||||
final Boolean installed = result.get();
|
||||
if (installed != null && installed.booleanValue()) {
|
||||
final String pluginName;
|
||||
if (myUploadedPlugins.size() == 1) {
|
||||
final PluginDownloader firstItem = ContainerUtil.getFirstItem(myUploadedPlugins);
|
||||
pluginName = firstItem != null ? firstItem.getPluginName() : null;
|
||||
}
|
||||
else {
|
||||
pluginName = null;
|
||||
}
|
||||
PluginManagerMain.notifyPluginsWereInstalled(pluginName, null);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean toRestart() {
|
||||
return PluginManagerConfigurable.showRestartIDEADialog() == Messages.YES;
|
||||
}
|
||||
|
||||
private boolean downloadPlugins() {
|
||||
UpdateChecker.saveDisabledToUpdatePlugins();
|
||||
return UpdateChecker.install(myUploadedPlugins);
|
||||
protected boolean downloadModal() {
|
||||
return false;
|
||||
}
|
||||
|
||||
private class PluginUpdateInfoPanel {
|
||||
|
||||
+45
-36
@@ -248,7 +248,7 @@ public final class UpdateChecker {
|
||||
final String idString = pluginId.getIdString();
|
||||
if (!toUpdate.containsKey(idString)) continue;
|
||||
if (!downloaded.containsKey(pluginId)) {
|
||||
prepareToInstall(indicator, idString, getDownloadUrl(loadedPlugin), loadedPlugin.getVersion(), loadedPlugin.getName(), buildNumber, downloaded, incompatiblePlugins);
|
||||
prepareToInstall(buildNumber, downloaded, incompatiblePlugins, PluginDownloader.createDownloader(loadedPlugin), indicator);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -272,42 +272,48 @@ public final class UpdateChecker {
|
||||
return oldPlugin == null || StringUtil.compareVersionNumbers(newVersion, oldPlugin.getPluginVersion()) > 0;
|
||||
}
|
||||
|
||||
private static void prepareToInstall(ProgressIndicator progressIndicator,
|
||||
String pluginId,
|
||||
String finalPluginUrl,
|
||||
String pluginVersion,
|
||||
String pluginName,
|
||||
BuildNumber buildNumber,
|
||||
private static void prepareToInstall(BuildNumber buildNumber,
|
||||
Map<PluginId, PluginDownloader> downloaded,
|
||||
Collection<IdeaPluginDescriptor> incompatiblePlugins) throws IOException {
|
||||
Collection<IdeaPluginDescriptor> incompatiblePlugins,
|
||||
PluginDownloader downloader,
|
||||
ProgressIndicator indicator) throws IOException {
|
||||
final String pluginId = downloader.getPluginId();
|
||||
final String pluginVersion = downloader.getPluginVersion();
|
||||
final List<String> disabledPlugins = PluginManagerCore.getDisabledPlugins();
|
||||
if (disabledPlugins.contains(pluginId)) return;
|
||||
final PluginDownloader downloader = new PluginDownloader(pluginId, finalPluginUrl, pluginVersion, null, pluginName);
|
||||
final IdeaPluginDescriptor loadedPlugin = PluginManager.getPlugin(PluginId.getId(pluginId));
|
||||
if (loadedPlugin == null || pluginVersion == null ||
|
||||
PluginDownloader.compareVersionsSkipBroken(loadedPlugin, pluginVersion) > 0) {
|
||||
final IdeaPluginDescriptor installedPlugin = PluginManager.getPlugin(PluginId.getId(pluginId));
|
||||
if (installedPlugin == null || pluginVersion == null ||
|
||||
PluginDownloader.compareVersionsSkipBroken(installedPlugin, pluginVersion) > 0) {
|
||||
|
||||
IdeaPluginDescriptor descriptor = null;
|
||||
if (isReadyToUpdate(pluginId, pluginVersion)) {
|
||||
if (downloader.prepareToInstall(progressIndicator, buildNumber)) {
|
||||
downloaded.put(PluginId.getId(pluginId), downloader);
|
||||
descriptor = downloader.getDescriptor();
|
||||
if (descriptor == null) {
|
||||
if (downloader.prepareToInstall(indicator, buildNumber)) {
|
||||
descriptor = downloader.getDescriptor();
|
||||
}
|
||||
ourUpdatedPlugins.put(pluginId, downloader);
|
||||
}
|
||||
} else {
|
||||
final PluginDownloader oldDownloader = ourUpdatedPlugins.get(pluginId);
|
||||
if (oldDownloader != null) {
|
||||
downloaded.put(PluginId.getId(pluginId), oldDownloader);
|
||||
downloader = oldDownloader;
|
||||
descriptor = oldDownloader.getDescriptor();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (loadedPlugin != null && !downloaded.containsKey(loadedPlugin.getPluginId())) {
|
||||
collectIncompatible(incompatiblePlugins, buildNumber, loadedPlugin);
|
||||
}
|
||||
}
|
||||
|
||||
private static void collectIncompatible(Collection<IdeaPluginDescriptor> incompatiblePlugins,
|
||||
BuildNumber buildNumber,
|
||||
IdeaPluginDescriptor descriptor) {
|
||||
if (incompatiblePlugins != null && descriptor != null && descriptor.isEnabled() && PluginManagerCore.isIncompatible(descriptor, buildNumber)) {
|
||||
incompatiblePlugins.add(descriptor);
|
||||
if (descriptor != null &&
|
||||
!PluginManagerCore.isIncompatible(descriptor, buildNumber) &&
|
||||
!InstalledPluginsTableModel.wasUpdated(descriptor.getPluginId())) {
|
||||
downloaded.put(PluginId.getId(pluginId), downloader);
|
||||
}
|
||||
}
|
||||
|
||||
//collect plugins which were not updated and would be incompatible with new version
|
||||
if (incompatiblePlugins != null &&
|
||||
installedPlugin != null && installedPlugin.isEnabled() && !downloaded.containsKey(installedPlugin.getPluginId()) &&
|
||||
PluginManagerCore.isIncompatible(installedPlugin, buildNumber)) {
|
||||
incompatiblePlugins.add(installedPlugin);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -377,7 +383,7 @@ public final class UpdateChecker {
|
||||
final List<IdeaPluginDescriptor> descriptors = RepositoryHelper.loadPluginsFromDescription(inputStream, indicator);
|
||||
for (IdeaPluginDescriptor descriptor : descriptors) {
|
||||
((PluginNode)descriptor).setRepositoryName(host);
|
||||
prepareToInstall(indicator, descriptor.getPluginId().getIdString(), ((PluginNode)descriptor).getDownloadUrl(), descriptor.getVersion(), descriptor.getName(), buildNumber, downloaded, incompatiblePlugins);
|
||||
prepareToInstall(buildNumber, downloaded, incompatiblePlugins, PluginDownloader.createDownloader(descriptor), indicator);
|
||||
downloaded.put(descriptor.getPluginId(), PluginDownloader.createDownloader(descriptor));
|
||||
}
|
||||
|
||||
@@ -425,7 +431,8 @@ public final class UpdateChecker {
|
||||
if (progressIndicator != null) {
|
||||
progressIndicator.setText2(finalPluginUrl);
|
||||
}
|
||||
prepareToInstall(progressIndicator, pluginId, finalPluginUrl, pluginVersion, null, buildNumber, downloaded, incompatiblePlugins);
|
||||
final PluginDownloader downloader = new PluginDownloader(pluginId, finalPluginUrl, pluginVersion, null, null);
|
||||
prepareToInstall(buildNumber, downloaded, incompatiblePlugins, downloader, indicator);
|
||||
}
|
||||
catch (IOException e) {
|
||||
LOG.info(e);
|
||||
@@ -705,17 +712,19 @@ public final class UpdateChecker {
|
||||
boolean installed = false;
|
||||
for (PluginDownloader downloader : downloaders) {
|
||||
if (getDisabledToUpdatePlugins().contains(downloader.getPluginId())) continue;
|
||||
final IdeaPluginDescriptor descriptor = downloader.getDescriptor();
|
||||
if (descriptor != null) {
|
||||
try {
|
||||
InstalledPluginsTableModel.updateExistingPlugin(descriptor, PluginManager.getPlugin(descriptor.getPluginId()));
|
||||
downloader.install();
|
||||
installed = true;
|
||||
}
|
||||
catch (IOException e) {
|
||||
LOG.info(e);
|
||||
try {
|
||||
if (downloader.prepareToInstall(ProgressManager.getInstance().getProgressIndicator())) {
|
||||
final IdeaPluginDescriptor descriptor = downloader.getDescriptor();
|
||||
if (descriptor != null) {
|
||||
InstalledPluginsTableModel.updateExistingPlugin(descriptor, PluginManager.getPlugin(descriptor.getPluginId()));
|
||||
downloader.install();
|
||||
installed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (IOException e) {
|
||||
LOG.info(e);
|
||||
}
|
||||
}
|
||||
return installed;
|
||||
}
|
||||
|
||||
+1
-1
@@ -144,7 +144,7 @@ class UpdateInfoDialog extends AbstractUpdateDialog {
|
||||
if (myUpdatedPlugins != null && !myUpdatedPlugins.isEmpty()) {
|
||||
new PluginUpdateInfoDialog(getContentPanel(), myUpdatedPlugins, true){
|
||||
@Override
|
||||
protected boolean toRestart() {
|
||||
protected boolean downloadModal() {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user