]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5022 Fix the "sonar.preview.includePlugins" property
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Wed, 5 Feb 2014 13:49:05 +0000 (14:49 +0100)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Wed, 5 Feb 2014 13:49:05 +0000 (14:49 +0100)
sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchPluginRepository.java
sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchPluginRepositoryTest.java

index b0ebab822af3c4a1546ed14abae3e0a643201a41..5ce8665d304c3b4de2435b54816c705e6154bd02 100644 (file)
@@ -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<String> whites = Sets.newHashSet(), blacks = Sets.newHashSet();
+    Set<String> 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<String> mergeList = newArrayList(blacks);
+      mergeList.removeAll(whites);
+      return mergeList.isEmpty() || !mergeList.contains(pluginKey);
     }
   }
 }
index de6e034ad968f6bf15927ba87f2871cf8bb9ab67..7108321518b2d21dbb650e6561869bd44f81ea70 100644 (file)
@@ -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);