Created
July 31, 2019 16:40
-
-
Save cloojure/072e38f60eb98de274ebc30be9b496da to your computer and use it in GitHub Desktop.
Temporarily redefine jvm system properties to include user-specified items
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defmacro with-properties | |
"Temporarily redefine jvm system properties to include entries from `props-user`." | |
[props-user & body] | |
`(let [props-orig# (into {} (for [[prop-key# prop-val#] ~props-user] | |
[prop-key# (System/getProperty prop-key#)]))] | |
(doseq [prop-key# (keys ~props-user)] | |
(System/setProperty prop-key# (get ~props-user prop-key#))) | |
(try | |
~@body | |
(finally | |
(doseq [prop-key# (keys ~props-user)] | |
(let [prop-val-orig# (get props-orig# prop-key#)] | |
(if prop-val-orig# | |
(System/setProperty prop-key# prop-val-orig#) | |
(System/clearProperty prop-key#)))))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment