Search in sources :

Example 1 with RequestBuilder

use of com.intellij.util.io.RequestBuilder in project intellij-community by JetBrains.

the class RepositoryHelper method loadPlugins.

@NotNull
public static List<IdeaPluginDescriptor> loadPlugins(@Nullable String repositoryUrl, @Nullable BuildNumber buildnumber, @Nullable String channel, boolean forceHttps, @Nullable final ProgressIndicator indicator) throws IOException {
    String url;
    final File pluginListFile;
    final String host;
    try {
        URIBuilder uriBuilder;
        if (repositoryUrl == null) {
            uriBuilder = new URIBuilder(ApplicationInfoImpl.getShadowInstance().getPluginsListUrl());
            pluginListFile = new File(PathManager.getPluginsPath(), channel == null ? PLUGIN_LIST_FILE : channel + "_" + PLUGIN_LIST_FILE);
            if (pluginListFile.length() > 0) {
                uriBuilder.addParameter("crc32", crc32(pluginListFile));
            }
        } else {
            uriBuilder = new URIBuilder(repositoryUrl);
            pluginListFile = null;
        }
        if (!URLUtil.FILE_PROTOCOL.equals(uriBuilder.getScheme())) {
            uriBuilder.addParameter("build", (buildnumber != null ? buildnumber.asString() : ApplicationInfoImpl.getShadowInstance().getApiVersion()));
            if (channel != null)
                uriBuilder.addParameter("channel", channel);
        }
        host = uriBuilder.getHost();
        url = uriBuilder.build().toString();
    } catch (URISyntaxException e) {
        throw new IOException(e);
    }
    if (indicator != null) {
        indicator.setText2(IdeBundle.message("progress.connecting.to.plugin.manager", host));
    }
    RequestBuilder request = HttpRequests.request(url).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) {
                indicator.checkCanceled();
            }
            URLConnection connection = request.getConnection();
            if (pluginListFile != null && pluginListFile.length() > 0 && connection instanceof HttpURLConnection && ((HttpURLConnection) connection).getResponseCode() == HttpURLConnection.HTTP_NOT_MODIFIED) {
                return loadPluginList(pluginListFile);
            }
            if (indicator != null) {
                indicator.checkCanceled();
                indicator.setText2(IdeBundle.message("progress.downloading.list.of.plugins", host));
            }
            if (pluginListFile != null) {
                synchronized (PLUGIN_LIST_FILE) {
                    FileUtil.ensureExists(pluginListFile.getParentFile());
                    request.saveToFile(pluginListFile, indicator);
                    return loadPluginList(pluginListFile);
                }
            } else {
                return parsePluginList(request.getReader());
            }
        }
    }));
}
Also used : HttpURLConnection(java.net.HttpURLConnection) RequestBuilder(com.intellij.util.io.RequestBuilder) URISyntaxException(java.net.URISyntaxException) NotNull(org.jetbrains.annotations.NotNull) HttpURLConnection(java.net.HttpURLConnection) URLConnection(java.net.URLConnection) URIBuilder(org.apache.http.client.utils.URIBuilder) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

RequestBuilder (com.intellij.util.io.RequestBuilder)1 HttpURLConnection (java.net.HttpURLConnection)1 URISyntaxException (java.net.URISyntaxException)1 URLConnection (java.net.URLConnection)1 URIBuilder (org.apache.http.client.utils.URIBuilder)1 NotNull (org.jetbrains.annotations.NotNull)1