Logic Variables
The default variable resolver also provides the following logic variables for performing simple logical operations:
- {@link oaj.svl.vars.IfVar} - $IF{arg,then[,else]}
- {@link oaj.svl.vars.SwitchVar} - $SW{arg,pattern1:then1[,pattern2:then2...]}
- {@link oaj.svl.vars.CoalesceVar} - $CO{arg1[,arg2...]}
- {@link oaj.svl.vars.PatternMatchVar} - $PM{arg,pattern}
- {@link oaj.svl.vars.NotEmptyVar} - $NE{arg}
- {@link oaj.svl.vars.UpperCaseVar} - $UC{arg}
- {@link oaj.svl.vars.LowerCaseVar} - $LC{arg}
The $IF variable can be used for simple if/else logic:
# Value set to 'foo' if myBooleanProperty is true
key1 =
$IF{
$S{myBooleanProperty},
foo
}
# Value set to 'foo' if myBooleanProperty is true, 'bar' if false.
key2 =
$IF{
$S{myBooleanProperty},
foo,
bar
}
# Value set to key1 value if myBooleanProperty is true, key2 value if false.
key3 =
$IF{
$S{myBooleanProperty},
$C{key1},
$C{key2}
}
The $SW variable can be used for switch blocks based on pattern matching:
# Shell command depends on the OS
shellCommand =
$SW{
$LC{$S{os.name}},
*win*: bat,
linux: bash,
*: sh
}
The $CO variable can be used for coalescing of values (finding the first non-null/empty match):
# Debug flag can be enabled by system property or environment variable.
debug =
$CO{
$S{debug},
$E{DEBUG},
false
}
The $PM variable can be used for calculating boolean values:
# Debug flag can be enabled by system property or environment variable.
isWindows =
$PM{
$LC{$S{os.name}},
*win*
}