Search in sources :

Example 11 with PluginInfo

use of org.sonar.core.platform.PluginInfo in project sonarqube by SonarSource.

the class CePluginRepository method start.

@Override
public void start() {
    Loggers.get(getClass()).info("Load plugins");
    for (File file : listJarFiles(fs.getInstalledPluginsDir())) {
        PluginInfo info = PluginInfo.create(file);
        pluginInfosByKeys.put(info.getKey(), info);
    }
    pluginInstancesByKeys.putAll(loader.load(pluginInfosByKeys));
    started.set(true);
}
Also used : PluginInfo(org.sonar.core.platform.PluginInfo) File(java.io.File)

Example 12 with PluginInfo

use of org.sonar.core.platform.PluginInfo in project sonarqube by SonarSource.

the class PluginsMonitor method attributes.

@Override
public Map<String, Object> attributes() {
    Map<String, Object> attributes = new LinkedHashMap<>();
    for (PluginInfo plugin : repository.getPluginInfos()) {
        LinkedHashMap<String, Object> pluginAttributes = new LinkedHashMap<>();
        pluginAttributes.put("Name", plugin.getName());
        Version version = plugin.getVersion();
        if (version != null) {
            pluginAttributes.put("Version", version.getName());
        }
        attributes.put(plugin.getKey(), pluginAttributes);
    }
    return attributes;
}
Also used : Version(org.sonar.updatecenter.common.Version) PluginInfo(org.sonar.core.platform.PluginInfo) LinkedHashMap(java.util.LinkedHashMap)

Example 13 with PluginInfo

use of org.sonar.core.platform.PluginInfo 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 14 with PluginInfo

use of org.sonar.core.platform.PluginInfo in project sonarqube by SonarSource.

the class ServerPluginRepository method registerPluginInfo.

private void registerPluginInfo(PluginInfo info) {
    String pluginKey = info.getKey();
    if (blacklistedPluginKeys.contains(pluginKey)) {
        LOG.warn("Plugin {} [{}] is blacklisted and is being uninstalled.", info.getName(), pluginKey);
        deleteQuietly(info.getNonNullJarFile());
        return;
    }
    if (FORBIDDEN_COMPATIBLE_PLUGINS.contains(pluginKey)) {
        throw MessageException.of(String.format("Plugin '%s' is no more compatible with this version of SonarQube", pluginKey));
    }
    PluginInfo existing = pluginInfosByKeys.put(pluginKey, info);
    if (existing != null) {
        throw MessageException.of(format("Found two files for the same plugin [%s]: %s and %s", pluginKey, info.getNonNullJarFile().getName(), existing.getNonNullJarFile().getName()));
    }
}
Also used : PluginInfo(org.sonar.core.platform.PluginInfo) PluginInfo.jarToPluginInfo(org.sonar.core.platform.PluginInfo.jarToPluginInfo)

Example 15 with PluginInfo

use of org.sonar.core.platform.PluginInfo in project sonarqube by SonarSource.

the class ServerPluginRepository method uninstall.

/**
   * Uninstall a plugin and its dependents
   */
public void uninstall(String pluginKey) {
    checkState(started.get(), NOT_STARTED_YET);
    Set<String> uninstallKeys = new HashSet<>();
    uninstallKeys.add(pluginKey);
    appendDependentPluginKeys(pluginKey, uninstallKeys);
    for (String uninstallKey : uninstallKeys) {
        PluginInfo info = pluginInfosByKeys.get(uninstallKey);
        try {
            LOG.info("Uninstalling plugin {} [{}]", info.getName(), info.getKey());
            // we don't reuse info.getFile() just to be sure that file is located in from extensions/plugins
            File masterFile = new File(fs.getInstalledPluginsDir(), info.getNonNullJarFile().getName());
            moveFileToDirectory(masterFile, uninstalledPluginsDir(), true);
        } catch (IOException e) {
            throw new IllegalStateException(format("Fail to uninstall plugin %s [%s]", info.getName(), info.getKey()), e);
        }
    }
}
Also used : PluginInfo(org.sonar.core.platform.PluginInfo) PluginInfo.jarToPluginInfo(org.sonar.core.platform.PluginInfo.jarToPluginInfo) IOException(java.io.IOException) FileUtils.moveFile(org.apache.commons.io.FileUtils.moveFile) File(java.io.File) FileUtils.copyFile(org.apache.commons.io.FileUtils.copyFile) HashSet(java.util.HashSet)

Aggregations

PluginInfo (org.sonar.core.platform.PluginInfo)50 Test (org.junit.Test)23 File (java.io.File)9 Plugin (org.sonar.api.Plugin)7 PluginInfo.jarToPluginInfo (org.sonar.core.platform.PluginInfo.jarToPluginInfo)7 PluginRepository (org.sonar.core.platform.PluginRepository)5 ExplodedPlugin (org.sonar.core.platform.ExplodedPlugin)4 FileUtils.copyFile (org.apache.commons.io.FileUtils.copyFile)3 FileUtils.moveFile (org.apache.commons.io.FileUtils.moveFile)3 SonarRuntime (org.sonar.api.SonarRuntime)3 AnalysisMode (org.sonar.api.batch.AnalysisMode)3 ComponentContainer (org.sonar.core.platform.ComponentContainer)3 Version (org.sonar.updatecenter.common.Version)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Before (org.junit.Before)2 ExtensionProvider (org.sonar.api.ExtensionProvider)2 JsonWriter (org.sonar.api.utils.text.JsonWriter)2