Liking cljdoc? Tell your friends :D

ez-plugin

Library for creating plugins.

Dependancy

[ez-plugin "0.1.1"]

Rationale

You wish to build a system and allow for third parties to extend the system with new functionality. ez-plugin allows for defining hooks to be loaded and executed by the system in any JAR file currently loaded on the classpath.

Combine with pomegranate for downloading JAR files at runtime.

Usage

  1. Library to be loaded as a plugin

  2. An EDN file in the file path (for example in resources)

    1. The EDN file can be named anything

    2. If placed in the root of resources, the path is the file name

  3. You run the following code

(require '[ez-plugin.core :as plugin])
(plugin/load-plugins "plugin.edn" {})
(plugin/load-plugins
  ;; look for this file in all the JAR files currently loaded
  "awesome/system/plugin.edn"
  ;; send in our context map
  {:version 1 :context-map? true}
  ;; an optional opt map
  {;; the EDN file should use this key for holding the hooks. defaults
   ;; to :hooks
   :hooks-key :foobar/hooks
   ;; should any exceptions bubble up or silently supressed
   ;; defaults to false
   :bubble? true}})

The EDN file must look like this. The hooks specified as a vector with the fully qualifed path to the functions you wish to call. The context map is passed as an argument to the function.

{:hooks [ez-plugin-test1.core/hook]}

See in the code base for examples.

Testing & development

In order to develop the library and to run the tests, the two test libraries must first be installed.

License

Copyright © 2019 Emil Bengtsson


Coram Deo

Can you improve this documentation?Edit on GitHub

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

× close