Liking cljdoc? Tell your friends :D

ancient-clj

Clojars Artifact Documentation CI codecov

ancient-clj is a library for accessing versioning metadata in Maven repositories. It is the base for the Leiningen plugin lein-ancient. Version comparison is done using version-clj and Clojure file manipulation relies on rewrite-clj.

Usage

(require '[ancient-clj.core :as ancient])

Maven Repository Access

You can create a loader function that'll allow you to pass an artifact (e.g. as a symbol) and returns a list of versions contained in that repository, represented as maps:

(let [load! (ancient/loader
              {:repositories {"clojars" "https://clojars.org/repo"}})]
  (load! 'ancient-clj))
;; => ({:version-clj.core/version {:version [(0 1 0) ["snapshot"]],
;;                                 :qualifiers #{"snapshot"},
;;                                 :snapshot? true,
;;                                 :qualified? true},
;;      :ancient-clj.artifact/version "0.1.0-SNAPSHOT"}, ...)

This loader will return a raw list of versions, unsorted and unfiltered. You can use the following wrappers:

  • wrap-ignore: remove SNAPSHOT/qualified versions as desired,
  • wrap-sort: sort the returned list of version maps,
  • wrap-as-string: only return the version string, not the whole map.

If you need a lower-level loader function that allows you to access exceptions and per-repository results, check out ancient-clj.repositories/loader.

Simple API

You can obtain a loader function via (default-loader) that will be pointing at Clojars and Maven Central. It's used automatically when, for example, fetching the latest version via:

(ancient/latest-version 'ancient-clj)
;; => {:version-clj.core/version {:version [(1 0 0)],
;;                                :qualifiers #{},
;;                                :snapshot? false,
;;                                :qualified? false},
;;     :ancient-clj.artifact/version "1.0.0"}

Same goes for the sorted list of versions in:

(ancient/sorted-versions 'ancient-clj)
;; => ({:version-clj.core/version {:version [(0 1 0) ["snapshot"]],
;;                                 :qualifiers #{"snapshot"},
;;                                 :snapshot? true,
;;                                 :qualified? true},
;;      :ancient-clj.artifact/version "0.1.0-SNAPSHOT"}, ...)

Both take an additional first parameter if you want to supply a custom (or wrapped) loader, e.g. to perform filtering of the returned versions via wrap-ignore.

File Operations

At the core of lein-ancient is the ability to collect dependencies from files and automatically update them in-place. With version 2.0.0 this has moved into ancient-clj.

(require '[ancient-clj.zip :refer [project-clj]]
         '[rewrite-clj.zip :as z])

The operations rely on a rewrite-clj zippers that can be created from files, strings, forms, etc... Internally, the concept of a visitor is used that will call a function for each dependency it encounters.

Finding outdated dependencies

(let [collect! (ancient/collector {:visitor (project-clj)})]
  (collect! (z/of-file "project.clj")))
;; => ({:ancient-clj.artifact/id "clojure",
;;      :ancient-clj.artifact/group "org.clojure",
;;      :version-clj.core/version {:version [(1 10 3)], ...},
;;      :ancient-clj.artifact/version "1.10.3",
;;      :ancient-clj.artifact/symbol org.clojure/clojure,
;;      :ancient-clj.artifact/form [org.clojure/clojure "1.10.3" :scope "provided"],
;;      :ancient-clj.artifact/latest-version
;;      {:version-clj.core/version {:version [(1 11 0) ("alpha" 1)], ...},
;;       :ancient-clj.artifact/version "1.11.0-alpha1"}}, ...)

You can supply a custom :loader, as well as a :check? predicate that allows you to be selective about what to check.

Updating outdated dependencies

(let [update! (ancient/updater {:visitor (project-clj)})]
  (-> (z/of-file "project.clj")
      (update!)
      (z/root-string)))
;; => "(defproject ... :dependencies [[org.clojure/clojure \"1.11.0-alpha1\" :scope \"provided\"]\n ...)"

Again, you can supply a custom :loader, a :check? predicate, as well as an :update? predicate. The last one can be especially useful, e.g. if you want to avoid performing major version updates.

Updating files directly

Use ancient-clj.core/file-updater to update files in-place. An exception will be thrown if the file changed before changes are written back.

Deprecated API

In version 2.0.0, part of the original API has been removed while most of the remaining functions have been marked deprecated. All functionality can be replicated with the new facilities, but if you're missing a convencience function, please open a PR and we can discuss.

Supported Repository Types

Since version 1.0.0, ancient-clj depends on pomegranate (and thus Aether) and can benefit from any wagons that are registered there. Please use cemerick.pomegranate.aether/register-wagon-factory! to utilise this feature.

License

MIT License

Copyright (c) 2013-2021 Yannick Scherer

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Can you improve this documentation?Edit on GitHub

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close