aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-webserver-api
diff options
context:
space:
mode:
authorDuarte Meneses <duarte.meneses@sonarsource.com>2020-09-10 14:04:14 -0500
committersonartech <sonartech@sonarsource.com>2020-09-18 20:07:16 +0000
commit3e861b4dc2810af234cfa2a97bd8519960ff3b4a (patch)
tree32eb144eb9eb30f4b2fa477af330c4324b40c6c3 /server/sonar-webserver-api
parent59f329469693de82d2f39c3b65aabafd47b366dc (diff)
downloadsonarqube-3e861b4dc2810af234cfa2a97bd8519960ff3b4a.tar.gz
sonarqube-3e861b4dc2810af234cfa2a97bd8519960ff3b4a.zip
SONAR-13643 Improve error message when duplicate plugins are present
Diffstat (limited to 'server/sonar-webserver-api')
-rw-r--r--server/sonar-webserver-api/src/main/java/org/sonar/server/plugins/PluginJarLoader.java32
-rw-r--r--server/sonar-webserver-api/src/test/java/org/sonar/server/plugins/PluginJarLoaderTest.java8
2 files changed, 26 insertions, 14 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 5deb216a54f..19c2bbdc6ee 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
@@ -47,6 +47,7 @@ import org.sonar.updatecenter.common.Version;
import static java.lang.String.format;
import static org.apache.commons.io.FileUtils.moveFile;
import static org.sonar.core.util.FileUtils.deleteQuietly;
+import static org.sonar.server.log.ServerProcessLogging.STARTUP_LOGGER_NAME;
import static org.sonar.server.plugins.PluginType.BUNDLED;
import static org.sonar.server.plugins.PluginType.EXTERNAL;
@@ -59,6 +60,8 @@ public class PluginJarLoader {
private static final Set<String> FORBIDDEN_INCOMPATIBLE_PLUGINS = ImmutableSet
.of("sqale", "report", "views", "authgithub", "authgitlab", "authsaml", "ldap", "scmgit", "scmsvn");
+ private static final String LOAD_ERROR_GENERIC_MESSAGE = "Startup failed: Plugins can't be loaded. See web logs for more information";
+
private final ServerFileSystem fs;
private final SonarRuntime runtime;
private final Set<String> blacklistedPluginKeys;
@@ -79,26 +82,27 @@ public class PluginJarLoader {
public Collection<ServerPluginInfo> loadPlugins() {
Map<String, ServerPluginInfo> bundledPluginsByKey = new LinkedHashMap<>();
for (ServerPluginInfo bundled : getBundledPluginsMetadata()) {
- failIfContains(bundledPluginsByKey, bundled, plugin ->
- MessageException.of(format("Found two versions of the plugin %s [%s] in the directory %s. Please remove one of %s or %s.",
+ failIfContains(bundledPluginsByKey, bundled,
+ plugin -> MessageException.of(format("Found two versions of the plugin %s [%s] in the directory %s. Please remove one of %s or %s.",
bundled.getName(), bundled.getKey(), getRelativeDir(fs.getInstalledBundledPluginsDir()), bundled.getNonNullJarFile().getName(), plugin.getNonNullJarFile().getName())));
bundledPluginsByKey.put(bundled.getKey(), bundled);
}
Map<String, ServerPluginInfo> externalPluginsByKey = new LinkedHashMap<>();
for (ServerPluginInfo external : getExternalPluginsMetadata()) {
- failIfContains(bundledPluginsByKey, external, plugin ->
- MessageException.of(format("Found a plugin '%s' in the directory %s with the same key [%s] as a bundled plugin '%s'. Please remove %s.",
- external.getName(), getRelativeDir(fs.getInstalledExternalPluginsDir()), external.getKey(), plugin.getName(), external.getNonNullJarFile().getName())));
- failIfContains(externalPluginsByKey, external, plugin ->
- MessageException.of(format("Found two versions of the plugin '%s' [%s] in the directory %s. Please remove %s or %s.", external.getName(), external.getKey(),
+ failIfContains(bundledPluginsByKey, external,
+ plugin -> MessageException.of(format("Found a plugin '%s' in the directory '%s' with the same key [%s] as a built-in feature '%s'. Please remove '%s'.",
+ external.getName(), getRelativeDir(fs.getInstalledExternalPluginsDir()), external.getKey(), plugin.getName(),
+ new File(getRelativeDir(fs.getInstalledExternalPluginsDir()), external.getNonNullJarFile().getName()))));
+ failIfContains(externalPluginsByKey, external,
+ plugin -> MessageException.of(format("Found two versions of the plugin '%s' [%s] in the directory '%s'. Please remove %s or %s.", external.getName(), external.getKey(),
getRelativeDir(fs.getInstalledExternalPluginsDir()), external.getNonNullJarFile().getName(), plugin.getNonNullJarFile().getName())));
externalPluginsByKey.put(external.getKey(), external);
}
for (PluginInfo downloaded : getDownloadedPluginsMetadata()) {
- failIfContains(bundledPluginsByKey, downloaded, plugin ->
- MessageException.of(format("Fail to update plugin: %s. Bundled plugin with same key already exists: %s. Move or delete plugin from %s directory",
+ failIfContains(bundledPluginsByKey, downloaded,
+ plugin -> MessageException.of(format("Fail to update plugin: %s. Built-in feature with same key already exists: %s. Move or delete plugin from %s directory",
plugin.getName(), plugin.getKey(), getRelativeDir(fs.getDownloadedPluginsDir()))));
ServerPluginInfo installedPlugin;
@@ -178,10 +182,17 @@ public class PluginJarLoader {
private static void failIfContains(Map<String, ? extends PluginInfo> map, PluginInfo value, Function<PluginInfo, RuntimeException> msg) {
PluginInfo pluginInfo = map.get(value.getKey());
if (pluginInfo != null) {
- throw msg.apply(pluginInfo);
+ RuntimeException exception = msg.apply(pluginInfo);
+ logGenericPluginLoadErrorLog();
+ throw exception;
}
}
+ private static void logGenericPluginLoadErrorLog() {
+ Logger logger = Loggers.get(STARTUP_LOGGER_NAME);
+ logger.error(LOAD_ERROR_GENERIC_MESSAGE);
+ }
+
private List<ServerPluginInfo> getBundledPluginsMetadata() {
return loadPluginsFromDir(fs.getInstalledBundledPluginsDir(), jar -> ServerPluginInfo.create(jar, BUNDLED));
}
@@ -230,6 +241,7 @@ public class PluginJarLoader {
.collect(Collectors.toList());
if (!incompatiblePlugins.isEmpty()) {
+ logGenericPluginLoadErrorLog();
throw MessageException.of(String.format("The following %s no longer compatible with this version of SonarQube: %s",
incompatiblePlugins.size() > 1 ? "plugins are" : "plugin is", String.join(", ", incompatiblePlugins)));
}
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 0297973bd14..aeb366501f0 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
@@ -202,8 +202,8 @@ public class PluginJarLoaderTest {
createJar(fs.getInstalledBundledPluginsDir(), "plugin1", "main", null);
String dir = getDirName(fs.getInstalledExternalPluginsDir());
- expectedException.expectMessage("Found a plugin 'plugin1' in the directory " + dir + " with the same key [plugin1] as a bundled plugin 'plugin1'. "
- + "Please remove " + jar.getName());
+ expectedException.expectMessage("Found a plugin 'plugin1' in the directory '" + dir + "' with the same key [plugin1] as a built-in feature 'plugin1'. "
+ + "Please remove '" + new File(dir, jar.getName()) + "'");
expectedException.expect(MessageException.class);
underTest.loadPlugins();
}
@@ -213,7 +213,7 @@ public class PluginJarLoaderTest {
File downloaded = createJar(fs.getDownloadedPluginsDir(), "plugin1", "main", null);
createJar(fs.getInstalledBundledPluginsDir(), "plugin1", "main", null);
String dir = getDirName(fs.getDownloadedPluginsDir());
- expectedException.expectMessage("Fail to update plugin: plugin1. Bundled plugin with same key already exists: plugin1. "
+ expectedException.expectMessage("Fail to update plugin: plugin1. Built-in feature with same key already exists: plugin1. "
+ "Move or delete plugin from " + dir + " directory");
expectedException.expect(MessageException.class);
underTest.loadPlugins();
@@ -225,7 +225,7 @@ public class PluginJarLoaderTest {
File jar2 = createJar(fs.getInstalledExternalPluginsDir(), "plugin1", "main", null);
String dir = getDirName(fs.getInstalledExternalPluginsDir());
- expectedException.expectMessage("Found two versions of the plugin 'plugin1' [plugin1] in the directory " + dir + ". Please remove ");
+ expectedException.expectMessage("Found two versions of the plugin 'plugin1' [plugin1] in the directory '" + dir + "'. Please remove ");
expectedException.expectMessage(jar2.getName());
expectedException.expectMessage(jar1.getName());
expectedException.expect(MessageException.class);