inline fun <T> withEnvironment(key: String, value: String?, mode: OverrideMode = SetOrError, block: () -> T): T
Modifies System Environment with chosen key and value
This is a helper function for code that uses Environment Variables. It changes the specific key from System.getenv with the specified value, only during the execution of block.
To do this, this function uses a trick that makes the System Environment editable, and changes key. Any previous environment (anything not overridden) will also be in the environment. If the chosen key is in the environment, it will be changed according to mode. If the chosen key is not in the environment, it will be included.
After the execution of block, the environment is set to what it was before.
ATTENTION: This code is susceptible to race conditions. If you attempt to change the environment while it was already changed, the result is inconsistent, as the System Environment Map is a single map.
inline fun <T> withEnvironment(environment: Pair<String, String?>, mode: OverrideMode = SetOrError, block: () -> T): T
Modifies System Environment with chosen key and value
This is a helper function for code that uses Environment Variables. It changes the specific key from System.getenv with the specified value, only during the execution of block.
To do this, this function uses a trick that makes the System Environment editable, and changes key. Any previous environment (anything not overridden) will also be in the environment. If the chosen key is in the environment, it will be changed according to mode. If the chosen key is not in the environment, it will be included.
After the execution of block, the environment is set to what it was before.
ATTENTION: This code is susceptible to race conditions. If you attempt to change the environment while it was already changed, the result is inconsistent, as the System Environment Map is a single map.
inline fun <T> withEnvironment(environment: Map<String, String?>, mode: OverrideMode = SetOrError, block: () -> T): T
Modifies System Environment with chosen keys and values
This is a helper function for code that uses Environment Variables. It changes the specific keys from System.getenv with the specified values, only during the execution of block.
To do this, this function uses a trick that makes the System Environment editable, and changes key. Any previous environment (anything not overridden) will also be in the environment. If the chosen key is in the environment, it will be changed according to mode. If the chosen key is not in the environment, it will be included.
After the execution of block, the environment is set to what it was before.
ATTENTION: This code is susceptible to race conditions. If you attempt to change the environment while it was already changed, the result is inconsistent, as the System Environment Map is a single map.