Stop using CharMatcher.javaLetterOrDigit
CharMatcher.javaLetterOrDigit is deprecated in Guava 23.2 [1]. Replace it with regular expression for matching. [1] https://github.com/google/guava/releases/tag/v23.2 Change-Id: Icaf7504e7250beaa92b9c86ad592649bd6fafcba
This commit is contained in:
@@ -14,7 +14,6 @@
|
||||
|
||||
package com.google.gerrit.server.config;
|
||||
|
||||
import com.google.common.base.CharMatcher;
|
||||
import com.google.gerrit.common.data.GlobalCapability;
|
||||
import com.google.gerrit.extensions.config.CapabilityDefinition;
|
||||
import com.google.gerrit.extensions.registration.DynamicMap;
|
||||
@@ -24,6 +23,7 @@ import com.google.inject.Provider;
|
||||
import com.google.inject.Singleton;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
import java.util.regex.Pattern;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -31,6 +31,8 @@ import org.slf4j.LoggerFactory;
|
||||
@Singleton
|
||||
public class ListCapabilities implements RestReadView<ConfigResource> {
|
||||
private static final Logger log = LoggerFactory.getLogger(ListCapabilities.class);
|
||||
private static final Pattern PLUGIN_NAME_PATTERN = Pattern.compile("^[a-zA-Z0-9-]+$");
|
||||
|
||||
private final DynamicMap<CapabilityDefinition> pluginCapabilities;
|
||||
|
||||
@Inject
|
||||
@@ -59,10 +61,11 @@ public class ListCapabilities implements RestReadView<ConfigResource> {
|
||||
|
||||
private void collectPluginCapabilities(Map<String, CapabilityInfo> output) {
|
||||
for (String pluginName : pluginCapabilities.plugins()) {
|
||||
if (!isPluginNameSane(pluginName)) {
|
||||
if (!PLUGIN_NAME_PATTERN.matcher(pluginName).matches()) {
|
||||
log.warn(
|
||||
"Plugin name {} must match [A-Za-z0-9-]+ to use capabilities;" + " rename the plugin",
|
||||
pluginName);
|
||||
"Plugin name '{}' must match '{}' to use capabilities; rename the plugin",
|
||||
pluginName,
|
||||
PLUGIN_NAME_PATTERN.pattern());
|
||||
continue;
|
||||
}
|
||||
for (Map.Entry<String, Provider<CapabilityDefinition>> entry :
|
||||
@@ -73,10 +76,6 @@ public class ListCapabilities implements RestReadView<ConfigResource> {
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isPluginNameSane(String pluginName) {
|
||||
return CharMatcher.javaLetterOrDigit().or(CharMatcher.is('-')).matchesAllOf(pluginName);
|
||||
}
|
||||
|
||||
public static class CapabilityInfo {
|
||||
public String id;
|
||||
public String name;
|
||||
|
@@ -14,7 +14,6 @@
|
||||
|
||||
package com.google.gerrit.server.project;
|
||||
|
||||
import com.google.common.base.CharMatcher;
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.gerrit.extensions.api.projects.ConfigInfo;
|
||||
@@ -44,6 +43,7 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.regex.Pattern;
|
||||
import org.eclipse.jgit.errors.ConfigInvalidException;
|
||||
import org.eclipse.jgit.errors.RepositoryNotFoundException;
|
||||
import org.slf4j.Logger;
|
||||
@@ -52,6 +52,8 @@ import org.slf4j.LoggerFactory;
|
||||
@Singleton
|
||||
public class PutConfig implements RestModifyView<ProjectResource, ConfigInput> {
|
||||
private static final Logger log = LoggerFactory.getLogger(PutConfig.class);
|
||||
private static final Pattern PARAMETER_NAME_PATTERN =
|
||||
Pattern.compile("^[a-zA-Z0-9]+[a-zA-Z0-9-]*$");
|
||||
|
||||
private final boolean serverEnableSignedPush;
|
||||
private final Provider<MetaDataUpdate.User> metaDataUpdateFactory;
|
||||
@@ -196,8 +198,12 @@ public class PutConfig implements RestModifyView<ProjectResource, ConfigInput> {
|
||||
for (Entry<String, ConfigValue> v : e.getValue().entrySet()) {
|
||||
ProjectConfigEntry projectConfigEntry = pluginConfigEntries.get(pluginName, v.getKey());
|
||||
if (projectConfigEntry != null) {
|
||||
if (!isValidParameterName(v.getKey())) {
|
||||
log.warn("Parameter name '{}' must match '^[a-zA-Z0-9]+[a-zA-Z0-9-]*$'", v.getKey());
|
||||
if (!PARAMETER_NAME_PATTERN.matcher(v.getKey()).matches()) {
|
||||
// TODO check why we have this restriction
|
||||
log.warn(
|
||||
"Parameter name '{}' must match '{}'",
|
||||
v.getKey(),
|
||||
PARAMETER_NAME_PATTERN.pattern());
|
||||
continue;
|
||||
}
|
||||
String oldValue = cfg.getString(v.getKey());
|
||||
@@ -287,9 +293,4 @@ public class PutConfig implements RestModifyView<ProjectResource, ConfigInput> {
|
||||
parameterName, pluginName, projectState.getProject().getName()));
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isValidParameterName(String name) {
|
||||
return CharMatcher.javaLetterOrDigit().or(CharMatcher.is('-')).matchesAllOf(name)
|
||||
&& !name.startsWith("-");
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user