From 6f157552dba9404955305851e14040031ee1257b Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Tue, 26 Sep 2017 10:41:09 +0200 Subject: [PATCH] Complete list of privileged plugins --- .../org/sonar/core/platform/PluginLoader.java | 6 ++-- .../sonar/core/platform/PluginLoaderTest.java | 31 +++++++------------ 2 files changed, 15 insertions(+), 22 deletions(-) diff --git a/sonar-core/src/main/java/org/sonar/core/platform/PluginLoader.java b/sonar-core/src/main/java/org/sonar/core/platform/PluginLoader.java index b084ba686b0..2dd1432bfc4 100644 --- a/sonar-core/src/main/java/org/sonar/core/platform/PluginLoader.java +++ b/sonar-core/src/main/java/org/sonar/core/platform/PluginLoader.java @@ -21,10 +21,10 @@ package org.sonar.core.platform; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Strings; -import com.google.common.collect.ImmutableSet; import java.io.Closeable; import java.util.Collection; import java.util.HashMap; +import java.util.HashSet; import java.util.Map; import java.util.Set; import org.apache.commons.lang.SystemUtils; @@ -33,6 +33,7 @@ import org.sonar.api.utils.log.Loggers; import org.sonar.updatecenter.common.Version; import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableSet; /** * Loads the plugin JAR files by creating the appropriate classloaders and by instantiating @@ -55,7 +56,8 @@ public class PluginLoader { * Defines the base keys (defined by {@link #basePluginKey(PluginInfo, Map)}) of the plugins which are allowed to * run a full server extensions. */ - private static final Set PRIVILEGED_PLUGINS_BASE_KEYS = ImmutableSet.of("views", "devcockpit", "governance", "billing", "developer", "incremental", "branch"); + private static final Set PRIVILEGED_PLUGINS_BASE_KEYS = unmodifiableSet(new HashSet<>( + asList("billing", "branch", "developer", "governance", "incremental", "license"))); public static final Version COMPATIBILITY_MODE_MAX_VERSION = Version.create("5.2"); diff --git a/sonar-core/src/test/java/org/sonar/core/platform/PluginLoaderTest.java b/sonar-core/src/test/java/org/sonar/core/platform/PluginLoaderTest.java index 02316218e9a..af5d587e78e 100644 --- a/sonar-core/src/test/java/org/sonar/core/platform/PluginLoaderTest.java +++ b/sonar-core/src/test/java/org/sonar/core/platform/PluginLoaderTest.java @@ -44,8 +44,8 @@ public class PluginLoaderTest { @Rule public TemporaryFolder temp = new TemporaryFolder(); - PluginClassloaderFactory classloaderFactory = mock(PluginClassloaderFactory.class); - PluginLoader loader = new PluginLoader(new FakePluginExploder(), classloaderFactory); + private PluginClassloaderFactory classloaderFactory = mock(PluginClassloaderFactory.class); + private PluginLoader loader = new PluginLoader(new FakePluginExploder(), classloaderFactory); @Test public void instantiate_plugin_entry_point() { @@ -148,40 +148,31 @@ public class PluginLoaderTest { } @Test - public void plugin_is_recognised_as_priviledge_if_key_is_views_and_extends_no_other_plugin_and_runs_in_compatibility_mode() throws IOException { - PluginInfo views = create52PluginInfo("views"); + public void plugin_is_recognised_as_privileged_if_key_is_views_and_extends_no_other_plugins() throws IOException { + PluginInfo governance = createPluginInfo("governance"); - Collection defs = loader.defineClassloaders(ImmutableMap.of("views", views)); + Collection defs = loader.defineClassloaders(ImmutableMap.of("governance", governance)); assertThat(defs.iterator().next().isPrivileged()).isTrue(); } @Test - public void plugin_is_recognised_as_priviledge_if_key_is_devcockpit_and_extends_no_other_plugin_and_runs_in_compatibility_mode() throws IOException { - PluginInfo views = create52PluginInfo("devcockpit"); - - Collection defs = loader.defineClassloaders(ImmutableMap.of("views", views)); - - assertThat(defs.iterator().next().isPrivileged()).isTrue(); - } - - @Test - public void plugin_is_not_recognised_as_system_extension_if_key_is_views_and_extends_another_plugin() throws IOException { - PluginInfo foo = create52PluginInfo("foo"); - PluginInfo views = create52PluginInfo("views") + public void plugin_is_not_recognised_as_system_extension_if_key_is_governance_and_extends_another_plugin() throws IOException { + PluginInfo foo = createPluginInfo("foo"); + PluginInfo governance = createPluginInfo("governance") .setBasePlugin("foo"); - Collection defs = loader.defineClassloaders(ImmutableMap.of("foo", foo, "views", views)); + Collection defs = loader.defineClassloaders(ImmutableMap.of("foo", foo, "governance", governance)); assertThat(defs).extracting("compatibilityMode").containsOnly(false, false); } - private PluginInfo create52PluginInfo(String pluginKey) throws IOException { + private PluginInfo createPluginInfo(String pluginKey) throws IOException { File jarFile = temp.newFile(); return new PluginInfo(pluginKey) .setJarFile(jarFile) .setMainClass("org.foo." + pluginKey + "Plugin") - .setMinimalSqVersion(Version.create("5.2")); + .setMinimalSqVersion(Version.create("6.6")); } /** -- 2.39.5