Remove ConfigUtil getEnum methods that are available in JGit

ConfigUtil getEnum methods were duplicate of methods available in JGit
Config.

Change-Id: Icb86a42d8bb37b761f30b8bb0a38b57e8c7c59b4
This commit is contained in:
Hugo Arès
2014-11-26 10:10:54 -05:00
parent 5d5475e260
commit 627c37ec3a
7 changed files with 6 additions and 51 deletions

View File

@@ -198,7 +198,7 @@ public class JettyServer {
final URI[] listenUrls = listenURLs(cfg); final URI[] listenUrls = listenURLs(cfg);
final boolean reuseAddress = cfg.getBoolean("httpd", "reuseaddress", true); final boolean reuseAddress = cfg.getBoolean("httpd", "reuseaddress", true);
final int acceptors = cfg.getInt("httpd", "acceptorThreads", 2); final int acceptors = cfg.getInt("httpd", "acceptorThreads", 2);
final AuthType authType = ConfigUtil.getEnum(cfg, "auth", null, "type", AuthType.OPENID); final AuthType authType = cfg.getEnum("auth", null, "type", AuthType.OPENID);
reverseProxy = isReverseProxied(listenUrls); reverseProxy = isReverseProxied(listenUrls);
final Connector[] connectors = new Connector[listenUrls.length]; final Connector[] connectors = new Connector[listenUrls.length];

View File

@@ -115,7 +115,7 @@ public class Section {
public <T extends Enum<?>> T select(final String title, final String name, public <T extends Enum<?>> T select(final String title, final String name,
final T defValue, final boolean nullIfDefault) { final T defValue, final boolean nullIfDefault) {
final boolean set = get(name) != null; final boolean set = get(name) != null;
T oldValue = ConfigUtil.getEnum(flags.cfg, section, subsection, name, defValue); T oldValue = flags.cfg.getEnum(section, subsection, name, defValue);
T newValue = ui.readEnum(oldValue, "%s", title); T newValue = ui.readEnum(oldValue, "%s", title);
if (nullIfDefault && newValue == defValue) { if (nullIfDefault && newValue == defValue) {
newValue = null; newValue = null;

View File

@@ -99,7 +99,7 @@ public class LdapRealm implements Realm {
} }
static SearchScope scope(final Config c, final String setting) { static SearchScope scope(final Config c, final String setting) {
return ConfigUtil.getEnum(c, "ldap", null, setting, SearchScope.SUBTREE); return c.getEnum("ldap", null, setting, SearchScope.SUBTREE);
} }
static String optional(final Config config, final String name) { static String optional(final Config config, final String name) {

View File

@@ -111,7 +111,7 @@ public class AuthConfig {
} }
private static AuthType toType(final Config cfg) { private static AuthType toType(final Config cfg) {
return ConfigUtil.getEnum(cfg, "auth", null, "type", AuthType.OPENID); return cfg.getEnum("auth", null, "type", AuthType.OPENID);
} }
/** Type of user authentication used by this Gerrit server. */ /** Type of user authentication used by this Gerrit server. */

View File

@@ -26,24 +26,6 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
public class ConfigUtil { public class ConfigUtil {
/**
* Parse a Java enumeration from the configuration.
*
* @param <T> type of the enumeration object.
* @param config the configuration file to read.
* @param section section the key is in.
* @param subsection subsection the key is in, or null if not in a subsection.
* @param setting name of the setting to read.
* @param defaultValue default value to return if the setting was not set.
* Must not be null as the enumeration values are derived from this.
* @return the selected enumeration value, or {@code defaultValue}.
*/
public static <T extends Enum<?>> T getEnum(final Config config,
final String section, final String subsection, final String setting,
final T defaultValue) {
final T[] all = allValuesOf(defaultValue);
return getEnum(config, section, subsection, setting, all, defaultValue);
}
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private static <T> T[] allValuesOf(final T defaultValue) { private static <T> T[] allValuesOf(final T defaultValue) {
@@ -62,31 +44,6 @@ public class ConfigUtil {
} }
} }
/**
* Parse a Java enumeration from the configuration.
*
* @param <T> type of the enumeration object.
* @param config the configuration file to read.
* @param section section the key is in.
* @param subsection subsection the key is in, or null if not in a subsection.
* @param setting name of the setting to read.
* @param all all possible values in the enumeration which should be
* recognized. This should be {@code EnumType.values()}.
* @param defaultValue default value to return if the setting was not set.
* This value may be null.
* @return the selected enumeration value, or {@code defaultValue}.
*/
public static <T extends Enum<?>> T getEnum(final Config config,
final String section, final String subsection, final String setting,
final T[] all, final T defaultValue) {
final String valueString = config.getString(section, subsection, setting);
if (valueString == null) {
return defaultValue;
}
return getEnum(section, subsection, setting, valueString, all);
}
/** /**
* Parse a Java enumeration from the configuration. * Parse a Java enumeration from the configuration.
* *

View File

@@ -506,8 +506,7 @@ public class ProjectConfig extends VersionedMetaData implements ValidationError.
NOTIFY, sectionName, KEY_TYPE, NOTIFY, sectionName, KEY_TYPE,
NotifyType.ALL)); NotifyType.ALL));
n.setTypes(types); n.setTypes(types);
n.setHeader(ConfigUtil.getEnum(rc, n.setHeader(rc.getEnum(NOTIFY, sectionName, KEY_HEADER,
NOTIFY, sectionName, KEY_HEADER,
NotifyConfig.Header.BCC)); NotifyConfig.Header.BCC));
for (String dst : rc.getStringList(NOTIFY, sectionName, KEY_EMAIL)) { for (String dst : rc.getStringList(NOTIFY, sectionName, KEY_EMAIL)) {

View File

@@ -86,8 +86,7 @@ public class SmtpEmailSender implements EmailSender {
} }
smtpEncryption = smtpEncryption =
ConfigUtil.getEnum(cfg, "sendemail", null, "smtpencryption", cfg.getEnum("sendemail", null, "smtpencryption", Encryption.NONE);
Encryption.NONE);
sslVerify = cfg.getBoolean("sendemail", null, "sslverify", true); sslVerify = cfg.getBoolean("sendemail", null, "sslverify", true);
final int defaultPort; final int defaultPort;