-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.boot
More file actions
90 lines (81 loc) · 2.99 KB
/
Copy pathbuild.boot
File metadata and controls
90 lines (81 loc) · 2.99 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
;; Copyright © 2017 Informatique, Inc.
;;
;; This software is licensed under the terms of the
;; Apache License, Version 2.0 which can be found in
;; the file LICENSE at the root of this distribution.
(def project 'informatique-inc/hellocli)
(def version "0.2.0")
(def description "Simple Clojure CLI example")
(def project-url "https://github.com/informatique-inc/hellocli")
(def main 'hellocli.cli)
(set-env!
:resource-paths #{"src"}
:source-paths #{"src" "test"}
:dependencies '[[org.clojure/clojure "1.8.0" :scope "provided"]
[environ "1.1.0"]
[org.clojure/tools.cli "0.3.5"]
;; testing/development
[adzerk/boot-test "1.1.2" :scope "test"]
[adzerk/bootlaces "0.1.13" :scope "test"]
])
(require
'[clojure.java.shell :as cjs]
'[adzerk.boot-test :refer [test]]
'[adzerk.bootlaces :refer :all])
(bootlaces! version)
(task-options!
pom {:project project
:version version
:description description
:url project-url
:scm {:url project-url}
:license {"Apache-2.0" "http://opensource.org/licenses/Apache-2.0"}}
aot {:namespace #{main}}
jar {:main main}
test {:namespaces #{'testing.hellocli.cli}})
(deftask uberjar
"Build the project locally as an uberjar"
[d dir PATH #{str} "the set of directories to write to (target)."]
(let [dir (if (seq dir) dir #{"target"})]
(comp
(sift :include #{#"~$"} :invert true) ;; don't include emacs backups
(aot)
(uber)
(jar :file (str (name project) ".jar"))
(target :dir dir))))
(deftask cli-test
"Run the command line tests."
[]
(comp
(uberjar)
(with-post-wrap [_]
(println "\nCLI Testing\n")
(let [jar "target/hellocli.jar"
cmd ["java" "-jar" jar "-v" "-v" "--foo" "bar" "aaa" "bbb" "ccc"]
expected "version: 0.2.0\nverbosity level: 2\nfoo: bar\nargs: [aaa bbb ccc]\n"
{:keys [exit out err]} (apply cjs/sh cmd)]
(if (or (not (zero? exit)) (not= out expected))
(do
(println "command line test failed for:" cmd)
(if (not (zero? exit))
(println (str "non-zero exit status: " exit "\nstdout:\n" out))
(println (str "--- Expected ---\n" expected "\n--- Actual ---\n" out)))
(println (str "stderr:\n" err))
(println "1 error.")
(throw (Exception. "command line test failed")))
(println "0 errors."))))))
(deftask all-tests
"Run the Clojure and command line tests."
[]
(comp
(test)
(cli-test)))
(deftask run
"Run the project. boot run -a \"arg1 arg2 arg3...\""
[a args ARG [str] "the arguments for the application."]
(require [main :as 'app])
(let [argv (if (pos? (count args))
(clojure.string/split (first args) #" ")
'())]
(apply (resolve 'app/-main) argv)
identity))