]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-6517 Remove the unused properties sonar.includePlugins/sonar.excludePlugins
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Tue, 5 May 2015 21:55:09 +0000 (23:55 +0200)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Mon, 11 May 2015 08:21:56 +0000 (10:21 +0200)
sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchPluginPredicate.java
sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchPluginPredicateTest.java
sonar-plugin-api/src/main/java/org/sonar/api/CoreProperties.java

index f283dcd72471e54bdf428992f242d5da2449d00d..09cb7d391f0392b073d143e4db621553f488ae42 100644 (file)
@@ -31,12 +31,11 @@ import org.sonar.api.utils.log.Logger;
 import org.sonar.api.utils.log.Loggers;
 
 import javax.annotation.Nonnull;
+
 import java.text.MessageFormat;
-import java.util.Arrays;
 import java.util.List;
 import java.util.Set;
 
-import static com.google.common.collect.Lists.newArrayList;
 import static com.google.common.collect.Sets.newHashSet;
 
 /**
@@ -55,12 +54,6 @@ public class BatchPluginPredicate implements Predicate<String>, BatchComponent {
 
   public BatchPluginPredicate(Settings settings, DefaultAnalysisMode mode) {
     this.mode = mode;
-    if (settings.hasKey(CoreProperties.BATCH_INCLUDE_PLUGINS)) {
-      whites.addAll(Arrays.asList(settings.getStringArray(CoreProperties.BATCH_INCLUDE_PLUGINS)));
-    }
-    if (settings.hasKey(CoreProperties.BATCH_EXCLUDE_PLUGINS)) {
-      blacks.addAll(Arrays.asList(settings.getStringArray(CoreProperties.BATCH_EXCLUDE_PLUGINS)));
-    }
     if (mode.isPreview()) {
       // These default values are not supported by Settings because the class CorePlugin
       // is not loaded yet.
@@ -100,10 +93,10 @@ public class BatchPluginPredicate implements Predicate<String>, BatchComponent {
       return false;
     }
 
-    // FIXME what happens if there are only white-listed plugins ?
-    List<String> mergeList = newArrayList(blacks);
-    mergeList.removeAll(whites);
-    return mergeList.isEmpty() || !mergeList.contains(pluginKey);
+    if (whites.isEmpty()) {
+      return blacks.isEmpty() || !blacks.contains(pluginKey);
+    }
+    return whites.contains(pluginKey);
   }
 
   Set<String> getWhites() {
@@ -114,8 +107,8 @@ public class BatchPluginPredicate implements Predicate<String>, BatchComponent {
     return blacks;
   }
 
-  static List<String> propertyValues(Settings settings, String key, String defaultValue) {
+  private static List<String> propertyValues(Settings settings, String key, String defaultValue) {
     String s = StringUtils.defaultIfEmpty(settings.getString(key), defaultValue);
-    return Lists.newArrayList(Splitter.on(",").trimResults().split(s));
+    return Lists.newArrayList(Splitter.on(",").trimResults().omitEmptyStrings().split(s));
   }
 }
index 9dcebd6d07f91e19aacd0a84fc1faa628bfcbcd5..95d9f18eb4c3a48157e4e64030c2d751cae673ca 100644 (file)
  */
 package org.sonar.batch.bootstrap;
 
