@Test public void test_exclusions_without_any_inclusions() { when(mode.isPreview()).thenReturn(true); settings.setProperty(CoreProperties.PREVIEW_EXCLUDE_PLUGINS, "checkstyle,pmd,findbugs"); ScannerPluginPredicate predicate = new ScannerPluginPredicate(settings.asConfig(), mode); assertThat(predicate.apply("checkstyle")).isFalse(); assertThat(predicate.apply("pmd")).isFalse(); assertThat(predicate.apply("cobertura")).isTrue(); }
public ScannerPluginPredicate(Configuration settings, GlobalAnalysisMode mode) { this.mode = mode; if (mode.isPreview() || mode.isIssues()) { // These default values are not supported by Settings because the class CorePlugin // is not loaded yet. whites.addAll(propertyValues(settings, CoreProperties.PREVIEW_INCLUDE_PLUGINS, CoreProperties.PREVIEW_INCLUDE_PLUGINS_DEFAULT_VALUE)); blacks.addAll(propertyValues(settings, CoreProperties.PREVIEW_EXCLUDE_PLUGINS, CoreProperties.PREVIEW_EXCLUDE_PLUGINS_DEFAULT_VALUE)); } if (!whites.isEmpty()) { LOG.info("Include plugins: " + COMMA_JOINER.join(whites)); } if (!blacks.isEmpty()) { LOG.info("Exclude plugins: " + COMMA_JOINER.join(blacks)); } }
@Test public void accept_if_no_inclusions_nor_exclusions() { ScannerPluginPredicate predicate = new ScannerPluginPredicate(settings.asConfig(), mode); assertThat(predicate.getWhites()).isEmpty(); assertThat(predicate.getBlacks()).isEmpty(); assertThat(predicate.apply("pmd")).isTrue(); assertThat(predicate.apply("buildbreaker")).isTrue(); }
private Loaded loadPlugins(Map<String, ScannerPlugin> result) { for (InstalledPlugin plugin : listInstalledPlugins()) { if (pluginPredicate.apply(plugin.key)) { Optional<File> jarFile = pluginFiles.get(plugin); if (!jarFile.isPresent()) { return new Loaded(false, plugin.key); } PluginInfo info = PluginInfo.create(jarFile.get()); result.put(info.getKey(), new ScannerPlugin(plugin.key, plugin.updatedAt, info)); } } return new Loaded(true, null); }
@Test public void filter_blacklisted_plugins() throws IOException { WsTestUtil.mockReader(wsClient, "api/plugins/installed", new InputStreamReader(getClass().getResourceAsStream("ScannerPluginInstallerTest/installed-plugins-ws.json"))); enqueueDownload("scmgit", "abc"); enqueueDownload("java", "def"); when(pluginPredicate.apply("scmgit")).thenReturn(true); when(pluginPredicate.apply("java")).thenReturn(false); Map<String, ScannerPlugin> result = underTest.installRemotes(); assertThat(result.keySet()).containsExactlyInAnyOrder("scmgit"); verify(pluginFiles, times(1)).get(any()); }
@Test public void verify_both_inclusions_and_exclusions() { when(mode.isPreview()).thenReturn(true); settings .setProperty(CoreProperties.PREVIEW_INCLUDE_PLUGINS, "checkstyle,pmd,findbugs") .setProperty(CoreProperties.PREVIEW_EXCLUDE_PLUGINS, "cobertura"); ScannerPluginPredicate predicate = new ScannerPluginPredicate(settings.asConfig(), mode); assertThat(predicate.apply("checkstyle")).isTrue(); assertThat(predicate.apply("pmd")).isTrue(); assertThat(predicate.apply("cobertura")).isFalse(); }
@Test public void reload_list_if_plugin_uninstalled_during_blue_green_switch() throws IOException { WsTestUtil.mockReader(wsClient, "api/plugins/installed", new InputStreamReader(getClass().getResourceAsStream("ScannerPluginInstallerTest/blue-installed.json")), new InputStreamReader(getClass().getResourceAsStream("ScannerPluginInstallerTest/green-installed.json"))); enqueueNotFoundDownload("scmgit", "abc"); enqueueDownload("java", "def"); enqueueDownload("cobol", "ghi"); when(pluginPredicate.apply(any())).thenReturn(true); Map<String, ScannerPlugin> result = underTest.installRemotes(); assertThat(result.keySet()).containsExactlyInAnyOrder("java", "cobol"); }
public ScannerPluginPredicate(Configuration settings, GlobalAnalysisMode mode) { this.mode = mode; if (mode.isPreview() || mode.isIssues()) { // These default values are not supported by Settings because the class CorePlugin // is not loaded yet. whites.addAll(propertyValues(settings, CoreProperties.PREVIEW_INCLUDE_PLUGINS, CoreProperties.PREVIEW_INCLUDE_PLUGINS_DEFAULT_VALUE)); blacks.addAll(propertyValues(settings, CoreProperties.PREVIEW_EXCLUDE_PLUGINS, CoreProperties.PREVIEW_EXCLUDE_PLUGINS_DEFAULT_VALUE)); } if (!whites.isEmpty()) { LOG.info("Include plugins: " + COMMA_JOINER.join(whites)); } if (!blacks.isEmpty()) { LOG.info("Exclude plugins: " + COMMA_JOINER.join(blacks)); } }
@Test public void verify_both_inclusions_and_exclusions_issues() { when(mode.isIssues()).thenReturn(true); settings .setProperty(CoreProperties.PREVIEW_INCLUDE_PLUGINS, "checkstyle,pmd,findbugs") .setProperty(CoreProperties.PREVIEW_EXCLUDE_PLUGINS, "cobertura"); ScannerPluginPredicate predicate = new ScannerPluginPredicate(settings.asConfig(), mode); assertThat(predicate.apply("checkstyle")).isTrue(); assertThat(predicate.apply("pmd")).isTrue(); assertThat(predicate.apply("cobertura")).isFalse(); }
@Test public void fail_if_plugin_not_found_two_times() throws IOException { WsTestUtil.mockReader(wsClient, "api/plugins/installed", new InputStreamReader(getClass().getResourceAsStream("ScannerPluginInstallerTest/blue-installed.json")), new InputStreamReader(getClass().getResourceAsStream("ScannerPluginInstallerTest/green-installed.json"))); enqueueDownload("scmgit", "abc"); enqueueDownload("cobol", "ghi"); enqueueNotFoundDownload("java", "def"); when(pluginPredicate.apply(any())).thenReturn(true); expectedException.expect(IllegalStateException.class); expectedException.expectMessage("Fail to download plugin [java]. Not found."); underTest.installRemotes(); }
@Test public void exclude_buildbreaker_in_preview_mode() { when(mode.isPreview()).thenReturn(true); ScannerPluginPredicate predicate = new ScannerPluginPredicate(settings.asConfig(), mode); assertThat(predicate.apply("buildbreaker")).isFalse(); }
@Test public void download_installed_plugins() throws IOException { WsTestUtil.mockReader(wsClient, "api/plugins/installed", new InputStreamReader(getClass().getResourceAsStream("ScannerPluginInstallerTest/installed-plugins-ws.json"))); enqueueDownload("scmgit", "abc"); enqueueDownload("java", "def"); when(pluginPredicate.apply(any())).thenReturn(true); Map<String, ScannerPlugin> result = underTest.installRemotes(); assertThat(result.keySet()).containsExactlyInAnyOrder("scmgit", "java"); ScannerPlugin gitPlugin = result.get("scmgit"); assertThat(gitPlugin.getKey()).isEqualTo("scmgit"); assertThat(gitPlugin.getInfo().getNonNullJarFile()).exists().isFile(); assertThat(gitPlugin.getUpdatedAt()).isEqualTo(100L); ScannerPlugin javaPlugin = result.get("java"); assertThat(javaPlugin.getKey()).isEqualTo("java"); assertThat(javaPlugin.getInfo().getNonNullJarFile()).exists().isFile(); assertThat(javaPlugin.getUpdatedAt()).isEqualTo(200L); }
@Test public void trim_inclusions_and_exclusions() { settings .setProperty(CoreProperties.PREVIEW_INCLUDE_PLUGINS, "checkstyle, pmd, findbugs") .setProperty(CoreProperties.PREVIEW_EXCLUDE_PLUGINS, "cobertura, pmd"); ScannerPluginPredicate predicate = new ScannerPluginPredicate(settings.asConfig(), mode); assertThat(predicate.apply("pmd")).isTrue(); }
private Loaded loadPlugins(Map<String, ScannerPlugin> result) { for (InstalledPlugin plugin : listInstalledPlugins()) { if (pluginPredicate.apply(plugin.key)) { Optional<File> jarFile = pluginFiles.get(plugin); if (!jarFile.isPresent()) { return new Loaded(false, plugin.key); } PluginInfo info = PluginInfo.create(jarFile.get()); result.put(info.getKey(), new ScannerPlugin(plugin.key, plugin.updatedAt, info)); } } return new Loaded(true, null); }
@Test 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"); ScannerPluginPredicate predicate = new ScannerPluginPredicate(settings.asConfig(), mode); assertThat(predicate.apply("pmd")).isTrue(); }