Skip to content

Commit

Permalink
Produce a warning when acting as plugin but no matching project depen…
Browse files Browse the repository at this point in the history
…dency

Fixes #45
  • Loading branch information
hlship committed Jul 15, 2016
1 parent b3301ab commit bc236bf
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 9 deletions.
7 changes: 7 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## 0.1.28 - 15 Jul 2016

A warning is now produced when using pretty as a plugin, but it is not a
project dependency.

[Closed Issues](https://github.com/AvisoNovate/pretty/issues?q=milestone%3A0.1.28+is%3Aclosed)

## 0.1.27 - 1 Jul 2016

Qualified keys in exception maps are now printed properly.
Expand Down
10 changes: 6 additions & 4 deletions project.clj
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
(defproject io.aviso/pretty "0.1.27"
(defproject io.aviso/pretty "0.1.28"
:description "Clojure library to help print things, prettily"
:url "https://github.com/AvisoNovate/pretty"
:license {:name "Apache Sofware License 2.0"
:url "http://www.apache.org/licenses/LICENSE-2.0.html"}
:dependencies [[org.clojure/clojure "1.5.0"]
[org.clojure/tools.logging "0.3.1" :optional true]]
:plugins [[lein-codox "0.9.3"]]
:profiles {:1.7 {:dependencies [[org.clojure/clojure "1.7.0"]]}
:1.8 {:dependencies [[org.clojure/clojure "1.8.0"]]}
:dev {:dependencies [[criterium "0.4.4"]]}}
:profiles {:1.7 {:dependencies [[org.clojure/clojure "1.7.0"]]}
:1.8 {:dependencies [[org.clojure/clojure "1.8.0"]]}
:1.9 {:dependencies [[org.clojure/clojure "1.9.0-alpha10"]]}
:dev {:dependencies [[criterium "0.4.4"]]}
:lein {:dependencies [[leiningen "2.6.1"]]}}
;; Part of release is currently manual; copy target/docs to the AvisoNovate/docs/pretty folder
:aliases {"release" ["do"
"clean,"
Expand Down
24 changes: 19 additions & 5 deletions src/pretty/plugin.clj
Original file line number Diff line number Diff line change
@@ -1,19 +1,33 @@
(ns pretty.plugin
"A plugin for Leiningen that automatically enables pretty printing."
{:added "0.1.19"}
(:require [io.aviso.repl :as repl]))
(:require [io.aviso.repl :as repl]
[leiningen.core.main :as main]))

(defn hooks
"Enables pretty printing of exceptions within Leiningen. This is evaluated in the Leinigen classpath, not the project's
(if any)."
[]
(repl/install-pretty-exceptions))


(def ^:private warning (atom true))

(defn middleware
"Automatically adds the :injections that enable Pretty."
[project]
(update-in project [:injections]
(fnil into [])
['(require 'io.aviso.repl)
'(io.aviso.repl/install-pretty-exceptions)]))
(if (contains? (->> project
:dependencies
(map first)
set)
'io.aviso/pretty)
(update-in project [:injections]
(fnil into [])
['(require 'io.aviso.repl)
'(io.aviso.repl/install-pretty-exceptions)])
(do
;; Ugly! But necessary since middleware gets invoked more than once for some unknown reason.
(when (compare-and-set! warning true false)
(main/warn "Unable to enable pretty exception reporting, as io.aviso/pretty is not a project dependency."))
project)))

0 comments on commit bc236bf

Please sign in to comment.