Search in sources :

Example 1 with Plugin

use of org.sonar.api.Plugin 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 Plugin

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

the class I18nClassloader method allPluginClassloaders.

private static List<ClassLoader> allPluginClassloaders(PluginRepository pluginRepository) {
    // accepted limitation: some plugins extend base plugins, sharing the same classloader, so
    // there may be duplicated classloaders in the list.
    List<ClassLoader> list = Lists.newArrayList();
    for (PluginInfo info : pluginRepository.getPluginInfos()) {
        Plugin plugin = pluginRepository.getPluginInstance(info.getKey());
        list.add(plugin.getClass().getClassLoader());
    }
    list.add(I18nClassloader.class.getClassLoader());
    return list;
}
Also used : URLClassLoader(java.net.URLClassLoader) PluginInfo(org.sonar.core.platform.PluginInfo) Plugin(org.sonar.api.Plugin) SonarPlugin(org.sonar.api.SonarPlugin)

Example 3 with Plugin

use of org.sonar.api.Plugin 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)

Example 4 with Plugin

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

the class GlobalContainer method installPlugins.

private 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.sonar.core.platform.PluginRepository) PluginInfo(org.sonar.core.platform.PluginInfo) Plugin(org.sonar.api.Plugin)

Example 5 with Plugin

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

the class CePluginRepository method getPluginInstance.

@Override
public Plugin getPluginInstance(String key) {
    checkState(started.get(), NOT_STARTED_YET);
    Plugin plugin = pluginInstancesByKeys.get(key);
    checkArgument(plugin != null, "Plugin [%s] does not exist", key);
    return plugin;
}
Also used : Plugin(org.sonar.api.Plugin)

Aggregations

Plugin (org.sonar.api.Plugin)10 PluginInfo (org.sonar.core.platform.PluginInfo)7 Map (java.util.Map)2 ExtensionProvider (org.sonar.api.ExtensionProvider)2 URLClassLoader (java.net.URLClassLoader)1 HashMap (java.util.HashMap)1 Test (org.junit.Test)1 SonarPlugin (org.sonar.api.SonarPlugin)1 PluginRepository (org.sonar.core.platform.PluginRepository)1