Skip to content

Commit 7b2f448

Browse files
committed
support for runtime loading of wagons
1 parent 903ed7a commit 7b2f448

File tree

4 files changed

+49
-51
lines changed

4 files changed

+49
-51
lines changed

boot/aether/src/boot/aether.clj

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
(defn transfer-listener
2828
[{type :type meth :method {name :name repo :repository} :resource err :error}]
2929
(when (and (.endsWith name ".jar") (= type :started))
30-
(util/info "Retrieving %s from %s\n" name repo)))
30+
(util/info "Retrieving %s from %s\n" (.getName (io/file name)) repo)))
3131

3232
(defn ^{:boot/from :technomancy/leiningen} build-url
3333
"Creates java.net.URL from string"
@@ -169,3 +169,17 @@
169169
:pom-file (io/file pomfile)
170170
:repository [repo]
171171
:local-repo (or (:local-repo env) @local-repo nil))))
172+
173+
(def ^:private wagon-files (atom #{}))
174+
175+
(defn add-wagon
176+
[env coord & [mapping]]
177+
(pod/add-dependencies (assoc env :dependencies [coord]))
178+
(let [m (or mapping (locking wagon-files
179+
(->> (pod/resources "leiningen/wagons.clj")
180+
(remove (partial contains? @wagon-files))
181+
(map #(do (swap! wagon-files conj %)
182+
(->> % io/input-stream slurp read-string)))
183+
(reduce into {}))))]
184+
(doseq [[scheme factory] m]
185+
(aether/register-wagon-factory! scheme (eval factory)))))

boot/core/src/boot/core.clj

Lines changed: 21 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"Add Maven dependencies to the classpath, fetching them if necessary."
3737
[old new env]
3838
(->> new rm-clojure-dep (assoc env :dependencies) pod/add-dependencies)
39-
(into (or old []) new))
39+
new)
4040

