Class ConfigUtil

java.lang.Object
com.google.gerrit.server.config.ConfigUtil

public class ConfigUtil extends Object
  • Method Summary

    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
     
    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

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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 be EnumType.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 of defaultValue 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 in units.
    • 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 of defaultValue 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 in units.
    • 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 stored
      section - section
      sub - subsection
      s - instance of class with config values
      defaults - 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 loaded
      section - section
      sub - subsection
      s - instance of class in which the values are set
      defaults - instance of class with default values
      i - 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

      public static <T> void updatePreferences(T original, T updateDelta) throws IOException
      Update user config by applying the specified delta

      As 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 input original 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 the UserPreferencesConverter classes.

      Fields marked with final or transient modifiers are skipped.

      Parameters:
      original - the original current user config
      updateDelta - instance of class with config values that need to be uplied to the original config
      Throws:
      IOException
    • skipField

      public static boolean skipField(Field field)