Skip to content

Commit

Permalink
fix: Fix to skip dependency exclusions in pom.xml
Browse files Browse the repository at this point in the history
cf. #217
  • Loading branch information
liquidz committed May 2, 2023
1 parent d53ee78 commit da6f5af
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 11 deletions.
39 changes: 28 additions & 11 deletions src/antq/upgrade/pom.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
22 changes: 22 additions & 0 deletions test/antq/upgrade/pom_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)))))

0 comments on commit da6f5af

Please sign in to comment.