Browse Source

SONAR-10286 Deprecate Plugin-ChildFirstClassLoader

tags/8.0
Duarte Meneses 5 years ago
parent
commit
198e19fe0c

+ 5
- 2
sonar-core/src/main/java/org/sonar/core/platform/PluginLoader.java View File

@@ -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, ...):
* <ul>
* <li>server verifies compatibility of JARs before deploying them at startup (see ServerPluginRepository)</li>
* <li>batch loads only the plugins deployed on server (see BatchPluginRepository)</li>
* <li>server verifies compatibility of JARs before deploying them at startup (see ServerPluginRepository)</li>
* <li>batch loads only the plugins deployed on server (see BatchPluginRepository)</li>
* </ul>
* <p/>
* 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;

+ 16
- 0
sonar-core/src/test/java/org/sonar/core/platform/PluginLoaderTest.java View File

@@ -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<PluginClassLoaderDef> defs = underTest.defineClassloaders(ImmutableMap.of("foo", info));
assertThat(defs).extracting(PluginClassLoaderDef::getBasePluginKey).containsExactly("foo");

List<String> 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();

Loading…
Cancel
Save