Package com.google.gerrit.server.config
Class ConfigUtil
- java.lang.Object
-
- com.google.gerrit.server.config.ConfigUtil
-
public class ConfigUtil extends Object
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T extends Enum<?>>
List<T>getEnumList(org.eclipse.jgit.lib.Config config, String section, String subsection, String setting, T defaultValue)
Parse a Java enumeration list from the configuration.static <T extends Enum<?>>
List<T>getEnumList(org.eclipse.jgit.lib.Config config, String section, String subsection, String setting, T[] all, T defaultValue)
Parse a Java enumeration list from the configuration.static String
getRequired(org.eclipse.jgit.lib.Config cfg, String section, String name)
static long
getTimeUnit(String valueString, long defaultValue, TimeUnit wantUnit)
Parse a numerical time unit, such as "1 minute", from a string.static long
getTimeUnit(org.eclipse.jgit.lib.Config config, String section, String subsection, String setting, long defaultValue, TimeUnit wantUnit)
Parse a numerical time unit, such as "1 minute", from the configuration.static <T> T
loadSection(org.eclipse.jgit.lib.Config cfg, String section, String sub, T s, T defaults, T i)
Load section by inspecting Java class attributes.static boolean
skipField(Field field)
static <T> void
storeSection(org.eclipse.jgit.lib.Config cfg, String section, String sub, T s, T defaults)
Store section by inspecting Java class attributes.
-
-
-
Method Detail
-
getEnumList
public static <T extends Enum<?>> List<T> getEnumList(org.eclipse.jgit.lib.Config config, String section, String subsection, String setting, T defaultValue)
Parse a Java enumeration list from the configuration.- Type Parameters:
T
- type of the enumeration object.- Parameters:
config
- the configuration file to read.section
- section the key is in.subsection
- subsection the key is in, or null if not in a subsection.setting
- name of the setting to read.defaultValue
- default value to return if the setting was not set. Must not be null as the enumeration values are derived from this.- Returns:
- the selected enumeration values list, or
defaultValue
.
-
getEnumList
public static <T extends Enum<?>> List<T> getEnumList(org.eclipse.jgit.lib.Config config, String section, String subsection, String setting, T[] all, T defaultValue)
Parse a Java enumeration list from the configuration.- Type Parameters:
T
- type of the enumeration object.- Parameters:
config
- the configuration file to read.section
- section the key is in.subsection
- subsection the key is in, or null if not in a subsection.setting
- name of the setting to read.all
- all possible values in the enumeration which should be recognized. This should beEnumType.values()
.defaultValue
- default value to return if the setting was not set. This value may be null.- Returns:
- the selected enumeration values list, or
defaultValue
.
-
getTimeUnit
public static long getTimeUnit(org.eclipse.jgit.lib.Config config, String section, String subsection, String setting, long defaultValue, TimeUnit wantUnit)
Parse a numerical time unit, such as "1 minute", from the configuration.- Parameters:
config
- the configuration file to read.section
- section the key is in.subsection
- subsection the key is in, or null if not in a subsection.setting
- name of the setting to read.defaultValue
- default value to return if no value was set in the configuration file.wantUnit
- the units ofdefaultValue
and the return value, as well as the units to assume if the value does not contain an indication of the units.- Returns:
- the setting, or
defaultValue
if not set, expressed inunits
.
-
getTimeUnit
public static long getTimeUnit(String valueString, long defaultValue, TimeUnit wantUnit)
Parse a numerical time unit, such as "1 minute", from a string.- Parameters:
valueString
- the string to parse.defaultValue
- default value to return if no value was set in the configuration file.wantUnit
- the units ofdefaultValue
and the return value, as well as the units to assume if the value does not contain an indication of the units.- Returns:
- the setting, or
defaultValue
if not set, expressed inunits
.
-
getRequired
public static String getRequired(org.eclipse.jgit.lib.Config cfg, String section, String name)
-
storeSection
public static <T> void storeSection(org.eclipse.jgit.lib.Config cfg, String section, String sub, T s, T defaults) throws org.eclipse.jgit.errors.ConfigInvalidException
Store section by inspecting Java class attributes.Optimize the storage by unsetting a variable if it is being set to default value by the server.
Fields marked with final or transient modifiers are skipped.
- Parameters:
cfg
- config in which the values should be storedsection
- sectionsub
- subsections
- instance of class with config valuesdefaults
- instance of class with default values- Throws:
org.eclipse.jgit.errors.ConfigInvalidException
-
loadSection
public static <T> T loadSection(org.eclipse.jgit.lib.Config cfg, String section, String sub, T s, T defaults, T i) throws org.eclipse.jgit.errors.ConfigInvalidException
Load section by inspecting Java class attributes.Config values are stored optimized: no default values are stored. The loading is performed eagerly: all values are set.
Fields marked with final or transient modifiers are skipped.
- Parameters:
cfg
- config from which the values are loadedsection
- sectionsub
- subsections
- instance of class in which the values are setdefaults
- instance of class with default valuesi
- instance to merge during the load. When present, the boolean fields are not nullified when their values are false- Returns:
- loaded instance
- Throws:
org.eclipse.jgit.errors.ConfigInvalidException
-
skipField
public static boolean skipField(Field field)
-
-