Support :fn in :filespecs for arbitrary additions to jar.

This commit is contained in:
Phil Hagelberg 2012-04-03 11:36:13 -07:00
parent 5fa6a7e501
commit 7f5e2b1a94
3 changed files with 14 additions and 1 deletions

View file

@ -133,9 +133,17 @@
(defmethod copy-to-jar :bytes [project jar-os acc spec]
(when-not (some #(re-find % (:path spec)) (:jar-exclusions project))
(.putNextEntry jar-os (JarEntry. (:path spec)))
(io/copy (ByteArrayInputStream. (:bytes spec)) jar-os))
(let [bytes (if (string? (:bytes spec))
(.getBytes (:bytes spec))
(:bytes spec))]
(io/copy (ByteArrayInputStream. bytes) jar-os)))
(conj acc (:path spec)))
(defmethod copy-to-jar :fn [project jar-os acc spec]
(let [f (eval (:fn spec))
dynamic-spec (f project)]
(copy-to-jar project jar-os acc dynamic-spec)))
(defn write-jar [project out-file filespecs]
(with-open [jar-os (-> out-file
(FileOutputStream.)

View file

@ -23,9 +23,11 @@
(let [jar-file (JarFile. (jar sample-project))
manifest (manifest-map (.getManifest jar-file))
bin (slurp (.getInputStream jar-file (.getEntry jar-file "bin/nom")))
bin (slurp (.getInputStream jar-file (.getEntry jar-file "bytes.clj")))
bat (slurp (.getInputStream jar-file (.getEntry jar-file
"bin/nom.bat")))]
(is (= "bin/nom" (manifest "Leiningen-shell-wrapper")))
(is (= [:bytes "are" 'nomnomnom] (read-string bytes)))
(is (re-find #"org/clojure/clojure/1\.1\.0/" bin))
(is (re-find #"org\\clojure\\clojure\\1\.1\.0" bat))
(is (re-find #"MAIN=\"nom\.nom\.nom\"" bin))

View file

@ -15,6 +15,9 @@
:shell-wrapper {:main nom.nom.nom
:bin "bin/nom"}
:jar-exclusions [#"^META-INF"]
:filespecs [{:type :fn :fn (fn [p] {:type :bytes :path "bytes.clj"
:bytes (str "[:bytes \"are\" "
(:name p) "]")})}]
:test-selectors {:integration :integration
:default (complement :integration)
:random (fn [_] (> (rand) ~(float 1/2)))