Search in sources :

Example 6 with Version

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

the class UpdateActionTest method if_plugin_has_an_update_download_is_triggered_with_latest_version_from_updatecenter.

@Test
public void if_plugin_has_an_update_download_is_triggered_with_latest_version_from_updatecenter() throws Exception {
    logInAsSystemAdministrator();
    Version version = Version.create("1.0");
    when(updateCenter.findPluginUpdates()).thenReturn(ImmutableList.of(PluginUpdate.createWithStatus(new Release(Plugin.factory(PLUGIN_KEY), version), Status.COMPATIBLE)));
    underTest.handle(validRequest, response);
    verify(pluginDownloader).download(PLUGIN_KEY, version);
    assertThat(response.outputAsString()).isEmpty();
}
Also used : Version(org.sonar.updatecenter.common.Version) Release(org.sonar.updatecenter.common.Release) Test(org.junit.Test)

Example 7 with Version

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

the class InstallActionTest method if_plugin_is_found_available_download_is_triggered_with_latest_version_from_updatecenter.

@Test
public void if_plugin_is_found_available_download_is_triggered_with_latest_version_from_updatecenter() throws Exception {
    logInAsSystemAdministrator();
    Version version = Version.create("1.0");
    when(updateCenter.findAvailablePlugins()).thenReturn(ImmutableList.of(PluginUpdate.createWithStatus(new Release(Plugin.factory(PLUGIN_KEY), version), PluginUpdate.Status.COMPATIBLE)));
    WsTester.Result result = validRequest.execute();
    verify(pluginDownloader).download(PLUGIN_KEY, version);
    result.assertNoContent();
}
Also used : WsTester(org.sonar.server.ws.WsTester) Version(org.sonar.updatecenter.common.Version) Release(org.sonar.updatecenter.common.Release) Test(org.junit.Test)

Example 8 with Version

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

the class PluginInfo method isCompatibleWith.

/**
   * Find out if this plugin is compatible with a given version of SonarQube.
   * The version of SQ must be greater than or equal to the minimal version
   * needed by the plugin.
   */
public boolean isCompatibleWith(String runtimeVersion) {
    if (null == this.minimalSqVersion) {
        // no constraint defined on the plugin
        return true;
    }
    Version effectiveMin = Version.create(minimalSqVersion.getName()).removeQualifier();
    Version effectiveVersion = Version.create(runtimeVersion).removeQualifier();
    if (runtimeVersion.endsWith("-SNAPSHOT")) {
        // check only the major and minor versions (two first fields)
        effectiveMin = Version.create(effectiveMin.getMajor() + "." + effectiveMin.getMinor());
    }
    return effectiveVersion.compareTo(effectiveMin) >= 0;
}
Also used : Version(org.sonar.updatecenter.common.Version)

Example 9 with Version

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

the class PluginLoader method defineClassloaders.

/**
   * Defines the different classloaders to be created. Number of classloaders can be
   * different than number of plugins.
   */
@VisibleForTesting
Collection<PluginClassLoaderDef> defineClassloaders(Map<String, PluginInfo> infoByKeys) {
    Map<String, PluginClassLoaderDef> classloadersByBasePlugin = new HashMap<>();
    for (PluginInfo info : infoByKeys.values()) {
        String baseKey = basePluginKey(info, infoByKeys);
        PluginClassLoaderDef def = classloadersByBasePlugin.get(baseKey);
        if (def == null) {
            def = new PluginClassLoaderDef(baseKey);
            classloadersByBasePlugin.put(baseKey, def);
        }
        ExplodedPlugin explodedPlugin = jarExploder.explode(info);
        def.addFiles(asList(explodedPlugin.getMain()));
        def.addFiles(explodedPlugin.getLibs());
        def.addMainClass(info.getKey(), info.getMainClass());
        for (String defaultSharedResource : DEFAULT_SHARED_RESOURCES) {
            def.getExportMask().addInclusion(String.format("%s/%s/api/", defaultSharedResource, info.getKey()));
        }
        // They can't change metadata like ordering strategy or compatibility mode.
        if (Strings.isNullOrEmpty(info.getBasePlugin())) {
            def.setSelfFirstStrategy(info.isUseChildFirstClassLoader());
            Version minSqVersion = info.getMinimalSqVersion();
            boolean compatibilityMode = minSqVersion != null && minSqVersion.compareToIgnoreQualifier(COMPATIBILITY_MODE_MAX_VERSION) < 0;
            def.setCompatibilityMode(compatibilityMode);
            def.setPrivileged(isPrivileged(baseKey));
            if (compatibilityMode) {
                Loggers.get(getClass()).debug("API compatibility mode is enabled on plugin {} [{}] " + "(built with API lower than {})", info.getName(), info.getKey(), COMPATIBILITY_MODE_MAX_VERSION);
            }
        }
    }
    return classloadersByBasePlugin.values();
}
Also used : HashMap(java.util.HashMap) Version(org.sonar.updatecenter.common.Version) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

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