Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Update to work with Leiningen 2.

Fixes #1.
  • Loading branch information...
commit 5a68c299e4559f0b55e6a4ea3bcd99a6201aba6b 1 parent f1ae186
@technomancy authored
View
4 .gitignore
@@ -1,4 +1,6 @@
pom.xml
*jar
lib
-classes
+classes
+/.lein-failures
+/target/stale/dependencies
View
4 project.clj
@@ -1,4 +1,4 @@
-(defproject lein-play "1.0.0-SNAPSHOT"
+(defproject lein-play "2.0.0-SNAPSHOT"
:description "Play a sound when your tests pass or fail."
:dependencies [[org.clojars.technomancy/jlayer "1.0"]]
- :eval-in-leinigen test)
+ :eval-in-leiningen true)
View
33 src/leiningen/hooks/play.clj
@@ -1,20 +1,25 @@
(ns leiningen.hooks.play
- (:use [robert.hooke :only [add-hook]])
- (:require [leiningen.test])
- (:import [java.io FileInputStream BufferedInputStream]
- [javazoom.jl.player Player]))
+ (:require [leiningen.test]
+ [leiningen.core.user :as user]
+ [robert.hooke :as hooke]
+ [clojure.java.io :as io])
+ (:import (java.io FileInputStream BufferedInputStream)
+ (javazoom.jl.player Player)))
(defn play [name]
- (let [r (.getResourceAsStream (.getContextClassLoader
- (Thread/currentThread))
- (format "leiningen/%s.mp3" name))]
- (-> (BufferedInputStream. r)
+ (let [user-file (io/file (user/leiningen-home) (str name ".mp3"))
+ is (io/input-stream (if (.exists user-file)
+ user-file
+ (io/resource (format "leiningen/%s.mp3" name))))]
+ (-> (BufferedInputStream. is)
(Player.)
(.play))))
-(add-hook #'leiningen.test/test
- (fn play-hook [f & args]
- (let [code (apply f args)]
- (play (if (zero? code)
- "pass" "fail"))
- code)))
+(defn activate []
+ (hooke/add-hook #'leiningen.test/test
+ (fn play-hook [f & args]
+ (try (apply f args)
+ (play "pass")
+ (catch Exception e
+ (play "fail")
+ (throw e))))))
View
3  test/leiningen/test_play_hook.clj
@@ -1,5 +1,6 @@
(ns leiningen.test-play-hook
- (:use [clojure.test]))
+ (:use [clojure.test]
+ [leiningen.hooks.play]))
(deftest flip-flop
(let [flop (java.io.File. "/tmp/test-lein-play")]
Please sign in to comment.
Something went wrong with that request. Please try again.