import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang.StringUtils;
+/**
+ * @deprecated since 6.6 Used for deprecated deploy/plugin/index.txt
+ *
+ */
+@Deprecated
public class RemotePlugin {
private String pluginKey;
private boolean sonarLintSupported;
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;
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;
@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);
}
}
@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);
}
}
* 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 {
package org.sonar.scanner.bootstrap;
import java.io.File;
-import java.io.StringReader;
-import java.util.List;
+import java.io.InputStreamReader;
+import java.nio.charset.StandardCharsets;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.rules.TemporaryFolder;
-import org.sonar.core.platform.RemotePlugin;
import org.sonar.home.cache.FileCache;
import org.sonar.scanner.WsTestUtil;
+import org.sonar.scanner.bootstrap.ScannerPluginInstaller.InstalledPlugin;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Matchers.any;
@Test
public void listRemotePlugins() {
- WsTestUtil.mockReader(wsClient, "/deploy/plugins/index.txt", new StringReader("checkstyle\nsqale"));
+ WsTestUtil.mockReader(wsClient, "/api/plugins/installed",
+ new InputStreamReader(this.getClass().getResourceAsStream("ScannerPluginInstallerTest/installed-plugins-ws.json"), StandardCharsets.UTF_8));
ScannerPluginInstaller underTest = new ScannerPluginInstaller(wsClient, fileCache, pluginPredicate);
- List<RemotePlugin> remotePlugins = underTest.listRemotePlugins();
- assertThat(remotePlugins).extracting("key").containsOnly("checkstyle", "sqale");
+ InstalledPlugin[] remotePlugins = underTest.listInstalledPlugins();
+ assertThat(remotePlugins).extracting("key").containsOnly("scmgit", "java", "scmsvn");
}
@Test
ScannerPluginInstaller underTest = new ScannerPluginInstaller(wsClient, fileCache, pluginPredicate);
- RemotePlugin remote = new RemotePlugin("checkstyle").setFile("checkstyle-plugin.jar", "fakemd5_1");
+ InstalledPlugin remote = new InstalledPlugin();
+ remote.key = "checkstyle";
+ remote.filename = "checkstyle-plugin.jar";
+ remote.hash = "fakemd5_1";
File file = underTest.download(remote);
assertThat(file).isEqualTo(pluginJar);
@Test
public void should_fail_to_get_plugin_index() {
- WsTestUtil.mockException(wsClient, "/deploy/plugins/index.txt", new IllegalStateException());
+ WsTestUtil.mockException(wsClient, "/api/plugins/installed", new IllegalStateException());
thrown.expect(IllegalStateException.class);
new ScannerPluginInstaller(wsClient, fileCache, pluginPredicate).installRemotes();
--- /dev/null
+{
+ "plugins": [
+ {
+ "key": "scmgit",
+ "name": "Git",
+ "description": "Git SCM Provider.",
+ "version": "1.0",
+ "license": "GNU LGPL 3",
+ "organizationName": "SonarSource",
+ "organizationUrl": "http://www.sonarsource.com",
+ "homepageUrl": "https://redirect.sonarsource.com/plugins/scmgit.html",
+ "issueTrackerUrl": "http://jira.sonarsource.com/browse/SONARSCGIT",
+ "implementationBuild": "9ce9d330c313c296fab051317cc5ad4b26319e07",
+ "filename": "sonar-scm-git-plugin-1.0.jar",
+ "hash": "abcdef123456",
+ "sonarLintSupported": false,
+ "updatedAt": 123456789
+ },
+ {
+ "key": "java",
+ "name": "Java",
+ "description": "SonarQube rule engine.",
+ "version": "3.0",
+ "license": "GNU LGPL 3",
+ "organizationName": "SonarSource",
+ "organizationUrl": "http://www.sonarsource.com",
+ "homepageUrl": "https://redirect.sonarsource.com/plugins/java.html",
+ "issueTrackerUrl": "http://jira.sonarsource.com/browse/SONARJAVA",
+ "implementationBuild": "65396a609ddface8b311a6a665aca92a7da694f1",
+ "filename": "sonar-java-plugin-3.0.jar",
+ "hash": "abcdef123456",
+ "sonarLintSupported": true,
+ "updatedAt": 123456789
+ },
+ {
+ "key": "scmsvn",
+ "name": "SVN",
+ "description": "SVN SCM Provider.",
+ "version": "1.0",
+ "license": "GNU LGPL 3",
+ "organizationName": "SonarSource",
+ "organizationUrl": "http://www.sonarsource.com",
+ "homepageUrl": "https://redirect.sonarsource.com/plugins/scmsvn.html",
+ "issueTrackerUrl": "http://jira.sonarsource.com/browse/SONARSCSVN",
+ "implementationBuild": "213fc8a8b582ff530b12dd4a59a6512be1071234",
+ "filename": "sonar-scm-svn-plugin-1.0.jar",
+ "hash": "abcdef123456",
+ "sonarLintSupported": false,
+ "updatedAt": 123456789
+ }
+ ]
+}
\ No newline at end of file