Pom: refactor write-scm-tag and make-git-scm
Makes it to return plain maps for all values of :scm to use xmlify and xml-tags in all cases. Apart from easier to read code, it will make it easy to implement merging values from git and from project map when (= "git" scm)
This commit is contained in:
parent
1cebb9a93b
commit
1937e561d2
2 changed files with 31 additions and 15 deletions
|
@ -86,19 +86,15 @@
|
|||
:dev-clone (str "ssh://git@github.com/" user "/" repo ".git")
|
||||
:browse (str "https://github.com/" user "/" repo)}))
|
||||
|
||||
(defn- make-git-scm [git-dir]
|
||||
(defn- make-git-scm-map [git-dir]
|
||||
(try
|
||||
(let [origin (read-git-origin git-dir)
|
||||
head (read-git-head git-dir)
|
||||
urls (github-urls origin)]
|
||||
[:scm
|
||||
(and (:public-clone urls)
|
||||
[:connection (str "scm:git:" (:public-clone urls))])
|
||||
(and (:dev-clone urls)
|
||||
[:developerConnection (str "scm:git:" (:dev-clone urls))])
|
||||
(and head
|
||||
[:tag head])
|
||||
[:url (:browse urls)]])
|
||||
(cond-> {:url (:browse urls)}
|
||||
(:public-clone urls) (assoc :connection (str "scm:git:" (:public-clone urls)))
|
||||
(:dev-clone urls) (assoc :developerConnection (str "scm:git:" (:dev-clone urls)))
|
||||
head (assoc :tag head)))
|
||||
(catch java.io.FileNotFoundException _)))
|
||||
|
||||
(def disclaimer
|
||||
|
@ -128,15 +124,20 @@
|
|||
[scm]
|
||||
(map #(xml-tags (first %) (second %)) scm))
|
||||
|
||||
(defn- make-project-scm-map [project]
|
||||
(select-keys (:scm project) [:url :connection
|
||||
:tag :developerConnection]))
|
||||
|
||||
(defn- write-scm-tag
|
||||
"Write the <scm> tag for pom.xml.
|
||||
Retains backwards compatibility without an :scm map."
|
||||
[scm project]
|
||||
(if (= "auto" scm)
|
||||
(make-git-scm (resolve-git-dir project))
|
||||
(xml-tags :scm (xmlify (select-keys (:scm project)
|
||||
[:url :connection
|
||||
:tag :developerConnection])))))
|
||||
(->> (case scm
|
||||
"auto" (make-git-scm-map (resolve-git-dir project))
|
||||
; else
|
||||
(make-project-scm-map project))
|
||||
xmlify
|
||||
(xml-tags :scm)))
|
||||
|
||||
(defmethod xml-tags :default
|
||||
([tag value]
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
(ns leiningen.test.pom
|
||||
(:use [clojure.test]
|
||||
[clojure.java.io :only [file delete-file]]
|
||||
[leiningen.pom :only [make-pom pom snapshot?]]
|
||||
[leiningen.pom :as pom :only [make-pom pom snapshot?]]
|
||||
[leiningen.core.user :as user]
|
||||
[leiningen.test.helper
|
||||
:only [sample-project sample-profile-meta-project
|
||||
|
@ -49,6 +49,21 @@
|
|||
([project name profile]
|
||||
(project/merge-profiles (with-profile project name profile) [name])))
|
||||
|
||||
(deftest test-pom-scm-auto
|
||||
(with-redefs [pom/parse-github-url (constantly ["techno" "lein"])
|
||||
pom/read-git-head (constantly "the git head")]
|
||||
(let [project (with-profile-merged sample-project
|
||||
^:leaky {:scm {:name "auto"
|
||||
:dir "." ;; so resolve-git-dir looks for lein project .git dir, not the sample
|
||||
:connection "https://example.org/ignored-url"
|
||||
:url "https://github.com/this-is/ignored"}})
|
||||
pom (make-pom project)
|
||||
xml (xml/parse-str pom)]
|
||||
(is (= "scm:git:git://github.com/techno/lein.git" (first-in xml [:project :scm :connection])))
|
||||
(is (= "scm:git:ssh://git@github.com/techno/lein.git" (first-in xml [:project :scm :developerConnection])))
|
||||
(is (= "https://github.com/techno/lein" (first-in xml [:project :scm :url])))
|
||||
(is (= "the git head" (first-in xml [:project :scm :tag]))))))
|
||||
|
||||
(deftest test-pom-default-values
|
||||
(let [xml (xml/parse-str (make-pom sample-project))]
|
||||
(is (= "nomnomnom" (first-in xml [:project :groupId]))
|
||||
|
|
Loading…
Reference in a new issue