From 332e3b7cddbd1e6187cb649d339deaef0955f098 Mon Sep 17 00:00:00 2001 From: Duarte Meneses Date: Tue, 9 Feb 2021 11:59:21 -0600 Subject: [PATCH] SONAR-14342 Deprecate Plugin-Dependencies attribute for plugins --- .../java/org/sonar/server/plugins/PluginJarLoader.java | 9 +++++++-- .../org/sonar/server/plugins/PluginJarLoaderTest.java | 10 ++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/server/sonar-webserver-api/src/main/java/org/sonar/server/plugins/PluginJarLoader.java b/server/sonar-webserver-api/src/main/java/org/sonar/server/plugins/PluginJarLoader.java index c9c7ccf5a29..e202dfa94df 100644 --- a/server/sonar-webserver-api/src/main/java/org/sonar/server/plugins/PluginJarLoader.java +++ b/server/sonar-webserver-api/src/main/java/org/sonar/server/plugins/PluginJarLoader.java @@ -137,7 +137,7 @@ public class PluginJarLoader { Set removedKeys = new HashSet<>(); do { removedKeys.clear(); - for (PluginInfo plugin : pluginsByKey.values()) { + for (ServerPluginInfo plugin : pluginsByKey.values()) { if (!isCompatible(plugin, pluginsByKey)) { removedKeys.add(plugin.getKey()); } @@ -149,13 +149,18 @@ public class PluginJarLoader { } @VisibleForTesting - static boolean isCompatible(PluginInfo plugin, Map allPluginsByKeys) { + static boolean isCompatible(ServerPluginInfo plugin, Map allPluginsByKeys) { 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; } + if (plugin.getType() != BUNDLED && !plugin.getRequiredPlugins().isEmpty()) { + LOG.warn("Use of 'Plugin-Dependencies' mechanism is planned for removal. Update the plugin {} [{}] to shade its dependencies instead.", + plugin.getName(), plugin.getKey()); + } + for (PluginInfo.RequiredPlugin requiredPlugin : plugin.getRequiredPlugins()) { PluginInfo installedRequirement = allPluginsByKeys.get(requiredPlugin.getKey()); if (installedRequirement == null) { diff --git a/server/sonar-webserver-api/src/test/java/org/sonar/server/plugins/PluginJarLoaderTest.java b/server/sonar-webserver-api/src/test/java/org/sonar/server/plugins/PluginJarLoaderTest.java index fba16066755..80686c8c23a 100644 --- a/server/sonar-webserver-api/src/test/java/org/sonar/server/plugins/PluginJarLoaderTest.java +++ b/server/sonar-webserver-api/src/test/java/org/sonar/server/plugins/PluginJarLoaderTest.java @@ -196,6 +196,16 @@ public class PluginJarLoaderTest { assertThat(logs.logs()).contains("Plugin test [test] is ignored because entry point class is not defined"); } + @Test + public void warn_if_external_plugin_has_dependencies() throws IOException { + copyTestPluginTo("test-base-plugin", fs.getInstalledExternalPluginsDir()); + copyTestPluginTo("test-require-plugin", fs.getInstalledExternalPluginsDir()); + + underTest.loadPlugins(); + assertThat(logs.logs()).contains("Use of 'Plugin-Dependencies' mechanism is planned for removal. " + + "Update the plugin Test Require Plugin [testrequire] to shade its dependencies instead."); + } + @Test public void fail_if_external_plugin_has_same_key_has_bundled_plugin() throws IOException { File jar = createJar(fs.getInstalledExternalPluginsDir(), "plugin1", "main", null); -- 2.39.5