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());
}
}
}));
}
Aggregations