Class ConfigUtils


  • public final class ConfigUtils
    extends Object
    • Field Detail

      • UUID_KEY

        static final String UUID_KEY
        The name of the property associated with a random UUID generated at launch time.
        See Also:
        Constant Field Values
    • Method Detail

      • configBuilder

        public static io.smallrye.config.SmallRyeConfigBuilder configBuilder​(boolean runTime,
                                                                             LaunchMode launchMode)
      • configBuilder

        public static io.smallrye.config.SmallRyeConfigBuilder configBuilder​(boolean runTime,
                                                                             boolean addDiscovered,
                                                                             LaunchMode launchMode)
        Get the basic configuration builder.
        Parameters:
        runTime - true if the configuration is run time, false if build time
        addDiscovered - true if the ConfigSource and Converter objects should be auto-discovered
        Returns:
        the configuration builder
      • configBuilder

        public static io.smallrye.config.SmallRyeConfigBuilder configBuilder​(boolean runTime,
                                                                             boolean bootstrap,
                                                                             boolean addDiscovered,
                                                                             LaunchMode launchMode)
        Get the basic configuration builder.
        Parameters:
        runTime - true if the configuration is run time, false if build time
        addDiscovered - true if the ConfigSource and Converter objects should be auto-discovered
        Returns:
        the configuration builder
      • emptyConfigBuilder

        public static io.smallrye.config.SmallRyeConfigBuilder emptyConfigBuilder()
      • configBuilder

        public static io.smallrye.config.SmallRyeConfigBuilder configBuilder​(io.smallrye.config.SmallRyeConfigBuilder builder,
                                                                             List<String> configBuildersNames)
      • addSourceProvider

        public static void addSourceProvider​(io.smallrye.config.SmallRyeConfigBuilder builder,
                                             org.eclipse.microprofile.config.spi.ConfigSourceProvider provider)
        Add a configuration source provider to the builder.
        Parameters:
        builder - the builder
        provider - the provider to add
      • addSourceProviders

        public static void addSourceProviders​(io.smallrye.config.SmallRyeConfigBuilder builder,
                                              Collection<org.eclipse.microprofile.config.spi.ConfigSourceProvider> providers)
        Add a configuration source providers to the builder.
        Parameters:
        builder - the builder
        providers - the providers to add
      • addSourceFactoryProvider

        public static void addSourceFactoryProvider​(io.smallrye.config.SmallRyeConfigBuilder builder,
                                                    ConfigSourceFactoryProvider provider)
      • getProfiles

        public static List<String> getProfiles()
      • isProfileActive

        public static boolean isProfileActive​(String profile)
      • isPropertyPresent

        public static boolean isPropertyPresent​(String propertyName)
        Checks if a property is present in the current Configuration.

        Because the sources may not expose the property directly in ConfigSource.getPropertyNames(), we cannot reliably determine if the property is present in the properties list. The property needs to be retrieved to make sure it exists. Also, if the value is an expression, we want to ignore expansion, because this is not relevant for the check and the expansion value may not be available at this point.

        It may be interesting to expose such API in SmallRyeConfig directly.

        Parameters:
        propertyName - the property name.
        Returns:
        true if the property is present or false otherwise.
      • isAnyPropertyPresent

        public static boolean isAnyPropertyPresent​(Collection<String> propertyNames)
        Checks if any of the given properties is present in the current Configuration.

        Because the sources may not expose the property directly in ConfigSource.getPropertyNames(), we cannot reliably determine if the property is present in the properties list. The property needs to be retrieved to make sure it exists. Also, if the value is an expression, we want to ignore expansion, because this is not relevant for the check and the expansion value may not be available at this point.

        It may be interesting to expose such API in SmallRyeConfig directly.

        Parameters:
        propertyNames - The configuration property names
        Returns:
        true if the property is present or false otherwise.
      • getFirstOptionalValue

        public static <T> Optional<T> getFirstOptionalValue​(List<String> propertyNames,
                                                            Class<T> propertyType)
        Get the value of the first given property present in the current Configuration, or Optional.empty() if none of the properties is present.
        Type Parameters:
        T - The property type
        Parameters:
        propertyNames - The configuration property names
        propertyType - The type that the resolved property value should be converted to
        Returns:
        true if the property is present or false otherwise.