Add a constant for the gerrit plugin name
We use "gerrit" as a plugin name when a plugin extension point is implemented by Gerrit core. The string for this plugin name was hard-coded in many places. It is better to have a constant for this. Change-Id: I032812d4f6e8d63197cd36e3b0399f60094725cf Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
@@ -78,7 +78,8 @@ public class DynamicItem<T> {
|
||||
* @param item item to store.
|
||||
*/
|
||||
public static <T> DynamicItem<T> itemOf(Class<T> member, T item) {
|
||||
return new DynamicItem<>(keyFor(TypeLiteral.get(member)), Providers.of(item), "gerrit");
|
||||
return new DynamicItem<>(
|
||||
keyFor(TypeLiteral.get(member)), Providers.of(item), PluginName.GERRIT);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@@ -169,7 +170,7 @@ public class DynamicItem<T> {
|
||||
NamedProvider<T> old = null;
|
||||
while (!ref.compareAndSet(old, item)) {
|
||||
old = ref.get();
|
||||
if (old != null && !"gerrit".equals(old.pluginName)) {
|
||||
if (old != null && !PluginName.GERRIT.equals(old.pluginName)) {
|
||||
throw new ProvisionException(
|
||||
String.format(
|
||||
"%s already provided by %s, ignoring plugin %s",
|
||||
@@ -201,7 +202,9 @@ public class DynamicItem<T> {
|
||||
NamedProvider<T> old = null;
|
||||
while (!ref.compareAndSet(old, item)) {
|
||||
old = ref.get();
|
||||
if (old != null && !"gerrit".equals(old.pluginName) && !pluginName.equals(old.pluginName)) {
|
||||
if (old != null
|
||||
&& !PluginName.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
|
||||
|
||||
@@ -36,7 +36,7 @@ class DynamicItemProvider<T> implements Provider<DynamicItem<T>> {
|
||||
|
||||
@Override
|
||||
public DynamicItem<T> get() {
|
||||
return new DynamicItem<>(key, find(injector, type), "gerrit");
|
||||
return new DynamicItem<>(key, find(injector, type), PluginName.GERRIT);
|
||||
}
|
||||
|
||||
private static <T> Provider<T> find(Injector src, TypeLiteral<T> type) {
|
||||
|
||||
@@ -37,7 +37,7 @@ class DynamicMapProvider<T> implements Provider<DynamicMap<T>> {
|
||||
if (bindings != null) {
|
||||
for (Binding<T> b : bindings) {
|
||||
if (b.getKey().getAnnotation() != null) {
|
||||
m.put("gerrit", b.getKey(), b.getProvider());
|
||||
m.put(PluginName.GERRIT, b.getKey(), b.getProvider());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
// 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;
|
||||
|
||||
public class PluginName {
|
||||
/** Name that is used as plugin name if Gerrit core implements a plugin extension point. */
|
||||
public static final String GERRIT = "gerrit";
|
||||
|
||||
private PluginName() {}
|
||||
}
|
||||
@@ -175,7 +175,7 @@ public class PrivateInternals_DynamicTypes {
|
||||
Injector parent = self.getParent();
|
||||
while (parent != null) {
|
||||
handles.addAll(attachSets(self, dynamicSetsOf(parent)));
|
||||
handles.addAll(attachMaps(self, "gerrit", dynamicMapsOf(parent)));
|
||||
handles.addAll(attachMaps(self, PluginName.GERRIT, dynamicMapsOf(parent)));
|
||||
parent = parent.getParent();
|
||||
}
|
||||
if (handles.isEmpty()) {
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
package com.google.gerrit.httpd.restapi;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.gerrit.extensions.registration.PluginName;
|
||||
import com.google.gerrit.httpd.restapi.RestApiServlet.ViewData;
|
||||
import com.google.gerrit.metrics.Counter1;
|
||||
import com.google.gerrit.metrics.Counter2;
|
||||
@@ -79,7 +80,8 @@ public class RestApiMetrics {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!Strings.isNullOrEmpty(viewData.pluginName) && !"gerrit".equals(viewData.pluginName)) {
|
||||
if (!Strings.isNullOrEmpty(viewData.pluginName)
|
||||
&& !PluginName.GERRIT.equals(viewData.pluginName)) {
|
||||
impl = viewData.pluginName + '-' + impl;
|
||||
}
|
||||
return impl;
|
||||
|
||||
@@ -70,6 +70,7 @@ import com.google.gerrit.common.RawInputUtil;
|
||||
import com.google.gerrit.common.TimeUtil;
|
||||
import com.google.gerrit.extensions.registration.DynamicItem;
|
||||
import com.google.gerrit.extensions.registration.DynamicMap;
|
||||
import com.google.gerrit.extensions.registration.PluginName;
|
||||
import com.google.gerrit.extensions.restapi.AuthException;
|
||||
import com.google.gerrit.extensions.restapi.BadRequestException;
|
||||
import com.google.gerrit.extensions.restapi.BinaryResult;
|
||||
@@ -324,7 +325,7 @@ public class RestApiServlet extends HttpServlet {
|
||||
viewData = new ViewData(null, rc.list());
|
||||
} else if (isPost(req)) {
|
||||
RestView<RestResource> restCollectionView =
|
||||
rc.views().get("gerrit", "POST_ON_COLLECTION./");
|
||||
rc.views().get(PluginName.GERRIT, "POST_ON_COLLECTION./");
|
||||
if (restCollectionView != null) {
|
||||
viewData = new ViewData(null, restCollectionView);
|
||||
} else {
|
||||
@@ -347,7 +348,7 @@ public class RestApiServlet extends HttpServlet {
|
||||
}
|
||||
|
||||
if (isPost(req) || isPut(req)) {
|
||||
RestView<RestResource> createView = rc.views().get("gerrit", "CREATE./");
|
||||
RestView<RestResource> createView = rc.views().get(PluginName.GERRIT, "CREATE./");
|
||||
if (createView != null) {
|
||||
viewData = new ViewData(null, createView);
|
||||
status = SC_CREATED;
|
||||
@@ -356,7 +357,8 @@ public class RestApiServlet extends HttpServlet {
|
||||
throw e;
|
||||
}
|
||||
} else if (isDelete(req)) {
|
||||
RestView<RestResource> deleteView = rc.views().get("gerrit", "DELETE_MISSING./");
|
||||
RestView<RestResource> deleteView =
|
||||
rc.views().get(PluginName.GERRIT, "DELETE_MISSING./");
|
||||
if (deleteView != null) {
|
||||
viewData = new ViewData(null, deleteView);
|
||||
status = SC_NO_CONTENT;
|
||||
@@ -414,7 +416,7 @@ public class RestApiServlet extends HttpServlet {
|
||||
}
|
||||
|
||||
if (isPost(req) || isPut(req)) {
|
||||
RestView<RestResource> createView = c.views().get("gerrit", "CREATE./");
|
||||
RestView<RestResource> createView = c.views().get(PluginName.GERRIT, "CREATE./");
|
||||
if (createView != null) {
|
||||
viewData = new ViewData(null, createView);
|
||||
status = SC_CREATED;
|
||||
@@ -423,7 +425,8 @@ public class RestApiServlet extends HttpServlet {
|
||||
throw e;
|
||||
}
|
||||
} else if (isDelete(req)) {
|
||||
RestView<RestResource> deleteView = c.views().get("gerrit", "DELETE_MISSING./");
|
||||
RestView<RestResource> deleteView =
|
||||
c.views().get(PluginName.GERRIT, "DELETE_MISSING./");
|
||||
if (deleteView != null) {
|
||||
viewData = new ViewData(null, deleteView);
|
||||
status = SC_NO_CONTENT;
|
||||
@@ -1245,14 +1248,14 @@ public class RestApiServlet extends HttpServlet {
|
||||
}
|
||||
|
||||
String name = method + "." + p.get(0);
|
||||
RestView<RestResource> core = views.get("gerrit", name);
|
||||
RestView<RestResource> core = views.get(PluginName.GERRIT, name);
|
||||
if (core != null) {
|
||||
return new ViewData("gerrit", core);
|
||||
return new ViewData(PluginName.GERRIT, core);
|
||||
}
|
||||
|
||||
core = views.get("gerrit", "GET." + p.get(0));
|
||||
core = views.get(PluginName.GERRIT, "GET." + p.get(0));
|
||||
if (core != null) {
|
||||
return new ViewData("gerrit", core);
|
||||
return new ViewData(PluginName.GERRIT, core);
|
||||
}
|
||||
|
||||
Map<String, RestView<RestResource>> r = new TreeMap<>();
|
||||
|
||||
@@ -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.PluginName;
|
||||
import com.google.gerrit.metrics.CallbackMetric;
|
||||
import com.google.gerrit.metrics.CallbackMetric1;
|
||||
import com.google.gerrit.metrics.Description;
|
||||
@@ -95,7 +96,7 @@ public class CacheMetrics {
|
||||
}
|
||||
|
||||
private static String metricNameOf(DynamicMap.Entry<Cache<?, ?>> e) {
|
||||
if ("gerrit".equals(e.getPluginName())) {
|
||||
if (PluginName.GERRIT.equals(e.getPluginName())) {
|
||||
return e.getExportName();
|
||||
}
|
||||
return String.format("plugin/%s/%s", e.getPluginName(), e.getExportName());
|
||||
|
||||
@@ -18,6 +18,7 @@ import com.google.common.base.Strings;
|
||||
import com.google.common.cache.RemovalListener;
|
||||
import com.google.common.cache.RemovalNotification;
|
||||
import com.google.gerrit.extensions.registration.DynamicSet;
|
||||
import com.google.gerrit.extensions.registration.PluginName;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.assistedinject.Assisted;
|
||||
|
||||
@@ -36,7 +37,7 @@ public class ForwardingRemovalListener<K, V> implements RemovalListener<K, V> {
|
||||
|
||||
private final DynamicSet<CacheRemovalListener> listeners;
|
||||
private final String cacheName;
|
||||
private String pluginName = "gerrit";
|
||||
private String pluginName = PluginName.GERRIT;
|
||||
|
||||
@Inject
|
||||
ForwardingRemovalListener(
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
package com.google.gerrit.server.config;
|
||||
|
||||
import com.google.common.cache.Cache;
|
||||
import com.google.gerrit.extensions.registration.PluginName;
|
||||
import com.google.gerrit.extensions.restapi.RestView;
|
||||
import com.google.inject.Provider;
|
||||
import com.google.inject.TypeLiteral;
|
||||
@@ -52,7 +53,7 @@ public class CacheResource extends ConfigResource {
|
||||
}
|
||||
|
||||
public static String cacheNameOf(String plugin, String name) {
|
||||
if ("gerrit".equals(plugin)) {
|
||||
if (PluginName.GERRIT.equals(plugin)) {
|
||||
return name;
|
||||
}
|
||||
return plugin + "-" + name;
|
||||
|
||||
@@ -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.PluginName;
|
||||
import com.google.gerrit.extensions.restapi.RestCollection;
|
||||
import com.google.gerrit.extensions.restapi.RestResource;
|
||||
import com.google.gerrit.extensions.restapi.RestView;
|
||||
@@ -169,7 +170,7 @@ public class UiActions {
|
||||
|
||||
PrivateInternals_UiActionDescription.setMethod(dsc, e.getExportName().substring(0, d));
|
||||
PrivateInternals_UiActionDescription.setId(
|
||||
dsc, "gerrit".equals(e.getPluginName()) ? name : e.getPluginName() + '~' + name);
|
||||
dsc, PluginName.GERRIT.equals(e.getPluginName()) ? name : e.getPluginName() + '~' + name);
|
||||
return dsc;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ import com.google.gerrit.extensions.annotations.RequiresCapability;
|
||||
import com.google.gerrit.extensions.api.access.GerritPermission;
|
||||
import com.google.gerrit.extensions.api.access.GlobalOrPluginPermission;
|
||||
import com.google.gerrit.extensions.api.access.PluginPermission;
|
||||
import com.google.gerrit.extensions.registration.PluginName;
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashSet;
|
||||
@@ -116,7 +117,7 @@ public enum GlobalPermission implements GlobalOrPluginPermission {
|
||||
Class<?> annotationClass)
|
||||
throws PermissionBackendException {
|
||||
if (pluginName != null
|
||||
&& !"gerrit".equals(pluginName)
|
||||
&& !PluginName.GERRIT.equals(pluginName)
|
||||
&& (scope == CapabilityScope.PLUGIN || scope == CapabilityScope.CONTEXT)) {
|
||||
return new PluginPermission(pluginName, capability, fallBackToAdmin);
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ package com.google.gerrit.server.plugins;
|
||||
|
||||
import com.google.common.base.MoreObjects;
|
||||
import com.google.common.flogger.FluentLogger;
|
||||
import com.google.gerrit.extensions.registration.PluginName;
|
||||
import com.google.gerrit.server.config.PluginConfig;
|
||||
import com.google.gerrit.server.config.PluginConfigFactory;
|
||||
import com.google.gerrit.server.config.SitePaths;
|
||||
@@ -90,7 +91,7 @@ public class JarPluginProvider implements ServerPluginProvider {
|
||||
|
||||
@Override
|
||||
public String getProviderPluginName() {
|
||||
return "gerrit";
|
||||
return PluginName.GERRIT;
|
||||
}
|
||||
|
||||
private static String getExtension(Path path) {
|
||||
|
||||
@@ -16,6 +16,7 @@ package com.google.gerrit.server.plugins;
|
||||
|
||||
import com.google.common.flogger.FluentLogger;
|
||||
import com.google.gerrit.extensions.registration.DynamicSet;
|
||||
import com.google.gerrit.extensions.registration.PluginName;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
import java.nio.file.Path;
|
||||
@@ -60,7 +61,7 @@ class UniversalServerPluginProvider implements ServerPluginProvider {
|
||||
|
||||
@Override
|
||||
public String getProviderPluginName() {
|
||||
return "gerrit";
|
||||
return PluginName.GERRIT;
|
||||
}
|
||||
|
||||
private ServerPluginProvider providerOf(Path srcPath) {
|
||||
|
||||
@@ -20,6 +20,7 @@ import static com.google.gerrit.common.data.GlobalCapability.VIEW_CACHES;
|
||||
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.PluginName;
|
||||
import com.google.gerrit.extensions.restapi.AuthException;
|
||||
import com.google.gerrit.extensions.restapi.ChildCollection;
|
||||
import com.google.gerrit.extensions.restapi.IdString;
|
||||
@@ -66,7 +67,7 @@ public class CachesCollection implements ChildCollection<ConfigResource, CacheRe
|
||||
permissionBackend.currentUser().check(GlobalPermission.VIEW_CACHES);
|
||||
|
||||
String cacheName = id.get();
|
||||
String pluginName = "gerrit";
|
||||
String pluginName = PluginName.GERRIT;
|
||||
int i = cacheName.lastIndexOf('-');
|
||||
if (i != -1) {
|
||||
pluginName = cacheName.substring(0, i);
|
||||
|
||||
@@ -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.PluginName;
|
||||
import com.google.gerrit.extensions.restapi.AuthException;
|
||||
import com.google.gerrit.extensions.restapi.BadRequestException;
|
||||
import com.google.gerrit.extensions.restapi.Response;
|
||||
@@ -110,7 +111,7 @@ public class PostCaches implements RestCollectionModifyView<ConfigResource, Cach
|
||||
List<CacheResource> cacheResources = new ArrayList<>(cacheNames.size());
|
||||
|
||||
for (String n : cacheNames) {
|
||||
String pluginName = "gerrit";
|
||||
String pluginName = PluginName.GERRIT;
|
||||
String cacheName = n;
|
||||
int i = cacheName.lastIndexOf('-');
|
||||
if (i != -1) {
|
||||
|
||||
Reference in New Issue
Block a user