Merge remote-tracking branch 'origin/master'

This commit is contained in:
Dmitry Trofimov
2014-12-17 18:23:08 +01:00
8 changed files with 193 additions and 210 deletions
@@ -16,7 +16,6 @@ import java.net.HttpURLConnection;
* @author Sergey Evdokimov
*/
public abstract class SourceSearcher {
/**
* @param indicator
* @param artifactId
@@ -7,17 +7,18 @@ import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Ref;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.util.ObjectUtils;
import com.intellij.util.Producer;
import com.intellij.util.containers.Predicate;
import com.intellij.util.net.HttpConfigurable;
import com.intellij.util.io.HttpRequests;
import com.intellij.util.net.NetUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.*;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URLConnection;
import java.util.Locale;
import java.util.concurrent.Callable;
@@ -34,28 +35,27 @@ public class DownloadUtil {
* {@code outputFile} isn't modified if an I/O error occurs or {@code contentChecker} is provided and returns false on the downloaded content.
* More formally, the steps are:
* <ol>
* <li>Download {@code url} to {@code tempFile}. Stop in case of any I/O errors.</li>
* <li>Stop if {@code contentChecker} is provided, and it returns false on the downloaded content.</li>
* <li>Move {@code tempFile} to {@code outputFile}. On most OS this operation is done atomically.</li>
* <li>Download {@code url} to {@code tempFile}. Stop in case of any I/O errors.</li>
* <li>Stop if {@code contentChecker} is provided, and it returns false on the downloaded content.</li>
* <li>Move {@code tempFile} to {@code outputFile}. On most OS this operation is done atomically.</li>
* </ol>
*
* <p/>
* Motivation: some web filtering products return pure HTML with HTTP 200 OK status instead of
* the asked content.
*
* @param indicator progress indicator
* @param url url to download
* @param outputFile output file
* @param tempFile temporary file to download to. This file is deleted on method exit.
* @param indicator progress indicator
* @param url url to download
* @param outputFile output file
* @param tempFile temporary file to download to. This file is deleted on method exit.
* @param contentChecker checks whether the downloaded content is OK or not
* @returns true if no {@code contentChecker} is provided or the provided one returned true
* @throws IOException if an I/O error occurs
* @returns true if no {@code contentChecker} is provided or the provided one returned true
*/
public static boolean downloadAtomically(@Nullable ProgressIndicator indicator,
@NotNull String url,
@NotNull File outputFile,
@NotNull File tempFile,
@Nullable Predicate<String> contentChecker) throws IOException
{
@NotNull String url,
@NotNull File outputFile,
@NotNull File tempFile,
@Nullable Predicate<String> contentChecker) throws IOException {
try {
downloadContentToFile(indicator, url, tempFile);
if (contentChecker != null) {
@@ -66,7 +66,8 @@ public class DownloadUtil {
}
FileUtil.rename(tempFile, outputFile);
return true;
} finally {
}
finally {
FileUtil.delete(tempFile);
}
}
@@ -75,14 +76,13 @@ public class DownloadUtil {
* Downloads content of {@code url} to {@code outputFile} atomically.
* {@code outputFile} won't be modified in case of any I/O download errors.
*
* @param indicator progress indicator
* @param url url to download
* @param outputFile output file
* @param indicator progress indicator
* @param url url to download
* @param outputFile output file
*/
public static void downloadAtomically(@Nullable ProgressIndicator indicator,
@NotNull String url,
@NotNull File outputFile) throws IOException
{
@NotNull File outputFile) throws IOException {
File tempFile = FileUtil.createTempFile("for-actual-downloading-", null);
downloadAtomically(indicator, url, outputFile, tempFile, null);
}
@@ -91,16 +91,15 @@ public class DownloadUtil {
* Downloads content of {@code url} to {@code outputFile} atomically.
* {@code outputFile} won't be modified in case of any I/O download errors.
*
* @param indicator progress indicator
* @param url url to download
* @param outputFile output file
* @param tempFile temporary file to download to. This file is deleted on method exit.
* @param indicator progress indicator
* @param url url to download
* @param outputFile output file
* @param tempFile temporary file to download to. This file is deleted on method exit.
*/
public static void downloadAtomically(@Nullable ProgressIndicator indicator,
@NotNull String url,
@NotNull File outputFile,
@NotNull File tempFile) throws IOException
{
@NotNull File tempFile) throws IOException {
downloadAtomically(indicator, url, outputFile, tempFile, null);
}
@@ -111,8 +110,7 @@ public class DownloadUtil {
@NotNull String progressTitle,
@NotNull final String actionShortDescription,
@NotNull final Callable<V> supplier,
@Nullable Producer<Boolean> tryAgainProvider)
{
@Nullable Producer<Boolean> tryAgainProvider) {
int attemptNumber = 1;
while (true) {
final Ref<V> dataRef = Ref.create(null);
@@ -160,44 +158,45 @@ public class DownloadUtil {
OutputStream out = new FileOutputStream(outputFile);
try {
download(progress, url, out);
} finally {
}
finally {
out.close();
}
}
private static void download(@Nullable ProgressIndicator progress,
@NotNull String location,
@NotNull OutputStream output) throws IOException {
String originalText = progress != null ? progress.getText() : null;
private static void download(@Nullable final ProgressIndicator progress,
@NotNull final String location,
@NotNull final OutputStream output) throws IOException {
final String originalText = progress != null ? progress.getText() : null;
substituteContentLength(progress, originalText, -1);
if (progress != null) {
progress.setText2("Downloading " + location);
}
URLConnection urlConnection = HttpConfigurable.getInstance().openConnection(location);
HttpURLConnection httpURLConnection = ObjectUtils.tryCast(urlConnection, HttpURLConnection.class);
try {
urlConnection.setRequestProperty("User-Agent", ApplicationInfoEx.getInstanceEx().getFullApplicationName());
urlConnection.connect();
InputStream in = urlConnection.getInputStream();
int contentLength = urlConnection.getContentLength();
substituteContentLength(progress, originalText, contentLength);
NetUtils.copyStreamContent(progress, in, output, contentLength);
} catch (IOException e) {
String errorMessage = "Can not download '" + location + ", headers: " + urlConnection.getHeaderFields();
if (httpURLConnection != null) {
errorMessage += "', response code: " + httpURLConnection.getResponseCode()
+ ", response message: " + httpURLConnection.getResponseMessage();
}
throw new IOException(errorMessage, e);
HttpRequests.request(location)
.userAgent(ApplicationInfoEx.getInstanceEx().getFullApplicationName())
.connect(new HttpRequests.RequestProcessor<Object>() {
@Override
public Object process(@NotNull HttpRequests.Request request) throws IOException {
try {
int contentLength = request.getConnection().getContentLength();
substituteContentLength(progress, originalText, contentLength);
NetUtils.copyStreamContent(progress, request.getInputStream(), output, contentLength);
}
catch (IOException e) {
HttpURLConnection connection = (HttpURLConnection)request.getConnection();
throw new IOException("Cannot download '" + location +
", headers: " + connection.getHeaderFields() +
"', response code: " + connection.getResponseCode() +
", response message: " + connection.getResponseMessage(), e);
}
return null;
}
});
}
finally {
if (httpURLConnection != null) {
try {
httpURLConnection.disconnect();
} catch (Exception e) {
LOG.warn("Exception at disconnect()", e);
}
}
catch (IOException e) {
throw new IOException("Cannot download '" + location, e);
}
}
@@ -225,5 +224,4 @@ public class DownloadUtil {
}
return String.format(Locale.US, ", %.1f MB", contentLengthInBytes / (1.0 * kilo * kilo));
}
}
@@ -24,7 +24,7 @@ import com.intellij.util.SystemProperties;
import com.intellij.util.net.HttpConfigurable;
import com.intellij.util.net.ssl.CertificateManager;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.io.Responses;
import org.jetbrains.annotations.Nullable;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
@@ -70,6 +70,7 @@ public final class HttpRequests {
private boolean myGzip = true;
private boolean myForceHttps;
private boolean myDisableHostVerification;
private String myUserAgent;
private RequestBuilder(@NotNull String url) {
myUrl = url;
@@ -111,6 +112,12 @@ public final class HttpRequests {
return this;
}
@NotNull
public RequestBuilder userAgent(@Nullable String userAgent) {
myUserAgent = userAgent;
return this;
}
public <T> T connect(@NotNull RequestProcessor<T> processor) throws IOException {
// todo[r.sh] drop condition in IDEA 15
if (ourWrapClassLoader) {
@@ -204,9 +211,8 @@ public final class HttpRequests {
connection.setConnectTimeout(builder.myConnectTimeout);
connection.setReadTimeout(builder.myTimeout);
String userAgent = Responses.getServerHeaderValue();
if (userAgent != null) {
connection.setRequestProperty("User-Agent", userAgent);
if (builder.myUserAgent != null) {
connection.setRequestProperty("User-Agent", builder.myUserAgent);
}
if (connection instanceof HttpsURLConnection) {
@@ -29,6 +29,7 @@ import com.intellij.ui.PortField;
import com.intellij.ui.RawCommandLineEditor;
import com.intellij.ui.RelativeFont;
import com.intellij.ui.components.JBRadioButton;
import com.intellij.util.io.HttpRequests;
import com.intellij.util.proxy.CommonProxy;
import com.intellij.util.proxy.JavaProxyProperty;
import org.jetbrains.annotations.NotNull;
@@ -172,27 +173,24 @@ class HttpProxySettingsUi implements ConfigurableUi<HttpConfigurable> {
ApplicationManager.getApplication().executeOnPooledThread(new Runnable() {
@Override
public void run() {
HttpURLConnection connection = null;
try {
//already checked for null above
//noinspection ConstantConditions
connection = settings.openHttpConnection(answer);
connection.setReadTimeout(3 * 1000);
connection.setConnectTimeout(3 * 1000);
connection.connect();
final int code = connection.getResponseCode();
if (HttpURLConnection.HTTP_OK != code) {
exceptionReference.set(new IOException("Error code: " + code));
}
HttpRequests.request(answer).connectTimeout(3 * 1000).readTimeout(3 * 1000).connect(new HttpRequests.RequestProcessor<Object>() {
@Override
public Object process(@NotNull HttpRequests.Request request) throws IOException {
int responseCode = ((HttpURLConnection)request.getConnection()).getResponseCode();
if (responseCode != HttpURLConnection.HTTP_OK) {
exceptionReference.set(new IOException("Error code: " + responseCode));
}
return null;
}
});
}
catch (IOException e) {
exceptionReference.set(e);
}
finally {
if (connection != null) {
connection.disconnect();
}
}
//noinspection SSBasedInspection
SwingUtilities.invokeLater(new Runnable() {
@Override
@@ -40,7 +40,7 @@ import com.intellij.openapi.util.text.StringUtil;
import com.intellij.reference.SoftReference;
import com.intellij.ui.EditorNotifications;
import com.intellij.util.PlatformUtils;
import com.intellij.util.net.HttpConfigurable;
import com.intellij.util.io.HttpRequests;
import com.intellij.util.xmlb.XmlSerializer;
import com.intellij.util.xmlb.annotations.MapAnnotation;
import com.intellij.util.xmlb.annotations.Tag;
@@ -54,7 +54,6 @@ import javax.swing.event.HyperlinkEvent;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.util.*;
public class PluginsAdvertiser implements StartupActivity {
@@ -80,28 +79,31 @@ public class PluginsAdvertiser implements StartupActivity {
"&implementationName=" + implementationName.replaceAll("#", "%23") +
"&build=" + buildNumber;
try {
HttpURLConnection connection = HttpConfigurable.getInstance().openHttpConnection(pluginRepositoryUrl);
connection.connect();
final InputStreamReader streamReader = new InputStreamReader(connection.getInputStream());
try {
final JsonReader jsonReader = new JsonReader(streamReader);
jsonReader.setLenient(true);
final JsonElement jsonRootElement = new JsonParser().parse(jsonReader);
final List<Plugin> result = new ArrayList<Plugin>();
for (JsonElement jsonElement : jsonRootElement.getAsJsonArray()) {
final JsonObject jsonObject = jsonElement.getAsJsonObject();
final JsonElement pluginId = jsonObject.get("pluginId");
final JsonElement pluginName = jsonObject.get("pluginName");
final JsonElement bundled = jsonObject.get("bundled");
result.add(new Plugin(PluginId.getId(StringUtil.unquoteString(pluginId.toString())),
pluginName != null ? StringUtil.unquoteString(pluginName.toString()) : null,
Boolean.parseBoolean(StringUtil.unquoteString(bundled.toString()))));
return HttpRequests.request(pluginRepositoryUrl).connect(new HttpRequests.RequestProcessor<List<Plugin>>() {
@Override
public List<Plugin> process(@NotNull HttpRequests.Request request) throws IOException {
final InputStreamReader streamReader = new InputStreamReader(request.getInputStream());
try {
final JsonReader jsonReader = new JsonReader(streamReader);
jsonReader.setLenient(true);
final JsonElement jsonRootElement = new JsonParser().parse(jsonReader);
final List<Plugin> result = new ArrayList<Plugin>();
for (JsonElement jsonElement : jsonRootElement.getAsJsonArray()) {
final JsonObject jsonObject = jsonElement.getAsJsonObject();
final JsonElement pluginId = jsonObject.get("pluginId");
final JsonElement pluginName = jsonObject.get("pluginName");
final JsonElement bundled = jsonObject.get("bundled");
result.add(new Plugin(PluginId.getId(StringUtil.unquoteString(pluginId.toString())),
pluginName != null ? StringUtil.unquoteString(pluginName.toString()) : null,
Boolean.parseBoolean(StringUtil.unquoteString(bundled.toString()))));
}
return result;
}
finally {
streamReader.close();
}
}
return result;
}
finally {
streamReader.close();
}
});
}
catch (IOException e) {
LOG.info(e);
@@ -116,47 +118,50 @@ public class PluginsAdvertiser implements StartupActivity {
}
final String pluginRepositoryUrl = FEATURE_IMPLEMENTATIONS_URL + "featureType=" + FileTypeFactory.FILE_TYPE_FACTORY_EP.getName();
try {
HttpURLConnection connection = HttpConfigurable.getInstance().openHttpConnection(pluginRepositoryUrl);
connection.connect();
final InputStreamReader streamReader = new InputStreamReader(connection.getInputStream());
try {
final JsonReader jsonReader = new JsonReader(streamReader);
jsonReader.setLenient(true);
final JsonElement jsonRootElement = new JsonParser().parse(jsonReader);
final Map<String, Set<Plugin>> result = new HashMap<String, Set<Plugin>>();
for (JsonElement jsonElement : jsonRootElement.getAsJsonArray()) {
final JsonObject jsonObject = jsonElement.getAsJsonObject();
return HttpRequests.request(pluginRepositoryUrl).connect(new HttpRequests.RequestProcessor<Map<String, Set<Plugin>>>() {
@Override
public Map<String, Set<Plugin>> process(@NotNull HttpRequests.Request request) throws IOException {
final InputStreamReader streamReader = new InputStreamReader(request.getInputStream());
try {
final JsonReader jsonReader = new JsonReader(streamReader);
jsonReader.setLenient(true);
final JsonElement jsonRootElement = new JsonParser().parse(jsonReader);
final Map<String, Set<Plugin>> result = new HashMap<String, Set<Plugin>>();
for (JsonElement jsonElement : jsonRootElement.getAsJsonArray()) {
final JsonObject jsonObject = jsonElement.getAsJsonObject();
final String pluginId = StringUtil.unquoteString(jsonObject.get("pluginId").toString());
final JsonElement bundledExt = jsonObject.get("bundled");
boolean isBundled = Boolean.parseBoolean(bundledExt.toString());
final IdeaPluginDescriptor fromServerPluginDescription = availableIds.get(pluginId);
if (fromServerPluginDescription == null && !isBundled) continue;
final String pluginId = StringUtil.unquoteString(jsonObject.get("pluginId").toString());
final JsonElement bundledExt = jsonObject.get("bundled");
boolean isBundled = Boolean.parseBoolean(bundledExt.toString());
final IdeaPluginDescriptor fromServerPluginDescription = availableIds.get(pluginId);
if (fromServerPluginDescription == null && !isBundled) continue;
final IdeaPluginDescriptor loadedPlugin = PluginManager.getPlugin(PluginId.getId(pluginId));
if (loadedPlugin != null && loadedPlugin.isEnabled()) continue;
final IdeaPluginDescriptor loadedPlugin = PluginManager.getPlugin(PluginId.getId(pluginId));
if (loadedPlugin != null && loadedPlugin.isEnabled()) continue;
if (loadedPlugin != null && fromServerPluginDescription != null &&
StringUtil.compareVersionNumbers(loadedPlugin.getVersion(), fromServerPluginDescription.getVersion()) >= 0) continue;
if (loadedPlugin != null && fromServerPluginDescription != null &&
StringUtil.compareVersionNumbers(loadedPlugin.getVersion(), fromServerPluginDescription.getVersion()) >= 0) continue;
if (fromServerPluginDescription != null && PluginManagerCore.isBrokenPlugin(fromServerPluginDescription)) continue;
if (fromServerPluginDescription != null && PluginManagerCore.isBrokenPlugin(fromServerPluginDescription)) continue;
final JsonElement ext = jsonObject.get("implementationName");
final String extension = StringUtil.unquoteString(ext.toString());
Set<Plugin> pluginIds = result.get(extension);
if (pluginIds == null) {
pluginIds = new HashSet<Plugin>();
result.put(extension, pluginIds);
final JsonElement ext = jsonObject.get("implementationName");
final String extension = StringUtil.unquoteString(ext.toString());
Set<Plugin> pluginIds = result.get(extension);
if (pluginIds == null) {
pluginIds = new HashSet<Plugin>();
result.put(extension, pluginIds);
}
final JsonElement pluginNameElement = jsonObject.get("pluginName");
pluginIds.add(new Plugin(PluginId.getId(pluginId), pluginNameElement != null ? StringUtil.unquoteString(pluginNameElement.toString()) : null, isBundled));
}
saveExtensions(result);
return result;
}
finally {
streamReader.close();
}
final JsonElement pluginNameElement = jsonObject.get("pluginName");
pluginIds.add(new Plugin(PluginId.getId(pluginId), pluginNameElement != null ? StringUtil.unquoteString(pluginNameElement.toString()) : null, isBundled));
}
saveExtensions(result);
return result;
}
finally {
streamReader.close();
}
});
}
catch (Throwable e) {
LOG.info(e);
@@ -28,6 +28,7 @@ import com.intellij.util.PathUtilRt;
import com.intellij.util.Url;
import com.intellij.util.io.HttpRequests;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.io.Responses;
import java.io.*;
import java.net.HttpURLConnection;
@@ -58,6 +59,7 @@ public class DefaultRemoteContentProvider extends RemoteContentProvider {
HttpRequests.request(url.toExternalForm())
.connectTimeout(60 * 1000)
.readTimeout(60 * 1000)
.userAgent(Responses.getServerHeaderValue())
.disableHostVerification()
.connect(new HttpRequests.RequestProcessor<Object>() {
@Override
@@ -17,15 +17,13 @@ import com.intellij.openapi.util.ActionCallback;
import com.intellij.openapi.vfs.JarFileSystem;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiFile;
import com.intellij.util.net.HttpConfigurable;
import com.intellij.util.io.HttpRequests;
import com.intellij.util.net.NetUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.util.Arrays;
import java.util.List;
@@ -148,28 +146,20 @@ public abstract class AbstractAttachSourceProvider implements AttachSourcesProvi
Task task = new Task.Backgroundable(myProject, "Downloading sources...", true) {
@Override
public void run(@NotNull ProgressIndicator indicator) {
public void run(@NotNull final ProgressIndicator indicator) {
final ByteArrayOutputStream out;
try {
LOG.info("Downloading sources JAR: " + myUrl);
indicator.checkCanceled();
HttpURLConnection urlConnection = HttpConfigurable.getInstance().openHttpConnection(myUrl);
int contentLength = urlConnection.getContentLength();
out = new ByteArrayOutputStream(contentLength > 0 ? contentLength : 100 * 1024);
InputStream in = urlConnection.getInputStream();
try {
NetUtils.copyStreamContent(indicator, in, out, contentLength);
}
finally {
in.close();
}
out = HttpRequests.request(myUrl).connect(new HttpRequests.RequestProcessor<ByteArrayOutputStream>() {
@Override
public ByteArrayOutputStream process(@NotNull HttpRequests.Request request) throws IOException {
int contentLength = request.getConnection().getContentLength();
ByteArrayOutputStream out = new ByteArrayOutputStream(contentLength > 0 ? contentLength : 100 * 1024);
NetUtils.copyStreamContent(indicator, request.getInputStream(), out, contentLength);
return out;
}
});
}
catch (IOException e) {
LOG.warn(e);
@@ -24,19 +24,22 @@ import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiManager;
import com.intellij.util.net.HttpConfigurable;
import com.intellij.util.io.HttpRequests;
import com.intellij.util.net.NetUtils;
import org.jetbrains.annotations.NotNull;
import java.io.*;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.lang.reflect.InvocationTargetException;
import java.net.URLConnection;
import java.util.Set;
@SuppressWarnings({"StringEquality"})
public abstract class DownloadManager {
private static final ExternalResourceManager resourceManager = ExternalResourceManager.getInstance();
@@ -49,57 +52,45 @@ public abstract class DownloadManager {
myProgress = progress;
myResourcePath = PathManager.getSystemPath() + File.separatorChar + "extResources";
final File dir = new File(myResourcePath);
dir.mkdirs();
//noinspection ResultOfMethodCallIgnored
new File(myResourcePath).mkdirs();
}
public void fetch(String location) throws DownloadException {
if (resourceManager.getResourceLocation(location) == location) {
myProgress.setText("Downloading " + location);
downloadAndRegister(location);
public void fetch(@NotNull final String location) throws DownloadException {
if (resourceManager.getResourceLocation(location, myProject) != location) {
return;
}
}
private void downloadAndRegister(final String location) throws DownloadException {
final ExternalResourceManager resourceManager = ExternalResourceManager.getInstance();
myProgress.setText("Downloading " + location);
File file = null;
try {
final URLConnection urlConnection = HttpConfigurable.getInstance().openConnection(location);
urlConnection.connect();
final InputStream in = urlConnection.getInputStream();
final OutputStream out;
try {
final int total = urlConnection.getContentLength();
final String name = Integer.toHexString(System.identityHashCode(this)) +
"_" +
Integer.toHexString(location.hashCode()) +
"_" +
location.substring(location.lastIndexOf('/') + 1);
file = new File(myResourcePath, name.lastIndexOf('.') == -1 ? name + ".xml" : name);
out = new FileOutputStream(file);
try {
NetUtils.copyStreamContent(myProgress, in, out, total);
file = HttpRequests.request(location).connect(new HttpRequests.RequestProcessor<File>() {
@Override
public File process(@NotNull HttpRequests.Request request) throws IOException {
int total = request.getConnection().getContentLength();
String name = Integer.toHexString(System.identityHashCode(this)) + "_" +
Integer.toHexString(location.hashCode()) + "_" +
location.substring(location.lastIndexOf('/') + 1);
File file = new File(myResourcePath, name.lastIndexOf('.') == -1 ? name + ".xml" : name);
OutputStream out = new FileOutputStream(file);
try {
NetUtils.copyStreamContent(myProgress, request.getInputStream(), out, total);
}
finally {
out.close();
}
return file;
}
finally {
out.close();
}
}
finally {
in.close();
}
});
try {
final File _file = file;
//noinspection unchecked
final Set<String>[] resourceDependencies = new Set[1];
new WriteAction() {
@Override
protected void run(Result result) throws Throwable {
protected void run(@NotNull Result result) throws Throwable {
final VirtualFile vf = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(_file);
if (vf != null) {
final PsiFile psiFile = PsiManager.getInstance(myProject).findFile(vf);
@@ -130,25 +121,19 @@ public abstract class DownloadManager {
}
catch (Error err) {
Throwable e = err.getCause();
if (e instanceof InterruptedException) {
// OK
}
else if (e instanceof InvocationTargetException) {
final Throwable targetException = ((InvocationTargetException)e).getTargetException();
if (e instanceof InvocationTargetException) {
Throwable targetException = ((InvocationTargetException)e).getTargetException();
if (targetException instanceof RuntimeException) {
throw (RuntimeException)targetException;
}
else if (targetException instanceof IOException) {
throw (IOException)targetException;
}
else if (targetException instanceof InterruptedException) {
// OK
}
else {
else if (!(targetException instanceof InterruptedException)) {
Logger.getInstance(getClass().getName()).error(e);
}
}
else {
else if (!(e instanceof InterruptedException)) {
throw err;
}
}
@@ -157,9 +142,9 @@ public abstract class DownloadManager {
throw new DownloadException(location, e);
}
finally {
if (file != null && resourceManager.getResourceLocation(location) == location) {
if (file != null && resourceManager.getResourceLocation(location, myProject) == location) {
// something went wrong. get rid of the file
file.delete();
FileUtil.delete(file);
}
}
}