Skip to content

Commit

Permalink
Merge pull request #219 from liquidz/dev
Browse files Browse the repository at this point in the history
Next release
  • Loading branch information
liquidz committed May 3, 2023
2 parents 2ca894e + 7f7aa9d commit 7cb4eb1
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 12 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
@@ -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)
// {{{
Expand Down
2 changes: 1 addition & 1 deletion deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
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)))))
26 changes: 26 additions & 0 deletions test/resources/dep/test_pom_exclusions.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>foo</groupId>
<artifactId>foo</artifactId>
<version>0.1.0-SNAPSHOT</version>
<name>foo</name>
<dependencies>
<dependency>
<groupId>com.foo</groupId>
<artifactId>foo</artifactId>
<version>1.0.0</version>
<exclusions>
<exclusion>
<groupId>com.bar</groupId>
<artifactId>bar</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.bar</groupId>
<artifactId>bar</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
</project>

0 comments on commit 7cb4eb1

Please sign in to comment.