diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index 664766b6..d2271669 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -1,6 +1,13 @@ All notable changes to this project will be documented in this file. This change log follows the conventions of http://keepachangelog.com/[keepachangelog.com]. == Unreleased (dev) +// {{{ +=== Changed +* Bumped build.edn to 0.9.216. + +=== Fixed +* https://github.com/liquidz/antq/issues/217[#217]: Fixed pom.xml upgrader to work correctly when pom.xml contains `exclusions` tag. +// }}} == 2.4.1062 (2023-05-01) // {{{ diff --git a/deps.edn b/deps.edn index 06bab17a..5d9b6d07 100644 --- a/deps.edn +++ b/deps.edn @@ -42,7 +42,7 @@ :main-opts ["-m" "cloverage.coverage" "--ns-exclude-regex" "leiningen.antq"]} :build - {:deps {com.github.liquidz/build.edn {:mvn/version "0.9.203"}} + {:deps {com.github.liquidz/build.edn {:mvn/version "0.9.216"}} :ns-default build} ;; -X diff --git a/src/antq/upgrade/pom.clj b/src/antq/upgrade/pom.clj index cfe7be2d..91c40390 100644 --- a/src/antq/upgrade/pom.clj +++ b/src/antq/upgrade/pom.clj @@ -24,20 +24,37 @@ (defn- target-dependency? [loc group-id artifact-id] (let [{:keys [tag content]} (zip/node loc)] - (if (and tag - (= "groupId" (name tag)) - (= [group-id] content)) - (->> (zip/rights loc) - (filter #(and (tag=? "artifactId") - (= [artifact-id] (:content %)))) - (seq) - (some?)) - false))) + + (cond + ;; group-id + (not (and tag + (= "groupId" (name tag)) + (= [group-id] content))) + false + + ;; artifact-id next to group-id + (not (->> (zip/rights loc) + (filter #(and (= "artifactId" (name (:tag %))) + (= [artifact-id] (:content %)))) + (seq) + (some?))) + false + + ;; exlusion + (-> loc + (zip/up) + (tag-name) + (= "exclusion")) + false + + :else + true))) (defn- version-property-name [loc] - (let [loc (find-version loc) - {:keys [content]} (zip/node loc)] + (let [{:keys [content]} (some-> loc + (find-version) + (zip/node))] (some->> (first content) (re-seq #"\$\{(.+?)\}") (first) diff --git a/test/antq/upgrade/pom_test.clj b/test/antq/upgrade/pom_test.clj index acb01bc7..dec40eac 100644 --- a/test/antq/upgrade/pom_test.clj +++ b/test/antq/upgrade/pom_test.clj @@ -32,6 +32,13 @@ :latest-version "9.0.0" :file (io/file (io/resource "dep/child_pom/child/pom.xml"))})) +(def ^:private dummy-java-with-exclusion-dep + (r/map->Dependency {:project :pom + :type :java + :name "com.bar/bar" + :latest-version "9.0.0" + :file (io/file (io/resource "dep/test_pom_exclusions.xml"))})) + (t/deftest upgrade-dep-test (let [tmp-file (File/createTempFile "upgrade-dep-test" "xml")] (try @@ -74,3 +81,18 @@ (t/deftest upgrade-dep-with-child-pom-test (t/is (nil? (->> dummy-parent-child-java-dep (upgrade/upgrader))))) + +(t/deftest upgrade-dep-with-exclusion-test + (let [tmp-file (File/createTempFile "upgrade-dep-test" "xml")] + (try + (let [from-deps (->> dummy-java-with-exclusion-dep + :file + (dep.pom/extract-deps "")) + _ (->> dummy-java-with-exclusion-dep + (upgrade/upgrader) + (spit tmp-file)) + to-deps (dep.pom/extract-deps "" tmp-file)] + (t/is (= #{{:name "com.bar/bar" :version {:- "1.0.0" :+ "9.0.0"}}} + (h/diff-deps from-deps to-deps)))) + (finally + (.delete tmp-file))))) diff --git a/test/resources/dep/test_pom_exclusions.xml b/test/resources/dep/test_pom_exclusions.xml new file mode 100644 index 00000000..3dbeea44 --- /dev/null +++ b/test/resources/dep/test_pom_exclusions.xml @@ -0,0 +1,26 @@ + + + 4.0.0 + foo + foo + 0.1.0-SNAPSHOT + foo + + + com.foo + foo + 1.0.0 + + + com.bar + bar + + + + + com.bar + bar + 1.0.0 + + +