From 198e19fe0c370f3a016c552f5a0fe0989f8b7dc4 Mon Sep 17 00:00:00 2001 From: Duarte Meneses Date: Wed, 26 Jun 2019 08:59:28 +0200 Subject: [PATCH] SONAR-10286 Deprecate Plugin-ChildFirstClassLoader --- .../org/sonar/core/platform/PluginLoader.java | 7 +++++-- .../sonar/core/platform/PluginLoaderTest.java | 16 ++++++++++++++++ 2 files changed, 21 insertions(+), 2 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 f2927029e3f..88696f03e4a 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 @@ -37,8 +37,8 @@ import static java.util.Arrays.asList; * the entry point classes as defined in manifests. It assumes that JAR files are compatible with current * environment (minimal sonarqube version, compatibility between plugins, ...): * *

* Plugins have their own isolated classloader, inheriting only from API classes. @@ -93,6 +93,9 @@ public class PluginLoader { // The plugins that extend other plugins can only add some files to classloader. // They can't change metadata like ordering strategy or compatibility mode. if (Strings.isNullOrEmpty(info.getBasePlugin())) { + if (info.isUseChildFirstClassLoader()) { + Loggers.get(getClass()).warn("Plugin {} [{}] uses a child first classloader which is deprecated", info.getName(), info.getKey()); + } def.setSelfFirstStrategy(info.isUseChildFirstClassLoader()); Version minSqVersion = info.getMinimalSqVersion(); boolean compatibilityMode = minSqVersion != null && minSqVersion.compareToIgnoreQualifier(COMPATIBILITY_MODE_MAX_VERSION) < 0; 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 34496c3a397..56b458d7616 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 @@ -21,6 +21,7 @@ package org.sonar.core.platform; import com.google.common.collect.ImmutableMap; import java.io.File; +import java.io.IOException; import java.util.Collection; import java.util.Collections; import java.util.List; @@ -109,6 +110,21 @@ public class PluginLoaderTest { // TODO test mask - require change in sonar-classloader } + @Test + public void log_warning_if_plugin_uses_child_first_classloader() throws IOException { + File jarFile = temp.newFile(); + PluginInfo info = new PluginInfo("foo") + .setJarFile(jarFile) + .setUseChildFirstClassLoader(true) + .setMainClass("org.foo.FooPlugin"); + + Collection defs = underTest.defineClassloaders(ImmutableMap.of("foo", info)); + assertThat(defs).extracting(PluginClassLoaderDef::getBasePluginKey).containsExactly("foo"); + + List warnings = logTester.logs(LoggerLevel.WARN); + assertThat(warnings).contains("Plugin foo [foo] uses a child first classloader which is deprecated"); + } + @Test public void log_warning_if_plugin_is_built_with_api_5_2_or_lower() throws Exception { File jarFile = temp.newFile(); -- 2.39.5