/
spec.clj
62 lines (54 loc) · 2.24 KB
/
spec.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
(ns leiningen.spec
(:use
[clojure.java.io :only [file]])
(:import
[java.io BufferedInputStream]))
(defn- copy-bytes [in out]
(with-open [input in]
(loop [b (.read input)]
(when-not (= -1 b)
(.write out b)
(recur (.read input))))))
(defn- java [jvm-args main-class args working-directory]
(let [java-exe (str (System/getProperty "java.home") "/bin/java")
command (into-array (concat [java-exe] jvm-args [main-class] args))
process (.exec (Runtime/getRuntime) command nil (file working-directory))
output (BufferedInputStream. (.getInputStream process))
output-thread (Thread. #(copy-bytes output System/out))
error (BufferedInputStream. (.getErrorStream process))
error-thread (Thread. #(copy-bytes error System/err))]
(.start output-thread)
(.start error-thread)
(.waitFor process)
(.join output-thread 1000)
(.join error-thread 1000)
(.exitValue process)))
(defn- compute-classpath-string [project]
(clojure.string/join java.io.File/pathSeparatorChar
((or (ns-resolve (the-ns 'leiningen.classpath) 'get-classpath)
(ns-resolve (the-ns 'leiningen.core.classpath) 'get-classpath))
project)))
(defn- prepare [project]
(try
(require 'leiningen.core.eval)
((ns-resolve 'leiningen.core.eval 'prep) project)
(catch java.io.FileNotFoundException e
(require 'leiningen.classpath
'leiningen.compile)
((ns-resolve 'leiningen.compile 'prep) project false))))
(defn spec
"Speclj - pronounced \"speckle\": a TDD/BDD framework for Clojure.
You're currently using Speclj's Leiningen plugin. To get the Speclj's help
documentation, as opposed to this message provided by Leiningen, try this:
lein spec --speclj
That ought to do the trick."
[project & args]
(prepare project)
(let [speclj-args (cons "-c" args)
classpath (compute-classpath-string project)
jvm-args ["-cp" classpath "-Dspeclj.invocation=lein spec"]]
(try
(require 'leiningen.core.main)
((ns-resolve (the-ns 'leiningen.core.main) 'exit) (java jvm-args "speclj.main" speclj-args (:root project)))
(catch java.io.FileNotFoundException e
(java jvm-args "speclj.main" speclj-args (:root project))))))