@Test public void should_provide_list_of_extensions() { when(pluginRepository.getPluginInfos()).thenReturn(Arrays.asList(new PluginInfo("foo"))); when(pluginRepository.getPluginInstance("foo")).thenReturn(newPluginInstance(new FooBarProvider())); ComponentContainer container = new ComponentContainer(); ExtensionInstaller installer = new ExtensionInstaller(mock(SonarRuntime.class), pluginRepository, mode, settings.asConfig()); installer.install(container, new TrueMatcher()); assertThat(container.getComponentByType(Foo.class)).isNotNull(); assertThat(container.getComponentByType(Bar.class)).isNotNull(); }
public ExtensionInstaller install(ComponentContainer container, ExtensionMatcher matcher) { // core components for (Object o : BatchComponents.all(analysisMode)) { doInstall(container, matcher, null, o); } // plugin extensions for (PluginInfo pluginInfo : pluginRepository.getPluginInfos()) { Plugin plugin = pluginRepository.getPluginInstance(pluginInfo.getKey()); Plugin.Context context = new PluginContextImpl.Builder() .setSonarRuntime(sonarRuntime) .setBootConfiguration(bootConfiguration) .build(); plugin.define(context); for (Object extension : context.getExtensions()) { doInstall(container, matcher, pluginInfo, extension); } } List<ExtensionProvider> providers = container.getComponentsByType(ExtensionProvider.class); for (ExtensionProvider provider : providers) { Object object = provider.provide(); if (object instanceof Iterable) { for (Object extension : (Iterable) object) { doInstall(container, matcher, null, extension); } } else { doInstall(container, matcher, null, object); } } return this; }
private void addExtensions() { ExtensionInstaller pluginInstaller = getComponentByType(ExtensionInstaller.class); pluginInstaller.install(this, e -> isDeprecatedScannerSide(e) && isInstantiationStrategy(e, PER_PROJECT)); }
private void addScannerExtensions() { getComponentByType(CoreExtensionsInstaller.class) .install(this, noExtensionFilter(), extension -> getScannerProjectExtensionsFilter().accept(extension)); getComponentByType(ExtensionInstaller.class) .install(this, getScannerProjectExtensionsFilter()); }
@Test public void should_filter_extensions_to_install() { when(pluginRepository.getPluginInfos()).thenReturn(Arrays.asList(new PluginInfo("foo"))); when(pluginRepository.getPluginInstance("foo")).thenReturn(newPluginInstance(Foo.class, Bar.class)); ComponentContainer container = new ComponentContainer(); ExtensionInstaller installer = new ExtensionInstaller(mock(SonarRuntime.class), pluginRepository, mode, settings.asConfig()); installer.install(container, new FooMatcher()); assertThat(container.getComponentByType(Foo.class)).isNotNull(); assertThat(container.getComponentByType(Bar.class)).isNull(); }
private void addExtensions() { ExtensionInstaller pluginInstaller = getComponentByType(ExtensionInstaller.class); pluginInstaller.install(this, e -> isDeprecatedScannerSide(e) && isInstantiationStrategy(e, PER_PROJECT)); }
public ExtensionInstaller install(ComponentContainer container, ExtensionMatcher matcher) { // core components for (Object o : BatchComponents.all(analysisMode)) { doInstall(container, matcher, null, o); } // plugin extensions for (PluginInfo pluginInfo : pluginRepository.getPluginInfos()) { Plugin plugin = pluginRepository.getPluginInstance(pluginInfo.getKey()); Plugin.Context context = new PluginContextImpl.Builder() .setSonarRuntime(sonarRuntime) .setBootConfiguration(bootConfiguration) .build(); plugin.define(context); for (Object extension : context.getExtensions()) { doInstall(container, matcher, pluginInfo, extension); } } List<ExtensionProvider> providers = container.getComponentsByType(ExtensionProvider.class); for (ExtensionProvider provider : providers) { Object object = provider.provide(); if (object instanceof Iterable) { for (Object extension : (Iterable) object) { doInstall(container, matcher, null, extension); } } else { doInstall(container, matcher, null, object); } } return this; }
@Test public void should_execute_extension_provider() { when(pluginRepository.getPluginInfos()).thenReturn(Arrays.asList(new PluginInfo("foo"))); when(pluginRepository.getPluginInstance("foo")).thenReturn(newPluginInstance(new FooProvider(), new BarProvider())); ComponentContainer container = new ComponentContainer(); ExtensionInstaller installer = new ExtensionInstaller(mock(SonarRuntime.class), pluginRepository, mode, settings.asConfig()); installer.install(container, new FooMatcher()); assertThat(container.getComponentByType(Foo.class)).isNotNull(); assertThat(container.getComponentByType(Bar.class)).isNull(); }
private void addScannerExtensions() { getComponentByType(CoreExtensionsInstaller.class) .install(this, noExtensionFilter(), extension -> getScannerProjectExtensionsFilter().accept(extension)); getComponentByType(ExtensionInstaller.class) .install(this, getScannerProjectExtensionsFilter()); }