Skip to content

Commit

Permalink
Merge pull request #215 from liquidz/feature/exclude-range
Browse files Browse the repository at this point in the history
Feature/exclude range
  • Loading branch information
liquidz committed May 1, 2023
2 parents 3cbc8e9 + e23d499 commit ef49951
Show file tree
Hide file tree
Showing 25 changed files with 252 additions and 84 deletions.
2 changes: 2 additions & 0 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ E.g.
--exclude=com.github.liquidz/antq
# Exclude specific version of specified artifact
--exclude=com.github.liquidz/antq@0.13.0
# Exclude version range of specified artifact
--exclude=com.github.liquidz/antq@0.13.x
----

When you specified a version number, antq will report the latest version excluding only the specified version.
Expand Down
26 changes: 26 additions & 0 deletions doc/exclusions.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,29 @@ Otherwise, the following ways are available.
----
{:deps {foo/bar ^:antq/exclude {:mvn/version "..."}}}
----

== Specify a version or version range via metadata

Please repalce `^:antq/exclude` as follows.

[source,clojure]
----
;; Specific version
^{:antq/exclude "1.2.3"}
^{:antq/exclude ["1.2.3" "1.2.4"]}
;; Version range
^{:antq/exclude "1.2.x"}
^{:antq/exclude ["1.2.x" "1.3.x"]}
----

=== Supported version ranges

[cols="50a,50a"]
|===
| Range | Description

| `1.2.x`
| Matches to `1.2.0`, `1.2.1`, etc.

|===
15 changes: 10 additions & 5 deletions src/antq/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
[antq.upgrade.shadow]
[antq.util.exception :as u.ex]
[antq.util.maven :as u.maven]
[antq.util.ver :as u.ver]
[antq.ver :as ver]
[antq.ver.git-sha]
[antq.ver.git-tag-and-sha]
Expand Down Expand Up @@ -109,13 +110,17 @@
(contains? exclude-artifacts (:name dep)))))

(defn remove-skipping-versions
[versions dep-name options]
(let [skip-vers (->> (:exclude options)
[versions dep options]
(let [dep-name (:name dep)
skip-vers (->> (:exclude options)
(map #(str/split % #"@" 2))
(filter #(= dep-name (first %)))
(keep second)
(set))]
(remove skip-vers versions)))
(concat (or (:exclude-versions dep) []))
(distinct))]
(remove (fn [target-version]
(some #(u.ver/in-range? % target-version) skip-vers))
versions)))

(defn using-release-version?
[dep]
Expand Down Expand Up @@ -146,7 +151,7 @@
(let [vers (cond->> (:_versions dep)
(not (ver/under-development? (:version dep)))
(drop-while ver/under-development?))
vers (remove-skipping-versions vers (:name dep) options)
vers (remove-skipping-versions vers dep options)
latest-version (first vers)]
(assoc dep :latest-version latest-version)))

Expand Down
14 changes: 11 additions & 3 deletions src/antq/dep/boot.clj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,14 @@
(defn- exclude?
[v]
(-> (meta v)
(contains? const/deps-exclude-key)))
(get const/deps-exclude-key)
(true?)))

(defn- exclude-version-range
[v]
(-> (meta v)
(get const/deps-exclude-key)
(u.dep/ensure-version-list)))

(defn extract-deps
{:malli/schema [:=>
Expand Down Expand Up @@ -42,7 +49,7 @@
form)
(read-string (str "(list " build-boot-content-str " )")))
(let [repositories (apply hash-map @repos)]
(for [[dep-name version] @deps
(for [[dep-name version :as dep] @deps
:when (and (string? version) (seq version))]
(r/map->Dependency {:project :boot
:type :java
Expand All @@ -51,7 +58,8 @@
(str dep-name)
(str dep-name "/" dep-name))
:version version
:repositories repositories})))))
:repositories repositories
:exclude-versions (seq (exclude-version-range dep))})))))

(defn load-deps
{:malli/schema [:function
Expand Down
15 changes: 12 additions & 3 deletions src/antq/dep/clojure.clj
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,15 @@
[dep]
(-> (second dep)
(meta)
(contains? const/deps-exclude-key)))
(get const/deps-exclude-key)
(true?)))

(defn- exclude-version-range
[dep]
(-> (second dep)
(meta)
(get const/deps-exclude-key)
(u.dep/ensure-version-list)))