-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.home.cache.FileCache;
-import org.sonar.home.cache.FileCacheBuilder;
-
-import java.io.File;
-import java.io.IOException;
 
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.Mockito.mock;
@@ -37,63 +29,57 @@ import static org.mockito.Mockito.when;
 
 public class BatchPluginPredicateTest {
 
-  @Rule
-  public TemporaryFolder temp = new TemporaryFolder();
-
+  Settings settings = new Settings();
   DefaultAnalysisMode mode = mock(DefaultAnalysisMode.class);
-  FileCache cache;
-  File userHome;
-
-  @Before
-  public void before() throws IOException {
-    userHome = temp.newFolder();
-    cache = new FileCacheBuilder().setUserHome(userHome).build();
-  }
 
   @Test
-  public void shouldAlwaysAcceptIfNoWhiteListAndBlackList() {
-    BatchPluginPredicate predicate = new BatchPluginPredicate(new Settings(), mode);
+  public void accept_if_no_inclusions_nor_exclusions() {
+    BatchPluginPredicate predicate = new BatchPluginPredicate(settings, mode);
+    assertThat(predicate.getWhites()).isEmpty();
+    assertThat(predicate.getBlacks()).isEmpty();
     assertThat(predicate.apply("pmd")).isTrue();
     assertThat(predicate.apply("buildbreaker")).isTrue();
   }
 
   @Test
-  public void shouldBlackListBuildBreakerInPreviewMode() {
+  public void exclude_buildbreaker_in_preview_mode() {
     when(mode.isPreview()).thenReturn(true);
-    BatchPluginPredicate predicate = new BatchPluginPredicate(new Settings(), mode);
+    BatchPluginPredicate predicate = new BatchPluginPredicate(settings, mode);
     assertThat(predicate.apply("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");
+  public void inclusions_take_precedence_over_exclusions() {
+    when(mode.isPreview()).thenReturn(true);
+    settings
+      .setProperty(CoreProperties.PREVIEW_INCLUDE_PLUGINS, "checkstyle,pmd,findbugs")
+      .setProperty(CoreProperties.PREVIEW_EXCLUDE_PLUGINS, "cobertura,pmd");
     BatchPluginPredicate predicate = new BatchPluginPredicate(settings, mode);
     assertThat(predicate.apply("pmd")).isTrue();
   }
 
   @Test
-  public void corePluginShouldAlwaysBeInWhiteList() {
-    Settings settings = new Settings()
-      .setProperty(CoreProperties.BATCH_INCLUDE_PLUGINS, "checkstyle,pmd,findbugs");
+  public void accept_core_plugin_even_if_not_in_inclusions() {
+    when(mode.isPreview()).thenReturn(true);
+    settings.setProperty(CoreProperties.PREVIEW_INCLUDE_PLUGINS, "checkstyle,pmd,findbugs");
     BatchPluginPredicate predicate = new BatchPluginPredicate(settings, mode);
     assertThat(predicate.apply("core")).isTrue();
   }
 
   @Test
-  public void corePluginShouldNeverBeInBlackList() {
-    Settings settings = new Settings()
-      .setProperty(CoreProperties.BATCH_EXCLUDE_PLUGINS, "core,findbugs");
+  public void accept_core_plugin_even_if_in_exclusions() {
+    when(mode.isPreview()).thenReturn(true);
+    settings.setProperty(CoreProperties.PREVIEW_EXCLUDE_PLUGINS, "core,findbugs");
     BatchPluginPredicate predicate = new BatchPluginPredicate(settings, mode);
     assertThat(predicate.apply("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");
+  public void both_inclusions_and_exclusions() {
+    when(mode.isPreview()).thenReturn(true);
+    settings
+      .setProperty(CoreProperties.PREVIEW_INCLUDE_PLUGINS, "checkstyle,pmd,findbugs")
+      .setProperty(CoreProperties.PREVIEW_EXCLUDE_PLUGINS, "cobertura");
     BatchPluginPredicate predicate = new BatchPluginPredicate(settings, mode);
     assertThat(predicate.apply("checkstyle")).isTrue();
     assertThat(predicate.apply("pmd")).isTrue();
@@ -101,20 +87,9 @@ public class BatchPluginPredicateTest {
   }
 
   @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");
-    BatchPluginPredicate predicate = new BatchPluginPredicate(settings, mode);
-    assertThat(predicate.apply("checkstyle")).isTrue();
-    assertThat(predicate.apply("pmd")).isTrue();
-    assertThat(predicate.apply("cobertura")).isTrue();
-  }
-
-  @Test
-  public void check_black_list_if_no_white_list() {
-    Settings settings = new Settings()
-      .setProperty(CoreProperties.BATCH_EXCLUDE_PLUGINS, "checkstyle,pmd,findbugs");
+  public void only_exclusions() {
+    when(mode.isPreview()).thenReturn(true);
+    settings.setProperty(CoreProperties.PREVIEW_EXCLUDE_PLUGINS, "checkstyle,pmd,findbugs");
     BatchPluginPredicate predicate = new BatchPluginPredicate(settings, mode);
     assertThat(predicate.apply("checkstyle")).isFalse();
     assertThat(predicate.apply("pmd")).isFalse();
@@ -122,34 +97,22 @@ public class BatchPluginPredicateTest {
   }
 
   @Test
-  public void should_concatenate_preview_predicates() {
-    Settings settings = new Settings()
-      .setProperty(CoreProperties.PREVIEW_INCLUDE_PLUGINS, "cockpit")
-      .setProperty(CoreProperties.PREVIEW_EXCLUDE_PLUGINS, "views")
-      .setProperty(CoreProperties.BATCH_EXCLUDE_PLUGINS, "checkstyle,pmd");
+  public void deprecated_dry_run_settings() {
     when(mode.isPreview()).thenReturn(true);
-    BatchPluginPredicate predicate = new BatchPluginPredicate(settings, mode);
-    assertThat(predicate.getWhites()).containsOnly("cockpit");
-    assertThat(predicate.getBlacks()).containsOnly("views", "checkstyle", "pmd");
-  }
-
-  @Test
-  public void should_concatenate_deprecated_dry_run_predicates() {
-    Settings settings = new Settings()
+    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);
+      .setProperty(CoreProperties.DRY_RUN_EXCLUDE_PLUGINS, "views,pmd");
     BatchPluginPredicate predicate = new BatchPluginPredicate(settings, mode);
+
     assertThat(predicate.getWhites()).containsOnly("cockpit");
-    assertThat(predicate.getBlacks()).containsOnly("views", "checkstyle", "pmd");
+    assertThat(predicate.getBlacks()).containsOnly("views", "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");
+  public void trim_inclusions_and_exclusions() {
+    settings
+      .setProperty(CoreProperties.PREVIEW_INCLUDE_PLUGINS, "checkstyle, pmd, findbugs")
+      .setProperty(CoreProperties.PREVIEW_EXCLUDE_PLUGINS, "cobertura, pmd");
     BatchPluginPredicate predicate = new BatchPluginPredicate(settings, mode);
     assertThat(predicate.apply("pmd")).isTrue();
   }
index 39d28c1b8cc8904f09eaa2418b36d82ea378466b..9d59b3ef358cf8aeadc187b3d0bebd1145f17abe 100644 (file)
@@ -465,9 +465,6 @@ public interface CoreProperties {
   String WORKING_DIRECTORY = "sonar.working.directory";
   String WORKING_DIRECTORY_DEFAULT_VALUE = ".sonar";
 
-  String BATCH_INCLUDE_PLUGINS = "sonar.includePlugins";
-  String BATCH_EXCLUDE_PLUGINS = "sonar.excludePlugins";
-
   /**
    * @since 3.4
    * @deprecated in 4.0 replaced by {@link CoreProperties#PREVIEW_INCLUDE_PLUGINS}