(defn eval-in-project
"Executes form in an isolated classloader with the classpath and compile path
set correctly for the project. Pass in a handler function to have it called
with the java task right before executing if you need to customize any of its
properties (classpath, library-path, etc)."
[project form & [handler skip-auto-compile]]
(when (and (not skip-auto-compile)
(empty? (.list (file (:compile-path project)))))
(binding [*silently* true]
(compile project)))
(when (empty? (find-lib-jars project))
(deps project))
(let [java (Java.)
native-path (or (:native-path project)
(find-native-lib-path project))]
(.setProject java lancet/ant-project)
(.addSysproperty java (doto (Environment$Variable.)
(.setKey "clojure.compile.path")
(.setValue (:compile-path project))))
(when native-path
(.addSysproperty java (doto (Environment$Variable.)
(.setKey "java.library.path")
(.setValue (cond
(= java.io.File (class native-path))
(.getAbsolutePath native-path)
(fn? native-path) (native-path)
:default native-path)))))
(.setClasspath java (apply make-path (get-classpath project)))
(.setFailonerror java true)
(.setFork java true)
(doseq [arg (get-jvm-args project)]
(when-not (re-matches #"^-Xbootclasspath.+" arg)
(.setValue (.createJvmarg java) arg)))
(.setClassname java "clojure.main")
(.setValue (.createArg java) "-e")
(let [cp (str (.getClasspath (.getCommandLine java)))
form `(do (def ~'*classpath* ~cp)
(set! ~'*warn-on-reflection*
~(:warn-on-reflection project))
~form)]
(.setValue (.createArg java) (prn-str form)))
;; to allow plugins and other tasks to customize
(when handler (handler java))
(.executeJava java)))
Used in 0 other vars
Comments top
No comments for eval-in-project. Log in to add a comment.