Skip to content

Commit

Permalink
Merge pull request #243 from liquidz/dev
Browse files Browse the repository at this point in the history
Next release
  • Loading branch information
liquidz authored Jan 2, 2024
2 parents eb44043 + 458a328 commit bea4763
Show file tree
Hide file tree
Showing 14 changed files with 174 additions and 28 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
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)
// {{{
=== Added
* https://github.com/liquidz/antq/issues/240[#240]: Added `--changes-in-table` option.
** Show changes URLs in table. This option is only available for `table` reporter.

=== Changed
* Bumped data.json to 2.5.0.
* Bumped tools.deps to 0.18.1385.

=== Fixed
* https://github.com/liquidz/antq/issues/241[#241]: Fixed upgrading process to be able to handle destructed map.
** e.g. `#:mvn{:version "x.y.z"}`
* Fixed `--directory` option to distinct same directories.
// }}}

== 2.7.1147 (2023-12-10)
// {{{
Expand Down
12 changes: 11 additions & 1 deletion README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,10 @@ The diff URL for Version Control System. (Nullable)

|===

Antq uses https://github.com/athos/pogonos[Pogonos] as a template engine, so you can use http://mustache.github.io/[Mustache] features.

e.g. `{{name}}{{#latest-name}} -> {{.}}{{/latest-name}}`

=== --reporter=REPORTER

|===
Expand Down Expand Up @@ -311,6 +315,12 @@ Please use `--no-changes` instead.

Skip checking diff between deps' versions. Disabled by default.

=== --changes-in-table

Show changes URLs in table.
This option is only available for `table` reporter.
Disabed by default.

=== --transitive

Scan outdated transitive dependencies. Disabled by default.
Expand Down Expand Up @@ -344,7 +354,7 @@ Otherwise, it may take a long time for the results to be reported.

== License

Copyright © 2020-2023 https://twitter.com/uochan[Masashi Iizuka]
Copyright © 2020-2024 https://scrapbox.io/uochan/uochan[Masashi Iizuka]

This program and the accompanying materials are made available under the
terms of the Eclipse Public License 2.0 which is available at
Expand Down
2 changes: 1 addition & 1 deletion build.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

(def ^:private config
{:lib 'com.github.liquidz/antq
:version "2.7.{{git/commit-count}}"
:version "2.8.{{git/commit-count}}"
:description "Point out your outdated dependencies"
:licenses [{:name "Eclipse Public License - v 2.0"
:url "https://www.eclipse.org/legal/epl-2.0/"}]
Expand Down
7 changes: 4 additions & 3 deletions deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
org.clojure/data.zip {:mvn/version "1.0.0"}
org.clojure/tools.cli {:mvn/version "1.0.219"}
org.clojure/core.async {:mvn/version "1.6.681"}
org.clojure/tools.deps {:mvn/version "0.18.1374"}
org.clojure/data.json {:mvn/version "2.4.0"}
org.clojure/tools.deps {:mvn/version "0.18.1394"}
org.clojure/data.json {:mvn/version "2.5.0"}
clj-commons/clj-yaml {:mvn/version "1.0.27"}
version-clj/version-clj {:mvn/version "2.0.2"}
rewrite-clj/rewrite-clj {:mvn/version "1.1.47"}
com.github.liquidz/rewrite-indented {:mvn/version "0.2.36"}}
com.github.liquidz/rewrite-indented {:mvn/version "0.2.36"}
pogonos/pogonos {:mvn/version "0.2.1"}}

:tools/usage
{:ns-default antq.tool}
Expand Down
9 changes: 7 additions & 2 deletions src/antq/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
[antq.upgrade.pom]
[antq.upgrade.shadow]
[antq.util.exception :as u.ex]
[antq.util.file :as u.file]
[antq.util.maven :as u.maven]
[antq.util.ver :as u.ver]
[antq.ver :as ver]
Expand Down Expand Up @@ -97,6 +98,7 @@
[nil "--check-clojure-tools"]
[nil "--no-diff"] ; deprecated (for backward compatibility)
[nil "--no-changes"]
[nil "--changes-in-table"]
[nil "--transitive"]])

