mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-10-06 06:21:16 +07:00
Cleanup (unused parameter; formatting)
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
* Copyright 2000-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -28,7 +28,6 @@ import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.vfs.CharsetToolkit;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.io.HttpRequests;
|
||||
import com.intellij.util.io.RequestBuilder;
|
||||
import com.intellij.util.io.URLUtil;
|
||||
import org.apache.http.client.utils.URIBuilder;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -52,6 +51,7 @@ import java.util.*;
|
||||
public class RepositoryHelper {
|
||||
private static final Logger LOG = Logger.getInstance(RepositoryHelper.class);
|
||||
@SuppressWarnings("SpellCheckingInspection") private static final String PLUGIN_LIST_FILE = "availables.xml";
|
||||
@SuppressWarnings("SpellCheckingInspection") private static final String TAG_EXT = ".etag";
|
||||
|
||||
/**
|
||||
* Returns a list of configured plugin hosts.
|
||||
@@ -95,32 +95,30 @@ public class RepositoryHelper {
|
||||
public static List<IdeaPluginDescriptor> loadPlugins(@Nullable String repositoryUrl, @Nullable ProgressIndicator indicator) throws IOException {
|
||||
return loadPlugins(repositoryUrl, null, indicator);
|
||||
}
|
||||
|
||||
|
||||
@NotNull
|
||||
public static List<IdeaPluginDescriptor> loadPlugins(@Nullable String repositoryUrl,
|
||||
@Nullable BuildNumber buildnumber,
|
||||
@Nullable ProgressIndicator indicator) throws IOException {
|
||||
boolean forceHttps = repositoryUrl == null && IdeaApplication.isLoaded() && UpdateSettings.getInstance().canUseSecureConnection();
|
||||
return loadPlugins(repositoryUrl, buildnumber, null, forceHttps, indicator);
|
||||
return loadPlugins(repositoryUrl, buildnumber, forceHttps, indicator);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static List<IdeaPluginDescriptor> loadPlugins(@Nullable String repositoryUrl,
|
||||
@Nullable BuildNumber buildnumber,
|
||||
@Nullable String channel,
|
||||
@Nullable BuildNumber build,
|
||||
boolean forceHttps,
|
||||
@Nullable final ProgressIndicator indicator) throws IOException {
|
||||
String url;
|
||||
final File pluginListFile;
|
||||
final String eTag;
|
||||
final String host;
|
||||
@Nullable ProgressIndicator indicator) throws IOException {
|
||||
String url, host, eTag;
|
||||
File pluginListFile;
|
||||
|
||||
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);
|
||||
eTag = pluginListFile.length() > 0 ? loadPluginListETag(pluginListFile) : "";
|
||||
pluginListFile = new File(PathManager.getPluginsPath(), PLUGIN_LIST_FILE);
|
||||
eTag = loadPluginListETag(pluginListFile);
|
||||
}
|
||||
else {
|
||||
uriBuilder = new URIBuilder(repositoryUrl);
|
||||
@@ -129,9 +127,7 @@ public class RepositoryHelper {
|
||||
}
|
||||
|
||||
if (!URLUtil.FILE_PROTOCOL.equals(uriBuilder.getScheme())) {
|
||||
uriBuilder.addParameter("build",
|
||||
(buildnumber != null ? buildnumber.asString() : ApplicationInfoImpl.getShadowInstance().getApiVersion()));
|
||||
if (channel != null) uriBuilder.addParameter("channel", channel);
|
||||
uriBuilder.addParameter("build", build != null ? build.asString() : ApplicationInfoImpl.getShadowInstance().getApiVersion());
|
||||
}
|
||||
|
||||
host = uriBuilder.getHost();
|
||||
@@ -145,10 +141,11 @@ public class RepositoryHelper {
|
||||
indicator.setText2(IdeBundle.message("progress.connecting.to.plugin.manager", host));
|
||||
}
|
||||
|
||||
RequestBuilder request = HttpRequests.request(url).forceHttps(forceHttps).tuner(connection -> connection.setRequestProperty("If-None-Match", eTag)).productNameAsUserAgent();
|
||||
return process(repositoryUrl, request.connect(new HttpRequests.RequestProcessor<List<IdeaPluginDescriptor>>() {
|
||||
@Override
|
||||
public List<IdeaPluginDescriptor> process(@NotNull HttpRequests.Request request) throws IOException {
|
||||
List<IdeaPluginDescriptor> descriptors = HttpRequests.request(url)
|
||||
.forceHttps(forceHttps)
|
||||
.tuner(connection -> connection.setRequestProperty("If-None-Match", eTag))
|
||||
.productNameAsUserAgent()
|
||||
.connect(request -> {
|
||||
if (indicator != null) {
|
||||
indicator.checkCanceled();
|
||||
}
|
||||
@@ -170,52 +167,53 @@ public class RepositoryHelper {
|
||||
synchronized (PLUGIN_LIST_FILE) {
|
||||
FileUtil.ensureExists(pluginListFile.getParentFile());
|
||||
request.saveToFile(pluginListFile, indicator);
|
||||
savePluginListETag(pluginListFile, connection);
|
||||
savePluginListETag(pluginListFile, connection.getHeaderField("ETag"));
|
||||
return loadPluginList(pluginListFile);
|
||||
}
|
||||
}
|
||||
else {
|
||||
return parsePluginList(request.getReader());
|
||||
}
|
||||
}
|
||||
}));
|
||||
});
|
||||
|
||||
return process(repositoryUrl, descriptors);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static String loadPluginListETag(@NotNull File pluginListFile) {
|
||||
String eTag = "";
|
||||
File pluginListETagFile = getPluginListETagFile(pluginListFile);
|
||||
try {
|
||||
List<String> lines = FileUtil.loadLines(pluginListETagFile);
|
||||
if (lines.size() != 1) {
|
||||
LOG.warn("Couldn't load plugin list ETag from '" + pluginListETagFile.getAbsolutePath() + "'. Unexpected number of lines: " + lines.size());
|
||||
FileUtil.delete(pluginListETagFile);
|
||||
} else {
|
||||
eTag = lines.get(0);
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
LOG.warn("Couldn't load plugin list ETag from '" + pluginListETagFile.getAbsolutePath() + "'", e);
|
||||
}
|
||||
return eTag;
|
||||
}
|
||||
|
||||
private static void savePluginListETag(@NotNull File pluginListFile, @NotNull URLConnection connection) {
|
||||
File pluginListETagFile = getPluginListETagFile(pluginListFile);
|
||||
String eTag = connection.getHeaderField("ETag");
|
||||
if (eTag != null) {
|
||||
private static String loadPluginListETag(File pluginListFile) {
|
||||
File file = getPluginListETagFile(pluginListFile);
|
||||
if (file.length() > 0) {
|
||||
try {
|
||||
FileUtil.writeToFile(pluginListETagFile, eTag);
|
||||
List<String> lines = FileUtil.loadLines(file);
|
||||
if (lines.size() != 1) {
|
||||
LOG.warn("Can't load plugin list ETag from '" + file.getAbsolutePath() + "'. Unexpected number of lines: " + lines.size());
|
||||
FileUtil.delete(file);
|
||||
}
|
||||
else {
|
||||
return lines.get(0);
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
LOG.warn("Couldn't save plugin list ETag to '" + pluginListETagFile.getAbsolutePath() + "'", e);
|
||||
catch (IOException e) {
|
||||
LOG.warn("Can't load plugin list ETag from '" + file.getAbsolutePath() + "'", e);
|
||||
}
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
private static void savePluginListETag(File pluginListFile, String eTag) {
|
||||
if (eTag != null) {
|
||||
File file = getPluginListETagFile(pluginListFile);
|
||||
try {
|
||||
FileUtil.writeToFile(file, eTag);
|
||||
}
|
||||
catch (IOException e) {
|
||||
LOG.warn("Can't save plugin list ETag to '" + file.getAbsolutePath() + "'", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static File getPluginListETagFile(@NotNull File pluginListFile) {
|
||||
return new File(pluginListFile.getParentFile(), pluginListFile.getName() + ".etag");
|
||||
private static File getPluginListETagFile(File pluginListFile) {
|
||||
return new File(pluginListFile.getParentFile(), pluginListFile.getName() + TAG_EXT);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -224,14 +222,14 @@ public class RepositoryHelper {
|
||||
@Nullable
|
||||
public static List<IdeaPluginDescriptor> loadCachedPlugins() throws IOException {
|
||||
File file = new File(PathManager.getPluginsPath(), PLUGIN_LIST_FILE);
|
||||
return file.length() == 0 ? null : loadPluginList(file);
|
||||
return file.length() > 0 ? loadPluginList(file) : null;
|
||||
}
|
||||
|
||||
private static List<IdeaPluginDescriptor> loadPluginList(@NotNull File file) throws IOException {
|
||||
private static List<IdeaPluginDescriptor> loadPluginList(File file) throws IOException {
|
||||
return parsePluginList(new InputStreamReader(new BufferedInputStream(new FileInputStream(file)), CharsetToolkit.UTF8_CHARSET));
|
||||
}
|
||||
|
||||
private static List<IdeaPluginDescriptor> parsePluginList(@NotNull Reader reader) throws IOException {
|
||||
private static List<IdeaPluginDescriptor> parsePluginList(Reader reader) throws IOException {
|
||||
try {
|
||||
SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
|
||||
RepositoryContentHandler handler = new RepositoryContentHandler();
|
||||
@@ -246,7 +244,7 @@ public class RepositoryHelper {
|
||||
}
|
||||
}
|
||||
|
||||
private static List<IdeaPluginDescriptor> process(@Nullable String repositoryUrl, List<IdeaPluginDescriptor> list) {
|
||||
private static List<IdeaPluginDescriptor> process(String repositoryUrl, List<IdeaPluginDescriptor> list) {
|
||||
for (Iterator<IdeaPluginDescriptor> i = list.iterator(); i.hasNext(); ) {
|
||||
PluginNode node = (PluginNode)i.next();
|
||||
|
||||
|
||||
+1
-1
@@ -212,7 +212,7 @@ object UpdateChecker {
|
||||
outer@ for (host in hosts) {
|
||||
try {
|
||||
val forceHttps = host == null && updateSettings.canUseSecureConnection()
|
||||
val list = RepositoryHelper.loadPlugins(host, buildNumber, null, forceHttps, indicator)
|
||||
val list = RepositoryHelper.loadPlugins(host, buildNumber, forceHttps, indicator)
|
||||
for (descriptor in list) {
|
||||
val id = descriptor.pluginId
|
||||
if (updateable.containsKey(id)) {
|
||||
|
||||
Reference in New Issue
Block a user