Search in sources :

Example 26 with PluginInfo

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

the class ServerPluginRepository method appendDependentPluginKeys.

private void appendDependentPluginKeys(String pluginKey, Set<String> appendTo) {
    for (PluginInfo otherPlugin : pluginInfosByKeys.values()) {
        if (!otherPlugin.getKey().equals(pluginKey)) {
            for (PluginInfo.RequiredPlugin requirement : otherPlugin.getRequiredPlugins()) {
                if (requirement.getKey().equals(pluginKey)) {
                    appendTo.add(otherPlugin.getKey());
                    appendDependentPluginKeys(otherPlugin.getKey(), appendTo);
                }
            }
        }
    }
}
Also used : PluginInfo(org.sonar.core.platform.PluginInfo) PluginInfo.jarToPluginInfo(org.sonar.core.platform.PluginInfo.jarToPluginInfo)

Example 27 with PluginInfo

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

the class ServerPluginRepository method overrideAndRegisterPlugin.

/**
   * Move or copy plugin to directory extensions/plugins. If a version of this plugin
   * already exists then it's deleted.
   */
private void overrideAndRegisterPlugin(File sourceFile, boolean deleteSource) {
    File destDir = fs.getInstalledPluginsDir();
    File destFile = new File(destDir, sourceFile.getName());
    if (destFile.exists()) {
        // plugin with same filename already installed
        deleteQuietly(destFile);
    }
    try {
        if (deleteSource) {
            moveFile(sourceFile, destFile);
        } else {
            copyFile(sourceFile, destFile, true);
        }
    } catch (IOException e) {
        throw new IllegalStateException(format("Fail to move or copy plugin: %s to %s", sourceFile.getAbsolutePath(), destFile.getAbsolutePath()), e);
    }
    PluginInfo info = PluginInfo.create(destFile);
    PluginInfo existing = pluginInfosByKeys.put(info.getKey(), info);
    if (existing != null) {
        if (!existing.getNonNullJarFile().getName().equals(destFile.getName())) {
            deleteQuietly(existing.getNonNullJarFile());
        }
        LOG.info("Plugin {} [{}] updated to version {}", info.getName(), info.getKey(), info.getVersion());
    } else {
        LOG.info("Plugin {} [{}] installed", info.getName(), info.getKey());
    }
}
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)

Example 28 with PluginInfo

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

the class ServerPluginRepository method getPluginInfo.

@Override
public PluginInfo getPluginInfo(String key) {
    checkState(started.get(), NOT_STARTED_YET);
    PluginInfo info = pluginInfosByKeys.get(key);
    if (info == null) {
        throw new IllegalArgumentException(format("Plugin [%s] does not exist", key));
    }
    return info;
}
Also used : PluginInfo(org.sonar.core.platform.PluginInfo) PluginInfo.jarToPluginInfo(org.sonar.core.platform.PluginInfo.jarToPluginInfo)

Example 29 with PluginInfo

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

the class PluginWSCommons method writePluginInfoList.

public void writePluginInfoList(JsonWriter json, Iterable<PluginInfo> plugins, Map<String, Plugin> compatiblePluginsByKey, String propertyName) {
    json.name(propertyName);
    json.beginArray();
    for (PluginInfo pluginInfo : copyOf(NAME_KEY_PLUGIN_METADATA_COMPARATOR, plugins)) {
        Plugin plugin = compatiblePluginsByKey.get(pluginInfo.getKey());
        writePluginInfo(json, pluginInfo, categoryOrNull(plugin));
    }
    json.endArray();
}
Also used : PluginInfo(org.sonar.core.platform.PluginInfo) Plugin(org.sonar.updatecenter.common.Plugin)

Example 30 with PluginInfo

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

the class InstalledPluginsAction method handle.

@Override
public void handle(Request request, Response response) throws Exception {
    JsonWriter json = response.newJsonWriter().beginArray();
    for (PluginInfo pluginInfo : pluginRepository.getPluginInfos()) {
        Version version = pluginInfo.getVersion();
        json.beginObject().prop("key", pluginInfo.getKey()).prop("name", pluginInfo.getName());
        if (version != null) {
            json.prop("version", version.getName());
        }
        json.endObject();
    }
    json.endArray().close();
}
Also used : Version(org.sonar.updatecenter.common.Version) PluginInfo(org.sonar.core.platform.PluginInfo) JsonWriter(org.sonar.api.utils.text.JsonWriter)

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