├── .gitignore ├── README.md ├── build.boot ├── resources └── boot-logo-3.png └── src └── jeluard └── boot_notify.clj /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ 2 | .nrepl-history 3 | gpg.edn 4 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # boot-notify [![License](http://img.shields.io/badge/license-EPL-blue.svg?style=flat)](https://www.eclipse.org/legal/epl-v10.html) 2 | 3 | [Boot](https://github.com/boot-clj/boot) task displaying visual notification based on the build status. 4 | 5 | Relies on [terminal-notifier](https://github.com/alloy/terminal-notifier) on OSX and [notify-send](http://manpages.ubuntu.com/manpages/gutsy/man1/notify-send.1.html) on Linux. 6 | 7 | ## Usage 8 | 9 | Add `boot-notify` to your `build.boot` dependencies and `require` the namespace: 10 | 11 | ```clj 12 | (set-env! :dependencies '[[jeluard/boot-notify "0.2.1" :scope "test"]]) 13 | (require '[jeluard.boot-notify :refer [notify]]) 14 | ``` 15 | 16 | Use `(notify)` wherever you would use `(speak)`. 17 | 18 | You can see the options available on the command line: 19 | 20 | ```bash 21 | boot notify -h 22 | ``` 23 | 24 | or in the REPL: 25 | 26 | ```clj 27 | boot.user=> (doc notify) 28 | ``` 29 | 30 | ## License 31 | 32 | Copyright © 2015 Julien Eluard 33 | 34 | Distributed under the Eclipse Public License, the same as Clojure. 35 | -------------------------------------------------------------------------------- /build.boot: -------------------------------------------------------------------------------- 1 | (set-env! 2 | :source-paths #{"src"} 3 | :resource-paths #{"resources"} 4 | :dependencies '[[org.clojure/clojure "1.6.0" :scope "provided"] 5 | [adzerk/bootlaces "0.1.13" :scope "test"]]) 6 | 7 | (require 8 | '[adzerk.bootlaces :refer :all]) 9 | 10 | (def +version+ "0.2.1") 11 | 12 | (bootlaces! +version+) 13 | 14 | (task-options! 15 | pom {:project 'jeluard/boot-notify 16 | :version +version+ 17 | :description "A boot task displaying visual notification based on the build status." 18 | :url "https://github.com/jeluard/boot-notify" 19 | :scm {:url "https://github.com/jeluard/boot-notify"} 20 | :license {"Eclipse Public License" "http://www.eclipse.org/legal/epl-v10.html"}}) 21 | -------------------------------------------------------------------------------- /resources/boot-logo-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeluard/boot-notify/00aa1a1cdc018acf81bab7d66bbd00173accc81b/resources/boot-logo-3.png -------------------------------------------------------------------------------- /src/jeluard/boot_notify.clj: -------------------------------------------------------------------------------- 1 | (ns jeluard.boot-notify 2 | {:boot/export-tasks true} 3 | (:require [clojure.java.io :as io] 4 | [clojure.java.shell :as sh] 5 | [boot.core :as core] 6 | [boot.util :as util])) 7 | 8 | (defn- program-exists? 9 | [s] 10 | (= 0 (:exit (sh/sh "sh" "-c" (format "command -v %s" s))))) 11 | 12 | (defprotocol Notifier 13 | (-supported? [this] "Check if this notifier is supported on current platform") 14 | (-notify [this m] "Perform the notification")) 15 | 16 | (deftype TerminalNotifierNotifier 17 | [] 18 | Notifier 19 | (-supported? [_] (program-exists? "terminal-notifier")) 20 | (-notify [_ {:keys [message title icon pid]}] (sh/sh "terminal-notifier" "-message" message "-title" title "-contentImage" icon "-group" pid))) 21 | 22 | (deftype NotifySendNotifier 23 | [] 24 | Notifier 25 | (-supported? [_] (program-exists? "notify-send")) 26 | (-notify [_ {:keys [message title icon]}] (sh/sh "notify-send" title message "--icon" icon))) 27 | 28 | (def default-notifier 29 | (condp = (System/getProperty "os.name") 30 | "Mac OS X" (TerminalNotifierNotifier.) 31 | "Linux" (NotifySendNotifier.))) 32 | 33 | (defn- notify! 34 | [n s m] 35 | (-notify n (assoc m :message s))) 36 | 37 | (defn boot-logo 38 | [] 39 | (let [d (core/tmp-dir!) 40 | f (io/file d "logo.png")] 41 | (io/copy (io/input-stream (io/resource "boot-logo-3.png")) f) 42 | (.getAbsolutePath f))) 43 | 44 | (core/deftask notify 45 | "Visible notifications during build." 46 | [n notifier VAL sym "Custom notifier. When not provided a platform specific notifier will be used." 47 | m template FOO=BAR {kw str} "Templates overriding default messages. Keys can be :success, :warning or :failure." 48 | t title VAL str "Title of the notification" 49 | i icon VAL str "Full path of the file used as notification icon" 50 | p pid VAL str "Unique ID identifying this boot process"] 51 | (let [title (or title "Boot notify") 52 | base-message {:title title :pid (or pid title) 53 | :icon (or icon (boot-logo))} 54 | messages (merge {:success "Success!" :warning "%s warning/s" :failure "%s"} template)] 55 | (if-let [n (or notifier default-notifier)] 56 | (if (-supported? n) 57 | (fn [next-task] 58 | (fn [fileset] 59 | (try 60 | (util/with-let [_ (next-task fileset)] 61 | (if (zero? @core/*warnings*) 62 | (notify! n (:success messages) base-message) 63 | (notify! n (format (:warning messages) @core/*warnings*) base-message))) 64 | (catch Throwable t 65 | (notify! n (format (:failure messages) (.getMessage t)) base-message) 66 | (throw t))))) 67 | (util/warn (str "Notifier <" n "> is not supported on this platform."))) 68 | (util/warn "Failed to find a Notifier for this platform.")))) 69 | --------------------------------------------------------------------------------