I'm new to Clojure, and I'm working with an application that has leiningen + clojure + java the problem is with the plugin lein-environ "1.0.0".
within the app, its using a lot the "env" map. either by reading existing values defined within the .lein_env or project.clj. But within the same application is doing a some:
(attach! :my-val (str (env :api-host) "/api/" (env :resource)))
if I print this value with a (println (env :my-val))
I do see the content. But if I try to send it to Java as a Map, I dont see this value. I get the previously defined values. I mean everything from .lein_env, but none application calculated value.
I havent found any api or documentation regarding the attach!
function, so to be honest I dont know what it does. But since the values are read from env, I thought it was attaching those keys to the map.
I tried to convert the env to a HashMap within clojure with:
(defn- creat-env-hash-map []
(java.util.HashMap. (env)))
But still getting the same result, those values are not mapped.
I wonder what am I doing wrong and if this is even possible.
Thanks a lot for your help.
Edit:
I call the java code in the way:
(println (com.my.package.HelperClass/staticMethod env))
The static method in java:
public static String staticMethod(HashMap<String, String> map) {
String result = "";
Iterator it = map.entrySet().iterator();
while (it.hasNext()) {
Map.Entry pair = (Map.Entry)it.next();
result += pair.getKey() + " = " + pair.getValue() + "\n";
it.remove(); // avoids a ConcurrentModificationException
}
return result;
}
I was not understanding correctly the "env" in clojure.
Environ has it as a function as well, its a kind of a smart object that when you call it like (env :value)
calls the function but not all the values are kind of added to the same map.
Environ has this kind of a context where it host some values you set in executions time.
What I end up doing was creating another map hosting both the "pre-defined" values and the ones
(defn- creat-env-hash-map []
(java.util.HashMap. (env)))
(defn- complete-hash-map []
(doto (creat-env-hash-map)
(.put "value-a" (str (env :value-a)))
(.put "value-b" (str (env :value-b)))
))
I maybe not using the best approach but as I mentioned, I'm new to clojure. If someone else has the correct answer is more than welcome.
Regards