4141
(defn- add-directories!
4242
"Add URLs (directories or jar files) to the classpath."
@@ -57,15 +57,6 @@
5757
(let [dk :dependencies]
5858
(->> kvs (sort-by first #(cond (= %1 dk) 1 (= %2 dk) -1 :else 0)))))
5959

60-
(def ^:private base-env
61-
"Returns initial boot environment settings."
62-
(fn []
63-
'{:dependencies []
64-
:src-paths #{}
65-
:tgt-path "target"
66-
:repositories [["clojars" "http://clojars.org/repo/"]
67-
["maven-central" "http://repo1.maven.org/maven2/"]]}))
68-
6960
;; ## Boot Environment
7061
;;
7162
;; _These functions are used internally by boot and are not part of the public
@@ -74,7 +65,7 @@
7465
(declare ^{:dynamic true :doc "The running version of boot."} *boot-version*)
7566
(declare ^{:dynamic true :doc "Command line options for boot itself."} *boot-opts*)
7667

77-
(def boot-env
68+
(def ^:private boot-env
7869
"Atom containing environment key/value pairs. Do not manipulate this atom
7970
directly. Use `set-env!` (below) instead."
8071
(atom nil))
@@ -84,7 +75,13 @@
8475
There should be no need to call this function directly."
8576
[& kvs]
8677
(doto boot-env
87-
(reset! (merge (base-env) (apply hash-map kvs)))
78+
(reset!
79+
(->> (apply hash-map kvs)
80+
(merge {:dependencies []
81+
:src-paths #{}
82+
:tgt-path "target"
83+
:repositories [["clojars" "http://clojars.org/repo/"]
84+
["maven-central" "http://repo1.maven.org/maven2/"]]})))
8885
(add-watch ::boot #(configure!* %3 %4))))
8986

9087
(defmulti on-env!
@@ -111,19 +108,6 @@
111108
;;
112109
;; _Functions provided for use in boot tasks._
113110

114-
;; Maven Repository Global Configuration
115-
116-
(defn set-offline!
117-
"Set/unset offline mode for dependency resolution."
118-
[x]
119-
(pod/call-worker `(boot.aether/set-offline! ~x)))
120-
121-
(defn set-update!
122-
"Set the snapshot update frequency for dependency resolution. Accepted values
123-
of x are `:always`, `:daily`, or `:never`."
124-
[x]
125-
(pod/call-worker `(boot.aether/set-update! ~x)))
126-
127111
;; ## Boot Environment Management Functions
128112

129113
(defn get-env
@@ -160,7 +144,13 @@
160144
[dst & [srcs]]
161145
(tmp/add-sync! @tmpregistry dst srcs))
162146

163-
;; ## Task helpers
147+
(defn add-wagon!
148+
"FIXME: document this."
149+
[maven-coord & [scheme-map]]
150+
(pod/call-worker
151+
`(boot.aether/add-wagon ~(get-env) ~maven-coord ~scheme-map)))
152+
153+
;; ## Task helpers – managed temp files
164154

165155
(def ^:private consumed-files (atom #{}))
166156

@@ -195,24 +185,15 @@
195185
[f]
196186
(tmp/tmpfile? @tmpregistry f))
197187

198-
(defn mktmp!
199-
"Create a temp file and return its `File` object. If `mktmp!` has already
200-
been called with the given `key` the tmpfile will be truncated. The optional
201-
`name` argument can be used to customize the temp file name (useful for
202-
creating temp files with a specific file extension, for example)."
203-
[key & [name]]
204-
(tmp/mk! @tmpregistry key name))
205-
206188
(defn mktmpdir!
207189
"Create a temp directory and return its `File` object. If `mktmpdir!` has
208190
already been called with the given `key` the directory's contents will be
209-
deleted. The optional `name` argument can be used to customize the temp
210-
directory name, as with `mktmp!` above."
211-
[key & [name]]
212-
(tmp/mkdir! @tmpregistry key name))
191+
deleted."
192+
[key]
193+
(tmp/mkdir! @tmpregistry key))
213194

214-
(def tgtdirs
215-
"Atom containing a vector of File objects--directories created by `mktgtdir!`.
195+
(def ^:private tgtdirs
196+
"Atom containing a vector of File objectsdirectories created by `mktgtdir!`.
216197
This atom is managed by boot and shouldn't be manipulated directly."
217198
(atom []))
218199

boot/core/src/boot/task/built_in.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@
301301
(assert "no serve function specified"))
302302
(util/info "Adding servlet impl...\n")
303303
(pod/copy-dependency-jar-entries
304-
(core/get-env) tgt implp implv #"^tailrecursion/.*\.(class|clj)$")
304+
(core/get-env) tgt [implp implv] #"^tailrecursion/.*\.(class|clj)$")
305305
(util/info "Writing %s...\n" (.getName xmlfile))
306306
(pod/call-worker
307307
`(boot.web/spit-web! ~(.getPath xmlfile) ~serve ~create ~destroy))))))

boot/pod/src/boot/pod.clj

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -144,20 +144,23 @@
144144
(.offer @shutdown-hooks f)
145145
(->> f Thread. (.addShutdownHook (Runtime/getRuntime)))))
146146

147+
(defn- eval-fn-call
148+
[[f & args]]
149+
(when-let [ns (namespace f)] (require (symbol ns)))
150+
(if-let [f (resolve f)]
151+
(apply f args)
152+
(throw (Exception. (format "can't resolve symbol (%s)" f)))))
153+
147154
(defn call-in
148155
([expr]
149-
(let [[f & args] (read-string expr)]
150-
(when-let [ns (namespace f)] (require (symbol ns)))
151-
(if-let [f (resolve f)]
152-
(pr-str (apply f args))
153-
(throw (Exception. (format "can't resolve symbol (%s)" f))))))
156+
(pr-str (eval-fn-call (read-string expr))))
154157
([pod expr]
155158
(let [ret (.invoke pod "boot.pod/call-in" (pr-str expr))]
156159
(util/guard (read-string ret)))))
157160

158161
(defn call-worker
159162
[expr]
160-
(call-in @worker-pod expr))
163+
(if @worker-pod (call-in @worker-pod expr) (eval-fn-call expr)))
161164

162165
(defn eval-in*
163166
([expr-str]
@@ -183,7 +186,7 @@
183186
(->> env resolve-dependencies (map (comp io/file :jar))))
184187

185188
(defn resolve-dependency-jar
186-
[env project version]
189+
[env [project version]]
187190
(let [jarname (format "%s-%s.jar" (name project) version)]
188191
(->> [[project version]]
189192
(assoc env :dependencies)
@@ -214,11 +217,11 @@
214217
(call-worker `(boot.aether/jar-entries-in-dep-order ~env)))
215218

216219
(defn copy-dependency-jar-entries
217-
[env outdir project version & regexes]
220+
[env outdir coord & regexes]
218221
(let [keep? (if-not (seq regexes)
219222
(constantly true)
220223
(apply some-fn (map #(partial re-find %) regexes)))
221-
ents (->> (resolve-dependency-jar env project version)
224+
ents (->> (resolve-dependency-jar env coord)
222225
jar-entries
223226
(filter (comp keep? first))
224227
(map (fn [[k v]] [v (.getPath (io/file outdir k))])))]

0 commit comments

Comments
 (0)