|
1 | 1 | (ns boot.aether |
2 | 2 | (:require |
3 | | - [clojure.java.io :as io] |
4 | | - [clojure.string :as string] |
5 | | - [clojure.pprint :as pprint] |
6 | | - [cemerick.pomegranate.aether :as aether] |
7 | | - [boot.util :as util] |
8 | | - [boot.pod :as pod] |
9 | | - [boot.gpg :as gpg] |
10 | | - [boot.from.io.aviso.ansi :as ansi] |
11 | | - [boot.kahnsort :as ksort]) |
| 3 | + [clojure.java.io :as io] |
| 4 | + [clojure.string :as string] |
| 5 | + [clojure.pprint :as pprint] |
| 6 | + [cemerick.pomegranate.aether :as aether] |
| 7 | + [boot.util :as util] |
| 8 | + [boot.pod :as pod] |
| 9 | + [boot.gpg :as gpg] |
| 10 | + [boot.from.io.aviso.ansi :as ansi] |
| 11 | + [boot.kahnsort :as ksort]) |
12 | 12 | (:import |
13 | | - [boot App] |
14 | | - [java.io File] |
15 | | - [java.util.jar JarFile] |
16 | | - [java.util.regex Pattern] |
17 | | - [org.sonatype.aether.resolution DependencyResolutionException])) |
| 13 | + [boot App] |
| 14 | + [java.io File] |
| 15 | + [java.util.jar JarFile] |
| 16 | + [java.util.regex Pattern] |
| 17 | + [org.sonatype.aether.resolution DependencyResolutionException] |
| 18 | + [org.sonatype.aether.transfer MetadataNotFoundException ArtifactNotFoundException])) |
18 | 19 |
|
19 | 20 | (def offline? (atom false)) |
20 | 21 | (def update? (atom :daily)) |
|
33 | 34 | (defn update-always! [] (set-update! :always)) |
34 | 35 | (defn set-local-repo! [x] (reset! local-repo x)) |
35 | 36 |
|
| 37 | +(defmulti on-transfer (fn [info] (:type info))) |
| 38 | + |
| 39 | +(defmethod on-transfer :started |
| 40 | + [{:keys [method] {:keys [name repository size]} :resource}] |
| 41 | + (letfn [(->k [size] |
| 42 | + (when-not (neg? size) |
| 43 | + (format " (%sk)" (Math/round (double (max 1 (/ size 1024)))))))] |
| 44 | + (util/info "%s %s %s %s%s\n" |
| 45 | + (case method :get "Retrieving" :put "Sending") |
| 46 | + (.getName (io/file name)) |
| 47 | + (case method :get "from" :put "to") |
| 48 | + repository |
| 49 | + (str (->k size))))) |
| 50 | + |
| 51 | +(defmethod on-transfer :succeeded |
| 52 | + [_]) |
| 53 | + |
| 54 | +(defmethod on-transfer :corrupted |
| 55 | + [{:keys [error]}] |
| 56 | + (when error |
| 57 | + (util/fail "%s\n" (.getMessage error)))) |
| 58 | + |
| 59 | +(defmethod on-transfer :failed |
| 60 | + [{:keys [error]}] |
| 61 | + (when (and error |
| 62 | + (not (instance? MetadataNotFoundException error)) |
| 63 | + (not (instance? ArtifactNotFoundException error))) |
| 64 | + (util/fail "%s\n" (.getMessage error)))) |
| 65 | + |
| 66 | +(defmethod on-transfer :default |
| 67 | + [_]) |
| 68 | + |
36 | 69 | (defn transfer-listener |
37 | | - [{type :type meth :method {name :name repo :repository size :size} :resource err :error :as info}] |
| 70 | + [info] |
38 | 71 | (util/dbug "Aether: %s\n" (with-out-str (pprint/pprint info))) |
39 | | - (letfn [(->k [size] (if (neg? size) "" (str (Math/round (double (max 1 (/ size 1024)))))))] |
40 | | - (case type |
41 | | - :started |
42 | | - (util/info "%s %s from %s (%sk)\n" |
43 | | - (case meth :get "Retrieving" :put "Sending") |
44 | | - (.getName (io/file name)) |
45 | | - repo |
46 | | - (->k size)) |
47 | | - |
48 | | - (:corrupted :failed) |
49 | | - (when err (util/fail "%s\n" (.getMessage err))) |
50 | | - |
51 | | - nil))) |
| 72 | + (on-transfer info)) |
52 | 73 |
|
53 | 74 | (defn ^{:boot/from :technomancy/leiningen} build-url |
54 | 75 | "Creates java.net.URL from string" |
|
0 commit comments