Skip to content

Commit

Permalink
Add project coordinate data to JAR metadata
Browse files Browse the repository at this point in the history
This causes entries like:

    Leiningen-Project-ArtifactId: bar
    Leiningen-Project-GroupId: foo
    Leiningen-Project-Version: 1.2.3-SNAPSHOT

to be added to META-INF/MANIFEST.MF in JARS for projects with
project.clj files like:

    (defproject foo/bar "1.2.3-SNAPSHOT"
      ...
      )
  • Loading branch information
conormcd committed Dec 21, 2017
1 parent e20c06b commit 14807e9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
9 changes: 6 additions & 3 deletions src/leiningen/jar.clj
Expand Up @@ -22,10 +22,13 @@
(defn- unix-path [path]
(.replace path "\\" "/"))

(def ^:private default-manifest
(defn- default-manifest [project]
{"Created-By" (str "Leiningen " (main/leiningen-version))
"Built-By" (System/getProperty "user.name")
"Build-Jdk" (System/getProperty "java.version")})
"Build-Jdk" (System/getProperty "java.version")
"Leiningen-Project-ArtifactId" (:name project)
"Leiningen-Project-GroupId" (:group project)
"Leiningen-Project-Version" (:version project)})

(declare ^:private manifest-entry)

Expand Down Expand Up @@ -55,7 +58,7 @@

(defn ^:internal make-manifest [project]
(let [project-manifest (into {} (:manifest project))
default-manifest' (cond-> default-manifest
default-manifest' (cond-> (default-manifest project)
;; Add default "Main-Class" only if :main is not
;; explicitly set to nil
(:main project :not-found)
Expand Down
11 changes: 9 additions & 2 deletions test/leiningen/test/jar.clj
Expand Up @@ -15,6 +15,7 @@

(def mock-project-1
{:name "mock-project"
:group "mock-group"
:version "1.0"
:main 'foo.one-two.three-four.bar
:manifest [["hello" "world"]
Expand All @@ -26,6 +27,7 @@

(def mock-project-2
{:name "mock-project"
:group "mock-group"
:version "1.0"
:main 'foo.one-two.three-four.bar
:manifest {"hello" "world"
Expand All @@ -45,9 +47,14 @@
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" "A" "G" "Created-By" "Built-By"
"Build-Jdk" "long-line"}
(is (= #{"A" "Build-Jdk" "Built-By" "Created-By" "G"
"Leiningen-Project-ArtifactId" "Leiningen-Project-GroupId"
"Leiningen-Project-Version" "Main-Class" "Manifest-Version"
"hello" "long-line"}
(-> mm keys set)))
(is (= (get mm "Leiningen-Project-ArtifactId") "mock-project"))
(is (= (get mm "Leiningen-Project-GroupId") "mock-group"))
(is (= (get mm "Leiningen-Project-Version") "1.0"))
(is (= (get mm "long-line") long-line))
(is (= #{"my-section-1" "my-section-2"}
(-> mock-project
Expand Down

0 comments on commit 14807e9

Please sign in to comment.