Allow plugins to replace gerrit-provided DynamicItem

This should make it possible in the future to allow plugins to
override items provided by core gerrit, such as the WebSession.

This only affects plugins trying to override gerrit core.  If two
plugins try to replace the same DynamicItem then the second will fail.

Change-Id: I399dfc1577003e6a1478f7cb7f40b0b2ffc86c36
This commit is contained in:
Jonathan Nieder
2014-03-24 14:58:31 -07:00
parent b3865f2744
commit c2f6812fce

View File

@@ -152,6 +152,12 @@ public class DynamicItem<T> {
while (!ref.compareAndSet(null, item)) {
NamedProvider<T> old = ref.get();
if (old != null) {
if ("gerrit".equals(old.pluginName)) {
if (ref.compareAndSet(old, item)) {
break;
}
old = ref.get();
}
throw new ProvisionException(String.format(
"%s already provided by %s, ignoring plugin %s",
key.getTypeLiteral(), old.pluginName, pluginName));