diff --git a/src/leiningen/jar.clj b/src/leiningen/jar.clj index e5aec284..e515ab60 100644 --- a/src/leiningen/jar.clj +++ b/src/leiningen/jar.clj @@ -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.) diff --git a/test/leiningen/test/jar.clj b/test/leiningen/test/jar.clj index 4cee03d6..a55dc97d 100644 --- a/test/leiningen/test/jar.clj +++ b/test/leiningen/test/jar.clj @@ -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)) diff --git a/test_projects/sample/project.clj b/test_projects/sample/project.clj index cb393682..07256b40 100644 --- a/test_projects/sample/project.clj +++ b/test_projects/sample/project.clj @@ -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)))