diff --git a/platform/lang-impl/src/com/intellij/lang/javascript/boilerplate/GithubTagListProvider.java b/platform/lang-impl/src/com/intellij/lang/javascript/boilerplate/GithubTagListProvider.java index 5deb52c5dae2..b240f62fb541 100644 --- a/platform/lang-impl/src/com/intellij/lang/javascript/boilerplate/GithubTagListProvider.java +++ b/platform/lang-impl/src/com/intellij/lang/javascript/boilerplate/GithubTagListProvider.java @@ -9,9 +9,6 @@ import com.google.gson.JsonObject; import com.google.gson.JsonParser; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.diagnostic.Logger; -import com.intellij.openapi.progress.ProgressIndicator; -import com.intellij.openapi.progress.ProgressManager; -import com.intellij.openapi.progress.Task; import com.intellij.platform.templates.github.DownloadUtil; import com.intellij.platform.templates.github.GeneratorException; import com.intellij.platform.templates.github.GithubTagInfo; @@ -53,36 +50,30 @@ public class GithubTagListProvider { return null; } - public Task.Backgroundable updateTagListAsynchronously(final GithubProjectGeneratorPeer peer) { + public void updateTagListAsynchronously(final GithubProjectGeneratorPeer peer) { final String url = formatTagListDownloadUrl(); - Task.Backgroundable task = - new Task.Backgroundable(null, "Updating versions of " + GithubTagListProvider.this.myRepositoryName + " repository...", true, null) { - - @Override - public void run(@NotNull ProgressIndicator indicator) { - File cacheFile = getCacheFile(); - try { - DownloadUtil.downloadAtomically(indicator, url, cacheFile, myUserName, myRepositoryName); - final ImmutableSet infos = readTagsFromFile(cacheFile); - peer.setErrorMessage(null); - UIUtil.invokeLaterIfNeeded(new Runnable() { - public void run() { - peer.updateTagList(infos); - } - }); - } - catch (IOException e) { - peer.setErrorMessage("Can not fetch tag list from '" + url + "'!"); - } - catch (GeneratorException e) { - peer.setErrorMessage(getGeneratorName() + " cache update failed"); - } - } - }; - LOG.info(getGeneratorName() + " starting cache update from " + url + " ..."); - ProgressManager.getInstance().run(task); - return task; + ApplicationManager.getApplication().executeOnPooledThread(new Runnable() { + public void run() { + File cacheFile = getCacheFile(); + try { + DownloadUtil.downloadAtomically(null, url, cacheFile, myUserName, myRepositoryName); + final ImmutableSet infos = readTagsFromFile(cacheFile); + peer.setErrorMessage(null); + UIUtil.invokeLaterIfNeeded(new Runnable() { + public void run() { + peer.updateTagList(infos); + } + }); + } + catch (IOException e) { + peer.setErrorMessage("Can not fetch tag list from '" + url + "'!"); + } + catch (GeneratorException e) { + peer.setErrorMessage(getGeneratorName() + " cache update failed"); + } + } + }); } private String getGeneratorName() { diff --git a/platform/lang-impl/src/com/intellij/platform/templates/github/DownloadUtil.java b/platform/lang-impl/src/com/intellij/platform/templates/github/DownloadUtil.java index 810a43c1fb6f..ffafbffb62eb 100644 --- a/platform/lang-impl/src/com/intellij/platform/templates/github/DownloadUtil.java +++ b/platform/lang-impl/src/com/intellij/platform/templates/github/DownloadUtil.java @@ -16,8 +16,6 @@ import org.jetbrains.annotations.Nullable; import java.io.*; import java.net.HttpURLConnection; -import java.net.URL; -import java.net.URLConnection; import java.util.Locale; import java.util.concurrent.Callable; import java.util.concurrent.TimeUnit; @@ -121,7 +119,7 @@ public class DownloadUtil { }, new Producer() { @Override public Boolean produce() { - return IOExceptionDialog.showErrorDialog("Download Error", "Can not download " + url + ""); + return IOExceptionDialog.showErrorDialog("Download Error", "Can not download '" + url + "'"); } } ); @@ -204,13 +202,7 @@ public class DownloadUtil { if (progress != null) { progress.setText2("Downloading " + location); } - URL url = new URL(location); - try { - HttpConfigurable.getInstance().prepareURL(location); - } catch (IOException e) { - LOG.info("Can not prepareURL '" + location + "'", e); - } - URLConnection urlConnection = url.openConnection(); + HttpURLConnection urlConnection = HttpConfigurable.getInstance().openHttpConnection(location); try { int timeout = (int) TimeUnit.MINUTES.toMillis(2); urlConnection.setConnectTimeout(timeout); @@ -221,16 +213,21 @@ public class DownloadUtil { substituteContentLength(progress, originalText, contentLength); NetUtils.copyStreamContent(progress, in, output, contentLength); } catch (IOException e) { - if (urlConnection instanceof HttpURLConnection) { - HttpURLConnection httpURLConnection = (HttpURLConnection) urlConnection; - LOG.warn("Can not download '" + location - + "', response code: " + httpURLConnection.getResponseCode() - + ", response message: " + httpURLConnection.getResponseMessage() - + ", headers: " + httpURLConnection.getHeaderFields() - ); - } + LOG.warn("Can not download '" + location + + "', response code: " + urlConnection.getResponseCode() + + ", response message: " + urlConnection.getResponseMessage() + + ", headers: " + urlConnection.getHeaderFields(), + e + ); throw e; } + finally { + try { + urlConnection.disconnect(); + } catch (Exception e) { + LOG.warn("Exception at disconnect()", e); + } + } } private static void substituteContentLength(@Nullable ProgressIndicator progress, @Nullable String text, int contentLengthInBytes) { diff --git a/platform/platform-api/src/com/intellij/util/net/HttpConfigurable.java b/platform/platform-api/src/com/intellij/util/net/HttpConfigurable.java index 81751a2f6793..0625791eff97 100644 --- a/platform/platform-api/src/com/intellij/util/net/HttpConfigurable.java +++ b/platform/platform-api/src/com/intellij/util/net/HttpConfigurable.java @@ -16,6 +16,7 @@ package com.intellij.util.net; import com.btr.proxy.search.ProxySearch; +import com.intellij.openapi.application.ModalityState; import com.intellij.openapi.components.*; import com.intellij.openapi.options.ShowSettingsUtil; import com.intellij.openapi.util.InvalidDataException; @@ -28,6 +29,7 @@ import com.intellij.util.xmlb.XmlSerializerUtil; import com.intellij.util.xmlb.annotations.Transient; import org.apache.commons.codec.binary.Base64; import org.jdom.Element; +import org.jetbrains.annotations.NotNull; import javax.swing.*; import java.io.IOException; @@ -104,7 +106,7 @@ public class HttpConfigurable implements PersistentStateComponent