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
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ fi

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 \:)"
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"
# CLOJURE_JAR="$HOME/.m2/repository/org/clojure/clojure/1.2.0/clojure-1.2.0.jar"
NULL_DEVICE=/dev/null
Expand Down
4 changes: 3 additions & 1 deletion sample.project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,6 @@
;; Set arbitrary key/value pairs for the jar's manifest.
:manifest {"Project-awesome-level" "super-great"}
;; 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
Original file line number Diff line number Diff line change
Expand Up @@ -142,33 +142,35 @@
(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
(if (:eval-in-leiningen project)
(eval form)
(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 "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")
;; 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)))
(.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")
;; 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 []
(file (if (= :windows (get-os))
Expand Down
8 changes: 8 additions & 0 deletions test/test_compile.clj
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,11 @@
(is (.exists (file "test_projects" "sample"
"classes" "nom" "nom" "nom.class")))
(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.