From abf6404f3b3f87e0f35de4ab2926b5df47c1dbfe Mon Sep 17 00:00:00 2001 From: Edwin Kempin Date: Fri, 14 Sep 2018 09:11:13 +0200 Subject: [PATCH] Have common class for entries in DynamicMap/DynamicSet/DynamicItem At the moment we have several classes to represent plugin extensions: DynamicMap.Entry, DynamicSet.Entry, NamedProvider They are all very similar and can be merged into one class. This has the advantage that we are now able to offer methods that deal with plugin extensions regardless from which source they come. Change-Id: I4293795800771ef06eae6ec6d64be4b0a8fd72f4 Signed-off-by: Edwin Kempin --- .../extensions/registration/DynamicItem.java | 47 ++++++------ .../extensions/registration/DynamicMap.java | 32 ++------ .../extensions/registration/DynamicSet.java | 73 +++++++------------ .../registration/DynamicSetProvider.java | 7 +- .../extensions/registration/Extension.java | 61 ++++++++++++++++ .../registration/NamedProvider.java | 28 ------- .../gerrit/httpd/ProjectOAuthFilter.java | 4 +- .../gerrit/server/cache/CacheMetrics.java | 5 +- .../gerrit/server/change/ChangeJson.java | 5 +- .../server/config/ProjectConfigEntry.java | 6 +- .../gerrit/server/edit/ChangeEditJson.java | 3 +- .../server/extensions/webui/UiActions.java | 3 +- .../server/git/receive/ReceiveCommits.java | 4 +- .../git/validators/MergeValidators.java | 4 +- .../server/mail/receive/MailProcessor.java | 3 +- .../query/change/ChangeQueryBuilder.java | 3 +- .../restapi/account/SetPreferences.java | 3 +- .../restapi/change/ReviewerRecommender.java | 3 +- .../server/restapi/config/GetServerInfo.java | 7 +- .../server/restapi/config/ListCaches.java | 3 +- .../server/restapi/config/PostCaches.java | 3 +- .../restapi/project/ConfigInfoImpl.java | 6 +- .../registration/DynamicSetTest.java | 4 +- 23 files changed, 160 insertions(+), 157 deletions(-) create mode 100644 java/com/google/gerrit/extensions/registration/Extension.java delete mode 100644 java/com/google/gerrit/extensions/registration/NamedProvider.java diff --git a/java/com/google/gerrit/extensions/registration/DynamicItem.java b/java/com/google/gerrit/extensions/registration/DynamicItem.java index 4f36ab4817..67982d9040 100644 --- a/java/com/google/gerrit/extensions/registration/DynamicItem.java +++ b/java/com/google/gerrit/extensions/registration/DynamicItem.java @@ -111,17 +111,22 @@ public class DynamicItem { } private final Key> key; - private final AtomicReference> ref; + private final AtomicReference> ref; DynamicItem(Key> key, Provider provider, String pluginName) { - NamedProvider in = null; + Extension in = null; if (provider != null) { - in = new NamedProvider<>(provider, pluginName); + in = new Extension<>(pluginName, provider); } this.key = key; this.ref = new AtomicReference<>(in); } + @Nullable + public Extension getEntry() { + return ref.get(); + } + /** * Get the configured item, or null. * @@ -130,8 +135,8 @@ public class DynamicItem { */ @Nullable public T get() { - NamedProvider item = ref.get(); - return item != null ? item.impl.get() : null; + Extension item = ref.get(); + return item != null ? item.get() : null; } /** @@ -143,8 +148,8 @@ public class DynamicItem { */ @Nullable public String getPluginName() { - NamedProvider item = ref.get(); - return item != null ? item.pluginName : null; + Extension item = ref.get(); + return item != null ? item.getPluginName() : null; } /** @@ -166,19 +171,19 @@ public class DynamicItem { * @return handle to remove the item at a later point in time. */ public RegistrationHandle set(Provider impl, String pluginName) { - final NamedProvider item = new NamedProvider<>(impl, pluginName); - NamedProvider old = null; + final Extension item = new Extension<>(pluginName, impl); + Extension old = null; while (!ref.compareAndSet(old, item)) { old = ref.get(); - if (old != null && !PluginName.GERRIT.equals(old.pluginName)) { + if (old != null && !PluginName.GERRIT.equals(old.getPluginName())) { throw new ProvisionException( String.format( "%s already provided by %s, ignoring plugin %s", - key.getTypeLiteral(), old.pluginName, pluginName)); + key.getTypeLiteral(), old.getPluginName(), pluginName)); } } - final NamedProvider defaultItem = old; + final Extension defaultItem = old; return new RegistrationHandle() { @Override public void remove() { @@ -198,13 +203,13 @@ public class DynamicItem { * @return a handle that can remove this item later, or hot-swap the item. */ public ReloadableRegistrationHandle set(Key key, Provider impl, String pluginName) { - final NamedProvider item = new NamedProvider<>(impl, pluginName); - NamedProvider old = null; + final Extension item = new Extension<>(pluginName, impl); + Extension old = null; while (!ref.compareAndSet(old, item)) { old = ref.get(); if (old != null - && !PluginName.GERRIT.equals(old.pluginName) - && !pluginName.equals(old.pluginName)) { + && !PluginName.GERRIT.equals(old.getPluginName()) + && !pluginName.equals(old.getPluginName())) { // We allow to replace: // 1. Gerrit core items, e.g. websession cache // can be replaced by plugin implementation @@ -212,7 +217,7 @@ public class DynamicItem { throw new ProvisionException( String.format( "%s already provided by %s, ignoring plugin %s", - this.key.getTypeLiteral(), old.pluginName, pluginName)); + this.key.getTypeLiteral(), old.getPluginName(), pluginName)); } } return new ReloadableHandle(key, item, old); @@ -220,10 +225,10 @@ public class DynamicItem { private class ReloadableHandle implements ReloadableRegistrationHandle { private final Key handleKey; - private final NamedProvider item; - private final NamedProvider defaultItem; + private final Extension item; + private final Extension defaultItem; - ReloadableHandle(Key handleKey, NamedProvider item, NamedProvider defaultItem) { + ReloadableHandle(Key handleKey, Extension item, Extension defaultItem) { this.handleKey = handleKey; this.item = item; this.defaultItem = defaultItem; @@ -242,7 +247,7 @@ public class DynamicItem { @Override @Nullable public ReloadableHandle replace(Key newKey, Provider newItem) { - NamedProvider n = new NamedProvider<>(newItem, item.pluginName); + Extension n = new Extension<>(item.getPluginName(), newItem); if (ref.compareAndSet(item, n)) { return new ReloadableHandle(newKey, n, defaultItem); } diff --git a/java/com/google/gerrit/extensions/registration/DynamicMap.java b/java/com/google/gerrit/extensions/registration/DynamicMap.java index 96d19b2090..48b1279489 100644 --- a/java/com/google/gerrit/extensions/registration/DynamicMap.java +++ b/java/com/google/gerrit/extensions/registration/DynamicMap.java @@ -40,29 +40,7 @@ import java.util.concurrent.ConcurrentMap; * resolve the provider to an instance on demand. This enables registrations to decide between * singleton and non-singleton members. */ -public abstract class DynamicMap implements Iterable> { - public static class Entry { - private final NamePair namePair; - private final Provider provider; - - private Entry(NamePair namePair, Provider provider) { - this.namePair = namePair; - this.provider = provider; - } - - public String getPluginName() { - return namePair.pluginName; - } - - public String getExportName() { - return namePair.exportName; - } - - public Provider getProvider() { - return provider; - } - } - +public abstract class DynamicMap implements Iterable> { /** * Declare a singleton {@code DynamicMap} with a binder. * @@ -166,18 +144,18 @@ public abstract class DynamicMap implements Iterable> { /** Iterate through all entries in an undefined order. */ @Override - public Iterator> iterator() { + public Iterator> iterator() { final Iterator>> i = items.entrySet().iterator(); - return new Iterator>() { + return new Iterator>() { @Override public boolean hasNext() { return i.hasNext(); } @Override - public Entry next() { + public Extension next() { Map.Entry> e = i.next(); - return new Entry<>(e.getKey(), e.getValue()); + return new Extension<>(e.getKey().pluginName, e.getKey().exportName, e.getValue()); } @Override diff --git a/java/com/google/gerrit/extensions/registration/DynamicSet.java b/java/com/google/gerrit/extensions/registration/DynamicSet.java index 6b3a49bffe..dcd0d8f1b0 100644 --- a/java/com/google/gerrit/extensions/registration/DynamicSet.java +++ b/java/com/google/gerrit/extensions/registration/DynamicSet.java @@ -45,24 +45,6 @@ import java.util.concurrent.atomic.AtomicReference; * singleton and non-singleton members. */ public class DynamicSet implements Iterable { - public static class Entry { - private final String pluginName; - private final Provider provider; - - private Entry(String pluginName, Provider provider) { - this.pluginName = pluginName; - this.provider = provider; - } - - public String getPluginName() { - return pluginName; - } - - public Provider getProvider() { - return provider; - } - } - /** * Declare a singleton {@code DynamicSet} with a binder. * @@ -153,12 +135,12 @@ public class DynamicSet implements Iterable { } public static DynamicSet emptySet() { - return new DynamicSet<>(Collections.>>emptySet()); + return new DynamicSet<>(Collections.>>emptySet()); } - private final CopyOnWriteArrayList>> items; + private final CopyOnWriteArrayList>> items; - DynamicSet(Collection>> base) { + DynamicSet(Collection>> base) { items = new CopyOnWriteArrayList<>(base); } @@ -168,7 +150,7 @@ public class DynamicSet implements Iterable { @Override public Iterator iterator() { - Iterator> entryIterator = entries().iterator(); + Iterator> entryIterator = entries().iterator(); return new Iterator() { @Override public boolean hasNext() { @@ -177,39 +159,35 @@ public class DynamicSet implements Iterable { @Override public T next() { - Entry next = entryIterator.next(); + Extension next = entryIterator.next(); return next != null ? next.getProvider().get() : null; } }; } - public Iterable> entries() { - final Iterator>> itr = items.iterator(); - return new Iterable>() { + public Iterable> entries() { + final Iterator>> itr = items.iterator(); + return new Iterable>() { @Override - public Iterator> iterator() { - return new Iterator>() { - private Entry next; + public Iterator> iterator() { + return new Iterator>() { + private Extension next; @Override public boolean hasNext() { while (next == null && itr.hasNext()) { - NamedProvider p = itr.next().get(); + Extension p = itr.next().get(); if (p != null) { - try { - next = new Entry<>(p.pluginName, p.impl); - } catch (RuntimeException e) { - // TODO Log failed member of DynamicSet. - } + next = p; } } return next != null; } @Override - public Entry next() { + public Extension next() { if (hasNext()) { - Entry result = next; + Extension result = next; next = null; return result; } @@ -250,7 +228,7 @@ public class DynamicSet implements Iterable { public ImmutableSortedSet plugins() { return items .stream() - .map(i -> i.get().pluginName) + .map(i -> i.get().getPluginName()) .collect(toImmutableSortedSet(naturalOrder())); } @@ -263,8 +241,8 @@ public class DynamicSet implements Iterable { public ImmutableSet> byPlugin(String pluginName) { return items .stream() - .filter(i -> i.get().pluginName.equals(pluginName)) - .map(i -> i.get().impl) + .filter(i -> i.get().getPluginName().equals(pluginName)) + .map(i -> i.get().getProvider()) .collect(toImmutableSet()); } @@ -285,8 +263,8 @@ public class DynamicSet implements Iterable { * @return handle to remove the item at a later point in time. */ public RegistrationHandle add(String pluginName, Provider item) { - final AtomicReference> ref = - new AtomicReference<>(new NamedProvider<>(item, pluginName)); + final AtomicReference> ref = + new AtomicReference<>(new Extension<>(pluginName, item)); items.add(ref); return new RegistrationHandle() { @Override @@ -310,18 +288,17 @@ public class DynamicSet implements Iterable { * the collection. */ public ReloadableRegistrationHandle add(String pluginName, Key key, Provider item) { - AtomicReference> ref = - new AtomicReference<>(new NamedProvider<>(item, pluginName)); + AtomicReference> ref = new AtomicReference<>(new Extension<>(pluginName, item)); items.add(ref); return new ReloadableHandle(ref, key, ref.get()); } private class ReloadableHandle implements ReloadableRegistrationHandle { - private final AtomicReference> ref; + private final AtomicReference> ref; private final Key key; - private final NamedProvider item; + private final Extension item; - ReloadableHandle(AtomicReference> ref, Key key, NamedProvider item) { + ReloadableHandle(AtomicReference> ref, Key key, Extension item) { this.ref = ref; this.key = key; this.item = item; @@ -341,7 +318,7 @@ public class DynamicSet implements Iterable { @Override public ReloadableHandle replace(Key newKey, Provider newItem) { - NamedProvider n = new NamedProvider<>(newItem, item.pluginName); + Extension n = new Extension<>(item.getPluginName(), newItem); if (ref.compareAndSet(item, n)) { return new ReloadableHandle(ref, newKey, n); } diff --git a/java/com/google/gerrit/extensions/registration/DynamicSetProvider.java b/java/com/google/gerrit/extensions/registration/DynamicSetProvider.java index 6d36f54bb3..832933b31c 100644 --- a/java/com/google/gerrit/extensions/registration/DynamicSetProvider.java +++ b/java/com/google/gerrit/extensions/registration/DynamicSetProvider.java @@ -38,17 +38,16 @@ class DynamicSetProvider implements Provider> { return new DynamicSet<>(find(injector, type)); } - private static List>> find( - Injector src, TypeLiteral type) { + private static List>> find(Injector src, TypeLiteral type) { List> bindings = src.findBindingsByType(type); int cnt = bindings != null ? bindings.size() : 0; if (cnt == 0) { return Collections.emptyList(); } - List>> r = new ArrayList<>(cnt); + List>> r = new ArrayList<>(cnt); for (Binding b : bindings) { if (b.getKey().getAnnotation() != null) { - r.add(new AtomicReference<>(new NamedProvider<>(b.getProvider(), PluginName.GERRIT))); + r.add(new AtomicReference<>(new Extension<>(PluginName.GERRIT, b.getProvider()))); } } return r; diff --git a/java/com/google/gerrit/extensions/registration/Extension.java b/java/com/google/gerrit/extensions/registration/Extension.java new file mode 100644 index 0000000000..aaec201bd7 --- /dev/null +++ b/java/com/google/gerrit/extensions/registration/Extension.java @@ -0,0 +1,61 @@ +// Copyright (C) 2018 The Android Open Source Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package com.google.gerrit.extensions.registration; + +import com.google.gerrit.common.Nullable; +import com.google.inject.Provider; + +/** + * An extension that is provided by a plugin. + * + *

Contains the name of the plugin that provides the extension, the extension point + * implementation and optionally the export name under which the extension was exported. + * + *

An export name is only available if this extension is an entry in a {@link DynamicMap}. + * + * @param Type of extension point that this extension implements + */ +public class Extension { + private final String pluginName; + private final @Nullable String exportName; + private final Provider provider; + + protected Extension(String pluginName, Provider provider) { + this(pluginName, null, provider); + } + + protected Extension(String pluginName, @Nullable String exportName, Provider provider) { + this.pluginName = pluginName; + this.exportName = exportName; + this.provider = provider; + } + + public String getPluginName() { + return pluginName; + } + + @Nullable + public String getExportName() { + return exportName; + } + + public Provider getProvider() { + return provider; + } + + public T get() { + return provider.get(); + } +} diff --git a/java/com/google/gerrit/extensions/registration/NamedProvider.java b/java/com/google/gerrit/extensions/registration/NamedProvider.java deleted file mode 100644 index aca651b5f8..0000000000 --- a/java/com/google/gerrit/extensions/registration/NamedProvider.java +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright (C) 2018 The Android Open Source Project -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package com.google.gerrit.extensions.registration; - -import com.google.inject.Provider; - -/** Pair of provider implementation and plugin providing it. */ -class NamedProvider { - final Provider impl; - final String pluginName; - - NamedProvider(Provider provider, String pluginName) { - this.impl = provider; - this.pluginName = pluginName; - } -} diff --git a/java/com/google/gerrit/httpd/ProjectOAuthFilter.java b/java/com/google/gerrit/httpd/ProjectOAuthFilter.java index 5e234d2e38..30ebe6e7cb 100644 --- a/java/com/google/gerrit/httpd/ProjectOAuthFilter.java +++ b/java/com/google/gerrit/httpd/ProjectOAuthFilter.java @@ -25,7 +25,7 @@ import com.google.common.flogger.FluentLogger; import com.google.gerrit.extensions.auth.oauth.OAuthLoginProvider; import com.google.gerrit.extensions.registration.DynamicItem; import com.google.gerrit.extensions.registration.DynamicMap; -import com.google.gerrit.extensions.registration.DynamicMap.Entry; +import com.google.gerrit.extensions.registration.Extension; import com.google.gerrit.reviewdb.client.Account; import com.google.gerrit.server.AccessPath; import com.google.gerrit.server.account.AccountCache; @@ -191,7 +191,7 @@ class ProjectOAuthFilter implements Filter { */ private void pickOnlyProvider() throws ServletException { try { - Entry loginProvider = Iterables.getOnlyElement(loginProviders); + Extension loginProvider = Iterables.getOnlyElement(loginProviders); defaultAuthPlugin = loginProvider.getPluginName(); defaultAuthProvider = loginProvider.getExportName(); } catch (NoSuchElementException e) { diff --git a/java/com/google/gerrit/server/cache/CacheMetrics.java b/java/com/google/gerrit/server/cache/CacheMetrics.java index 343565266f..c652d50d73 100644 --- a/java/com/google/gerrit/server/cache/CacheMetrics.java +++ b/java/com/google/gerrit/server/cache/CacheMetrics.java @@ -18,6 +18,7 @@ import com.google.common.cache.Cache; import com.google.common.cache.CacheStats; import com.google.common.collect.ImmutableSet; import com.google.gerrit.extensions.registration.DynamicMap; +import com.google.gerrit.extensions.registration.Extension; import com.google.gerrit.extensions.registration.PluginName; import com.google.gerrit.metrics.CallbackMetric; import com.google.gerrit.metrics.CallbackMetric1; @@ -71,7 +72,7 @@ public class CacheMetrics { metrics.newTrigger( cacheMetrics, () -> { - for (DynamicMap.Entry> e : cacheMap) { + for (Extension> e : cacheMap) { Cache c = e.getProvider().get(); String name = metricNameOf(e); CacheStats cstats = c.stats(); @@ -95,7 +96,7 @@ public class CacheMetrics { return ((double) d.hitCount() / d.requestCount() * 100); } - private static String metricNameOf(DynamicMap.Entry> e) { + private static String metricNameOf(Extension> e) { if (PluginName.GERRIT.equals(e.getPluginName())) { return e.getExportName(); } diff --git a/java/com/google/gerrit/server/change/ChangeJson.java b/java/com/google/gerrit/server/change/ChangeJson.java index 43f7b2f742..e1a0aa7917 100644 --- a/java/com/google/gerrit/server/change/ChangeJson.java +++ b/java/com/google/gerrit/server/change/ChangeJson.java @@ -88,6 +88,7 @@ import com.google.gerrit.extensions.common.WebLinkInfo; import com.google.gerrit.extensions.config.DownloadCommand; import com.google.gerrit.extensions.config.DownloadScheme; import com.google.gerrit.extensions.registration.DynamicMap; +import com.google.gerrit.extensions.registration.Extension; import com.google.gerrit.extensions.restapi.AuthException; import com.google.gerrit.extensions.restapi.Url; import com.google.gerrit.index.query.QueryResult; @@ -1471,7 +1472,7 @@ public class ChangeJson { private Map makeFetchMap(ChangeData cd, PatchSet in) throws PermissionBackendException, OrmException, IOException { Map r = new LinkedHashMap<>(); - for (DynamicMap.Entry e : downloadSchemes) { + for (Extension e : downloadSchemes) { String schemeName = e.getExportName(); DownloadScheme scheme = e.getProvider().get(); if (!scheme.isEnabled() @@ -1502,7 +1503,7 @@ public class ChangeJson { String projectName, String refName, FetchInfo fetchInfo) { - for (DynamicMap.Entry e2 : commands) { + for (Extension e2 : commands) { String commandName = e2.getExportName(); DownloadCommand command = e2.getProvider().get(); String c = command.getCommand(scheme, projectName, refName); diff --git a/java/com/google/gerrit/server/config/ProjectConfigEntry.java b/java/com/google/gerrit/server/config/ProjectConfigEntry.java index d30e080aef..5515f0ebc3 100644 --- a/java/com/google/gerrit/server/config/ProjectConfigEntry.java +++ b/java/com/google/gerrit/server/config/ProjectConfigEntry.java @@ -22,7 +22,7 @@ import com.google.gerrit.extensions.api.projects.ConfigValue; import com.google.gerrit.extensions.api.projects.ProjectConfigEntryType; import com.google.gerrit.extensions.events.GitReferenceUpdatedListener; import com.google.gerrit.extensions.registration.DynamicMap; -import com.google.gerrit.extensions.registration.DynamicMap.Entry; +import com.google.gerrit.extensions.registration.Extension; import com.google.gerrit.reviewdb.client.Project; import com.google.gerrit.reviewdb.client.RefNames; import com.google.gerrit.server.git.GitRepositoryManager; @@ -321,7 +321,7 @@ public class ProjectConfigEntry { ProjectConfig oldCfg = parseConfig(p, event.getOldObjectId()); ProjectConfig newCfg = parseConfig(p, event.getNewObjectId()); if (oldCfg != null && newCfg != null) { - for (Entry e : pluginConfigEntries) { + for (Extension e : pluginConfigEntries) { ProjectConfigEntry configEntry = e.getProvider().get(); String newValue = getValue(newCfg, e); String oldValue = getValue(oldCfg, e); @@ -367,7 +367,7 @@ public class ProjectConfigEntry { } } - private static String getValue(ProjectConfig cfg, Entry e) { + private static String getValue(ProjectConfig cfg, Extension e) { String value = cfg.getPluginConfig(e.getPluginName()).getString(e.getExportName()); if (value == null) { value = e.getProvider().get().getDefaultValue(); diff --git a/java/com/google/gerrit/server/edit/ChangeEditJson.java b/java/com/google/gerrit/server/edit/ChangeEditJson.java index 78baef7195..bd9c3a616b 100644 --- a/java/com/google/gerrit/server/edit/ChangeEditJson.java +++ b/java/com/google/gerrit/server/edit/ChangeEditJson.java @@ -20,6 +20,7 @@ import com.google.gerrit.extensions.common.FetchInfo; import com.google.gerrit.extensions.config.DownloadCommand; import com.google.gerrit.extensions.config.DownloadScheme; import com.google.gerrit.extensions.registration.DynamicMap; +import com.google.gerrit.extensions.registration.Extension; import com.google.gerrit.server.CommonConverters; import com.google.gerrit.server.CurrentUser; import com.google.gerrit.server.change.ChangeJson; @@ -78,7 +79,7 @@ public class ChangeEditJson { private Map fillFetchMap(ChangeEdit edit) { Map r = new LinkedHashMap<>(); - for (DynamicMap.Entry e : downloadSchemes) { + for (Extension e : downloadSchemes) { String schemeName = e.getExportName(); DownloadScheme scheme = e.getProvider().get(); if (!scheme.isEnabled() diff --git a/java/com/google/gerrit/server/extensions/webui/UiActions.java b/java/com/google/gerrit/server/extensions/webui/UiActions.java index af28bed3fe..3ca2bdb93d 100644 --- a/java/com/google/gerrit/server/extensions/webui/UiActions.java +++ b/java/com/google/gerrit/server/extensions/webui/UiActions.java @@ -26,6 +26,7 @@ import com.google.gerrit.common.Nullable; import com.google.gerrit.extensions.api.access.GlobalOrPluginPermission; import com.google.gerrit.extensions.conditions.BooleanCondition; import com.google.gerrit.extensions.registration.DynamicMap; +import com.google.gerrit.extensions.registration.Extension; import com.google.gerrit.extensions.registration.PluginName; import com.google.gerrit.extensions.restapi.RestCollection; import com.google.gerrit.extensions.restapi.RestResource; @@ -121,7 +122,7 @@ public class UiActions { @Nullable private UiAction.Description describe( - DynamicMap.Entry> e, R resource) { + Extension> e, R resource) { int d = e.getExportName().indexOf('.'); if (d < 0) { return null; diff --git a/java/com/google/gerrit/server/git/receive/ReceiveCommits.java b/java/com/google/gerrit/server/git/receive/ReceiveCommits.java index ee751d7541..325002babf 100644 --- a/java/com/google/gerrit/server/git/receive/ReceiveCommits.java +++ b/java/com/google/gerrit/server/git/receive/ReceiveCommits.java @@ -70,8 +70,8 @@ import com.google.gerrit.extensions.api.projects.ProjectConfigEntryType; import com.google.gerrit.extensions.client.GeneralPreferencesInfo; import com.google.gerrit.extensions.registration.DynamicItem; import com.google.gerrit.extensions.registration.DynamicMap; -import com.google.gerrit.extensions.registration.DynamicMap.Entry; import com.google.gerrit.extensions.registration.DynamicSet; +import com.google.gerrit.extensions.registration.Extension; import com.google.gerrit.extensions.restapi.AuthException; import com.google.gerrit.extensions.restapi.BadRequestException; import com.google.gerrit.extensions.restapi.ResourceConflictException; @@ -1131,7 +1131,7 @@ class ReceiveCommits { * fails. */ private void validatePluginConfig(ReceiveCommand cmd, ProjectConfig cfg) { - for (Entry e : pluginConfigEntries) { + for (Extension e : pluginConfigEntries) { PluginConfig pluginCfg = cfg.getPluginConfig(e.getPluginName()); ProjectConfigEntry configEntry = e.getProvider().get(); String value = pluginCfg.getString(e.getExportName()); diff --git a/java/com/google/gerrit/server/git/validators/MergeValidators.java b/java/com/google/gerrit/server/git/validators/MergeValidators.java index c4df4dd11c..f755aab162 100644 --- a/java/com/google/gerrit/server/git/validators/MergeValidators.java +++ b/java/com/google/gerrit/server/git/validators/MergeValidators.java @@ -19,8 +19,8 @@ import com.google.common.collect.ImmutableList; import com.google.common.flogger.FluentLogger; import com.google.gerrit.extensions.api.projects.ProjectConfigEntryType; import com.google.gerrit.extensions.registration.DynamicMap; -import com.google.gerrit.extensions.registration.DynamicMap.Entry; import com.google.gerrit.extensions.registration.DynamicSet; +import com.google.gerrit.extensions.registration.Extension; import com.google.gerrit.extensions.restapi.AuthException; import com.google.gerrit.reviewdb.client.Account; import com.google.gerrit.reviewdb.client.Branch; @@ -207,7 +207,7 @@ public class MergeValidators { } } - for (Entry e : pluginConfigEntries) { + for (Extension e : pluginConfigEntries) { PluginConfig pluginCfg = cfg.getPluginConfig(e.getPluginName()); ProjectConfigEntry configEntry = e.getProvider().get(); diff --git a/java/com/google/gerrit/server/mail/receive/MailProcessor.java b/java/com/google/gerrit/server/mail/receive/MailProcessor.java index ec0c1f2e23..4cf9d7bb47 100644 --- a/java/com/google/gerrit/server/mail/receive/MailProcessor.java +++ b/java/com/google/gerrit/server/mail/receive/MailProcessor.java @@ -23,6 +23,7 @@ import com.google.common.flogger.FluentLogger; import com.google.gerrit.extensions.api.changes.NotifyHandling; import com.google.gerrit.extensions.client.Side; import com.google.gerrit.extensions.registration.DynamicMap; +import com.google.gerrit.extensions.registration.Extension; import com.google.gerrit.extensions.restapi.RestApiException; import com.google.gerrit.extensions.restapi.UnprocessableEntityException; import com.google.gerrit.mail.HtmlParser; @@ -148,7 +149,7 @@ public class MailProcessor { private void processImpl(BatchUpdate.Factory buf, MailMessage message) throws OrmException, UpdateException, RestApiException, IOException { - for (DynamicMap.Entry filter : mailFilters) { + for (Extension filter : mailFilters) { if (!filter.getProvider().get().shouldProcessMessage(message)) { logger.atWarning().log( "Message %s filtered by plugin %s %s. Will delete message.", diff --git a/java/com/google/gerrit/server/query/change/ChangeQueryBuilder.java b/java/com/google/gerrit/server/query/change/ChangeQueryBuilder.java index 566786984b..cc17899a03 100644 --- a/java/com/google/gerrit/server/query/change/ChangeQueryBuilder.java +++ b/java/com/google/gerrit/server/query/change/ChangeQueryBuilder.java @@ -31,6 +31,7 @@ import com.google.gerrit.common.data.GroupReference; import com.google.gerrit.common.data.SubmitRecord; import com.google.gerrit.common.errors.NotSignedInException; import com.google.gerrit.extensions.registration.DynamicMap; +import com.google.gerrit.extensions.registration.Extension; import com.google.gerrit.index.IndexConfig; import com.google.gerrit.index.Schema; import com.google.gerrit.index.SchemaUtil; @@ -427,7 +428,7 @@ public class ChangeQueryBuilder extends QueryBuilder { } private void setupDynamicOperators() { - for (DynamicMap.Entry e : args.opFactories) { + for (Extension e : args.opFactories) { String name = e.getExportName() + "_" + e.getPluginName(); opFactories.put(name, e.getProvider().get()); } diff --git a/java/com/google/gerrit/server/restapi/account/SetPreferences.java b/java/com/google/gerrit/server/restapi/account/SetPreferences.java index fccdabe984..2471689644 100644 --- a/java/com/google/gerrit/server/restapi/account/SetPreferences.java +++ b/java/com/google/gerrit/server/restapi/account/SetPreferences.java @@ -18,6 +18,7 @@ import com.google.common.base.Strings; import com.google.gerrit.extensions.client.GeneralPreferencesInfo; import com.google.gerrit.extensions.config.DownloadScheme; import com.google.gerrit.extensions.registration.DynamicMap; +import com.google.gerrit.extensions.registration.Extension; import com.google.gerrit.extensions.restapi.BadRequestException; import com.google.gerrit.extensions.restapi.IdString; import com.google.gerrit.extensions.restapi.ResourceNotFoundException; @@ -83,7 +84,7 @@ public class SetPreferences implements RestModifyView e : downloadSchemes) { + for (Extension e : downloadSchemes) { if (e.getExportName().equals(downloadScheme) && e.getProvider().get().isEnabled()) { return; } diff --git a/java/com/google/gerrit/server/restapi/change/ReviewerRecommender.java b/java/com/google/gerrit/server/restapi/change/ReviewerRecommender.java index 6b7a708c1f..ae6e5d1c6d 100644 --- a/java/com/google/gerrit/server/restapi/change/ReviewerRecommender.java +++ b/java/com/google/gerrit/server/restapi/change/ReviewerRecommender.java @@ -24,6 +24,7 @@ import com.google.common.flogger.FluentLogger; import com.google.gerrit.common.Nullable; import com.google.gerrit.common.data.LabelType; import com.google.gerrit.extensions.registration.DynamicMap; +import com.google.gerrit.extensions.registration.Extension; import com.google.gerrit.index.query.Predicate; import com.google.gerrit.index.query.QueryParseException; import com.google.gerrit.reviewdb.client.Account; @@ -130,7 +131,7 @@ public class ReviewerRecommender { new ArrayList<>(reviewerSuggestionPluginMap.plugins().size()); List weights = new ArrayList<>(reviewerSuggestionPluginMap.plugins().size()); - for (DynamicMap.Entry plugin : reviewerSuggestionPluginMap) { + for (Extension plugin : reviewerSuggestionPluginMap) { tasks.add( () -> plugin diff --git a/java/com/google/gerrit/server/restapi/config/GetServerInfo.java b/java/com/google/gerrit/server/restapi/config/GetServerInfo.java index 66e9f90cd3..2ff2d55a88 100644 --- a/java/com/google/gerrit/server/restapi/config/GetServerInfo.java +++ b/java/com/google/gerrit/server/restapi/config/GetServerInfo.java @@ -39,6 +39,7 @@ import com.google.gerrit.extensions.config.DownloadScheme; import com.google.gerrit.extensions.registration.DynamicItem; import com.google.gerrit.extensions.registration.DynamicMap; import com.google.gerrit.extensions.registration.DynamicSet; +import com.google.gerrit.extensions.registration.Extension; import com.google.gerrit.extensions.restapi.RestReadView; import com.google.gerrit.extensions.webui.WebUiPlugin; import com.google.gerrit.server.EnableSignedPush; @@ -254,7 +255,7 @@ public class GetServerInfo implements RestReadView { private DownloadInfo getDownloadInfo() { DownloadInfo info = new DownloadInfo(); info.schemes = new HashMap<>(); - for (DynamicMap.Entry e : downloadSchemes) { + for (Extension e : downloadSchemes) { DownloadScheme scheme = e.getProvider().get(); if (scheme.isEnabled() && scheme.getUrl("${project}") != null) { info.schemes.put(e.getExportName(), getDownloadSchemeInfo(scheme)); @@ -272,7 +273,7 @@ public class GetServerInfo implements RestReadView { info.isAuthSupported = toBoolean(scheme.isAuthSupported()); info.commands = new HashMap<>(); - for (DynamicMap.Entry e : downloadCommands) { + for (Extension e : downloadCommands) { String commandName = e.getExportName(); DownloadCommand command = e.getProvider().get(); String c = command.getCommand(scheme, "${project}", "${ref}"); @@ -282,7 +283,7 @@ public class GetServerInfo implements RestReadView { } info.cloneCommands = new HashMap<>(); - for (DynamicMap.Entry e : cloneCommands) { + for (Extension e : cloneCommands) { String commandName = e.getExportName(); CloneCommand command = e.getProvider().get(); String c = command.getCommand(scheme, "${project-path}/${project-base-name}"); diff --git a/java/com/google/gerrit/server/restapi/config/ListCaches.java b/java/com/google/gerrit/server/restapi/config/ListCaches.java index 38664fbc61..f310ed7e71 100644 --- a/java/com/google/gerrit/server/restapi/config/ListCaches.java +++ b/java/com/google/gerrit/server/restapi/config/ListCaches.java @@ -26,6 +26,7 @@ import com.google.common.cache.CacheStats; import com.google.common.collect.Streams; import com.google.gerrit.extensions.annotations.RequiresAnyCapability; import com.google.gerrit.extensions.registration.DynamicMap; +import com.google.gerrit.extensions.registration.Extension; import com.google.gerrit.extensions.restapi.BinaryResult; import com.google.gerrit.extensions.restapi.RestReadView; import com.google.gerrit.server.cache.PersistentCache; @@ -60,7 +61,7 @@ public class ListCaches implements RestReadView { public Map getCacheInfos() { Map cacheInfos = new TreeMap<>(); - for (DynamicMap.Entry> e : cacheMap) { + for (Extension> e : cacheMap) { cacheInfos.put( cacheNameOf(e.getPluginName(), e.getExportName()), new CacheInfo(e.getProvider().get())); } diff --git a/java/com/google/gerrit/server/restapi/config/PostCaches.java b/java/com/google/gerrit/server/restapi/config/PostCaches.java index 57ba097f9f..c633af0ce5 100644 --- a/java/com/google/gerrit/server/restapi/config/PostCaches.java +++ b/java/com/google/gerrit/server/restapi/config/PostCaches.java @@ -20,6 +20,7 @@ import static com.google.gerrit.common.data.GlobalCapability.MAINTAIN_SERVER; import com.google.common.cache.Cache; import com.google.gerrit.extensions.annotations.RequiresAnyCapability; import com.google.gerrit.extensions.registration.DynamicMap; +import com.google.gerrit.extensions.registration.Extension; import com.google.gerrit.extensions.registration.PluginName; import com.google.gerrit.extensions.restapi.AuthException; import com.google.gerrit.extensions.restapi.BadRequestException; @@ -96,7 +97,7 @@ public class PostCaches implements RestCollectionModifyView> e : cacheMap) { + for (Extension> e : cacheMap) { CacheResource cacheResource = new CacheResource(e.getPluginName(), e.getExportName(), e.getProvider()); if (FlushCache.WEB_SESSIONS.equals(cacheResource.getName())) { diff --git a/java/com/google/gerrit/server/restapi/project/ConfigInfoImpl.java b/java/com/google/gerrit/server/restapi/project/ConfigInfoImpl.java index 60b5dee4ea..e1798962fb 100644 --- a/java/com/google/gerrit/server/restapi/project/ConfigInfoImpl.java +++ b/java/com/google/gerrit/server/restapi/project/ConfigInfoImpl.java @@ -22,7 +22,7 @@ import com.google.gerrit.extensions.api.projects.ConfigInfo; import com.google.gerrit.extensions.api.projects.ProjectConfigEntryType; import com.google.gerrit.extensions.common.ActionInfo; import com.google.gerrit.extensions.registration.DynamicMap; -import com.google.gerrit.extensions.registration.DynamicMap.Entry; +import com.google.gerrit.extensions.registration.Extension; import com.google.gerrit.extensions.restapi.RestView; import com.google.gerrit.extensions.webui.UiAction; import com.google.gerrit.reviewdb.client.BooleanProjectConfig; @@ -122,7 +122,7 @@ public class ConfigInfoImpl extends ConfigInfo { PluginConfigFactory cfgFactory, AllProjectsName allProjects) { TreeMap> pluginConfig = new TreeMap<>(); - for (Entry e : pluginConfigEntries) { + for (Extension e : pluginConfigEntries) { ProjectConfigEntry configEntry = e.getProvider().get(); PluginConfig cfg = cfgFactory.getFromProjectConfig(project, e.getPluginName()); String configuredValue = cfg.getString(e.getExportName()); @@ -165,7 +165,7 @@ public class ConfigInfoImpl extends ConfigInfo { } private String getInheritedValue( - ProjectState project, PluginConfigFactory cfgFactory, Entry e) { + ProjectState project, PluginConfigFactory cfgFactory, Extension e) { ProjectConfigEntry configEntry = e.getProvider().get(); ProjectState parent = Iterables.getFirst(project.parents(), null); String inheritedValue = configEntry.getDefaultValue(); diff --git a/javatests/com/google/gerrit/extensions/registration/DynamicSetTest.java b/javatests/com/google/gerrit/extensions/registration/DynamicSetTest.java index c86160f9bb..0542c35d1c 100644 --- a/javatests/com/google/gerrit/extensions/registration/DynamicSetTest.java +++ b/javatests/com/google/gerrit/extensions/registration/DynamicSetTest.java @@ -123,8 +123,8 @@ public class DynamicSetTest { ds.add("bar", 2); ds.add("bar", 3); - Iterator> entryIterator = ds.entries().iterator(); - DynamicSet.Entry next = entryIterator.next(); + Iterator> entryIterator = ds.entries().iterator(); + Extension next = entryIterator.next(); assertThat(next.getPluginName()).isEqualTo("foo"); assertThat(next.getProvider().get()).isEqualTo(1);