Merge pull request #1218 from leon-barrett/line-fix

Fixed long line support in make-manifest.
This commit is contained in:
Phil Hagelberg 2013-06-10 16:32:13 -07:00
commit 8f566613df
2 changed files with 26 additions and 16 deletions

View file

@ -22,21 +22,25 @@
"Built-By" (System/getProperty "user.name") "Built-By" (System/getProperty "user.name")
"Build-Jdk" (System/getProperty "java.version")}) "Build-Jdk" (System/getProperty "java.version")})
(defn- manifest-entry [project manifest [k v]] (defn- manifest-entry [project [k v]]
(cond (symbol? v) (manifest-entry project manifest [k (resolve v)]) (cond (symbol? v) (manifest-entry project [k (resolve v)])
(fn? v) (manifest-entry project manifest [k (v project)]) (fn? v) (manifest-entry project [k (v project)])
:else (str manifest "\n" (name k) ": " v))) :else (->> (str (name k) ": " v)
(partition-all 70) ;; Manifest spec says lines <= 72 chars
(map (partial apply str))
(string/join "\n ") ;; Manifest spec says join with "\n "
(format "%s\n"))))
(defn ^:internal make-manifest [project] (defn ^:internal make-manifest [project]
(-> (reduce (partial manifest-entry project) (->> (merge default-manifest (:manifest project)
"Manifest-Version: 1.0" (if-let [main (:main project)]
(merge default-manifest (:manifest project) {"Main-Class" (.replaceAll (str main) "-" "_")}))
(if-let [main (:main project)] (map (partial manifest-entry project))
{"Main-Class" (.replaceAll (str main) "-" "_")}))) (cons "Manifest-Version: 1.0\n") ;; Manifest-Version line must be first
(str "\n") ;; Add an endline character to make Manifest happy. (string/join "")
.getBytes .getBytes
ByteArrayInputStream. ByteArrayInputStream.
Manifest.)) Manifest.))
(defn ^:internal manifest-map [manifest] (defn ^:internal manifest-map [manifest]
(let [attrs (.getMainAttributes manifest)] (let [attrs (.getMainAttributes manifest)]

View file

@ -9,9 +9,13 @@
overlapped-sourcepaths-project]]) overlapped-sourcepaths-project]])
(:import (java.util.jar JarFile))) (:import (java.util.jar JarFile)))
(def long-line
(apply str (repeat 10000 "a")))
(def mock-project {:name "mock-project" :version "1.0" (def mock-project {:name "mock-project" :version "1.0"
:main 'foo.one-two.three-four.bar :main 'foo.one-two.three-four.bar
:manifest {"hello" "world"}}) :manifest {"hello" "world"
"long-line" long-line}})
(deftest test-manifest (deftest test-manifest
(let [mm (-> mock-project (let [mm (-> mock-project
@ -19,8 +23,10 @@
manifest-map)] manifest-map)]
(is (= {"Main-Class" "foo.one_two.three_four.bar", "hello" "world"} (is (= {"Main-Class" "foo.one_two.three_four.bar", "hello" "world"}
(select-keys mm ["hello" "Main-Class"]))) (select-keys mm ["hello" "Main-Class"])))
(is (= #{"Manifest-Version" "Main-Class" "hello" "Created-By" "Built-By" "Build-Jdk"} (is (= #{"Manifest-Version" "Main-Class" "hello" "Created-By" "Built-By"
(-> mm keys set))))) "Build-Jdk" "long-line"}
(-> mm keys set)))
(is (= (get mm "long-line") long-line))))
(deftest test-jar-fails (deftest test-jar-fails
(binding [*err* (java.io.PrintWriter. (platform-nullsink))] (binding [*err* (java.io.PrintWriter. (platform-nullsink))]