(defn extract-deps
{:malli/schema [:=>
Expand All @@ -119,7 +127,7 @@
form)
edn)
(->> @deps
(mapcat (fn [[dep-name opt]]
(mapcat (fn [[dep-name opt :as dep]]
(let [opt (adjust-version-via-deduction dep-name opt)
type-and-version (extract-type-and-version opt)]
(cond
Expand All @@ -138,7 +146,8 @@
(str dep-name)
(str dep-name "/" dep-name))
:repositories (merge cross-project-repositories
(:mvn/repos edn))}
(:mvn/repos edn))
:exclude-versions (seq (exclude-version-range dep))}
(merge type-and-version)
(r/map->Dependency)
(vector))
Expand Down
14 changes: 11 additions & 3 deletions src/antq/dep/leiningen.clj
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,14 @@
(defn- exclude?
[v]
(-> (meta v)
(contains? const/deps-exclude-key)))
(get const/deps-exclude-key)
(true?)))

(defn- exclude-version-range
[v]
(-> (meta v)
(get const/deps-exclude-key)
(u.dep/ensure-version-list)))

(defn extract-deps
{:malli/schema [:=>
Expand Down Expand Up @@ -56,14 +63,15 @@
form)
(read-string (str "(list " project-clj-content-str " )")))
(let [repositories (normalize-repositories @repos)]
(for [[dep-name version] @deps
(for [[dep-name version :as dep] @deps
:when (acceptable-version? version)]
(r/map->Dependency {:project :leiningen
:type :java
:file file-path
:name (normalize-name dep-name)
:version version
:repositories repositories})))))
:repositories repositories
:exclude-versions (seq (exclude-version-range dep))})))))

(defn load-deps
{:malli/schema [:function
Expand Down
14 changes: 11 additions & 3 deletions src/antq/dep/shadow.clj
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,14 @@
(defn- exclude?
[v]
(-> (meta v)
(contains? const/deps-exclude-key)))
(get const/deps-exclude-key)
(true?)))

(defn- exclude-version-range
[v]
(-> (meta v)
(get const/deps-exclude-key)
(u.dep/ensure-version-list)))

(defn extract-deps
{:malli/schema [:=>
Expand All @@ -47,13 +54,14 @@
(swap! deps concat)))
form)
(edn/read-string readers shadow-cljs-edn-content-str))
(for [[dep-name version] @deps
(for [[dep-name version :as dep] @deps
:when (and (string? version) (seq version))]
(r/map->Dependency {:project :shadow-cljs
:type :java
:file file-path
:name (str dep-name)
:version version}))))
:version version
:exclude-versions (seq (exclude-version-range dep))}))))

(defn load-deps
{:malli/schema [:function
Expand Down
7 changes: 5 additions & 2 deletions src/antq/record.clj
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
[:repositories [:maybe [:map-of 'string? ?repository]]]
[:changes-url [:maybe 'string?]]
[:latest-name [:maybe 'string?]]
[:only-newest-version? [:maybe 'boolean?]]])
[:only-newest-version? [:maybe 'boolean?]]
[:exclude-versions [:maybe [:sequential 'string?]]]])

(def ?dependencies
[:sequential ?dependency])
Expand Down Expand Up @@ -52,4 +53,6 @@
;; c.f. https://github.com/clojars/clojars-web/wiki/Verified-Group-Names
latest-name
;; Keep only the newest version in the same file.
only-newest-version?])
only-newest-version?
;; Ignore versions that match the specified version range
exclude-versions])
13 changes: 13 additions & 0 deletions src/antq/util/dep.clj
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,16 @@
;; Skip showing diff URL when POM file is not found
(catch java.io.FileNotFoundException _ nil)))
(def get-scm-url (u.fn/memoize-by get-scm-url* :name))

(defn ensure-version-list
[x]
(cond
(string? x)
[x]

(and (sequential? x)
(every? string? x))
x

:else
[]))
10 changes: 10 additions & 0 deletions src/antq/util/ver.clj
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,13 @@

:else
no-latest-version-error))

(defn in-range?
"e.g. '1.x' matches '1.0.0', '1.1.0' and so on."
[version-range target-version]
(let [re (-> version-range
(str/replace "." "\\.")
(str/replace "\\.x" "\\.+")
(->> (str "^"))
(re-pattern))]
(some? (re-seq re target-version))))
9 changes: 9 additions & 0 deletions src/antq/ver/git_tag_and_sha.clj
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,12 @@
[ex]
(throw ex)))))

(defmethod ver/latest? :git-tag-and-sha
[dep]
(and (:version dep)
(:latest-version dep)
(string? (:version dep))
(string? (:latest-version dep))
(<= 0 (version/version-compare
(u.ver/normalize-version (:version dep))
(u.ver/normalize-version (:latest-version dep))))))
59 changes: 37 additions & 22 deletions test/antq/core_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -118,30 +118,45 @@
:focus ["org.clojure/clojure"]})))))

