aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-scanner-engine/src/main/java/org/sonar
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2017-08-07 16:22:59 +0200
committerJulien HENRY <julien.henry@sonarsource.com>2017-09-07 08:33:31 +0200
commit82b2e9e5c327119ede2ee66cd63c65722b40409c (patch)
tree51b4f092485d8398d75503e9c31c40ceccea89f8 /sonar-scanner-engine/src/main/java/org/sonar
parent5312732c79afcddb26b81e6be4278279f186cc22 (diff)
downloadsonarqube-82b2e9e5c327119ede2ee66cd63c65722b40409c.tar.gz
sonarqube-82b2e9e5c327119ede2ee66cd63c65722b40409c.zip
SONAR-9684 Use api/plugins/installed to load plugins
Diffstat (limited to 'sonar-scanner-engine/src/main/java/org/sonar')
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ScannerPluginInstaller.java64
1 files changed, 26 insertions, 38 deletions
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ScannerPluginInstaller.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ScannerPluginInstaller.java
index 4b0db1f328e..a8f40fdb6e1 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ScannerPluginInstaller.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ScannerPluginInstaller.java
@@ -20,26 +20,20 @@
package org.sonar.scanner.bootstrap;
import com.google.common.annotations.VisibleForTesting;
+import com.google.gson.Gson;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
-import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
-import java.util.List;
import java.util.Map;
import org.apache.commons.io.FileUtils;
-import org.apache.commons.io.IOUtils;
-import org.apache.commons.lang.CharUtils;
-import org.apache.commons.lang.StringUtils;
import org.sonar.api.Plugin;
import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;
import org.sonar.api.utils.log.Profiler;
import org.sonar.core.platform.PluginInfo;
-import org.sonar.core.platform.RemotePlugin;
-import org.sonar.core.platform.RemotePluginFile;
import org.sonar.home.cache.FileCache;
import org.sonarqube.ws.client.GetRequest;
import org.sonarqube.ws.client.WsResponse;
@@ -53,7 +47,7 @@ import static java.lang.String.format;
public class ScannerPluginInstaller implements PluginInstaller {
private static final Logger LOG = Loggers.get(ScannerPluginInstaller.class);
- private static final String PLUGINS_INDEX_URL = "/deploy/plugins/index.txt";
+ private static final String PLUGINS_WS_URL = "/api/plugins/installed";
private final FileCache fileCache;
private final ScannerPluginPredicate pluginPredicate;
@@ -67,17 +61,17 @@ public class ScannerPluginInstaller implements PluginInstaller {
@Override
public Map<String, PluginInfo> installRemotes() {
- return loadPlugins(listRemotePlugins());
+ return loadPlugins(listInstalledPlugins());
}
- private Map<String, PluginInfo> loadPlugins(List<RemotePlugin> remotePlugins) {
- Map<String, PluginInfo> infosByKey = new HashMap<>(remotePlugins.size());
+ private Map<String, PluginInfo> loadPlugins(InstalledPlugin[] remotePlugins) {
+ Map<String, PluginInfo> infosByKey = new HashMap<>(remotePlugins.length);
Profiler profiler = Profiler.create(LOG).startDebug("Load plugins");
- for (RemotePlugin remotePlugin : remotePlugins) {
- if (pluginPredicate.apply(remotePlugin.getKey())) {
- File jarFile = download(remotePlugin);
+ for (InstalledPlugin installedPlugin : remotePlugins) {
+ if (pluginPredicate.apply(installedPlugin.key)) {
+ File jarFile = download(installedPlugin);
PluginInfo info = PluginInfo.create(jarFile);
infosByKey.put(info.getKey(), info);
}
@@ -97,12 +91,11 @@ public class ScannerPluginInstaller implements PluginInstaller {
}
@VisibleForTesting
- File download(final RemotePlugin remote) {
+ File download(final InstalledPlugin remote) {
try {
- final RemotePluginFile file = remote.file();
- return fileCache.get(file.getFilename(), file.getHash(), new FileDownloader(remote.getKey()));
+ return fileCache.get(remote.filename, remote.hash, new FileDownloader(remote.key));
} catch (Exception e) {
- throw new IllegalStateException("Fail to download plugin: " + remote.getKey(), e);
+ throw new IllegalStateException("Fail to download plugin: " + remote.key, e);
}
}
@@ -110,33 +103,28 @@ public class ScannerPluginInstaller implements PluginInstaller {
* Gets information about the plugins installed on server (filename, checksum)
*/
@VisibleForTesting
- List<RemotePlugin> listRemotePlugins() {
- try {
- String pluginIndex = loadPluginIndex();
- String[] rows = StringUtils.split(pluginIndex, CharUtils.LF);
- List<RemotePlugin> result = new ArrayList<>();
- for (String row : rows) {
- result.add(RemotePlugin.unmarshal(row));
- }
- return result;
-
- } catch (Exception e) {
- throw new IllegalStateException("Fail to load plugin index: " + PLUGINS_INDEX_URL, e);
- }
- }
-
- private String loadPluginIndex() {
+ InstalledPlugin[] listInstalledPlugins() {
Profiler profiler = Profiler.create(LOG).startInfo("Load plugins index");
- GetRequest getRequest = new GetRequest(PLUGINS_INDEX_URL);
- String str;
+ GetRequest getRequest = new GetRequest(PLUGINS_WS_URL);
+ InstalledPlugins installedPlugins;
try (Reader reader = wsClient.call(getRequest).contentReader()) {
- str = IOUtils.toString(reader);
+ installedPlugins = new Gson().fromJson(reader, InstalledPlugins.class);
} catch (IOException e) {
throw new IllegalStateException(e);
}
profiler.stopInfo();
- return str;
+ return installedPlugins.plugins;
+ }
+
+ private static class InstalledPlugins {
+ InstalledPlugin[] plugins;
+ }
+
+ static class InstalledPlugin {
+ String key;
+ String hash;
+ String filename;
}
private class FileDownloader implements FileCache.Downloader {