IDEA-133305 (the option used in connection to update server and main plugin repository)
authorRoman Shevchenko <roman.shevchenko@jetbrains.com>
Tue, 16 Dec 2014 10:00:27 +0000 (11:00 +0100)
committerRoman Shevchenko <roman.shevchenko@jetbrains.com>
Tue, 16 Dec 2014 10:00:27 +0000 (11:00 +0100)
platform/platform-impl/src/com/intellij/ide/plugins/RepositoryHelper.java
platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/PluginDownloader.java
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 635e49c25cffea3c237e8ec0fce0f842743557dd..0c626909e9205fa0e8ff212ae2adb477827cfea0 100644 (file)
@@ -22,6 +22,7 @@ import com.intellij.openapi.application.PathManager;
 import com.intellij.openapi.application.impl.ApplicationInfoImpl;
 import com.intellij.openapi.diagnostic.Logger;
 import com.intellij.openapi.progress.ProgressIndicator;
+import com.intellij.openapi.updateSettings.impl.UpdateSettings;
 import com.intellij.openapi.util.BuildNumber;
 import com.intellij.openapi.util.io.FileUtil;
 import com.intellij.util.io.HttpRequests;
@@ -65,6 +66,15 @@ public class RepositoryHelper {
   public static List<IdeaPluginDescriptor> loadPlugins(@Nullable String repositoryUrl,
                                                        @Nullable BuildNumber buildnumber,
                                                        @Nullable final ProgressIndicator indicator) throws IOException {
+    boolean forceHttps = repositoryUrl == null && UpdateSettings.getInstance().SECURE_CONNECTION;
+    return loadPlugins(repositoryUrl, buildnumber, forceHttps, indicator);
+  }
+
+  @NotNull
+  public static List<IdeaPluginDescriptor> loadPlugins(@Nullable String repositoryUrl,
+                                                       @Nullable BuildNumber buildnumber,
+                                                       boolean forceHttps,
+                                                       @Nullable final ProgressIndicator indicator) throws IOException {
     final URIBuilder uriBuilder;
     final File pluginListFile;
     try {
@@ -91,7 +101,8 @@ public class RepositoryHelper {
       indicator.setText2(IdeBundle.message("progress.connecting.to.plugin.manager", uriBuilder.getHost()));
     }
 
-    return process(repositoryUrl, HttpRequests.request(uriBuilder.toString()).connect(new HttpRequests.RequestProcessor<List<IdeaPluginDescriptor>>() {
+    HttpRequests.RequestBuilder request = HttpRequests.request(uriBuilder.toString()).forceHttps(forceHttps);
+    return process(repositoryUrl, request.connect(new HttpRequests.RequestProcessor<List<IdeaPluginDescriptor>>() {
       @Override
       public List<IdeaPluginDescriptor> process(@NotNull HttpRequests.Request request) throws IOException {
         if (indicator != null) {
index 73591b2dd6e9e7503fddc474d17427bb67bf38f2..28ed36dc4d546aae89cadaf4b52ce3c1af189261 100644 (file)
@@ -60,6 +60,7 @@ public class PluginDownloader {
   private String myFileName;
   private String myPluginName;
   private BuildNumber myBuildNumber;
+  private boolean myForceHttps;
 
   private File myFile;
   private File myOldFile;
@@ -131,6 +132,10 @@ public class PluginDownloader {
     myDescriptor = descriptor;
   }
 
+  public void setForceHttps(boolean forceHttps) {
+    myForceHttps = forceHttps;
+  }
+
   public boolean prepareToInstall(@NotNull ProgressIndicator indicator) throws IOException {
     if (myFile != null) {
       return true;
@@ -246,7 +251,7 @@ public class PluginDownloader {
     indicator.checkCanceled();
     indicator.setText2(IdeBundle.message("progress.downloading.plugin", getPluginName()));
 
-    return HttpRequests.request(myPluginUrl).gzip(false).connect(new HttpRequests.RequestProcessor<File>() {
+    return HttpRequests.request(myPluginUrl).gzip(false).forceHttps(myForceHttps).connect(new HttpRequests.RequestProcessor<File>() {
       @Override
       public File process(@NotNull HttpRequests.Request request) throws IOException {
         indicator.checkCanceled();
index 820cb5e65e100bd617306fad3a3fa41848165cf4..518b50ad9dd82d3bd79553da26250bb03e96cfff 100644 (file)
@@ -147,7 +147,7 @@ public final class UpdateChecker {
   private static void doUpdateAndShowResult(@Nullable final Project project,
                                             final boolean enableLink,
                                             final boolean manualCheck,
-                                            @NotNull UpdateSettings updateSettings,
+                                            @NotNull final UpdateSettings updateSettings,
                                             @Nullable ProgressIndicator indicator,
                                             @Nullable final ActionCallback callback) {
     // check platform update
@@ -195,7 +195,7 @@ public final class UpdateChecker {
       }
 
       incompatiblePlugins = buildNumber != null ? new HashSet<IdeaPluginDescriptor>() : null;
-      updatedPlugins = checkPluginsUpdate(manualCheck, indicator, incompatiblePlugins, buildNumber);
+      updatedPlugins = checkPluginsUpdate(manualCheck, updateSettings, indicator, incompatiblePlugins, buildNumber);
     }
 
     // show result
@@ -203,7 +203,7 @@ public final class UpdateChecker {
     ApplicationManager.getApplication().invokeLater(new Runnable() {
       @Override
       public void run() {
-        showUpdateResult(project, result, updatedPlugins, incompatiblePlugins, enableLink, manualCheck);
+        showUpdateResult(project, result, updateSettings, updatedPlugins, incompatiblePlugins, enableLink, manualCheck);
         if (callback != null) {
           callback.setDone();
         }
@@ -222,7 +222,7 @@ public final class UpdateChecker {
       String updateUrl = uriBuilder.toString();
       LogUtil.debug(LOG, "load update xml (UPDATE_URL='%s')", updateUrl);
 
-      info = HttpRequests.request(updateUrl).connect(new HttpRequests.RequestProcessor<UpdatesInfo>() {
+      info = HttpRequests.request(updateUrl).forceHttps(settings.SECURE_CONNECTION).connect(new HttpRequests.RequestProcessor<UpdatesInfo>() {
         @Override
         public UpdatesInfo process(@NotNull HttpRequests.Request request) throws IOException {
           try {
@@ -254,6 +254,7 @@ public final class UpdateChecker {
   }
 
   private static Collection<PluginDownloader> checkPluginsUpdate(boolean manualCheck,
+                                                                 @NotNull UpdateSettings updateSettings,
                                                                  @Nullable ProgressIndicator indicator,
                                                                  @Nullable Collection<IdeaPluginDescriptor> incompatiblePlugins,
                                                                  @Nullable BuildNumber buildNumber) {
@@ -295,13 +296,15 @@ public final class UpdateChecker {
     outer:
     for (String host : hosts) {
       try {
-        List<IdeaPluginDescriptor> list = RepositoryHelper.loadPlugins(host, buildNumber, indicator);
+        boolean forceHttps = host == null && updateSettings.SECURE_CONNECTION;
+        List<IdeaPluginDescriptor> list = RepositoryHelper.loadPlugins(host, buildNumber, forceHttps, indicator);
         for (IdeaPluginDescriptor descriptor : list) {
           PluginId id = descriptor.getPluginId();
           if (updateable.containsKey(id)) {
             updateable.remove(id);
             state.onDescriptorDownload(descriptor);
             PluginDownloader downloader = PluginDownloader.createDownloader(descriptor, host, buildNumber);
+            downloader.setForceHttps(forceHttps);
             checkAndPrepareToInstall(downloader, state, toUpdate, incompatiblePlugins, indicator);
             if (updateable.isEmpty()) {
               break outer;
@@ -387,8 +390,9 @@ public final class UpdateChecker {
 
   private static void showUpdateResult(@Nullable final Project project,
                                        final CheckForUpdateResult checkForUpdateResult,
+                                       final UpdateSettings updateSettings,
                                        final Collection<PluginDownloader> updatedPlugins,
-                                       final Collection<IdeaPluginDescriptor> incompatiblePlugins, 
+                                       final Collection<IdeaPluginDescriptor> incompatiblePlugins,
                                        final boolean enableLink,
                                        final boolean alwaysShowResults) {
     final UpdateChannel channelToPropose = checkForUpdateResult.getChannelToPropose();
@@ -414,7 +418,7 @@ public final class UpdateChecker {
       Runnable runnable = new Runnable() {
         @Override
         public void run() {
-          new UpdateInfoDialog(updatedChannel, enableLink, updatedPlugins, incompatiblePlugins).show();
+          new UpdateInfoDialog(updatedChannel, enableLink, updateSettings.SECURE_CONNECTION, updatedPlugins, incompatiblePlugins).show();
         }
       };
 
@@ -560,17 +564,18 @@ public final class UpdateChecker {
     return installed;
   }
 
-  public static DownloadPatchResult downloadAndInstallPatch(final BuildInfo newVersion) {
+  public static DownloadPatchResult downloadAndInstallPatch(final PatchInfo patch, final BuildNumber toBuild, final boolean forceHttps) {
     final DownloadPatchResult[] result = new DownloadPatchResult[]{DownloadPatchResult.CANCELED};
 
     if (!ProgressManager.getInstance().runProcessWithProgressSynchronously(new Runnable() {
       @Override
       public void run() {
         try {
-          doDownloadAndInstallPatch(newVersion, ProgressManager.getInstance().getProgressIndicator());
+          ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
+          doDownloadAndInstallPatch(patch, toBuild, forceHttps, indicator);
           result[0] = DownloadPatchResult.SUCCESS;
         }
-        catch (final IOException e) {
+        catch (IOException e) {
           LOG.info(e);
           result[0] = DownloadPatchResult.FAILED;
           Notifications.Bus.notify(new Notification("Updater", "Failed to download patch file", e.getMessage(), NotificationType.ERROR));
@@ -583,13 +588,13 @@ public final class UpdateChecker {
     return result[0];
   }
 
-  private static void doDownloadAndInstallPatch(BuildInfo newVersion, final ProgressIndicator indicator) throws IOException {
-    PatchInfo patch = newVersion.findPatchForCurrentBuild();
-    if (patch == null) throw new IOException("No patch is available for current version");
-
+  private static void doDownloadAndInstallPatch(PatchInfo patch,
+                                                BuildNumber toBuild,
+                                                boolean forceHttps,
+                                                final ProgressIndicator indicator) throws IOException {
     String productCode = ApplicationInfo.getInstance().getBuild().getProductCode();
     String fromBuildNumber = patch.getFromBuild().asStringWithoutProductCode();
-    String toBuildNumber = newVersion.getNumber().asStringWithoutProductCode();
+    String toBuildNumber = toBuild.asStringWithoutProductCode();
 
     String bundledJdk = "";
     String jdkMacRedist = System.getProperty("idea.java.redist");
@@ -602,7 +607,7 @@ public final class UpdateChecker {
     String fileName = productCode + "-" + fromBuildNumber + "-" + toBuildNumber + "-patch" + bundledJdk + osSuffix + ".jar";
 
     String url = new URL(new URL(getPatchesUrl()), fileName).toString();
-    File tempFile = HttpRequests.request(url).connect(new HttpRequests.RequestProcessor<File>() {
+    File tempFile = HttpRequests.request(url).gzip(false).forceHttps(forceHttps).connect(new HttpRequests.RequestProcessor<File>() {
       @Override
       public File process(@NotNull HttpRequests.Request request) throws IOException {
         File tempFile = FileUtil.createTempFile("ij.platform.", ".patch", true);
index 12634dd4363470d3e03952fb2593662888658f6e..065093f9a85add0cf7d8bac3da52ae3b1243a39e 100644 (file)
@@ -42,6 +42,7 @@ import java.util.List;
  */
 class UpdateInfoDialog extends AbstractUpdateDialog {
   private final UpdateChannel myUpdatedChannel;
+  private final boolean myForceHttps;
   private final Collection<PluginDownloader> myUpdatedPlugins;
   private final BuildInfo myLatestBuild;
   private final PatchInfo myPatch;
@@ -49,10 +50,12 @@ class UpdateInfoDialog extends AbstractUpdateDialog {
 
   protected UpdateInfoDialog(@NotNull UpdateChannel channel,
                              boolean enableLink,
+                             boolean forceHttps,
                              Collection<PluginDownloader> updatedPlugins,
                              Collection<IdeaPluginDescriptor> incompatiblePlugins) {
     super(enableLink);
     myUpdatedChannel = channel;
+    myForceHttps = forceHttps;
     myUpdatedPlugins = updatedPlugins;
     myLatestBuild = channel.getLatestBuild();
     myPatch = myLatestBuild != null ? myLatestBuild.findPatchForCurrentBuild() : null;
@@ -64,17 +67,13 @@ class UpdateInfoDialog extends AbstractUpdateDialog {
     init();
 
     if (incompatiblePlugins != null && !incompatiblePlugins.isEmpty()) {
-      final boolean onePluginFound = incompatiblePlugins.size() == 1;
-      String incompatibilityError = "Incompatible with new version plugin";
-      incompatibilityError += (onePluginFound ? " is" : "s are") + " detected: ";
-      incompatibilityError += onePluginFound ? "" : "<br>";
-      incompatibilityError += StringUtil.join(incompatiblePlugins, new Function<IdeaPluginDescriptor, String>() {
+      String list = StringUtil.join(incompatiblePlugins, new Function<IdeaPluginDescriptor, String>() {
         @Override
         public String fun(IdeaPluginDescriptor downloader) {
           return downloader.getName();
         }
       }, "<br/>");
-      setErrorText(incompatibilityError);
+      setErrorText(IdeBundle.message("updates.incompatible.plugins.found", incompatiblePlugins, list));
     }
   }
 
@@ -140,7 +139,7 @@ class UpdateInfoDialog extends AbstractUpdateDialog {
   }
 
   private void downloadPatch(final boolean canRestart) {
-    final UpdateChecker.DownloadPatchResult result = UpdateChecker.downloadAndInstallPatch(myLatestBuild);
+    final UpdateChecker.DownloadPatchResult result = UpdateChecker.downloadAndInstallPatch(myPatch, myLatestBuild.getNumber(), myForceHttps);
     if (result == UpdateChecker.DownloadPatchResult.SUCCESS) {
       if (myUpdatedPlugins != null && !myUpdatedPlugins.isEmpty()) {
         new PluginUpdateInfoDialog(getContentPanel(), myUpdatedPlugins, true){
index 287e08b5beaddcdf7e0cb89f2021a52d80bae584..59d571dc9bb0e61e1606439ee5899c8f40c76c93 100644 (file)
@@ -908,6 +908,7 @@ updates.plugins.ready.header=<html><b>Plugins from configured hosts are ready to
   Uncheck plugins you do not want to update.</html>
 updates.configure.label=To configure automatic update settings, see the <b><a href=\"updates\">Updates</a></b> dialog of your IDE {0}.
 updates.timeout.error=Connection timed out
+updates.incompatible.plugins.found={0,choice,1#Plugin|2#Plugins} incompatible with the new build found:{0,choice,1# |2#<br/>} {1}
 updates.download.and.install.button=&Download Patch and Shutdown
 updates.download.and.restart.button=Up&date and Restart
 updates.more.info.button=&More Info...