(defn skip-artifacts?
Expand Down Expand Up @@ -292,7 +294,7 @@
(defn main*
[options errors]
(u.maven/initialize-proxy-setting!)
(let [options (cond-> options
(let [options (cond-> (update options :directory u.file/distinct-directory)
;; Force "format" reporter when :error-format is specified
(some? (:error-format options)) (assoc :reporter "format"))
deps (and (not errors)
Expand Down Expand Up @@ -325,6 +327,9 @@

(defn -main
[& args]
(let [{:keys [options errors]} (cli/parse-opts args cli-options)]
(let [{:keys [options errors]} (cli/parse-opts args cli-options)
options (update options :error-format #(some-> %
(str/replace #"\\n" "\n")
(str/replace #"\\t" "\t")))]
(binding [log/*verbose* (:verbose options false)]
(main* options errors))))
7 changes: 2 additions & 5 deletions src/antq/report/format.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[antq.report :as report]
[antq.util.dep :as u.dep]
[antq.util.ver :as u.ver]
[clojure.string :as str]))
[pogonos.core :as pg]))

(def ^:private default-outdated-message-format
"{{name}} {{version}} is outdated. Latest version is {{latest-version}}. {{changes-url}}")
Expand All @@ -21,10 +21,7 @@
;; NOTE Add diff-url for backward compatibility
:diff-url (:changes-url dep))
(select-keys [:file :name :version :latest-version :message :diff-url :changes-url :latest-name]))]
(reduce-kv (fn [s k v]
(str/replace s (str "{{" (name k) "}}") (or v "")))
format-string
dep)))
(pg/render-string format-string dep)))

(defmethod report/reporter "format"
[deps options]
Expand Down
32 changes: 18 additions & 14 deletions src/antq/report/table.clj
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
(->> columns
(map-indexed (fn [i column]
(format (str "%-" (nth max-lengths i) "s")
(get dep column))))
(or (get dep column)
""))))
(str/join " | ")
(format "| %s |")))

Expand All @@ -43,8 +44,10 @@
s)))

(defn- print-table
[deps]
(let [columns [:file :name :current :latest]
[options deps]
(let [columns (cond-> [:file :name :current :latest]
(:changes-in-table options)
(conj :changes-url))
max-lengths (map #(calc-max-length % deps) columns)]
(println (generate-row (->> columns
(map #(vector % (str %)))
Expand All @@ -58,7 +61,7 @@
(println (generate-row dep columns max-lengths)))))

(defmethod report/reporter "table"
[deps _options]
[deps options]
;; Show table
(if (empty? deps)
(println "All dependencies are up-to-date.")
Expand All @@ -76,18 +79,19 @@
(set/rename-keys % {:version :current
latest-key :latest})))
(map #(update % :name (partial apply-level (or (:level %) 0))))
(print-table))))
(print-table options))))

;; Show changes URLs
(let [urls (->> deps
(filter :latest-version)
(sort u.dep/compare-deps)
(keep :changes-url)
(distinct))]
(when (seq urls)
(println "\nAvailable changes:")
(doseq [u urls]
(println "-" u)))))
(when-not (:changes-in-table options)
(let [urls (->> deps
(filter :latest-version)
(sort u.dep/compare-deps)
(keep :changes-url)
(distinct))]
(when (seq urls)
(println "\nAvailable changes:")
(doseq [u urls]
(println "-" u))))))

(defn- progress-text
[{:keys [width total-count current-count]}]
Expand Down
1 change: 1 addition & 0 deletions src/antq/tool.clj
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
- :ignore-locals <boolean>
- :check-clojure-tools <boolean>
- :no-diff <boolean>
- :changes-in-table <boolean>
- :transitive <boolean>"
[& [options]]
(let [options (prepare-options options)]
Expand Down
12 changes: 11 additions & 1 deletion src/antq/upgrade/clojure.clj
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@
(and (in-deps? loc)
(not (ignoring-meta? (z/right loc)))))

(defn- down-considering-namespaced-map
"cf. https://github.com/clj-commons/rewrite-clj/blob/main/doc/01-user-guide.adoc#impact-of-namespaced-map-context-on-keywords-and-symbols"
[loc]
(if (z/namespaced-map? loc)
(-> loc
(z/down)
(z/rightmost)
(z/down))
(z/down loc)))

(defmulti replace-versions
(fn [_loc version-checked-dep]
(:type version-checked-dep)))
Expand Down Expand Up @@ -87,7 +97,7 @@
(z/right)
;; TODO check antq/ignore
(skip-meta)
(z/down)
(down-considering-namespaced-map)
(replace-versions version-checked-dep))
(z/next loc))
(z/next loc)))
Expand Down
16 changes: 16 additions & 0 deletions src/antq/util/file.clj
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,19 @@
const.project-file/maven :pom
const.project-file/shadow-cljs :shadow-cljs
::unknown))

(defn distinct-directory
[dirs]
(:result
(reduce
(fn [{:as accm :keys [fixme]} dir]
(let [path (if (str/starts-with? dir "~")
dir
(normalize-path (.getAbsolutePath (io/file dir))))]
(if (contains? fixme path)
accm
(-> accm
(update :fixme conj path)
(update :result conj dir)))))
{:fixme #{} :result []}
dirs)))
8 changes: 7 additions & 1 deletion test/antq/dep/clojure_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,13 @@
:repositories nil})
(java-dependency {:name "local/nested-core" :version "8.8.8"
:file (.getAbsolutePath (io/file (io/resource "dep/local/nested/test_deps.edn")))
:repositories nil})}
:repositories nil})
(java-dependency {:name "namespaced/mvn" :version "1.0.0"})
(git-sha-dependency {:name "namespaced/sha" :version "1234567890abcdefghijklmnopqrstuvwxyz1234"
:extra {:url "https://github.com/example/git-sha.git"}})
(git-tag-dependency {:name "namespaced/tag-and-sha" :version "v1.2.3"
:extra {:url "https://github.com/example/tag-short.git"
:sha "123abcd"}})}
(set deps))))))

(t/deftest extract-deps-cross-project-configuration-test
Expand Down
62 changes: 62 additions & 0 deletions test/antq/upgrade/clojure_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,28 @@
:latest-version "9.9.9"
:file (io/resource "dep/test_deps.edn")}))

(def ^:private dummy-namespaced-mvn-dep
(r/map->Dependency {:project :clojure
:type :java
:name "namespaced/mvn"
:latest-version "9.0.0"
:file (io/resource "dep/test_deps.edn")}))

(def ^:private dummy-namespaced-sha-dep
(r/map->Dependency {:project :clojure
:type :git-sha
:name "namespaced/sha"
:latest-version "new-sha"
:file (io/resource "dep/test_deps.edn")}))

(def ^:private dummy-namespaced-tag-and-sha-dep
(r/map->Dependency {:project :clojure
:type :git-tag-and-sha
:name "namespaced/tag-and-sha"
:latest-version "v9.9.9"
:file (io/resource "dep/test_deps.edn")
:extra {:sha "123abcd"}}))

(t/deftest upgrade-dep-test
(t/testing "java"
(let [from-deps (->> dummy-java-dep
Expand Down Expand Up @@ -169,6 +191,46 @@
(t/is (= #{{:name "full-meta/full-meta" :version {:- "2.6.9" :+ "9.0.0"}}}
(h/diff-deps from-deps to-deps)))))

(t/testing "namespaced mvn"
(let [from-deps (->> dummy-namespaced-mvn-dep
:file
(slurp)
(dep.clj/extract-deps ""))
to-deps (->> dummy-namespaced-mvn-dep
(upgrade/upgrader)
(dep.clj/extract-deps ""))]
(t/is (= #{{:name "namespaced/mvn" :version {:- "1.0.0" :+ "9.0.0"}}}
(h/diff-deps from-deps to-deps)))))

(t/testing "namespaced git-sha"
(let [from-deps (->> dummy-namespaced-sha-dep
:file
(slurp)
(dep.clj/extract-deps ""))
to-deps (->> dummy-namespaced-sha-dep
(upgrade/upgrader)
(dep.clj/extract-deps ""))]
(t/is (= #{{:name "namespaced/sha"
:url "https://github.com/example/git-sha.git"
:version {:- "1234567890abcdefghijklmnopqrstuvwxyz1234"
:+ "new-sha"}}}
(h/diff-deps from-deps to-deps)))))

(t/testing "namespaced git-tag-and-sha"
(with-redefs [u.git/tag-sha-by-ls-remote (constantly "9876543210abcdefghijklmnopqrstuvwxyz1234")]
(let [from-deps (->> dummy-namespaced-tag-and-sha-dep
:file
(slurp)
(dep.clj/extract-deps ""))
to-deps (->> dummy-namespaced-tag-and-sha-dep
(upgrade/upgrader)
(dep.clj/extract-deps ""))]
(t/is (= #{{:name "namespaced/tag-and-sha"
:url "https://github.com/example/tag-short.git"
:version {:- "v1.2.3" :+ "v9.9.9"}
:sha {:- "123abcd" :+ "9876543"}}}
(h/diff-deps from-deps to-deps))))))

(t/testing "no corresponding value"
(let [from-deps (->> dummy-no-version-dep
:file
Expand Down
13 changes: 13 additions & 0 deletions test/antq/util/file_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
(:require
[antq.util.env :as u.env]
[antq.util.file :as sut]
[clojure.java.io :as io]
[clojure.test :as t]))

(t/deftest normalize-path-test
Expand All @@ -26,3 +27,15 @@
:leiningen "/path/to/project.clj"
:shadow-cljs "/path/to/shadow-cljs.edn"
::sut/unknown "/path/to/invalid"))

(t/deftest distinct-directory-test
(let [absolute-path (.getAbsolutePath (io/file "."))
relative-path (sut/normalize-path absolute-path)]
(t/is (= ["a" "b" "c"]
(sut/distinct-directory ["a" "b" "c"])))
(t/is (= ["."]
(sut/distinct-directory ["." absolute-path relative-path])))
(t/is (= [absolute-path]
(sut/distinct-directory [absolute-path relative-path "."])))
(t/is (= ["a" absolute-path]
(sut/distinct-directory ["a" absolute-path relative-path])))))
7 changes: 7 additions & 0 deletions test/resources/dep/test_deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@
short-meta ^:foo/bar {:mvn/version "2.5.8"}
full-meta ^{:foo/bar true} {:mvn/version "2.6.9"}

;; namespaced map
namespaced/mvn #:mvn{:version "1.0.0"}
namespaced/sha #:git{:url "https://github.com/example/git-sha.git"
:sha "1234567890abcdefghijklmnopqrstuvwxyz1234"}
namespaced/tag-and-sha #:git{:url "https://github.com/example/tag-short.git"
:tag "v1.2.3" :sha "123abcd"}

;; should be ignored
local-repo/non-existing {:local/root "/path/to/non-existing-local/repo"}
meta-ignore ^:antq/exclude {:mvn/version "3.5.8"}
Expand Down

0 comments on commit bea4763

Please sign in to comment.