/src/clojure-tools-deps/test/clojure/tools/deps/alpha/extensions/faken.clj

https://github.com/arrdem/katamari · Clojure · 64 lines · 39 code · 14 blank · 11 comment · 0 complexity · 97054ffc7389293ec4242758c9ea2e3a MD5 · raw file

  1. ; Copyright (c) Rich Hickey. All rights reserved.
  2. ; The use and distribution terms for this software are covered by the
  3. ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
  4. ; which can be found in the file epl-v10.html at the root of this distribution.
  5. ; By using this software in any fashion, you are agreeing to be bound by
  6. ; the terms of this license.
  7. ; You must not remove this notice, or any other, from this software.
  8. (ns clojure.tools.deps.alpha.extensions.faken
  9. (:require
  10. [clojure.java.io :as jio]
  11. [clojure.string :as str]
  12. [clojure.tools.deps.alpha.extensions :as ext])
  13. (:import
  14. ;; maven-resolver-util
  15. [org.eclipse.aether.util.version GenericVersionScheme]))
  16. ;; Fake Maven extension for testing dependency resolution
  17. ;; Use the functions to construct a faux Maven repo
  18. ;; {lib {coord [dep1 ...]}}
  19. (def ^:dynamic repo {})
  20. (defmacro with-libs
  21. [libs & body]
  22. `(binding [repo ~libs]
  23. ~@body))
  24. (defmethod ext/dep-id :fkn
  25. [lib coord config]
  26. (select-keys coord [:fkn/version :classifier]))
  27. (defmethod ext/manifest-type :fkn
  28. [lib coord config]
  29. {:deps/manifest :fkn})
  30. (defonce ^:private version-scheme (GenericVersionScheme.))
  31. (defn- parse-version [{version :fkn/version :as coord}]
  32. (.parseVersion ^GenericVersionScheme version-scheme ^String version))
  33. (defmethod ext/compare-versions [:fkn :fkn]
  34. [lib coord-x coord-y config]
  35. (apply compare (map parse-version [coord-x coord-y])))
  36. (defmethod ext/coord-deps :fkn
  37. [lib coord _manifest config]
  38. (get-in repo [lib (ext/dep-id lib coord config)]))
  39. (defn make-path
  40. [lib {:keys [fkn/version]}]
  41. (str "REPO/" (namespace lib) "/" (name lib) "/" version "/" (name lib) "-" version ".jar"))
  42. (defmethod ext/coord-paths :fkn
  43. [lib coord _manifest _config]
  44. [(make-path lib coord)])
  45. (comment
  46. (with-libs
  47. {'a/a {{:fkn/version "0.1.2"} [['b/b {:fkn/version "1.2.3"}]]}
  48. 'b/b {{:fkn/version "1.2.3"} nil}}
  49. (ext/coord-deps 'a/a {:fkn/version "0.1.2"} :fkn nil))
  50. )