Class ConfigUtil


  • public class ConfigUtil
    extends Object
    • 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 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
      • skipField

        public static boolean skipField​(Field field)