diff --git a/build.clj b/build.clj index a63f83c..c62d757 100644 --- a/build.clj +++ b/build.clj @@ -3,7 +3,7 @@ [deps-deploy.deps-deploy :as dd])) (def lib 'org.clojars.some/depo) -(def version "0.3.28") +(def version "0.4.29") (def jar-file (format "target/%s-%s.jar" (name lib) version)) (def class-dir "target/classes") (def url "https://github.com/somecho/depo") diff --git a/src/depo/core.clj b/src/depo/core.clj index 793f9dd..49965dc 100644 --- a/src/depo/core.clj +++ b/src/depo/core.clj @@ -1,13 +1,14 @@ (ns ^:no-doc depo.core (:require [cli-matic.core :refer [run-cmd]] - [depo.readwrite :as rw] - [depo.errors :as e])) + [depo.dispatch :as dd] + [depo.errors :as e] + [depo.zoperations :as zo])) (defn add-cmd [{:keys [_arguments file]}] (let [args _arguments - config-path (if file file (rw/get-config))] + config-path (if file file (dd/get-config))] (if-not (empty? args) - (do (mapv #(rw/apply-operation {:config-path config-path + (do (mapv #(dd/apply-operation {:config-path config-path :id % :operation :add}) args) (println "Done!")) @@ -15,9 +16,9 @@ (defn remove-cmd [{:keys [_arguments file]}] (let [args _arguments - config-path (if file file (rw/get-config))] + config-path (if file file (dd/get-config))] (if-not (empty? args) - (do (mapv #(rw/apply-operation {:config-path config-path + (do (mapv #(dd/apply-operation {:config-path config-path :id % :operation :remove}) args) (println "Done!")) @@ -25,21 +26,21 @@ (defn update-cmd [{:keys [_arguments file]}] (let [args _arguments - config-path (if file file (rw/get-config))] + config-path (if file file (dd/get-config))] (if (empty? args) - (do (mapv #(rw/apply-operation {:config-path config-path + (do (mapv #(dd/apply-operation {:config-path config-path :id % :operation :update}) - (rw/get-all-dependency-names config-path)) + (zo/get-all-dependency-names config-path)) (println "Done!")) - (mapv #(rw/apply-operation {:config-path config-path + (mapv #(dd/apply-operation {:config-path config-path :id % :operation :update}) args)))) (def CONFIGURATION {:command "depo" :description "Manage dependencies for Clojure projects easily" - :version "0.3.28" + :version "0.4.29" :opts [{:as "path to configuration file" :default nil :option "file" diff --git a/src/depo/dispatch.clj b/src/depo/dispatch.clj new file mode 100644 index 0000000..e4fa827 --- /dev/null +++ b/src/depo/dispatch.clj @@ -0,0 +1,86 @@ +(ns depo.dispatch + (:require [clojure.java.io :as io] + [depo.schema :as schema] + [depo.utils :as dutils] + [depo.zoperations :as zo] + [malli.core :as m] + [rewrite-clj.zip :as z] + [zprint.core :as zp])) + +(defn skip-procedure + [{:keys [zloc]} & reason] + (apply println (concat reason ["Skipping."])) + zloc) + +(defn ignore-pass + [{:keys [dep-data deps-type identifier] + :as procedure} f] + (case deps-type + :map (cond + (= "RELEASE" (:mvn/version dep-data)) + (skip-procedure procedure "Version has been set as release.") + (contains? dep-data :local/root) + (skip-procedure procedure identifier "is a local dependency.") + :else (f)) + :vector (f))) + +(defn dispatch + [{:keys [operation dep-exists identifier] + :as procedure}] + (case operation + :add (if dep-exists + (ignore-pass procedure + #(zo/update-dependency procedure)) + (zo/append-dependency procedure)) + :remove (if dep-exists + (zo/remove-dependency procedure) + (skip-procedure identifier "is not a dependency.")) + :update (if dep-exists + (ignore-pass procedure + #(zo/update-dependency procedure)) + (skip-procedure procedure identifier "is not a dependency.")))) + +(defn apply-operation + [{:keys [config-path id operation]}] + (let [config-zip (z/of-string (slurp config-path)) + project-type (dutils/get-project-type config-path) + access-keys [(dutils/create-keys project-type)] + deps (zo/get-deps config-zip access-keys project-type) + {:keys [groupID artifactID]} (dutils/parse id) + deps-type (cond + (z/map? deps) :map + (z/vector? deps) :vector) + identifier (symbol (dutils/create-identifier groupID artifactID deps-type)) + dependency-data (zo/get-dependency-data deps identifier) + procedure {:operation operation + :dep-exists (if dependency-data true false) + :identifier identifier + :project-type project-type + :argument id + :dep-data dependency-data + :deps-type deps-type + :zloc deps}] + (if (m/validate schema/PROCEDURE procedure) + (-> (dispatch procedure) + (z/root-string) + (zp/zprint-str {:parse-string? true + :style :indent-only}) + (as-> new-conf (spit config-path new-conf))) + (println "Failed to validate procedure.")))) + +(defn get-config + "Looks in the current directory for the following files + - deps.edn + - project.clj + - shadow-cljs.edn + - bb.edn + + Returns the a string matching the first file that it finds. + + Returns nil otherwise" + [] + (cond + (.exists (io/file "deps.edn")) "deps.edn" + (.exists (io/file "project.clj")) "project.clj" + (.exists (io/file "shadow-cljs.edn")) "shadow-cljs.edn" + (.exists (io/file "bb.edn")) "bb.edn")) diff --git a/src/depo/readwrite.clj b/src/depo/readwrite.clj deleted file mode 100644 index e501889..0000000 --- a/src/depo/readwrite.clj +++ /dev/null @@ -1,414 +0,0 @@ -(ns depo.readwrite - (:require [clojure.java.io :as io] - [clojure.string :as str] - [depo.resolver :as r] - [malli.core :as m] - [zprint.core :as zp] - [depo.parser :as dp] - [rewrite-clj.zip :as z])) - -(def PROCEDURE [:map - [:zloc [:vector :any]] - [:dep-exists :boolean] - [:identifier :symbol] - [:argument :string] - [:project-type [:enum :lein :shadow :default]] - [:deps-type [:enum :map :vector]] - [:dep-data :any] - [:operation [:enum :add :remove :update]]]) - -(defn create-identifier - [groupID artifactID dep-type] - (case dep-type - :map (str groupID "/" artifactID) - :vector (if (= groupID artifactID) - artifactID - (str groupID "/" artifactID)))) - -(defn create-keys - "- `config-path` - the full path to the config file as a string - - Returns - - `:dependencies` for `:lein` and `:shadow` - - `:deps` for `:default` - " - [project-type] - (case project-type - (or :lein :shadow) :dependencies - :default :deps)) - -(defn get-config - "Looks in the current directory for the following files - - deps.edn - - project.clj - - shadow-cljs.edn - - bb.edn - - Returns the a string matching the first file that it finds. - - Returns nil otherwise" - [] - (cond - (.exists (io/file "deps.edn")) "deps.edn" - (.exists (io/file "project.clj")) "project.clj" - (.exists (io/file "shadow-cljs.edn")) "shadow-cljs.edn" - (.exists (io/file "bb.edn")) "bb.edn")) - -(defn get-dependency-type - [deps] - (cond - (map? deps) :map - (vector? deps) :vector)) - -(defn traverse-zip-map - "- `zloc` - a zipper object created by rewrite-clj - - `keys` - a vector of keys - - Traverses the zipper object using `z/get`, `z` being - the `rewrite-clj.zip` namespace, using `keys` from left - to right" - [zloc keys] - (loop [zloc zloc - keys keys] - (if (not-empty keys) - (recur (z/get zloc (first keys)) - (rest keys)) - zloc))) - -(defn get-project-type - "- `config-path` - the full path to the config file as a string - - Returns - - `:shadow` for shadow-cljs.edn - - `:lein` for project.clj - - `:default` for everything else - " - [config-path] - (let [config-name (-> config-path - (str/split #"/") - (last))] - (case config-name - "shadow-cljs.edn" :shadow - "project.clj" :lein - :default))) - -(defn get-all-dependency-names - [config-path] - (let [zloc (z/of-string (slurp config-path)) - project-type (get-project-type config-path) - deps-key (case project-type - (or :shadow :lein) :dependencies - :deps)] - (-> zloc - (as-> zipper - (case project-type - :lein (-> zipper - (z/find-value z/next deps-key) - (z/next)) - (z/get zipper deps-key))) - (z/string) - (read-string) - (as-> vec-map - (case (get-dependency-type vec-map) - :map (keys vec-map) - :vector (map #(str (first %)) vec-map)))))) - -(defn get-deps - [zloc keys project-type] - (case project-type - :lein (-> (z/find-value zloc z/next (first keys)) - (z/next) - (as-> zpos - (if (not-empty (rest keys)) - (traverse-zip-map zpos (rest keys)) - zpos))) - (traverse-zip-map zloc keys))) - -; (defn dep-exists? -; [zloc identifier] -; (let [deps-type (cond -; (z/map? zloc) :map -; (z/vector? zloc) :vector)] -; (case deps-type -; :map (z/string (z/get zloc identifier)) -; :vector (loop [cur (z/down zloc)] -; (if (= (z/string (z/down cur)) (str identifier)) -; (-> cur z/down z/right z/string) -; (when-not (z/rightmost? cur) -; (recur (z/right cur)))))))) - -(defn get-dependency-data - [zloc identifier] - (let [deps-type (cond - (z/map? zloc) :map - (z/vector? zloc) :vector)] - (case deps-type - :map (-> (z/get zloc identifier) - (z/string) - (as-> s - (if (nil? s) nil (read-string s)))) - :vector (loop [cur (z/down zloc)] - (if (= (z/string (z/down cur)) (str identifier)) - (-> cur z/down z/right z/string read-string) - (when-not (z/rightmost? cur) - (recur (z/right cur)))))))) - -; (defn add-dependency -; [{:keys [zloc keys project-type id]}] -; (let [{:keys [groupID artifactID version]} (r/conform-version id) -; dep-type (case project-type :default :map :vector) -; identifier (symbol (create-identifier groupID -; artifactID -; dep-type)) -; dep-zloc (get-deps zloc keys project-type) -; dep-exists (dep-exists? dep-zloc identifier)] -; (println "Adding" identifier version) -; (-> dep-zloc -; (as-> dz -; (case dep-type -; :map (-> dz -; (as-> dz -; (if dep-exists -; dz -; (-> (z/down dz) -; (z/rightmost) -; (z/insert-newline-right) -; (z/up)))) -; (z/assoc (symbol identifier) {:mvn/version version})) -; :vector (-> dz -; (as-> dz -; (if-not dep-exists -; (-> (z/down dz) -; (z/rightmost) -; (z/insert-newline-right) -; (z/up) -; (z/append-child [identifier version])) -; (loop [cur (z/down dz)] -; (if (= (z/string (z/down cur)) (str identifier)) -; (-> (z/down cur) -; (z/next) -; (z/replace version)) -; (when-not (z/rightmost? cur) -; (recur (z/right cur)))))))))) -; z/root-string))) - -; (defn remove-dependency -; [{:keys [zloc keys project-type id]}] -; (let [{:keys [groupID artifactID version]} (r/conform-version id) -; dep-type (case project-type :default :map :vector) -; identifier (symbol (create-identifier groupID -; artifactID -; dep-type)) -; dep-zloc (get-deps zloc keys project-type) -; dep-exists (dep-exists? dep-zloc identifier)] -; (if-not dep-exists -; (do (println identifier "is not a dependency. Skipping.") -; dep-zloc) -; (do (println "Removing" identifier) -; (-> dep-zloc -; (as-> dep-zloc -; (case dep-type -; :vector (loop [cur (z/down dep-zloc)] -; (if (= (z/string (z/down cur)) (str identifier)) -; (z/remove cur) -; (when-not (z/rightmost? cur) -; (recur (z/right cur))))) -; :map (-> dep-zloc -; (z/get identifier) -; (z/remove) -; (z/remove)))) -; (z/root-string)))))) - -; (defn update-dependency -; [{:keys [zloc keys project-type id]}] -; (let [{:keys [groupID artifactID version]} (r/conform-version id) -; dep-type (case project-type :default :map :vector) -; identifier (symbol (create-identifier groupID -; artifactID -; dep-type)) -; dep-zloc (get-deps zloc keys project-type) -; dep-exists (dep-exists? dep-zloc identifier) -; cur-version (when dep-exists -; (case dep-type -; :map (-> dep-exists -; (z/get :mvn/version) -; z/string -; read-string) -; :vector (-> dep-exists -; z/down -; z/right -; z/string -; read-string)))] -; (if-not dep-exists -; (do (println identifier "is not a dependency. Skipping.") -; (z/root-string dep-zloc)) -; (if (= cur-version version) -; (println identifier version "is up-to-date") -; (do (println "Updating" identifier cur-version "->" version) -; (-> dep-zloc -; (as-> dep-zloc -; (case dep-type -; :vector (-> dep-zloc -; (as-> dz -; (if-not dep-exists -; (-> (z/down dz) -; (z/rightmost) -; (z/insert-newline-right) -; (z/up) -; (z/append-child [identifier version])) -; (loop [cur (z/down dz)] -; (if (= (z/string (z/down cur)) (str identifier)) -; (-> (z/down cur) -; (z/next) -; (z/replace version)) -; (when-not (z/rightmost? cur) -; (recur (z/right cur)))))))) -; :map (-> dep-zloc -; (as-> dz -; (if dep-exists -; dz -; (-> (z/down dz) -; (z/rightmost) -; (z/insert-newline-right) -; (z/up)))) -; (z/assoc (symbol identifier) {:mvn/version version})))) -; (z/root-string))))))) - -; (defn operate -; "- `operation` - `:add`,`:update` or `:remove` -; - `packet` - a map containing the keys `:deps` and `:id` - -; Keys -; - `deps` - either a map or a vector containing the dependencies, -; as defined in `project.clj` or `deps.edn` files -; - `id` - the artifact identifier, which follows the -; `[groupID/]artifactID[@version]` schema - -; Operates on the given packet and returns a new set of dependencies, -; which is either a map or vec, depending on what was given to `:deps`" -; [operation packet] -; (case operation -; :add (add-dependency packet) -; :remove (remove-dependency packet) -; :update (update-dependency packet))) - -(defn append-dependency - [{:keys [argument deps-type identifier zloc]}] - (let [{:keys [version]} (r/conform-version argument)] - (println "Adding" identifier version) - (case deps-type - :map (-> zloc - (z/down) - (z/rightmost) - (z/insert-newline-right) - (z/up) - (z/assoc identifier {:mvn/version version})) - :vector (-> zloc - (z/down) - (z/rightmost) - (z/insert-newline-right) - (z/up) - (z/append-child [identifier version]))))) - -(defn update-dependency - [{:keys [argument deps-type identifier zloc dep-data]}] - (let [{:keys [version]} (r/conform-version argument) - current-version (case deps-type - :map (:mvn/version dep-data) - :vector dep-data)] - (println "Updating" identifier current-version "->" version) - (case deps-type - :map (z/assoc zloc identifier {:mvn/version version}) - :vector (loop [cur (z/down zloc)] - (if (= (z/string (z/down cur)) (str identifier)) - (-> (z/down cur) - (z/next) - (z/replace version)) - (when-not (z/rightmost? cur) - (recur (z/right cur)))))))) -(defn skip-procedure - [{:keys [zloc]} & reason] - (apply println (concat reason ["Skipping."])) - zloc) - -(defn ignore-pass - [{:keys [dep-data deps-type identifier] - :as procedure} f] - (case deps-type - :map (cond - (= "RELEASE" (:mvn/version dep-data)) - (skip-procedure procedure "Version has been set as release.") - (contains? dep-data :local/root) - (skip-procedure procedure identifier "is a local dependency.") - :else (f)) - :vector (f))) - -(defn remove-dependency - [{:keys [deps-type identifier zloc]}] - (println "Removing" identifier) - (case deps-type - :map (-> zloc - (z/get identifier) - (z/remove) - (z/remove)) - :vector (loop [cur (z/down zloc)] - (if (= (z/string (z/down cur)) (str identifier)) - (z/remove cur) - (when-not (z/rightmost? cur) - (recur (z/right cur))))))) - -(defn dispatch - [{:keys [operation dep-exists identifier] - :as procedure}] - (case operation - :add (if dep-exists - (ignore-pass procedure - #(update-dependency procedure)) - (append-dependency procedure)) - :remove (if dep-exists - (remove-dependency procedure) - (skip-procedure identifier "is not a dependency.")) - :update (if dep-exists - (ignore-pass procedure - #(update-dependency procedure)) - (skip-procedure procedure identifier "is not a dependency.")))) - -(defn apply-operation - [{:keys [config-path id operation]}] - (let [config-zip (z/of-string (slurp config-path)) - project-type (get-project-type config-path) - access-keys [(create-keys project-type)] - deps (get-deps config-zip access-keys project-type) - {:keys [groupID artifactID]} (dp/parse id) - deps-type (cond - (z/map? deps) :map - (z/vector? deps) :vector) - identifier (symbol (create-identifier groupID artifactID deps-type)) - dependency-data (get-dependency-data deps identifier) - procedure {:operation operation - :dep-exists (if dependency-data true false) - :identifier identifier - :project-type project-type - :argument id - :dep-data dependency-data - :deps-type deps-type - :zloc deps}] - (m/validate PROCEDURE procedure) - (-> (dispatch procedure) - (z/root-string) - (zp/zprint-str {:parse-string? true - :style :indent-only}) - (as-> new-conf (spit config-path new-conf))))) - ; (println)))) - ; (-> (operate operation {:id id - ; :zloc config-zip - ; :project-type project-type - ; :keys access-keys}) - ; (zp/zprint-str {:parse-string? true - ; :style :indent-only}) - ; (as-> newconf (spit config-path newconf))))) - ; println))) - -; (apply-operation {:config-path "test/resources/input/bb.edn" -; :id "reagent" -; :operation :add}) diff --git a/src/depo/resolver.clj b/src/depo/resolver.clj index 1e08cad..086430c 100644 --- a/src/depo/resolver.clj +++ b/src/depo/resolver.clj @@ -1,9 +1,9 @@ (ns depo.resolver (:require [clojure.string :as s] [clj-http.client :as client] - [depo.parser :as p] [depo.errors :as e] - [depo.validate :as v])) + [depo.utils :as dutils] + [depo.schema :as schema])) (def ^:no-doc repos {:clojars "https://repo.clojars.org" :central "https://repo1.maven.org/maven2"}) @@ -25,13 +25,13 @@ Returns a vec containing versioning metadata, which includes release version, all published versions and, if it exists, latest version." [arg] - (let [dep-map (p/parse arg) + (let [dep-map (dutils/parse arg) path (form-path dep-map) urls (map #(s/join "/" [(val %) path "maven-metadata.xml"]) repos) metadata (-> (try (client/get (first urls)) (catch Exception _ (client/get (second urls)))) :body - p/xml->map)] + dutils/xml->map)] (-> (:content metadata) (as-> content (filter #(= (:tag %) :versioning) content)) @@ -87,8 +87,8 @@ If a version is provided, it will check if the version exists. If it doesn't, it will default to use the release version." [arg] - (let [dep-map (p/parse arg)] - (if-not (v/valid-dependency-map? dep-map) + (let [dep-map (dutils/parse arg)] + (if-not (schema/valid-dependency-map? dep-map) (println (e/err :invalid-argument {:argument arg})) (if-not (:version dep-map) (assoc dep-map :version (get-release-version arg)) diff --git a/src/depo/validate.clj b/src/depo/schema.clj similarity index 62% rename from src/depo/validate.clj rename to src/depo/schema.clj index 5e04593..7ae1fa9 100644 --- a/src/depo/validate.clj +++ b/src/depo/schema.clj @@ -1,6 +1,16 @@ -(ns depo.validate +(ns depo.schema (:require [malli.core :as m])) +(def PROCEDURE [:map + [:zloc [:vector :any]] + [:dep-exists :boolean] + [:identifier :symbol] + [:argument :string] + [:project-type [:enum :lein :shadow :default]] + [:deps-type [:enum :map :vector]] + [:dep-data :any] + [:operation [:enum :add :remove :update]]]) + (defn valid-id? "Returns `true` if the groupID or artifactID are valid IDs. `false` otherwise." @@ -12,7 +22,6 @@ [ver] (m/validate [:re #"^(\d+\.)+\d[/-]?[a-zA-Z0-9]*$"] ver)) -(valid-version? "0.11.1-alpha") (defn valid-dependency-map? "Given a map with dependency coordinate data, return true if valid." [{:keys [groupID artifactID version]}] diff --git a/src/depo/parser.clj b/src/depo/utils.clj similarity index 53% rename from src/depo/parser.clj rename to src/depo/utils.clj index 815364e..85eaa7b 100644 --- a/src/depo/parser.clj +++ b/src/depo/utils.clj @@ -1,7 +1,44 @@ -(ns depo.parser +(ns depo.utils (:require [clojure.string :as s] [clojure.xml :as xml])) +(defn create-identifier + [groupID artifactID dep-type] + (case dep-type + :map (str groupID "/" artifactID) + :vector (if (= groupID artifactID) + artifactID + (str groupID "/" artifactID)))) + +(defn create-keys + "- `config-path` - the full path to the config file as a string + + Returns + - `:dependencies` for `:lein` and `:shadow` + - `:deps` for `:default` + " + [project-type] + (case project-type + (or :lein :shadow) :dependencies + :default :deps)) + +(defn get-project-type + "- `config-path` - the full path to the config file as a string + + Returns + - `:shadow` for shadow-cljs.edn + - `:lein` for project.clj + - `:default` for everything else + " + [config-path] + (let [config-name (-> config-path + (s/split #"/") + (last))] + (case config-name + "shadow-cljs.edn" :shadow + "project.clj" :lein + :default))) + (defn parse "Given a dependency string that follows the following schema `[groupID/]artifactID[@version]` diff --git a/src/depo/zoperations.clj b/src/depo/zoperations.clj new file mode 100644 index 0000000..76577c0 --- /dev/null +++ b/src/depo/zoperations.clj @@ -0,0 +1,124 @@ +(ns depo.zoperations + "Zipper based operations." + (:require [clojure.string :as str] + [depo.resolver :as r] + [depo.utils :as dutils] + [rewrite-clj.zip :as z])) + +(defn get-dependency-type + [deps] + (cond + (map? deps) :map + (vector? deps) :vector)) + +(defn traverse-zip-map + "- `zloc` - a zipper object created by rewrite-clj + - `keys` - a vector of keys + + Traverses the zipper object using `z/get`, `z` being + the `rewrite-clj.zip` namespace, using `keys` from left + to right" + [zloc keys] + (loop [zloc zloc + keys keys] + (if (not-empty keys) + (recur (z/get zloc (first keys)) + (rest keys)) + zloc))) + +(defn get-all-dependency-names + [config-path] + (let [zloc (z/of-string (slurp config-path)) + project-type (dutils/get-project-type config-path) + deps-key (case project-type + (or :shadow :lein) :dependencies + :deps)] + (-> zloc + (as-> zipper + (case project-type + :lein (-> zipper + (z/find-value z/next deps-key) + (z/next)) + (z/get zipper deps-key))) + (z/string) + (read-string) + (as-> vec-map + (case (get-dependency-type vec-map) + :map (keys vec-map) + :vector (map #(str (first %)) vec-map)))))) + +(defn get-deps + [zloc keys project-type] + (case project-type + :lein (-> (z/find-value zloc z/next (first keys)) + (z/next) + (as-> zpos + (if (not-empty (rest keys)) + (traverse-zip-map zpos (rest keys)) + zpos))) + (traverse-zip-map zloc keys))) + +(defn get-dependency-data + [zloc identifier] + (let [deps-type (cond + (z/map? zloc) :map + (z/vector? zloc) :vector)] + (case deps-type + :map (-> (z/get zloc identifier) + (z/string) + (as-> s + (if (nil? s) nil (read-string s)))) + :vector (loop [cur (z/down zloc)] + (if (= (z/string (z/down cur)) (str identifier)) + (-> cur z/down z/right z/string read-string) + (when-not (z/rightmost? cur) + (recur (z/right cur)))))))) + +(defn append-dependency + [{:keys [argument deps-type identifier zloc]}] + (let [{:keys [version]} (r/conform-version argument)] + (println "Adding" identifier version) + (case deps-type + :map (-> zloc + (z/down) + (z/rightmost) + (z/insert-newline-right) + (z/up) + (z/assoc identifier {:mvn/version version})) + :vector (-> zloc + (z/down) + (z/rightmost) + (z/insert-newline-right) + (z/up) + (z/append-child [identifier version]))))) + +(defn update-dependency + [{:keys [argument deps-type identifier zloc dep-data]}] + (let [{:keys [version]} (r/conform-version argument) + current-version (case deps-type + :map (:mvn/version dep-data) + :vector dep-data)] + (println "Updating" identifier current-version "->" version) + (case deps-type + :map (z/assoc zloc identifier {:mvn/version version}) + :vector (loop [cur (z/down zloc)] + (if (= (z/string (z/down cur)) (str identifier)) + (-> (z/down cur) + (z/next) + (z/replace version)) + (when-not (z/rightmost? cur) + (recur (z/right cur)))))))) + +(defn remove-dependency + [{:keys [deps-type identifier zloc]}] + (println "Removing" identifier) + (case deps-type + :map (-> zloc + (z/get identifier) + (z/remove) + (z/remove)) + :vector (loop [cur (z/down zloc)] + (if (= (z/string (z/down cur)) (str identifier)) + (z/remove cur) + (when-not (z/rightmost? cur) + (recur (z/right cur))))))) diff --git a/test/depo/depo_e2e_test.clj b/test/depo/depo_e2e_test.clj index beb6513..8bea8e3 100644 --- a/test/depo/depo_e2e_test.clj +++ b/test/depo/depo_e2e_test.clj @@ -25,7 +25,7 @@ (defn delete-directories [] (for [{:keys [name]} tests] - (delete-directory (io/file (str "test/resources/temp/" name "/FILE"))))) + (delete-directory (io/file (str "test/resources/temp/" name))))) (defn before-after [f] (setup-directories) diff --git a/test/depo/parser_unit_test.clj b/test/depo/parser_unit_test.clj deleted file mode 100644 index 5827b36..0000000 --- a/test/depo/parser_unit_test.clj +++ /dev/null @@ -1,30 +0,0 @@ -(ns depo.parser-unit-test - (:require [clojure.test :refer [testing deftest is]] - [depo.parser :as p])) - -(deftest parse - (testing "artifactID only" - (is (= (p/parse "reagent") {:groupID "reagent" - :artifactID "reagent" - :version nil}))) - (testing "groupID and artifactID only" - (is (= (p/parse "org.clojure/clojure") {:groupID "org.clojure" - :artifactID "clojure" - :version nil}))) - (testing "artifactID and version only" - (is (= (p/parse "emotion-cljs@0.2.0") {:groupID "emotion-cljs" - :artifactID "emotion-cljs" - :version "0.2.0"}))) - (testing "artifactID and version with qualifier only" - (is (= (p/parse "org.clojure/clojure@1.11.1-rc1") {:groupID "org.clojure" - :artifactID "clojure" - :version "1.11.1-rc1"}))) - (testing "groupID, artifactID and version" - (is (= (p/parse "org.clojure/data.xml@0.0.8") {:groupID "org.clojure" - :artifactID "data.xml" - :version "0.0.8"}))) - (testing "groupID, artifactID and version with qualifier" - (is (= (p/parse "org.clojure/data.xml@0.0.1-beta1") {:groupID "org.clojure" - :artifactID "data.xml" - :version "0.0.1-beta1"})))) - diff --git a/test/depo/utils_unit_test.clj b/test/depo/utils_unit_test.clj new file mode 100644 index 0000000..5a72b28 --- /dev/null +++ b/test/depo/utils_unit_test.clj @@ -0,0 +1,30 @@ +(ns depo.utils-unit-test + (:require [clojure.test :refer [testing deftest is]] + [depo.utils :as dutils])) + +(deftest parse + (testing "artifactID only" + (is (= (dutils/parse "reagent") {:groupID "reagent" + :artifactID "reagent" + :version nil}))) + (testing "groupID and artifactID only" + (is (= (dutils/parse "org.clojure/clojure") {:groupID "org.clojure" + :artifactID "clojure" + :version nil}))) + (testing "artifactID and version only" + (is (= (dutils/parse "emotion-cljs@0.2.0") {:groupID "emotion-cljs" + :artifactID "emotion-cljs" + :version "0.2.0"}))) + (testing "artifactID and version with qualifier only" + (is (= (dutils/parse "org.clojure/clojure@1.11.1-rc1") {:groupID "org.clojure" + :artifactID "clojure" + :version "1.11.1-rc1"}))) + (testing "groupID, artifactID and version" + (is (= (dutils/parse "org.clojure/data.xml@0.0.8") {:groupID "org.clojure" + :artifactID "data.xml" + :version "0.0.8"}))) + (testing "groupID, artifactID and version with qualifier" + (is (= (dutils/parse "org.clojure/data.xml@0.0.1-beta1") {:groupID "org.clojure" + :artifactID "data.xml" + :version "0.0.1-beta1"})))) +