Search in sources :

Example 1 with PluginInfo

use of org.sonarsource.sonarlint.core.plugin.PluginInfo in project sonarlint-core by SonarSource.

the class ComponentContainerTest method shouldDeclareExtensionWithoutAddingIt.

@Test
public void shouldDeclareExtensionWithoutAddingIt() {
    ComponentContainer container = new ComponentContainer();
    PluginInfo plugin = mock(PluginInfo.class);
    container.declareExtension(plugin, ComponentWithProperty.class);
    PropertyDefinitions propertyDefinitions = container.getComponentByType(PropertyDefinitions.class);
    assertThat(propertyDefinitions.get("foo")).isNotNull();
    assertThat(container.getComponentByType(ComponentWithProperty.class)).isNull();
}
Also used : PropertyDefinitions(org.sonar.api.config.PropertyDefinitions) PluginInfo(org.sonarsource.sonarlint.core.plugin.PluginInfo) Test(org.junit.Test)

Example 2 with PluginInfo

use of org.sonarsource.sonarlint.core.plugin.PluginInfo in project sonarlint-core by SonarSource.

the class ExtensionInstaller method install.

public ExtensionInstaller install(ComponentContainer container, boolean global) {
    // plugin extensions
    for (PluginInfo pluginInfo : pluginRepository.getPluginInfos()) {
        Plugin plugin = pluginRepository.getPluginInstance(pluginInfo.getKey());
        Plugin.Context context = new Plugin.Context(sqRuntime);
        plugin.define(context);
        loadExtensions(container, pluginInfo, context, global);
    }
    if (!global) {
        List<ExtensionProvider> providers = container.getComponentsByType(ExtensionProvider.class);
        for (ExtensionProvider provider : providers) {
            Object object = provider.provide();
            if (object instanceof Iterable) {
                for (Object extension : (Iterable) object) {
                    container.addExtension(null, extension);
                }
            } else {
                container.addExtension(null, object);
            }
        }
    }
    return this;
}
Also used : PluginInfo(org.sonarsource.sonarlint.core.plugin.PluginInfo) ExtensionProvider(org.sonar.api.ExtensionProvider) Plugin(org.sonar.api.Plugin)

Example 3 with PluginInfo

use of org.sonarsource.sonarlint.core.plugin.PluginInfo in project sonarlint-core by SonarSource.

the class StorageContainer method installPlugins.

protected void installPlugins() {
    PluginRepository pluginRepository = getComponentByType(PluginRepository.class);
    for (PluginInfo pluginInfo : pluginRepository.getPluginInfos()) {
        Plugin instance = pluginRepository.getPluginInstance(pluginInfo.getKey());
        addExtension(pluginInfo, instance);
    }
}
Also used : PluginRepository(org.sonarsource.sonarlint.core.plugin.PluginRepository) PluginInfo(org.sonarsource.sonarlint.core.plugin.PluginInfo) Plugin(org.sonar.api.Plugin)

Example 4 with PluginInfo

use of org.sonarsource.sonarlint.core.plugin.PluginInfo in project sonarlint-core by SonarSource.

the class ComponentContainerTest method shouldDeclareExtensionWhenAdding.

@Test
public void shouldDeclareExtensionWhenAdding() {
    ComponentContainer container = new ComponentContainer();
    PluginInfo plugin = mock(PluginInfo.class);
    container.addExtension(plugin, ComponentWithProperty.class);
    PropertyDefinitions propertyDefinitions = container.getComponentByType(PropertyDefinitions.class);
    assertThat(propertyDefinitions.get("foo")).isNotNull();
    assertThat(container.getComponentByType(ComponentWithProperty.class)).isNotNull();
    assertThat(container.getComponentByKey(ComponentWithProperty.class)).isNotNull();
}
Also used : PropertyDefinitions(org.sonar.api.config.PropertyDefinitions) PluginInfo(org.sonarsource.sonarlint.core.plugin.PluginInfo) Test(org.junit.Test)

Example 5 with PluginInfo

use of org.sonarsource.sonarlint.core.plugin.PluginInfo in project sonarlint-core by SonarSource.

the class ComponentContainerTest method display_plugin_name_when_failing_to_add_extension.

@Test
public void display_plugin_name_when_failing_to_add_extension() {
    ComponentContainer container = new ComponentContainer();
    PluginInfo plugin = mock(PluginInfo.class);
    container.startComponents();
    thrown.expect(IllegalStateException.class);
    thrown.expectMessage("Unable to register extension org.sonarsource.sonarlint.core.container.ComponentContainerTest$UnstartableComponent");
    container.addExtension(plugin, UnstartableComponent.class);
}
Also used : PluginInfo(org.sonarsource.sonarlint.core.plugin.PluginInfo) Test(org.junit.Test)

Aggregations

PluginInfo (org.sonarsource.sonarlint.core.plugin.PluginInfo)6 Test (org.junit.Test)3 Plugin (org.sonar.api.Plugin)3 PropertyDefinitions (org.sonar.api.config.PropertyDefinitions)2 PluginRepository (org.sonarsource.sonarlint.core.plugin.PluginRepository)2 ExtensionProvider (org.sonar.api.ExtensionProvider)1