Class UpdateConfig.Configurator<T extends UpdateConfig.Configurator<T>>

  • Type Parameters:
    T - actual builder type (could be extended)
    Direct Known Subclasses:
    ProdConfigurator, TestConfigurator
    Enclosing class:
    UpdateConfig

    public abstract static class UpdateConfig.Configurator<T extends UpdateConfig.Configurator<T>>
    extends java.lang.Object
    Updater configurator. Class might be extended to extend functionality (see TestConfigurator as example).
    • Constructor Summary

      Constructors 
      Constructor Description
      Configurator​(java.io.File current, java.io.InputStream update)
      Yaml updater configurator.
    • Method Summary

      All Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      T backup​(boolean backup)  
      T backupDir​(java.io.File dir)
      By default, backup is created in the same directory with configuration.
      T deleteProps​(java.lang.String... deleteProps)
      IMPORTANT: yaml property names could contain '.' and so '/' used as property separator.
      T deleteProps​(java.util.List<java.lang.String> deleteProps)
      Properties paths to delete in current file.
      T dryRun​(boolean dryRun)
      Test execution - performs complete update, but did not override existing file.
      T envVars​(java.util.Map<java.lang.String,​java.lang.String> env)
      Deprecated.
      T listen​(UpdateListener listener)
      Register listener for accessing internal files model during merge process.
      UpdateReport update()
      Performs configuration migration.
      T validateResult​(boolean validate)
      Merged file validation (checks that all old values remains and new values added).
      T var​(java.lang.String name, java.lang.String value)
      Adds variable for source config substitution.
      T vars​(java.util.Map<java.lang.String,​java.lang.String> env)
      Variables use special syntax #{name} because with it yaml file still remains valid (variable treated as comment).
      T varsFile​(java.lang.String path, boolean failIfNotFound)
      Load variables (see vars(java.util.Map)) from properties file.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Configurator

        public Configurator​(java.io.File current,
                            java.io.InputStream update)
        Yaml updater configurator.
        Parameters:
        current - current configuration file
        update - update file stream
    • Method Detail

      • backup

        public T backup​(boolean backup)
        Parameters:
        backup - true to do backup of configuration before update
        Returns:
        builder instance for chained calls
      • backupDir

        public T backupDir​(java.io.File dir)
        By default, backup is created in the same directory with configuration.
        Parameters:
        dir - directory to store backup into
        Returns:
        builder instance for chained calls
      • deleteProps

        public T deleteProps​(java.lang.String... deleteProps)
        IMPORTANT: yaml property names could contain '.' and so '/' used as property separator. But, as it would be a common point of confusion merger will try both: property as is and with replaced dots (fallback).

        Yaml path may include list values with syntax: prop/sublist[0]/foo. It would match first item of list prop/sublist and select foo item property.

         prop:
            sublist:
              - foo: 1
                bar: 2
         

        Method may be called multiple times.

        Parameters:
        deleteProps - yaml paths to delete in the old file (would be replaced with props from new file; null ignored)
        Returns:
        builder instance for chained calls
      • deleteProps

        public T deleteProps​(java.util.List<java.lang.String> deleteProps)
        Properties paths to delete in current file. Method may be called multiple times.
        Parameters:
        deleteProps - yaml paths to delete in the old file (would be replaced with props from new file; null ignored)
        Returns:
        builder instance for chained calls
        See Also:
        deleteProps(String...)
      • validateResult

        public T validateResult​(boolean validate)
        Merged file validation (checks that all old values remains and new values added). Disabling might be only useful in case of bugs in validation logic (comparing yaml trees). When validation is disabled, merged file is still parsed with snakeyaml to make sure it's readable.
        Parameters:
        validate - true to enable validation
        Returns:
        builder instance for chained calls
      • envVars

        @Deprecated
        public T envVars​(java.util.Map<java.lang.String,​java.lang.String> env)
        Deprecated.
        Variables use special syntax #{name} because with it yaml file still remains valid (variable treated as comment). Method may be called multiple times.
        Parameters:
        env - variables to replace in updating file (null ignored)
        Returns:
        builder instance for chained calls
      • vars

        public T vars​(java.util.Map<java.lang.String,​java.lang.String> env)
        Variables use special syntax #{name} because with it yaml file still remains valid (variable treated as comment). Method may be called multiple times.
        Parameters:
        env - variables to replace in updating file (null ignored)
        Returns:
        builder instance for chained calls
        See Also:
        for loading
      • varsFile

        public T varsFile​(java.lang.String path,
                          boolean failIfNotFound)
        Load variables (see vars(java.util.Map)) from properties file. May be called multiple times.
        Parameters:
        path - fs file path, classpath or file url
        failIfNotFound - true to fail when file not found, false to bypass
        Returns:
        builder instance for chained calls
      • var

        public T var​(java.lang.String name,
                     java.lang.String value)
        Adds variable for source config substitution. May be called multiple times.
        Parameters:
        name - variable name
        value - variable value
        Returns:
        builder instance for chained calls
        See Also:
        vars(java.util.Map)
      • listen

        public T listen​(UpdateListener listener)
        Register listener for accessing internal files model during merge process. Mainly used for testing.

        Only one listener allowed.

        Parameters:
        listener - merge process stages listener (null ignored)
        Returns:
        builder instance for chained calls
      • dryRun

        public T dryRun​(boolean dryRun)
        Test execution - performs complete update, but did not override existing file. Useful for validations (in tests or with CLI to make sure upgrade would be successful).
        Parameters:
        dryRun - true to not perform any modifications (test run)
        Returns:
        builder instance for chained calls