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;
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 {
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;
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)) {
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);
}
}
}
}
@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();
}
@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);