Fix plugin reloading for DynamicItems
Since DynamicItems could only ever be loaded by a single
plugin at a time (they are singletons), the code enforcing
this prevented those plugins from being reloaded.
Test Plan: reload the following plugins:
* gravatar-avatar-provider
* websession-flatfile
Bug: issue 2895
Change-Id: I52a07f34d1fa0b756f4cc22d0d83d2ef6906840e
(cherry picked from commit 9a5e78aa73fc4cf1159e2bcca95bf11c1f0b5cb5)
diff --git a/gerrit-extension-api/src/main/java/com/google/gerrit/extensions/registration/DynamicItem.java b/gerrit-extension-api/src/main/java/com/google/gerrit/extensions/registration/DynamicItem.java
index 9ef7d1b..7edfaed 100644
--- a/gerrit-extension-api/src/main/java/com/google/gerrit/extensions/registration/DynamicItem.java
+++ b/gerrit-extension-api/src/main/java/com/google/gerrit/extensions/registration/DynamicItem.java
@@ -184,7 +184,13 @@
NamedProvider<T> old = null;
while (!ref.compareAndSet(old, item)) {
old = ref.get();
- if (old != null && !"gerrit".equals(old.pluginName)) {
+ if (old != null
+ && !"gerrit".equals(old.pluginName)
+ && !pluginName.equals(old.pluginName)) {
+ // We allow to replace:
+ // 1. Gerrit core items, e.g. websession cache
+ // can be replaced by plugin implementation
+ // 2. Reload of current plugin
throw new ProvisionException(String.format(
"%s already provided by %s, ignoring plugin %s",
this.key.getTypeLiteral(), old.pluginName, pluginName));