diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index e361a07c..319b9814 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -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) // {{{ diff --git a/README.adoc b/README.adoc index a71d6a68..f5bd2ecc 100644 --- a/README.adoc +++ b/README.adoc @@ -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 |=== @@ -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. @@ -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 diff --git a/build.clj b/build.clj index 8c102e0f..09b6150a 100644 --- a/build.clj +++ b/build.clj @@ -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/"}] diff --git a/deps.edn b/deps.edn index eaf327f8..7369a00f 100644 --- a/deps.edn +++ b/deps.edn @@ -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} diff --git a/src/antq/core.clj b/src/antq/core.clj index fc87a2f0..3e1a251b 100644 --- a/src/antq/core.clj +++ b/src/antq/core.clj @@ -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] @@ -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? @@ -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) @@ -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)))) diff --git a/src/antq/report/format.clj b/src/antq/report/format.clj index 88319a09..5ae488e1 100644 --- a/src/antq/report/format.clj +++ b/src/antq/report/format.clj @@ -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}}") @@ -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] diff --git a/src/antq/report/table.clj b/src/antq/report/table.clj index 8b5b5cd3..059f7577 100644 --- a/src/antq/report/table.clj +++ b/src/antq/report/table.clj @@ -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 |"))) @@ -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 %))) @@ -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.") @@ -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]}] diff --git a/src/antq/tool.clj b/src/antq/tool.clj index 08115c3e..2ed2e047 100644 --- a/src/antq/tool.clj +++ b/src/antq/tool.clj @@ -46,6 +46,7 @@ - :ignore-locals - :check-clojure-tools - :no-diff + - :changes-in-table - :transitive " [& [options]] (let [options (prepare-options options)] diff --git a/src/antq/upgrade/clojure.clj b/src/antq/upgrade/clojure.clj index 3e124183..d22fad56 100644 --- a/src/antq/upgrade/clojure.clj +++ b/src/antq/upgrade/clojure.clj @@ -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))) @@ -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))) diff --git a/src/antq/util/file.clj b/src/antq/util/file.clj index 117452b5..d6e3c6a1 100644 --- a/src/antq/util/file.clj +++ b/src/antq/util/file.clj @@ -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))) diff --git a/test/antq/dep/clojure_test.clj b/test/antq/dep/clojure_test.clj index 285cc9e5..a77d632b 100644 --- a/test/antq/dep/clojure_test.clj +++ b/test/antq/dep/clojure_test.clj @@ -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 diff --git a/test/antq/upgrade/clojure_test.clj b/test/antq/upgrade/clojure_test.clj index ed4cba2e..1771d891 100644 --- a/test/antq/upgrade/clojure_test.clj +++ b/test/antq/upgrade/clojure_test.clj @@ -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 @@ -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 diff --git a/test/antq/util/file_test.clj b/test/antq/util/file_test.clj index 4b4218b6..29a7bdbe 100644 --- a/test/antq/util/file_test.clj +++ b/test/antq/util/file_test.clj @@ -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 @@ -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]))))) diff --git a/test/resources/dep/test_deps.edn b/test/resources/dep/test_deps.edn index ae2e9a77..9ce58e56 100644 --- a/test/resources/dep/test_deps.edn +++ b/test/resources/dep/test_deps.edn @@ -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"}