Search in sources :

Example 1 with Version

use of org.sonar.updatecenter.common.Version 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 2 with Version

use of org.sonar.updatecenter.common.Version in project sonarqube by SonarSource.

the class ServerPluginRepository method isCompatible.

@VisibleForTesting
static boolean isCompatible(PluginInfo plugin, SonarRuntime runtime, Map<String, PluginInfo> allPluginsByKeys) {
    if (Strings.isNullOrEmpty(plugin.getMainClass()) && Strings.isNullOrEmpty(plugin.getBasePlugin())) {
        LOG.warn("Plugin {} [{}] is ignored because entry point class is not defined", plugin.getName(), plugin.getKey());
        return false;
    }
    if (!plugin.isCompatibleWith(runtime.getApiVersion().toString())) {
        throw MessageException.of(format("Plugin %s [%s] requires at least SonarQube %s", plugin.getName(), plugin.getKey(), plugin.getMinimalSqVersion()));
    }
    if (!Strings.isNullOrEmpty(plugin.getBasePlugin()) && !allPluginsByKeys.containsKey(plugin.getBasePlugin())) {
        // it extends a plugin that is not installed
        LOG.warn("Plugin {} [{}] is ignored because its base plugin [{}] is not installed", plugin.getName(), plugin.getKey(), plugin.getBasePlugin());
        return false;
    }
    for (PluginInfo.RequiredPlugin requiredPlugin : plugin.getRequiredPlugins()) {
        PluginInfo installedRequirement = allPluginsByKeys.get(requiredPlugin.getKey());
        if (installedRequirement == null) {
            // it requires a plugin that is not installed
            LOG.warn("Plugin {} [{}] is ignored because the required plugin [{}] is not installed", plugin.getName(), plugin.getKey(), requiredPlugin.getKey());
            return false;
        }
        Version installedRequirementVersion = installedRequirement.getVersion();
        if (installedRequirementVersion != null && requiredPlugin.getMinimalVersion().compareToIgnoreQualifier(installedRequirementVersion) > 0) {
            // it requires a more recent version
            LOG.warn("Plugin {} [{}] is ignored because the version {} of required plugin [{}] is not supported", plugin.getName(), plugin.getKey(), requiredPlugin.getKey(), requiredPlugin.getMinimalVersion());
            return false;
        }
    }
    return true;
}
Also used : Version(org.sonar.updatecenter.common.Version) PluginInfo(org.sonar.core.platform.PluginInfo) PluginInfo.jarToPluginInfo(org.sonar.core.platform.PluginInfo.jarToPluginInfo) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 3 with Version

use of org.sonar.updatecenter.common.Version in project sonarqube by SonarSource.

the class PluginWSCommons method writePluginInfo.

void writePluginInfo(JsonWriter json, PluginInfo pluginInfo, @Nullable String category) {
    json.beginObject();
    json.prop(PROPERTY_KEY, pluginInfo.getKey());
    json.prop(PROPERTY_NAME, pluginInfo.getName());
    json.prop(PROPERTY_DESCRIPTION, pluginInfo.getDescription());
    Version version = pluginInfo.getVersion();
    if (version != null) {
        String functionalVersion = isNotBlank(pluginInfo.getDisplayVersion()) ? pluginInfo.getDisplayVersion() : version.getName();
        json.prop(PROPERTY_VERSION, functionalVersion);
    }
    json.prop(PROPERTY_CATEGORY, category);
    json.prop(PROPERTY_LICENSE, pluginInfo.getLicense());
    json.prop(PROPERTY_ORGANIZATION_NAME, pluginInfo.getOrganizationName());
    json.prop(PROPERTY_ORGANIZATION_URL, pluginInfo.getOrganizationUrl());
    json.prop(PROPERTY_HOMEPAGE_URL, pluginInfo.getHomepageUrl());
    json.prop(PROPERTY_ISSUE_TRACKER_URL, pluginInfo.getIssueTrackerUrl());
    json.prop(PROPERTY_IMPLEMENTATION_BUILD, pluginInfo.getImplementationBuild());
    json.endObject();
}
Also used : Version(org.sonar.updatecenter.common.Version)

Example 4 with Version

use of org.sonar.updatecenter.common.Version in project sonarqube by SonarSource.

the class PluginReferentialMetadataConverter method toPluginManifest.

private static PluginManifest toPluginManifest(PluginInfo metadata) {
    PluginManifest pluginManifest = new PluginManifest();
    pluginManifest.setKey(metadata.getKey());
    pluginManifest.setName(metadata.getName());
    Version version = metadata.getVersion();
    if (version != null) {
        pluginManifest.setVersion(version.getName());
    }
    pluginManifest.setDescription(metadata.getDescription());
    pluginManifest.setMainClass(metadata.getMainClass());
    pluginManifest.setOrganization(metadata.getOrganizationName());
    pluginManifest.setOrganizationUrl(metadata.getOrganizationUrl());
    pluginManifest.setLicense(metadata.getLicense());
    pluginManifest.setHomepage(metadata.getHomepageUrl());
    pluginManifest.setIssueTrackerUrl(metadata.getIssueTrackerUrl());
    pluginManifest.setBasePlugin(metadata.getBasePlugin());
    pluginManifest.setRequirePlugins(Collections2.transform(metadata.getRequiredPlugins(), RequiredPluginToString.INSTANCE).toArray(new String[metadata.getRequiredPlugins().size()]));
    return pluginManifest;
}
Also used : Version(org.sonar.updatecenter.common.Version) PluginManifest(org.sonar.updatecenter.common.PluginManifest)

Example 5 with Version

use of org.sonar.updatecenter.common.Version 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

Version (org.sonar.updatecenter.common.Version)9 PluginInfo (org.sonar.core.platform.PluginInfo)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 Test (org.junit.Test)2 Release (org.sonar.updatecenter.common.Release)2 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 JsonWriter (org.sonar.api.utils.text.JsonWriter)1 PluginInfo.jarToPluginInfo (org.sonar.core.platform.PluginInfo.jarToPluginInfo)1 WsTester (org.sonar.server.ws.WsTester)1 PluginManifest (org.sonar.updatecenter.common.PluginManifest)1