Last active
November 13, 2023 14:53
-
-
Save eigenhombre/a1e7d98efddf5ebfdd90efdcebaffff6 to your computer and use it in GitHub Desktop.
Temporarily set Java System properties (Clojure macro)
This file contains hidden or 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 [property-map & body] | |
| `(let [pm# ~property-map | |
| props# (into {} (for [[k# v#] pm#] | |
| [k# (System/getProperty k#)]))] | |
| (doseq [k# (keys pm#)] | |
| (System/setProperty k# (get pm# k#))) | |
| (try | |
| ~@body | |
| (finally | |
| (doseq [k# (keys pm#)] | |
| (if-not (get props# k#) | |
| (System/clearProperty k#) | |
| (System/setProperty k# (get props# k#)))))))) | |
| (with-properties {"bank2" "1"} | |
| (System/getProperty "bank2")) | |
| ;;=> | |
| '"1" | |
| (System/getProperty "bank2") | |
| ;;=> | |
| 'nil |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment