Skip to content

Commit

Permalink
Fix a bug where the manifest is missing its last line.
Browse files Browse the repository at this point in the history
Despite the documentation on java.util.jar.Manifest [1], the Manifest class
seems to require an endline in its input. If not, it drops the last line (on my
system, version [2], anyway).

[1] http://docs.oracle.com/javase/6/docs/technotes/guides/jar/jar.html
[2] $ java -version
java version "1.7.0_21"
OpenJDK Runtime Environment (IcedTea 2.3.9) (7u21-2.3.9-0ubuntu0.12.04.1)
OpenJDK 64-Bit Server VM (build 23.7-b01, mixed mode)
  • Loading branch information
Leon Barrett committed May 31, 2013
1 parent ea443fe commit 3809077
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
17 changes: 9 additions & 8 deletions src/leiningen/jar.clj
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,15 @@
:else (str manifest "\n" (name k) ": " v)))

(defn ^:internal make-manifest [project]
(Manifest.
(ByteArrayInputStream.
(.getBytes
(reduce (partial manifest-entry project)
"Manifest-Version: 1.0"
(merge default-manifest (:manifest project)
(if-let [main (:main project)]
{"Main-Class" (.replaceAll (str main) "-" "_")})))))))
(-> (reduce (partial manifest-entry project)
"Manifest-Version: 1.0"
(merge default-manifest (:manifest project)
(if-let [main (:main project)]
{"Main-Class" (.replaceAll (str main) "-" "_")})))
(str "\n") ;; Add an endline character to make Manifest happy.
.getBytes
ByteArrayInputStream.
Manifest.))

(defn ^:internal manifest-map [manifest]
(let [attrs (.getMainAttributes manifest)]
Expand Down
12 changes: 7 additions & 5 deletions test/leiningen/test/jar.clj
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@
:manifest {"hello" "world"}})

(deftest test-manifest
(is (= {"Main-Class" "foo.one_two.three_four.bar", "hello" "world"}
(-> mock-project
make-manifest
manifest-map
(select-keys ["hello" "Main-Class"])))))
(let [mm (-> mock-project
make-manifest
manifest-map)]
(is (= {"Main-Class" "foo.one_two.three_four.bar", "hello" "world"}
(select-keys mm ["hello" "Main-Class"])))
(is (= #{"Manifest-Version" "Main-Class" "hello" "Created-By" "Built-By" "Build-Jdk"}
(-> mm keys set)))))

(deftest test-jar-fails
(binding [*err* (java.io.PrintWriter. (platform-nullsink))]
Expand Down

0 comments on commit 3809077

Please sign in to comment.