(t/deftest remove-skipping-versions-test
(t/testing "there are no target to remove"
(t/is (= ["1" "2" "3"]
(sut/remove-skipping-versions ["1" "2" "3"] "foo" {})))
(t/is (= ["1" "2" "3"]
(sut/remove-skipping-versions ["1" "2" "3"] "foo" {:exclude ["foo@4"]}))))

(t/testing "only dep's name is matched"
(t/is (= ["1" "2" "3"]
(sut/remove-skipping-versions ["1" "2" "3"] "foo" {:exclude ["foo"]}))))

(t/testing "only version number is matched"
(t/is (= ["1" "2" "3"]
(sut/remove-skipping-versions ["1" "2" "3"] "foo" {:exclude ["bar@2"]}))))

(t/testing "dep's name and version number are matched"
(t/is (= ["1" "3"]
(sut/remove-skipping-versions ["1" "2" "3"] "foo" {:exclude ["foo@2"]})))
(t/is (= ["1"]
(sut/remove-skipping-versions ["1" "2" "3"] "foo" {:exclude ["foo@2"
(let [dep (r/map->Dependency {:name "foo"})]
(t/testing "there are no target to remove"
(t/is (= ["1" "2" "3"]
(sut/remove-skipping-versions ["1" "2" "3"] dep {})))
(t/is (= ["1" "2" "3"]
(sut/remove-skipping-versions ["1" "2" "3"] dep {:exclude ["foo@4"]}))))

(t/testing "only dep's name is matched"
(t/is (= ["1" "2" "3"]
(sut/remove-skipping-versions ["1" "2" "3"] dep {:exclude ["foo"]}))))

(t/testing "only version number is matched"
(t/is (= ["1" "2" "3"]
(sut/remove-skipping-versions ["1" "2" "3"] dep {:exclude ["bar@2"]}))))

(t/testing "dep's name and version number are matched"
(t/is (= ["1" "3"]
(sut/remove-skipping-versions ["1" "2" "3"] dep {:exclude ["foo@2"]})))
(t/is (= ["1"]
(sut/remove-skipping-versions ["1" "2" "3"] dep {:exclude ["foo@2"
"foo@3"]})))
(t/is (= []
(sut/remove-skipping-versions ["1" "2" "3"] "foo" {:exclude ["foo@1"
(t/is (= []
(sut/remove-skipping-versions ["1" "2" "3"] dep {:exclude ["foo@1"
"foo@2"
"foo@3"]})))))
"foo@3"]}))))

(t/testing "version range"
(let [vers ["1.0.0" "1.0.1" "1.1.0" "1.1.1" "1.2.0" "2.0.0"]]
(t/is (= ["2.0.0"]
(sut/remove-skipping-versions vers dep {:exclude ["foo@1.x"]})))
(t/is (= ["1.1.0" "1.1.1" "1.2.0" "2.0.0"]
(sut/remove-skipping-versions vers dep {:exclude ["foo@1.0.x"]})))
(t/is (= ["1.0.0" "1.0.1" "1.1.0" "1.1.1"]
(sut/remove-skipping-versions vers dep {:exclude ["foo@1.2.x"
"foo@2.x"]})))
(t/is (= ["1.0.0" "1.0.1" "1.1.0" "1.1.1" "1.2.0"]
(sut/remove-skipping-versions vers dep {:exclude ["foo@2.x"]})))
(t/is (= ["1.0.0" "1.0.1" "1.1.0" "1.1.1" "1.2.0" "2.0.0"]
(sut/remove-skipping-versions vers dep {:exclude ["foo@9.x"]})))))))

(t/deftest using-release-version?-test
(t/are [expected in] (= expected (sut/using-release-version?
Expand Down
35 changes: 23 additions & 12 deletions test/antq/dep/babashka_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,28 @@

(t/deftest load-deps-test
(with-redefs [const.project-file/babashka "test_bb.edn"]
(t/is (= [(r/map->Dependency {:type :java
:file "test/resources/dep/test_bb.edn"
:name "bb/core"
:version "1.0.0"
:project :clojure
:repositories nil})
(r/map->Dependency {:type :java
:file "test/resources/dep/test_bb.edn"
:name "with/meta"
:version "2.0.0"
:project :clojure
:repositories nil})]
(t/is (= (->> [(r/map->Dependency {:type :java
:file "test/resources/dep/test_bb.edn"
:name "bb/core"
:version "1.0.0"
:project :clojure})
(r/map->Dependency {:type :java
:file "test/resources/dep/test_bb.edn"
:name "with/meta"
:version "2.0.0"
:project :clojure})
(r/map->Dependency {:type :java
:file "test/resources/dep/test_bb.edn"
:name "meta/range-ignore1"
:version "4.0.0"
:project :clojure
:exclude-versions ["5.x"]})
(r/map->Dependency {:type :java
:file "test/resources/dep/test_bb.edn"
:name "meta/range-ignore2"
:version "5.0.0"
:project :clojure
:exclude-versions ["6.x" "7.x"]})]
(sort-by :name))
(->> (sut/load-deps "test/resources/dep")
(sort-by :name))))))
Loading

0 comments on commit ef49951

Please sign in to comment.