Enable aliases for change query operators
Site administrators can alias change query operators from a plugin using the 'operator-alias' section and 'change' subsection in gerrit.config: [operator-alias "change"] oldage = age number = change Aliases are already supported for SSH commands [1] and URLs [2]. This feature is particularly useful to alias operator names which may be long and clunky because they include a plugin name in them to a shorter name without the plugin name. Admins should take care to pick short names that are unique and unlikely to be used by future operators. Aliases are resolved dynamically at invocation time to any currently loaded versions of plugins. If the alias points to an operator provided by a plugin which is not currently loaded, or the plugin does not define the operator, then "unsupported operator" is returned to the user. Aliases will override existing operators. In the case of multiple aliases with the same name, the last one defined will be used. When the target of an alias doesn't exist, the operator with the name of the alias will be used (if present). This enables an admin to config the system to override a core operator with an operator provided by a plugin when present and otherwise fall back to the operator provided by core. The above three features can make aliases useful for cases of moving functionality from Gerrit core to plugins and vice versa. [1] https://gerrit-review.googlesource.com/Documentation/config-gerrit.html#ssh-alias [2] https://gerrit-review.googlesource.com/Documentation/config-gerrit.html#urlAlias Change-Id: I3c60b0b9bc84467fece4b7d30dc735509e28071d
This commit is contained in:

committed by
Nasser Grainawi

parent
547b110806
commit
70a16104e3
@@ -0,0 +1,46 @@
|
||||
// Copyright (C) 2019 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.server.config;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import org.eclipse.jgit.lib.Config;
|
||||
|
||||
@Singleton
|
||||
public class OperatorAliasConfig {
|
||||
private static final String SECTION = "operator-alias";
|
||||
private static final String SUBSECTION_CHANGE = "change";
|
||||
private final Config cfg;
|
||||
private final Map<String, String> changeQueryOperatorAliases;
|
||||
|
||||
@Inject
|
||||
OperatorAliasConfig(@GerritServerConfig Config cfg) {
|
||||
this.cfg = cfg;
|
||||
changeQueryOperatorAliases = new HashMap<>();
|
||||
loadChangeOperatorAliases();
|
||||
}
|
||||
|
||||
public Map<String, String> getChangeQueryOperatorAliases() {
|
||||
return changeQueryOperatorAliases;
|
||||
}
|
||||
|
||||
private void loadChangeOperatorAliases() {
|
||||
for (String name : cfg.getNames(SECTION, SUBSECTION_CHANGE)) {
|
||||
changeQueryOperatorAliases.put(name, cfg.getString(SECTION, SUBSECTION_CHANGE, name));
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user