From 3eb8efb05a2c64bc0013b60c405ac829ca67435f Mon Sep 17 00:00:00 2001 From: Julien HENRY Date: Wed, 25 Feb 2015 18:49:15 +0100 Subject: [PATCH] SONAR-5927 Blacklist the build breaker plugin in preview mode --- .../batch/bootstrap/BatchPluginRepository.java | 12 +++++++----- ...rential.java => DefaultPluginsRepository.java} | 6 +++--- .../sonar/batch/bootstrap/GlobalContainer.java | 2 +- .../bootstrap/BatchPluginRepositoryTest.java | 15 ++++++++++++--- ...est.java => DefaultPluginsRepositoryTest.java} | 8 ++++---- 5 files changed, 27 insertions(+), 16 deletions(-) rename sonar-batch/src/main/java/org/sonar/batch/bootstrap/{DefaultPluginsReferential.java => DefaultPluginsRepository.java} (94%) rename sonar-batch/src/test/java/org/sonar/batch/bootstrap/{DefaultPluginsReferentialTest.java => DefaultPluginsRepositoryTest.java} (90%) 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 42f21fe9104..b8a44c0d97c 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 @@ -37,11 +37,7 @@ import org.sonar.core.plugins.RemotePlugin; import java.io.File; import java.text.MessageFormat; -import java.util.Arrays; -import java.util.Collection; -import java.util.List; -import java.util.Map; -import java.util.Set; +import java.util.*; import static com.google.common.collect.Lists.newArrayList; import static com.google.common.collect.Sets.newHashSet; @@ -132,6 +128,7 @@ public class BatchPluginRepository implements PluginRepository { } static class PluginFilter { + private static final String BUILDBREAKER_PLUGIN_KEY = "buildbreaker"; private static final String PROPERTY_IS_DEPRECATED_MSG = "Property {0} is deprecated. Please use {1} instead."; Set whites = newHashSet(), blacks = newHashSet(); private DefaultAnalysisMode mode; @@ -182,6 +179,11 @@ public class BatchPluginRepository implements PluginRepository { return !mode.isMediumTest(); } + if (BUILDBREAKER_PLUGIN_KEY.equals(pluginKey) && mode.isPreview()) { + LOG.info("Build Breaker plugin is no more supported in preview/incremental mode"); + return false; + } + List mergeList = newArrayList(blacks); mergeList.removeAll(whites); return mergeList.isEmpty() || !mergeList.contains(pluginKey); diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/DefaultPluginsReferential.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/DefaultPluginsRepository.java similarity index 94% rename from sonar-batch/src/main/java/org/sonar/batch/bootstrap/DefaultPluginsReferential.java rename to sonar-batch/src/main/java/org/sonar/batch/bootstrap/DefaultPluginsRepository.java index d023b5e75e0..2687ebc56df 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/DefaultPluginsReferential.java +++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/DefaultPluginsRepository.java @@ -39,14 +39,14 @@ import java.util.Map; /** * A {@link PluginsRepository} implementation that put downloaded plugins in a FS cache. */ -public class DefaultPluginsReferential implements PluginsRepository { +public class DefaultPluginsRepository implements PluginsRepository { - private static final Logger LOG = LoggerFactory.getLogger(DefaultPluginsReferential.class); + private static final Logger LOG = LoggerFactory.getLogger(DefaultPluginsRepository.class); private ServerClient server; private FileCache fileCache; - public DefaultPluginsReferential(FileCache fileCache, ServerClient server) { + public DefaultPluginsRepository(FileCache fileCache, ServerClient server) { this.server = server; this.fileCache = fileCache; } 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 011329d9421..bffee518e54 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 @@ -96,7 +96,7 @@ public class GlobalContainer extends ComponentContainer { new GlobalRepositoriesProvider(), UserRepository.class); if (getComponentByType(PluginsRepository.class) == null) { - add(DefaultPluginsReferential.class); + add(DefaultPluginsRepository.class); } if (getComponentByType(GlobalRepositoriesLoader.class) == null) { add(DefaultGlobalRepositoriesLoader.class); 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 d0c959abb87..66a499b01c0 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 @@ -53,6 +53,7 @@ public class BatchPluginRepositoryTest { @Before public void before() throws IOException { mode = mock(DefaultAnalysisMode.class); + when(mode.isPreview()).thenReturn(false); userHome = temp.newFolder(); cache = new FileCacheBuilder().setUserHome(userHome).build(); } @@ -68,7 +69,7 @@ public class BatchPluginRepositoryTest { public void shouldLoadPlugin() throws Exception { RemotePlugin checkstyle = new RemotePlugin("checkstyle", true); - DefaultPluginsReferential downloader = mock(DefaultPluginsReferential.class); + DefaultPluginsRepository downloader = mock(DefaultPluginsRepository.class); when(downloader.pluginFile(checkstyle)).thenReturn(fileFromCache("sonar-checkstyle-plugin-2.8.jar")); repository = new BatchPluginRepository(downloader, new Settings(), mode, new BatchPluginJarInstaller(cache)); @@ -86,7 +87,7 @@ public class BatchPluginRepositoryTest { RemotePlugin checkstyle = new RemotePlugin("checkstyle", true); RemotePlugin checkstyleExt = new RemotePlugin("checkstyleextensions", false); - DefaultPluginsReferential downloader = mock(DefaultPluginsReferential.class); + 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")); @@ -106,7 +107,7 @@ public class BatchPluginRepositoryTest { RemotePlugin checkstyle = new RemotePlugin("checkstyle", true); RemotePlugin checkstyleExt = new RemotePlugin("checkstyleextensions", false); - DefaultPluginsReferential downloader = mock(DefaultPluginsReferential.class); + 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")); @@ -131,6 +132,14 @@ public class BatchPluginRepositoryTest { 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 diff --git a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/DefaultPluginsReferentialTest.java b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/DefaultPluginsRepositoryTest.java similarity index 90% rename from sonar-batch/src/test/java/org/sonar/batch/bootstrap/DefaultPluginsReferentialTest.java rename to sonar-batch/src/test/java/org/sonar/batch/bootstrap/DefaultPluginsRepositoryTest.java index 2abff9e97fe..f03d16bbd32 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/DefaultPluginsReferentialTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/DefaultPluginsRepositoryTest.java @@ -36,7 +36,7 @@ import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -public class DefaultPluginsReferentialTest { +public class DefaultPluginsRepositoryTest { @Rule public TemporaryFolder temp = new TemporaryFolder(); @@ -49,7 +49,7 @@ public class DefaultPluginsReferentialTest { FileCache cache = mock(FileCache.class); ServerClient server = mock(ServerClient.class); when(server.request("/deploy/plugins/index.txt")).thenReturn("checkstyle,true\nsqale,false"); - DefaultPluginsReferential downloader = new DefaultPluginsReferential(cache, server); + DefaultPluginsRepository downloader = new DefaultPluginsRepository(cache, server); List plugins = downloader.pluginList(); assertThat(plugins).hasSize(2); @@ -67,7 +67,7 @@ public class DefaultPluginsReferentialTest { when(cache.get(eq("checkstyle-plugin.jar"), eq("fakemd5_1"), any(FileCache.Downloader.class))).thenReturn(pluginJar); ServerClient server = mock(ServerClient.class); - DefaultPluginsReferential downloader = new DefaultPluginsReferential(cache, server); + DefaultPluginsRepository downloader = new DefaultPluginsRepository(cache, server); RemotePlugin plugin = new RemotePlugin("checkstyle", true) .setFile("checkstyle-plugin.jar", "fakemd5_1"); @@ -83,6 +83,6 @@ public class DefaultPluginsReferentialTest { ServerClient server = mock(ServerClient.class); doThrow(new IllegalStateException()).when(server).request("/deploy/plugins/index.txt"); - new DefaultPluginsReferential(mock(FileCache.class), server).pluginList(); + new DefaultPluginsRepository(mock(FileCache.class), server).pluginList(); } } -- 2.39.5