From 14fd192531cad48f7904aea3196841d5479a9251 Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Wed, 5 Feb 2014 14:49:05 +0100 Subject: [PATCH] SONAR-5022 Fix the "sonar.preview.includePlugins" property --- .../bootstrap/BatchPluginRepository.java | 22 +++++++++---------- .../bootstrap/BatchPluginRepositoryTest.java | 18 ++++++++++++--- 2 files changed, 25 insertions(+), 15 deletions(-) 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 b0ebab822af..5ce8665d304 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 @@ -21,7 +21,6 @@ package org.sonar.batch.bootstrap; import com.google.common.base.Joiner; import com.google.common.collect.Maps; -import com.google.common.collect.Sets; import org.apache.commons.lang.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -35,11 +34,10 @@ 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; public class BatchPluginRepository implements PluginRepository { @@ -56,7 +54,7 @@ public class BatchPluginRepository implements PluginRepository { private final BatchPluginInstaller pluginInstaller; public BatchPluginRepository(PluginDownloader pluginDownloader, Settings settings, AnalysisMode analysisMode, - BatchPluginInstaller pluginInstaller) { + BatchPluginInstaller pluginInstaller) { this.pluginDownloader = pluginDownloader; this.settings = settings; this.analysisMode = analysisMode; @@ -117,7 +115,7 @@ public class BatchPluginRepository implements PluginRepository { static class PluginFilter { private static final String PROPERTY_IS_DEPRECATED_MSG = "Property {0} is deprecated. Please use {1} instead."; - Set whites = Sets.newHashSet(), blacks = Sets.newHashSet(); + Set whites = newHashSet(), blacks = newHashSet(); PluginFilter(Settings settings, AnalysisMode mode) { if (settings.hasKey(CoreProperties.BATCH_INCLUDE_PLUGINS)) { @@ -163,10 +161,10 @@ public class BatchPluginRepository implements PluginRepository { if (CORE_PLUGIN.equals(pluginKey) || ENGLISH_PACK_PLUGIN.equals(pluginKey)) { return true; } - if (!whites.isEmpty()) { - return whites.contains(pluginKey); - } - return blacks.isEmpty() || !blacks.contains(pluginKey); + + List mergeList = newArrayList(blacks); + mergeList.removeAll(whites); + return mergeList.isEmpty() || !mergeList.contains(pluginKey); } } } 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 de6e034ad96..7108321518b 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 @@ -168,9 +168,10 @@ public class BatchPluginRepositoryTest { } @Test - public void shouldCheckWhitelist() { + public void check_white_list_with_black_list() { Settings settings = new Settings() - .setProperty(CoreProperties.BATCH_INCLUDE_PLUGINS, "checkstyle,pmd,findbugs"); + .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(); @@ -178,7 +179,18 @@ public class BatchPluginRepositoryTest { } @Test - public void shouldCheckBlackListIfNoWhiteList() { + 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); -- 2.39.5