Search in sources :

Example 1 with ExtensionProvider

use of org.sonar.api.ExtensionProvider in project sonarqube by SonarSource.

the class ServerExtensionInstaller method installExtensions.

public void installExtensions(ComponentContainer container) {
    ListMultimap<PluginInfo, Object> installedExtensionsByPlugin = ArrayListMultimap.create();
    for (PluginInfo pluginInfo : pluginRepository.getPluginInfos()) {
        try {
            String pluginKey = pluginInfo.getKey();
            Plugin plugin = pluginRepository.getPluginInstance(pluginKey);
            container.addExtension(pluginInfo, plugin);
            Plugin.Context context = new Plugin.Context(sonarRuntime);
            plugin.define(context);
            for (Object extension : context.getExtensions()) {
                if (installExtension(container, pluginInfo, extension, true) != null) {
                    installedExtensionsByPlugin.put(pluginInfo, extension);
                } else {
                    container.declareExtension(pluginInfo, extension);
                }
            }
        } catch (Throwable e) {
            // catch Throwable because we want to catch Error too (IncompatibleClassChangeError, ...)
            throw new IllegalStateException(String.format("Fail to load plugin %s [%s]", pluginInfo.getName(), pluginInfo.getKey()), e);
        }
    }
    for (Map.Entry<PluginInfo, Object> entry : installedExtensionsByPlugin.entries()) {
        PluginInfo pluginInfo = entry.getKey();
        try {
            Object extension = entry.getValue();
            if (isExtensionProvider(extension)) {
                ExtensionProvider provider = (ExtensionProvider) container.getComponentByKey(extension);
                installProvider(container, pluginInfo, provider);
            }
        } catch (Throwable e) {
            // catch Throwable because we want to catch Error too (IncompatibleClassChangeError, ...)
            throw new IllegalStateException(String.format("Fail to load plugin %s [%s]", pluginInfo.getName(), pluginInfo.getKey()), e);
        }
    }
}
Also used : PluginInfo(org.sonar.core.platform.PluginInfo) ExtensionProvider(org.sonar.api.ExtensionProvider) Map(java.util.Map) Plugin(org.sonar.api.Plugin)

Example 2 with ExtensionProvider

use of org.sonar.api.ExtensionProvider in project sonarqube by SonarSource.

the class ExtensionInstaller method install.

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 Plugin.Context(sonarRuntime);
        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;
}
Also used : PluginInfo(org.sonar.core.platform.PluginInfo) ExtensionProvider(org.sonar.api.ExtensionProvider) Plugin(org.sonar.api.Plugin)

Aggregations

ExtensionProvider (org.sonar.api.ExtensionProvider)2 Plugin (org.sonar.api.Plugin)2 PluginInfo (org.sonar.core.platform.PluginInfo)2 Map (java.util.Map)1