aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-batch/src
diff options
context:
space:
mode:
Diffstat (limited to 'sonar-batch/src')
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchPluginExploder.java (renamed from sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchPluginUnzipper.java)16
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchPluginInstaller.java6
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchPluginPredicate.java5
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchPluginRepository.java20
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/GlobalContainer.java2
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchPluginExploderTest.java (renamed from sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchPluginUnzipperTest.java)20
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchPluginPredicateTest.java13
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchPluginRepositoryTest.java291
8 files changed, 105 insertions, 268 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchPluginUnzipper.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchPluginExploder.java
index 29f554ddc89..3ecb3e244c8 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchPluginUnzipper.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchPluginExploder.java
@@ -22,30 +22,30 @@ package org.sonar.batch.bootstrap;
import org.apache.commons.io.FileUtils;
import org.sonar.api.BatchComponent;
import org.sonar.api.utils.ZipUtils;
+import org.sonar.core.platform.ExplodedPlugin;
+import org.sonar.core.platform.PluginExploder;
import org.sonar.core.platform.PluginInfo;
-import org.sonar.core.platform.PluginUnzipper;
-import org.sonar.core.platform.UnzippedPlugin;
import org.sonar.home.cache.FileCache;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
-public class BatchPluginUnzipper extends PluginUnzipper implements BatchComponent {
+public class BatchPluginExploder extends PluginExploder implements BatchComponent {
private final FileCache fileCache;
- public BatchPluginUnzipper(FileCache fileCache) {
+ public BatchPluginExploder(FileCache fileCache) {
this.fileCache = fileCache;
}
@Override
- public UnzippedPlugin unzip(PluginInfo info) {
+ public ExplodedPlugin explode(PluginInfo info) {
try {
- File dir = unzipFile(info.getFile());
- return UnzippedPlugin.createFromUnzippedDir(info.getKey(), info.getFile(), dir);
+ File dir = unzipFile(info.getNonNullJarFile());
+ return explodeFromUnzippedDir(info.getKey(), info.getNonNullJarFile(), dir);
} catch (Exception e) {
- throw new IllegalStateException(String.format("Fail to open plugin [%s]: %s", info.getKey(), info.getFile().getAbsolutePath()), e);
+ throw new IllegalStateException(String.format("Fail to open plugin [%s]: %s", info.getKey(), info.getNonNullJarFile().getAbsolutePath()), e);
}
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchPluginInstaller.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchPluginInstaller.java
index 6e2c5886c60..190ad8a5e82 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchPluginInstaller.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchPluginInstaller.java
@@ -45,6 +45,7 @@ import java.util.Map;
public class BatchPluginInstaller implements PluginInstaller {
private static final Logger LOG = Loggers.get(BatchPluginInstaller.class);
+ private static final String PLUGINS_INDEX_URL = "/deploy/plugins/index.txt";
private final ServerClient server;
private final FileCache fileCache;
@@ -105,10 +106,9 @@ public class BatchPluginInstaller implements PluginInstaller {
*/
@VisibleForTesting
List<RemotePlugin> listRemotePlugins() {
- String url = "/deploy/plugins/index.txt";
try {
LOG.debug("Download index of plugins");
- String indexContent = server.request(url);
+ String indexContent = server.request(PLUGINS_INDEX_URL);
String[] rows = StringUtils.split(indexContent, CharUtils.LF);
List<RemotePlugin> result = Lists.newArrayList();
for (String row : rows) {
@@ -117,7 +117,7 @@ public class BatchPluginInstaller implements PluginInstaller {
return result;
} catch (Exception e) {
- throw new IllegalStateException("Fail to download list of plugins: " + url, e);
+ throw new IllegalStateException("Fail to download list of plugins: " + PLUGINS_INDEX_URL, e);
}
}
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchPluginPredicate.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchPluginPredicate.java
index 09cb7d391f0..0cd7f1c62e7 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchPluginPredicate.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchPluginPredicate.java
@@ -48,6 +48,7 @@ public class BatchPluginPredicate implements Predicate<String>, BatchComponent {
private static final String CORE_PLUGIN_KEY = "core";
private static final String BUILDBREAKER_PLUGIN_KEY = "buildbreaker";
private static final String PROPERTY_IS_DEPRECATED_MSG = "Property {0} is deprecated. Please use {1} instead.";
+ private static final Joiner COMMA_JOINER = Joiner.on(", ");
private final Set<String> whites = newHashSet(), blacks = newHashSet();
private final DefaultAnalysisMode mode;
@@ -75,10 +76,10 @@ public class BatchPluginPredicate implements Predicate<String>, BatchComponent {
}
}
if (!whites.isEmpty()) {
- LOG.info("Include plugins: " + Joiner.on(", ").join(whites));
+ LOG.info("Include plugins: " + COMMA_JOINER.join(whites));
}
if (!blacks.isEmpty()) {
- LOG.info("Exclude plugins: " + Joiner.on(", ").join(blacks));
+ LOG.info("Exclude plugins: " + COMMA_JOINER.join(blacks));
}
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchPluginRepository.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchPluginRepository.java
index b20c85114ed..37658fe8b1e 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchPluginRepository.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchPluginRepository.java
@@ -19,6 +19,9 @@
*/
package org.sonar.batch.bootstrap;
+import com.google.common.base.Preconditions;
+import com.google.common.collect.Maps;
+import java.util.HashMap;
import org.picocontainer.Startable;
import org.sonar.api.Plugin;
import org.sonar.core.platform.PluginInfo;
@@ -28,6 +31,9 @@ import org.sonar.core.platform.PluginRepository;
import java.util.Collection;
import java.util.Map;
+/**
+ * Orchestrates the installation and loading of plugins
+ */
public class BatchPluginRepository implements PluginRepository, Startable {
private final PluginInstaller installer;
@@ -43,8 +49,8 @@ public class BatchPluginRepository implements PluginRepository, Startable {
@Override
public void start() {
- infosByKeys = installer.installRemotes();
- pluginInstancesByKeys = loader.load(infosByKeys);
+ infosByKeys = Maps.newHashMap(installer.installRemotes());
+ pluginInstancesByKeys = Maps.newHashMap(loader.load(infosByKeys));
// this part is only used by tests
for (Map.Entry<String, Plugin> entry : installer.installLocals().entrySet()) {
@@ -70,14 +76,16 @@ public class BatchPluginRepository implements PluginRepository, Startable {
@Override
public PluginInfo getPluginInfo(String key) {
- // TODO check null result
- return infosByKeys.get(key);
+ PluginInfo info = infosByKeys.get(key);
+ Preconditions.checkState(info != null, String.format("Plugin [%s] does not exist", key));
+ return info;
}
@Override
public Plugin getPluginInstance(String key) {
- // TODO check null result
- return pluginInstancesByKeys.get(key);
+ Plugin instance = pluginInstancesByKeys.get(key);
+ Preconditions.checkState(instance != null, String.format("Plugin [%s] does not exist", key));
+ return instance;
}
@Override
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/GlobalContainer.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/GlobalContainer.java
index 09d217122af..18be773ae8c 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/GlobalContainer.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/GlobalContainer.java
@@ -98,7 +98,7 @@ public class GlobalContainer extends ComponentContainer {
// plugins
BatchPluginRepository.class,
PluginLoader.class,
- BatchPluginUnzipper.class,
+ BatchPluginExploder.class,
BatchPluginPredicate.class,
ExtensionInstaller.class,
diff --git a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchPluginUnzipperTest.java b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchPluginExploderTest.java
index 06a25148775..3d080e35d82 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchPluginUnzipperTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchPluginExploderTest.java
@@ -25,7 +25,7 @@ import org.junit.ClassRule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.sonar.core.platform.PluginInfo;
-import org.sonar.core.platform.UnzippedPlugin;
+import org.sonar.core.platform.ExplodedPlugin;
import org.sonar.home.cache.FileCache;
import org.sonar.home.cache.FileCacheBuilder;
@@ -34,29 +34,29 @@ import java.io.IOException;
import static org.assertj.core.api.Assertions.assertThat;
-public class BatchPluginUnzipperTest {
+public class BatchPluginExploderTest {
@ClassRule
public static TemporaryFolder temp = new TemporaryFolder();
File userHome;
- BatchPluginUnzipper underTest;
+ BatchPluginExploder underTest;
@Before
public void setUp() throws IOException {
userHome = temp.newFolder();
FileCache fileCache = new FileCacheBuilder().setUserHome(userHome).build();
- underTest = new BatchPluginUnzipper(fileCache);
+ underTest = new BatchPluginExploder(fileCache);
}
@Test
public void copy_and_extract_libs() throws IOException {
File fileFromCache = getFileFromCache("sonar-checkstyle-plugin-2.8.jar");
- UnzippedPlugin unzipped = underTest.unzip(PluginInfo.create(fileFromCache));
+ ExplodedPlugin exploded = underTest.explode(PluginInfo.create(fileFromCache));
- assertThat(unzipped.getKey()).isEqualTo("checkstyle");
- assertThat(unzipped.getMain()).isFile().exists();
- assertThat(unzipped.getLibs()).extracting("name").containsOnly("antlr-2.7.6.jar", "checkstyle-5.1.jar", "commons-cli-1.0.jar");
+ assertThat(exploded.getKey()).isEqualTo("checkstyle");
+ assertThat(exploded.getMain()).isFile().exists();
+ assertThat(exploded.getLibs()).extracting("name").containsOnly("antlr-2.7.6.jar", "checkstyle-5.1.jar", "commons-cli-1.0.jar");
assertThat(new File(fileFromCache.getParent(), "sonar-checkstyle-plugin-2.8.jar")).exists();
assertThat(new File(fileFromCache.getParent(), "sonar-checkstyle-plugin-2.8.jar_unzip/META-INF/lib/checkstyle-5.1.jar")).exists();
}
@@ -64,7 +64,7 @@ public class BatchPluginUnzipperTest {
@Test
public void extract_only_libs() throws IOException {
File fileFromCache = getFileFromCache("sonar-checkstyle-plugin-2.8.jar");
- underTest.unzip(PluginInfo.create(fileFromCache));
+ underTest.explode(PluginInfo.create(fileFromCache));
assertThat(new File(fileFromCache.getParent(), "sonar-checkstyle-plugin-2.8.jar")).exists();
assertThat(new File(fileFromCache.getParent(), "sonar-checkstyle-plugin-2.8.jar_unzip/META-INF/MANIFEST.MF")).doesNotExist();
@@ -72,7 +72,7 @@ public class BatchPluginUnzipperTest {
}
File getFileFromCache(String filename) throws IOException {
- File src = FileUtils.toFile(BatchPluginUnzipperTest.class.getResource("/org/sonar/batch/bootstrap/BatchPluginUnzipperTest/" + filename));
+ File src = FileUtils.toFile(BatchPluginExploderTest.class.getResource("/org/sonar/batch/bootstrap/BatchPluginUnzipperTest/" + filename));
File destFile = new File(new File(userHome, "" + filename.hashCode()), filename);
FileUtils.copyFile(src, destFile);
return destFile;
diff --git a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchPluginPredicateTest.java b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchPluginPredicateTest.java
index 95d9f18eb4c..57176404845 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchPluginPredicateTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchPluginPredicateTest.java
@@ -67,7 +67,7 @@ public class BatchPluginPredicateTest {
}
@Test
- public void accept_core_plugin_even_if_in_exclusions() {
+ public void accept_core_plugin_even_if_declared_in_exclusions() {
when(mode.isPreview()).thenReturn(true);
settings.setProperty(CoreProperties.PREVIEW_EXCLUDE_PLUGINS, "core,findbugs");
BatchPluginPredicate predicate = new BatchPluginPredicate(settings, mode);
@@ -75,7 +75,7 @@ public class BatchPluginPredicateTest {
}
@Test
- public void both_inclusions_and_exclusions() {
+ public void verify_both_inclusions_and_exclusions() {
when(mode.isPreview()).thenReturn(true);
settings
.setProperty(CoreProperties.PREVIEW_INCLUDE_PLUGINS, "checkstyle,pmd,findbugs")
@@ -87,7 +87,7 @@ public class BatchPluginPredicateTest {
}
@Test
- public void only_exclusions() {
+ public void test_exclusions_without_any_inclusions() {
when(mode.isPreview()).thenReturn(true);
settings.setProperty(CoreProperties.PREVIEW_EXCLUDE_PLUGINS, "checkstyle,pmd,findbugs");
BatchPluginPredicate predicate = new BatchPluginPredicate(settings, mode);
@@ -96,8 +96,13 @@ public class BatchPluginPredicateTest {
assertThat(predicate.apply("cobertura")).isTrue();
}
+ /**
+ * The properties sonar.dryRun.includePlugins and sonar.dryRun.excludePlugins
+ * are deprecated. They are replaced by sonar.preview.includePlugins and
+ * sonar.preview.excludePlugins.
+ */
@Test
- public void deprecated_dry_run_settings() {
+ public void support_deprecated_dry_run_settings() {
when(mode.isPreview()).thenReturn(true);
settings
.setProperty(CoreProperties.DRY_RUN_INCLUDE_PLUGINS, "cockpit")
diff --git a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchPluginRepositoryTest.java b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchPluginRepositoryTest.java
index 7c82edbb64f..cafee2bebf2 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchPluginRepositoryTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchPluginRepositoryTest.java
@@ -17,237 +17,60 @@
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-///*
-// * SonarQube, open source software quality management tool.
-// * Copyright (C) 2008-2014 SonarSource
-// * mailto:contact AT sonarsource DOT com
-// *
-// * SonarQube is free software; you can redistribute it and/or
-// * modify it under the terms of the GNU Lesser General Public
-// * License as published by the Free Software Foundation; either
-// * version 3 of the License, or (at your option) any later version.
-// *
-// * SonarQube is distributed in the hope that it will be useful,
-// * but WITHOUT ANY WARRANTY; without even the implied warranty of
-// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// * Lesser General Public License for more details.
-// *
-// * You should have received a copy of the GNU Lesser General Public License
-// * along with this program; if not, write to the Free Software Foundation,
-// * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-// */
-//package org.sonar.batch.bootstrap;
-//
-//import com.google.common.io.Resources;
-//import org.apache.commons.io.FileUtils;
-//import org.junit.After;
-//import org.junit.Before;
-//import org.junit.Rule;
-//import org.junit.Test;
-//import org.junit.rules.TemporaryFolder;
-//import org.sonar.api.CoreProperties;
-//import org.sonar.api.config.Settings;
-//import org.sonar.core.plugins.RemotePlugin;
-//import org.sonar.home.cache.FileCache;
-//import org.sonar.home.cache.FileCacheBuilder;
-//
-//import java.io.File;
-//import java.io.IOException;
-//import java.util.Arrays;
-//
-//import static org.mockito.Mockito.mock;
-//import static org.mockito.Mockito.when;
-//
-//public class BatchPluginRepositoryTest {
-//
-// @Rule
-// public TemporaryFolder temp = new TemporaryFolder();
-//
-// private BatchPluginRepository repository;
-// private DefaultAnalysisMode mode;
-// private FileCache cache;
-// private File userHome;
-//
-// @Before
-// public void before() throws IOException {
-// mode = mock(DefaultAnalysisMode.class);
-// when(mode.isPreview()).thenReturn(false);
-// userHome = temp.newFolder();
-// cache = new FileCacheBuilder().setUserHome(userHome).build();
-// }
-//
-// @After
-// public void tearDown() {
-// if (repository != null) {
-// repository.stop();
-// }
-// }
-//
-// @Test
-// public void shouldLoadPlugin() throws Exception {
-// RemotePlugin checkstyle = new RemotePlugin("checkstyle", true);
-//
-// DefaultPluginRepository installer = mock(DefaultPluginsRepository.class);
-// when(installer.pluginFile(checkstyle)).thenReturn(fileFromCache("sonar-checkstyle-plugin-2.8.jar"));
-//
-// repository = new BatchPluginRepository(installer, new Settings(), mode, new BatchPluginJarInstaller(cache));
-//
-// repository.doStart(Arrays.asList(checkstyle));
-//
-// assertThat(repository.getPlugin("checkstyle")).isNotNull();
-// assertThat(repository.getMetadata()).hasSize(1);
-// assertThat(repository.getMetadata("checkstyle").getName()).isEqualTo("Checkstyle");
-// assertThat(repository.getMetadata("checkstyle").getDeployedFiles()).hasSize(4); // plugin + 3 dependencies
-// }
-//
-// @Test
-// public void shouldLoadPluginExtension() throws Exception {
-// RemotePlugin checkstyle = new RemotePlugin("checkstyle", true);
-// RemotePlugin checkstyleExt = new RemotePlugin("checkstyleextensions", false);
-//
-// DefaultPluginsRepository downloader = mock(DefaultPluginsRepository.class);
-// when(downloader.pluginFile(checkstyle)).thenReturn(fileFromCache("sonar-checkstyle-plugin-2.8.jar"));
-// when(downloader.pluginFile(checkstyleExt)).thenReturn(fileFromCache("sonar-checkstyle-extensions-plugin-0.1-SNAPSHOT.jar"));
-//
-// repository = new BatchPluginRepository(downloader, new Settings(), mode, new BatchPluginJarInstaller(cache));
-//
-// repository.doStart(Arrays.asList(checkstyle, checkstyleExt));
-//
-// assertThat(repository.getPlugin("checkstyle")).isNotNull();
-// assertThat(repository.getPlugin("checkstyleextensions")).isNotNull();
-// assertThat(repository.getMetadata()).hasSize(2);
-// assertThat(repository.getMetadata("checkstyle").getName()).isEqualTo("Checkstyle");
-// assertThat(repository.getMetadata("checkstyleextensions").getVersion()).isEqualTo("0.1-SNAPSHOT");
-// }
-//
-// @Test
-// public void shouldExcludePluginAndItsExtensions() throws Exception {
-// RemotePlugin checkstyle = new RemotePlugin("checkstyle", true);
-// RemotePlugin checkstyleExt = new RemotePlugin("checkstyleextensions", false);
-//
-// DefaultPluginsRepository downloader = mock(DefaultPluginsRepository.class);
-// when(downloader.pluginFile(checkstyle)).thenReturn(fileFromCache("sonar-checkstyle-plugin-2.8.jar"));
-// when(downloader.pluginFile(checkstyleExt)).thenReturn(fileFromCache("sonar-checkstyle-extensions-plugin-0.1-SNAPSHOT.jar"));
-//
-// Settings settings = new Settings();
-// settings.setProperty(CoreProperties.BATCH_EXCLUDE_PLUGINS, "checkstyle");
-// repository = new BatchPluginRepository(downloader, settings, mode, new BatchPluginJarInstaller(cache));
-//
-// repository.doStart(Arrays.asList(checkstyle, checkstyleExt));
-//
-// assertThat(repository.getMetadata()).isEmpty();
-// }
-//
-// private File fileFromCache(String filename) throws Exception {
-// File file = new File(Resources.getResource("org/sonar/batch/bootstrap/BatchPluginRepositoryTest/" + filename).toURI());
-// File destDir = new File(userHome, "cache/foomd5");
-// FileUtils.forceMkdir(destDir);
-// FileUtils.copyFileToDirectory(file, destDir);
-// return new File(destDir, filename);
-// }
-//
-// @Test
-// public void shouldAlwaysAcceptIfNoWhiteListAndBlackList() {
-// BatchPluginRepository.PluginFilter filter = new BatchPluginRepository.PluginFilter(new Settings(), mode);
-// assertThat(filter.accepts("pmd")).isTrue();
-// assertThat(filter.accepts("buildbreaker")).isTrue();
-// }
-//
-// @Test
-// public void shouldBlackListBuildBreakerInPreviewMode() {
-// when(mode.isPreview()).thenReturn(true);
-// BatchPluginRepository.PluginFilter filter = new BatchPluginRepository.PluginFilter(new Settings(), mode);
-// assertThat(filter.accepts("buildbreaker")).isFalse();
-// }
-//
-// @Test
-// public void whiteListShouldTakePrecedenceOverBlackList() {
-// Settings settings = new Settings()
-// .setProperty(CoreProperties.BATCH_INCLUDE_PLUGINS, "checkstyle,pmd,findbugs")
-// .setProperty(CoreProperties.BATCH_EXCLUDE_PLUGINS, "cobertura,pmd");
-// BatchPluginRepository.PluginFilter filter = new BatchPluginRepository.PluginFilter(settings, mode);
-// assertThat(filter.accepts("pmd")).isTrue();
-// }
-//
-// @Test
-// public void corePluginShouldAlwaysBeInWhiteList() {
-// Settings settings = new Settings()
-// .setProperty(CoreProperties.BATCH_INCLUDE_PLUGINS, "checkstyle,pmd,findbugs");
-// BatchPluginRepository.PluginFilter filter = new BatchPluginRepository.PluginFilter(settings, mode);
-// assertThat(filter.accepts("core")).isTrue();
-// }
-//
-// @Test
-// public void corePluginShouldNeverBeInBlackList() {
-// Settings settings = new Settings()
-// .setProperty(CoreProperties.BATCH_EXCLUDE_PLUGINS, "core,findbugs");
-// BatchPluginRepository.PluginFilter filter = new BatchPluginRepository.PluginFilter(settings, mode);
-// assertThat(filter.accepts("core")).isTrue();
-// }
-//
-// @Test
-// public void check_white_list_with_black_list() {
-// Settings settings = new Settings()
-// .setProperty(CoreProperties.BATCH_INCLUDE_PLUGINS, "checkstyle,pmd,findbugs")
-// .setProperty(CoreProperties.BATCH_EXCLUDE_PLUGINS, "cobertura");
-// BatchPluginRepository.PluginFilter filter = new BatchPluginRepository.PluginFilter(settings, mode);
-// assertThat(filter.accepts("checkstyle")).isTrue();
-// assertThat(filter.accepts("pmd")).isTrue();
-// assertThat(filter.accepts("cobertura")).isFalse();
-// }
-//
-// @Test
-// public void check_white_list_when_plugin_is_in_both_list() {
-// Settings settings = new Settings()
-// .setProperty(CoreProperties.BATCH_INCLUDE_PLUGINS, "cobertura,checkstyle,pmd,findbugs")
-// .setProperty(CoreProperties.BATCH_EXCLUDE_PLUGINS, "cobertura");
-// BatchPluginRepository.PluginFilter filter = new BatchPluginRepository.PluginFilter(settings, mode);
-// assertThat(filter.accepts("checkstyle")).isTrue();
-// assertThat(filter.accepts("pmd")).isTrue();
-// assertThat(filter.accepts("cobertura")).isTrue();
-// }
-//
-// @Test
-// public void check_black_list_if_no_white_list() {
-// Settings settings = new Settings()
-// .setProperty(CoreProperties.BATCH_EXCLUDE_PLUGINS, "checkstyle,pmd,findbugs");
-// BatchPluginRepository.PluginFilter filter = new BatchPluginRepository.PluginFilter(settings, mode);
-// assertThat(filter.accepts("checkstyle")).isFalse();
-// assertThat(filter.accepts("pmd")).isFalse();
-// assertThat(filter.accepts("cobertura")).isTrue();
-// }
-//
-// @Test
-// public void should_concatenate_preview_filters() {
-// Settings settings = new Settings()
-// .setProperty(CoreProperties.PREVIEW_INCLUDE_PLUGINS, "cockpit")
-// .setProperty(CoreProperties.PREVIEW_EXCLUDE_PLUGINS, "views")
-// .setProperty(CoreProperties.BATCH_EXCLUDE_PLUGINS, "checkstyle,pmd");
-// when(mode.isPreview()).thenReturn(true);
-// BatchPluginRepository.PluginFilter filter = new BatchPluginRepository.PluginFilter(settings, mode);
-// assertThat(filter.whites).containsOnly("cockpit");
-// assertThat(filter.blacks).containsOnly("views", "checkstyle", "pmd");
-// }
-//
-// @Test
-// public void should_concatenate_deprecated_dry_run_filters() {
-// Settings settings = new Settings()
-// .setProperty(CoreProperties.DRY_RUN_INCLUDE_PLUGINS, "cockpit")
-// .setProperty(CoreProperties.DRY_RUN_EXCLUDE_PLUGINS, "views")
-// .setProperty(CoreProperties.BATCH_EXCLUDE_PLUGINS, "checkstyle,pmd");
-// when(mode.isPreview()).thenReturn(true);
-// BatchPluginRepository.PluginFilter filter = new BatchPluginRepository.PluginFilter(settings, mode);
-// assertThat(filter.whites).containsOnly("cockpit");
-// assertThat(filter.blacks).containsOnly("views", "checkstyle", "pmd");
-// }
-//
-// @Test
-// public void inclusions_and_exclusions_should_be_trimmed() {
-// Settings settings = new Settings()
-// .setProperty(CoreProperties.BATCH_INCLUDE_PLUGINS, "checkstyle, pmd, findbugs")
-// .setProperty(CoreProperties.BATCH_EXCLUDE_PLUGINS, "cobertura, pmd");
-// BatchPluginRepository.PluginFilter filter = new BatchPluginRepository.PluginFilter(settings, mode);
-// assertThat(filter.accepts("pmd")).isTrue();
-// }
-//
-//}
+package org.sonar.batch.bootstrap;
+
+import com.google.common.collect.ImmutableMap;
+import org.junit.Test;
+import org.sonar.api.Plugin;
+import org.sonar.core.platform.PluginInfo;
+import org.sonar.core.platform.PluginLoader;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.Assert.fail;
+import static org.mockito.Matchers.anyCollectionOf;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+public class BatchPluginRepositoryTest {
+
+ PluginInstaller installer = mock(PluginInstaller.class);
+ PluginLoader loader = mock(PluginLoader.class);
+ BatchPluginRepository underTest = new BatchPluginRepository(installer, loader);
+
+ @Test
+ public void install_and_load_plugins() throws Exception {
+ PluginInfo info = new PluginInfo("squid");
+ ImmutableMap<String, PluginInfo> infos = ImmutableMap.of("squid", info);
+ Plugin instance = mock(Plugin.class);
+ when(loader.load(infos)).thenReturn(ImmutableMap.of("squid", instance));
+ when(installer.installRemotes()).thenReturn(infos);
+
+ underTest.start();
+
+ assertThat(underTest.getPluginInfos()).containsOnly(info);
+ assertThat(underTest.getPluginInfo("squid")).isSameAs(info);
+ assertThat(underTest.getPluginInstance("squid")).isSameAs(instance);
+
+ underTest.stop();
+ verify(loader).unload(anyCollectionOf(Plugin.class));
+ }
+
+ @Test
+ public void fail_if_requesting_missing_plugin() throws Exception {
+ underTest.start();
+
+ try {
+ underTest.getPluginInfo("unknown");
+ fail();
+ } catch (IllegalStateException e) {
+ assertThat(e).hasMessage("Plugin [unknown] does not exist");
+ }
+ try {
+ underTest.getPluginInstance("unknown");
+ fail();
+ } catch (IllegalStateException e) {
+ assertThat(e).hasMessage("Plugin [unknown] does not exist");
+ }
+ }
+}