Class ConfigUtil
-
Method Summary
Modifier and TypeMethodDescriptiongetEnumList
(org.eclipse.jgit.lib.Config config, String section, String subsection, String setting, T defaultValue) Parse a Java enumeration list from the configuration.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
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.static <T> void
updatePreferences
(T original, T updateDelta) Update user config by applying the specified delta
-
Method Details
-
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
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
-
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
-
updatePreferences
Update user config by applying the specified deltaAs opposed to
storeSection(org.eclipse.jgit.lib.Config, java.lang.String, java.lang.String, T, T)
, this method does not unset a variable that are set to default, because it is expected that the inputoriginal
is the raw user config value (does not include the defaults)To use this method with the proto config (see
CachedPreferences.asUserPreferencesProto()
), the caller can first convert the proto to a java class usign one of theUserPreferencesConverter
classes.Fields marked with final or transient modifiers are skipped.
- Parameters:
original
- the original current user configupdateDelta
- instance of class with config values that need to be uplied to the original config- Throws:
IOException
-
skipField
-