Package ru.vyarus.yaml.updater
Class UpdateConfig.Configurator<T extends UpdateConfig.Configurator<T>>
- java.lang.Object
-
- ru.vyarus.yaml.updater.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.ObjectUpdater configurator. Class might be extended to extend functionality (seeTestConfiguratoras example).
-
-
Field Summary
Fields Modifier and Type Field Description protected UpdateConfigconfig
-
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 Tbackup(boolean backup)TbackupDir(java.io.File dir)By default, backup is created in the same directory with configuration.TdeleteProps(java.lang.String... deleteProps)IMPORTANT: yaml property names could contain '.' and so '/' used as property separator.TdeleteProps(java.util.List<java.lang.String> deleteProps)Properties paths to delete in current file.TdryRun(boolean dryRun)Test execution - performs complete update, but did not override existing file.TenvVars(java.util.Map<java.lang.String,java.lang.String> env)Deprecated.usevars(java.util.Map)insteadTlisten(UpdateListener listener)Register listener for accessing internal files model during merge process.UpdateReportupdate()Performs configuration migration.TvalidateResult(boolean validate)Merged file validation (checks that all old values remains and new values added).Tvar(java.lang.String name, java.lang.String value)Adds variable for source config substitution.Tvars(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).TvarsFile(java.lang.String path, boolean failIfNotFound)Load variables (seevars(java.util.Map)) from properties file.
-
-
-
Field Detail
-
config
protected final UpdateConfig config
-
-
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: 2Method 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.usevars(java.util.Map)insteadVariables 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 (seevars(java.util.Map)) from properties file. May be called multiple times.- Parameters:
path- fs file path, classpath or file urlfailIfNotFound- 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 namevalue- 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
-
update
public UpdateReport update()
Performs configuration migration.- Returns:
- update report
- See Also:
for default report formatter
-
-