IDEA-136333 (show connection errors)
authorRoman Shevchenko <roman.shevchenko@jetbrains.com>
Thu, 12 Feb 2015 14:27:58 +0000 (15:27 +0100)
committerRoman Shevchenko <roman.shevchenko@jetbrains.com>
Thu, 12 Feb 2015 14:27:58 +0000 (15:27 +0100)
platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/UpdateChecker.java
platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/UpdateInfoDialog.java
platform/platform-resources-en/src/messages/IdeBundle.properties

index 1ced92ad9f9786971acbf1864bfc8ce06a048900..536c012e3347394cd04fd13ce24d3156286ed422 100644 (file)
@@ -68,10 +68,6 @@ import java.util.*;
 public final class UpdateChecker {
   private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.updateSettings.impl.UpdateChecker");
 
-  public enum DownloadPatchResult {
-    SUCCESS, FAILED, CANCELED
-  }
-
   public static final NotificationGroup NOTIFICATIONS =
     new NotificationGroup(IdeBundle.message("update.notifications.group"), NotificationDisplayType.STICKY_BALLOON, true);
 
@@ -535,28 +531,15 @@ public final class UpdateChecker {
     return "";
   }
 
-  public static DownloadPatchResult installPlatformUpdate(final PatchInfo patch, final BuildNumber toBuild, final boolean forceHttps) {
-    final Ref<DownloadPatchResult> result = Ref.create(DownloadPatchResult.CANCELED);
-
-    if (!ProgressManager.getInstance().runProcessWithProgressSynchronously(new Runnable() {
+  public static void installPlatformUpdate(final PatchInfo patch, final BuildNumber toBuild, final boolean forceHttps) throws IOException {
+    ProgressManager.getInstance().runProcessWithProgressSynchronously(new ThrowableComputable<Void, IOException>() {
       @Override
-      public void run() {
-        try {
-          ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
-          downloadAndInstallPatch(patch, toBuild, forceHttps, indicator);
-          result.set(DownloadPatchResult.SUCCESS);
-        }
-        catch (IOException e) {
-          LOG.info(e);
-          result.set(DownloadPatchResult.FAILED);
-          Notifications.Bus.notify(new Notification("Updater", "Failed to download patch file", e.getMessage(), NotificationType.ERROR));
-        }
+      public Void compute() throws IOException {
+        ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
+        downloadAndInstallPatch(patch, toBuild, forceHttps, indicator);
+        return null;
       }
-    }, IdeBundle.message("update.downloading.patch.progress.title"), true, null)) {
-      return DownloadPatchResult.CANCELED;
-    }
-
-    return result.get();
+    }, IdeBundle.message("update.downloading.patch.progress.title"), true, null);
   }
 
   private static void downloadAndInstallPatch(PatchInfo patch, BuildNumber toBuild, boolean forceHttps, final ProgressIndicator indicator) throws IOException {
index e3d62b3afcc4dd2d4f93fdcd32d804e3ed0febd9..99e3d59c43f261bf47a6d44ead2c915525fbef09 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2000-2014 JetBrains s.r.o.
+ * Copyright 2000-2015 JetBrains s.r.o.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -15,6 +15,7 @@
  */
 package com.intellij.openapi.updateSettings.impl;
 
+import com.intellij.CommonBundle;
 import com.intellij.ide.BrowserUtil;
 import com.intellij.ide.IdeBundle;
 import com.intellij.ide.plugins.IdeaPluginDescriptor;
@@ -23,6 +24,8 @@ import com.intellij.openapi.application.ApplicationManager;
 import com.intellij.openapi.application.ApplicationNamesInfo;
 import com.intellij.openapi.application.PathManager;
 import com.intellij.openapi.application.ex.ApplicationInfoEx;
+import com.intellij.openapi.diagnostic.Logger;
+import com.intellij.openapi.ui.Messages;
 import com.intellij.openapi.util.text.StringUtil;
 import com.intellij.ui.BrowserHyperlinkListener;
 import com.intellij.ui.JBColor;
@@ -34,6 +37,7 @@ import org.jetbrains.annotations.NotNull;
 import javax.swing.*;
 import java.awt.event.ActionEvent;
 import java.io.File;
+import java.io.IOException;
 import java.util.Collection;
 import java.util.List;
 
@@ -139,15 +143,22 @@ class UpdateInfoDialog extends AbstractUpdateDialog {
   }
 
   private void downloadPatch() {
-    UpdateChecker.DownloadPatchResult result = UpdateChecker.installPlatformUpdate(myPatch, myLatestBuild.getNumber(), myForceHttps);
-    if (result == UpdateChecker.DownloadPatchResult.SUCCESS) {
-      if (myUpdatedPlugins != null && !myUpdatedPlugins.isEmpty()) {
-        new PluginUpdateInfoDialog(getContentPanel(), myUpdatedPlugins).show();
+    try {
+      UpdateChecker.installPlatformUpdate(myPatch, myLatestBuild.getNumber(), myForceHttps);
+    }
+    catch (IOException e) {
+      Logger.getInstance(UpdateChecker.class).warn(e);
+      if (Messages.showOkCancelDialog(IdeBundle.message("update.downloading.patch.error", e.getMessage()),
+                                      IdeBundle.message("updates.error.connection.title"),
+                                      IdeBundle.message("updates.download.page.button"), CommonBundle.message("button.cancel"),
+                                      Messages.getErrorIcon()) == Messages.OK) {
+        openDownloadPage();
       }
-      restart();
+      return;
     }
-    else if (result == UpdateChecker.DownloadPatchResult.FAILED) {
-      openDownloadPage();
+
+    if (myUpdatedPlugins != null && !myUpdatedPlugins.isEmpty()) {
+      new PluginUpdateInfoDialog(getContentPanel(), myUpdatedPlugins).show();
     }
   }
 
index 105cd16d548241dbd5ea100a7518e5607975bbbb..5de712dc4af0c6afbeb67043e68afda9bec330cd 100644 (file)
@@ -917,6 +917,7 @@ updates.incompatible.plugins.found={0,choice,1#Plugin|2#Plugins} incompatible wi
 updates.download.and.install.button=&Download Patch and Shutdown
 updates.download.and.restart.button=Up&date and Restart
 updates.more.info.button=&More Info...
+updates.download.page.button=Open &Download Page
 updates.ignore.update.button=&Ignore This Update
 updates.remind.later.button=&Remind Me Later
 updates.buy.online.button=&Buy Upgrade Online
@@ -934,6 +935,15 @@ updates.settings.secure=Use secure connection
 updates.settings.build.number=Build number:
 updates.settings.current.version=Current version:
 updates.settings.last.check=Last checked:
+update.plugin.host.url.message=Repository URL:
+update.no.update.hosts=No plugin repositories configured
+update.edit.plugin.host.title=Edit Repository
+update.add.new.plugin.host.title=Add Repository
+update.downloading.patch.progress.title=Downloading Patch File
+update.downloading.patch.error=Failed to download patch file:\n{0}
+update.plugins.update.action=&Update
+update.restart.plugins.update.action=&Update and Restart
+update.shutdown.plugins.update.action=&Update and Shutdown
 
 hierarchy.method.next.occurence.name=Go to next method
 hierarchy.method.prev.occurence.name=Go to previous method
@@ -1067,15 +1077,8 @@ project.new.wizard.project.identification=project
 project.new.wizard.module.identification=module
 changelist.todo.title={0} Changelist
 hierarchy.scope.test=Test
-update.plugin.host.url.message=Repository URL:
-update.no.update.hosts=No plugin repositories configured
-update.edit.plugin.host.title=Edit Repository
-update.add.new.plugin.host.title=Add Repository
-update.downloading.patch.progress.title=Downloading Patch file
+
 file.structure.toggle.show.inherited=&Show inherited members
-update.plugins.update.action=&Update
-update.restart.plugins.update.action=&Update and Restart
-update.shutdown.plugins.update.action=&Update and Shutdown
 fail.open.project.message=Unable to open project from ''{0}''
 checkbox.show.icons.in.menu.items=Display icons in menu items
 custom.icon.validation.message=Icon is too big to appear in menu