Skip to content

Commit

Permalink
Support :eval-in-leiningen key in project.clj for plugins.
Browse files Browse the repository at this point in the history
  • Loading branch information
technomancy committed Oct 24, 2010
1 parent 1551ebc commit f732bfe
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 28 deletions.
2 changes: 1 addition & 1 deletion bin/lein
Expand Up @@ -36,7 +36,7 @@ fi


LEIN_PLUGINS="$(ls -1 lib/dev/*jar 2> /dev/null | tr \\n \:)" LEIN_PLUGINS="$(ls -1 lib/dev/*jar 2> /dev/null | tr \\n \:)"
LEIN_USER_PLUGINS="$(ls -1 $LEIN_HOME/plugins/*jar 2> /dev/null | tr \\n \:)" LEIN_USER_PLUGINS="$(ls -1 $LEIN_HOME/plugins/*jar 2> /dev/null | tr \\n \:)"
CLASSPATH=$LEIN_USER_PLUGINS:$LEIN_PLUGINS:src/:$CLASSPATH CLASSPATH=$LEIN_USER_PLUGINS:$LEIN_PLUGINS:test/:src/:$CLASSPATH
LEIN_JAR="$HOME/.m2/repository/leiningen/leiningen/$LEIN_VERSION/leiningen-$LEIN_VERSION-standalone.jar" LEIN_JAR="$HOME/.m2/repository/leiningen/leiningen/$LEIN_VERSION/leiningen-$LEIN_VERSION-standalone.jar"
# CLOJURE_JAR="$HOME/.m2/repository/org/clojure/clojure/1.2.0/clojure-1.2.0.jar" # CLOJURE_JAR="$HOME/.m2/repository/org/clojure/clojure/1.2.0/clojure-1.2.0.jar"
NULL_DEVICE=/dev/null NULL_DEVICE=/dev/null
Expand Down
4 changes: 3 additions & 1 deletion sample.project.clj
Expand Up @@ -92,4 +92,6 @@
;; Set arbitrary key/value pairs for the jar's manifest. ;; Set arbitrary key/value pairs for the jar's manifest.
:manifest {"Project-awesome-level" "super-great"} :manifest {"Project-awesome-level" "super-great"}
;; You can set JVM-level options here. ;; You can set JVM-level options here.
:jvm-opts ["-Xmx1g"]) :jvm-opts ["-Xmx1g"]
;; If your project is a Leiningen plugin, set this to skip the subprocess step
:eval-in-leiningen false)
54 changes: 28 additions & 26 deletions src/leiningen/compile.clj
Expand Up @@ -142,33 +142,35 @@
(compile project))) (compile project)))
(when (empty? (find-lib-jars project)) (when (empty? (find-lib-jars project))
(deps project)) (deps project))
(let [java (Java.) (if (:eval-in-leiningen project)
native-path (or (:native-path project) (eval form)
(find-native-lib-path project))] (let [java (Java.)
(.setProject java lancet/ant-project) native-path (or (:native-path project)
(.addSysproperty java (doto (Environment$Variable.) (find-native-lib-path project))]
(.setKey "clojure.compile.path") (.setProject java lancet/ant-project)
(.setValue (:compile-path project))))
(when native-path
(.addSysproperty java (doto (Environment$Variable.) (.addSysproperty java (doto (Environment$Variable.)
(.setKey "java.library.path") (.setKey "clojure.compile.path")
(.setValue (cond (.setValue (:compile-path project))))
(= java.io.File (class native-path)) (when native-path
(.getAbsolutePath native-path) (.addSysproperty java (doto (Environment$Variable.)
(fn? native-path) (native-path) (.setKey "java.library.path")
:default native-path))))) (.setValue (cond
(.setClasspath java (apply make-path (get-classpath project))) (= java.io.File (class native-path))
(.setFailonerror java true) (.getAbsolutePath native-path)
(.setFork java true) (fn? native-path) (native-path)
(doseq [arg (get-jvm-args project)] :default native-path)))))
(when-not (re-matches #"^-Xbootclasspath.+" arg) (.setClasspath java (apply make-path (get-classpath project)))
(.setValue (.createJvmarg java) arg))) (.setFailonerror java true)
(.setClassname java "clojure.main") (.setFork java true)
;; to allow plugins and other tasks to customize (doseq [arg (get-jvm-args project)]
(when handler (handler java)) (when-not (re-matches #"^-Xbootclasspath.+" arg)
(.setValue (.createArg java) "-e") (.setValue (.createJvmarg java) arg)))
(.setValue (.createArg java) (get-readable-form java project form init)) (.setClassname java "clojure.main")
(.executeJava java))) ;; to allow plugins and other tasks to customize
(when handler (handler java))
(.setValue (.createArg java) "-e")
(.setValue (.createArg java) (get-readable-form java project form init))
(.executeJava java))))


(defn- platform-nullsink [] (defn- platform-nullsink []
(file (if (= :windows (get-os)) (file (if (= :windows (get-os))
Expand Down
8 changes: 8 additions & 0 deletions test/test_compile.clj
Expand Up @@ -23,3 +23,11 @@
(is (.exists (file "test_projects" "sample" (is (.exists (file "test_projects" "sample"
"classes" "nom" "nom" "nom.class"))) "classes" "nom" "nom" "nom.class")))
(is (pos? (compile (make-project "test_projects/sample_failing"))))) (is (pos? (compile (make-project "test_projects/sample_failing")))))

(deftest test-plugin
(is (= (eval-in-project (assoc (make-project "test_projects/sample")
:eval-in-leiningen true
:main nil)
'(do (require 'leiningen.compile)
:compiled))
:compiled)))

0 comments on commit f732bfe

Please sign in to comment.