Unmemoize in order to fix tests.
This commit is contained in:
parent
ad6c4bd290
commit
63305fcccd
6 changed files with 77 additions and 67 deletions
|
@ -252,70 +252,71 @@
|
|||
(def ^:private ^:dynamic *dependencies-session*
|
||||
"This is dynamic in order to avoid memoization issues.")
|
||||
|
||||
(def ^:private get-dependencies-memoized
|
||||
(memoize
|
||||
(fn [dependencies-key managed-dependencies-key
|
||||
{:keys [repositories local-repo offline? update
|
||||
checksum mirrors] :as project}
|
||||
{:keys [add-classpath?] :as args}]
|
||||
{:pre [(every? vector? (get project dependencies-key))
|
||||
(every? vector? (get project managed-dependencies-key))]}
|
||||
(try
|
||||
((if add-classpath?
|
||||
pomegranate/add-dependencies
|
||||
aether/resolve-dependencies)
|
||||
:repository-session-fn *dependencies-session*
|
||||
:local-repo local-repo
|
||||
:offline? offline?
|
||||
:repositories (->> repositories
|
||||
(map add-repo-auth)
|
||||
(map (partial update-policies update checksum)))
|
||||
:managed-coordinates (get project managed-dependencies-key)
|
||||
:coordinates (get project dependencies-key)
|
||||
:mirrors (->> mirrors
|
||||
(map add-repo-auth)
|
||||
(map (partial update-policies update checksum)))
|
||||
:transfer-listener
|
||||
(bound-fn [e]
|
||||
(let [{:keys [type resource error]} e]
|
||||
(let [{:keys [repository name size trace]} resource]
|
||||
(let [aether-repos (if trace (.getRepositories (.getData trace)))]
|
||||
(case type
|
||||
:started
|
||||
(if-let [repo (first (filter
|
||||
#(or (= (.getUrl %) repository)
|
||||
;; sometimes the "base" url
|
||||
;; doesn't have a slash on it
|
||||
(= (str (.getUrl %) "/") repository))
|
||||
aether-repos))]
|
||||
(locking *err*
|
||||
(warn "Retrieving" name "from" (.getId repo)))
|
||||
;; else case happens for metadata files
|
||||
)
|
||||
nil)))))
|
||||
:proxy (get-proxy-settings))
|
||||
(catch DependencyResolutionException e
|
||||
;; Cannot recur from catch/finally so have to put this in its own defn
|
||||
(print-failures e)
|
||||
(warn "This could be due to a typo in :dependencies, file system permissions, or network issues.")
|
||||
(warn "If you are behind a proxy, try setting the 'http_proxy' environment variable.")
|
||||
(throw (ex-info "Could not resolve dependencies" {:suppress-msg true
|
||||
:exit-code 1} e)))
|
||||
(catch Exception e
|
||||
(let [exception-cause (root-cause e)]
|
||||
(if (and (or (instance? java.net.UnknownHostException exception-cause)
|
||||
(instance? java.net.NoRouteToHostException exception-cause))
|
||||
(not offline?))
|
||||
(get-dependencies-memoized dependencies-key managed-dependencies-key
|
||||
(assoc project :offline? true) args)
|
||||
(throw e))))))))
|
||||
(defn- get-dependencies*
|
||||
[dependencies-key managed-dependencies-key
|
||||
{:keys [repositories local-repo offline? update
|
||||
checksum mirrors] :as project}
|
||||
{:keys [add-classpath?] :as args}]
|
||||
{:pre [(every? vector? (get project dependencies-key))
|
||||
(every? vector? (get project managed-dependencies-key))]}
|
||||
(try
|
||||
((if add-classpath?
|
||||
pomegranate/add-dependencies
|
||||
aether/resolve-dependencies)
|
||||
:repository-session-fn *dependencies-session*
|
||||
:local-repo local-repo
|
||||
:offline? offline?
|
||||
:repositories (->> repositories
|
||||
(map add-repo-auth)
|
||||
(map (partial update-policies update checksum)))
|
||||
:managed-coordinates (get project managed-dependencies-key)
|
||||
:coordinates (get project dependencies-key)
|
||||
:mirrors (->> mirrors
|
||||
(map add-repo-auth)
|
||||
(map (partial update-policies update checksum)))
|
||||
:transfer-listener
|
||||
(bound-fn [e]
|
||||
(let [{:keys [type resource error]} e]
|
||||
(let [{:keys [repository name size trace]} resource]
|
||||
(let [aether-repos (if trace (.getRepositories (.getData trace)))]
|
||||
(case type
|
||||
:started
|
||||
(if-let [repo (first (filter
|
||||
#(or (= (.getUrl %) repository)
|
||||
;; sometimes the "base" url
|
||||
;; doesn't have a slash on it
|
||||
(= (str (.getUrl %) "/") repository))
|
||||
aether-repos))]
|
||||
(locking *err*
|
||||
(warn "Retrieving" name "from" (.getId repo)))
|
||||
;; else case happens for metadata files
|
||||
)
|
||||
nil)))))
|
||||
:proxy (get-proxy-settings))
|
||||
(catch DependencyResolutionException e
|
||||
;; Cannot recur from catch/finally so have to put this in its own defn
|
||||
(print-failures e)
|
||||
(warn "This could be due to a typo in :dependencies, file system permissions, or network issues.")
|
||||
(warn "If you are behind a proxy, try setting the 'http_proxy' environment variable.")
|
||||
(throw (ex-info "Could not resolve dependencies" {:suppress-msg true
|
||||
:exit-code 1} e)))
|
||||
(catch Exception e
|
||||
(let [exception-cause (root-cause e)]
|
||||
(if (and (or (instance? java.net.UnknownHostException exception-cause)
|
||||
(instance? java.net.NoRouteToHostException exception-cause))
|
||||
(not offline?))
|
||||
(get-dependencies* dependencies-key managed-dependencies-key
|
||||
(assoc project :offline? true) args)
|
||||
(throw e))))))
|
||||
|
||||
(def ^:private get-dependencies-memoized (memoize get-dependencies*))
|
||||
|
||||
(defn ^:internal get-dependencies [dependencies-key managed-dependencies-key
|
||||
project & args]
|
||||
(let [ranges (atom []), overrides (atom [])
|
||||
trimmed (select-keys project [dependencies-key managed-dependencies-key
|
||||
:repositories :checksum :local-repo
|
||||
:offline? :update :mirrors])
|
||||
:offline? :update :mirrors :memoize-buster])
|
||||
deps-result (binding [*dependencies-session* (pedantic/session
|
||||
project ranges overrides)]
|
||||
(get-dependencies-memoized dependencies-key
|
||||
|
|
|
@ -96,8 +96,8 @@
|
|||
;; :plugins and will also be available to deploy to.
|
||||
;; Add ^:replace (:repositories ^:replace [...]) to only use repositories you
|
||||
;; list below.
|
||||
:repositories [["java.net" "http://download.java.net/maven/2"]
|
||||
["sonatype" {:url "http://oss.sonatype.org/content/repositories/releases"
|
||||
:repositories [["java.net" "https://download.java.net/maven/2"]
|
||||
["sonatype" {:url "https://oss.sonatype.org/content/repositories/releases"
|
||||
;; If a repository contains releases only setting
|
||||
;; :snapshots to false will speed up dependencies.
|
||||
:snapshots false
|
||||
|
@ -117,8 +117,8 @@
|
|||
;; Credentials for repositories should *not* be stored
|
||||
;; in project.clj but in ~/.lein/credentials.clj.gpg instead,
|
||||
;; see `lein help deploying` under "Authentication".
|
||||
["snapshots" "http://blueant.com/archiva/snapshots"]
|
||||
["releases" {:url "http://blueant.com/archiva/internal"
|
||||
["snapshots" "https://blueant.com/archiva/snapshots"]
|
||||
["releases" {:url "https://blueant.com/archiva/internal"
|
||||
;; Using :env as a value here will cause an
|
||||
;; environment variable to be used based on
|
||||
;; the key; in this case LEIN_PASSWORD.
|
||||
|
|
|
@ -136,3 +136,6 @@
|
|||
(def #^{:macro true} with-system-out-str #'utils/with-system-out-str)
|
||||
|
||||
(def #^{:macro true} with-system-err-str #'utils/with-system-err-str)
|
||||
|
||||
(defn unmemoize [v underlying]
|
||||
(alter-var-root v (constantly underlying)))
|
||||
|
|
|
@ -6,12 +6,12 @@
|
|||
[clojure.java.io :only [file]]))
|
||||
|
||||
(deftest ^:online test-install
|
||||
(unmemoize #'leiningen.core.classpath/get-dependencies-memoized
|
||||
#'leiningen.core.classpath/get-dependencies*)
|
||||
(delete-file-recursively (m2-dir "nomnomnom" "0.5.0-SNAPSHOT") true)
|
||||
(install sample-project)
|
||||
(is (not (empty? (.listFiles (m2-dir "nomnomnom" "0.5.0-SNAPSHOT"))))))
|
||||
|
||||
(def jdom-dir (file local-repo "jdom" "jdom" "1.0"))
|
||||
|
||||
(def tricky-m2-dir (file local-repo "org" "domain" "tricky-name" "1.0"))
|
||||
|
||||
(deftest ^:online test-tricky-name-install
|
||||
|
|
|
@ -5,7 +5,8 @@
|
|||
[leiningen.core.utils :refer [platform-nullsink]]
|
||||
[leiningen.test.helper :as helper]
|
||||
[robert.hooke :as hooke]
|
||||
[leiningen.javac :as javac])
|
||||
[leiningen.javac :as javac]
|
||||
[leiningen.test.helper :refer [unmemoize]])
|
||||
(:use [clojure.test]
|
||||
[leiningen.jar]))
|
||||
|
||||
|
@ -92,6 +93,8 @@
|
|||
"jar produces two jar files")))
|
||||
|
||||
(deftest ^:online test-no-deps-jar
|
||||
(unmemoize #'leiningen.core.classpath/get-dependencies-memoized
|
||||
#'leiningen.core.classpath/get-dependencies*)
|
||||
(let [[coord jar-file] (first
|
||||
(jar (dissoc helper/sample-project
|
||||
:dependencies :main)))]
|
||||
|
|
|
@ -4,7 +4,8 @@
|
|||
[clojure.java.io :refer [delete-file]]
|
||||
[clojure.java.shell :refer [sh]]
|
||||
[clojure.xml :as xml]
|
||||
[leiningen.test.helper :refer [sample-no-aot-project
|
||||
[leiningen.test.helper :refer [unmemoize
|
||||
sample-no-aot-project
|
||||
uberjar-merging-project
|
||||
provided-project
|
||||
managed-deps-project
|
||||
|
@ -68,6 +69,8 @@
|
|||
(is (= 0 (:exit (sh "java" bootclasspath "-jar" filename))))))
|
||||
|
||||
(deftest test-uberjar-managed-dependencies
|
||||
(unmemoize #'leiningen.core.classpath/get-dependencies-memoized
|
||||
#'leiningen.core.classpath/get-dependencies*)
|
||||
(doseq [[proj jarfile] [[managed-deps-snapshot-project
|
||||
(str "test_projects/managed-deps-snapshot/target/"
|
||||
"mgmt-0.99.0-SNAPSHOT-standalone.jar")]
|
||||
|
@ -77,4 +80,4 @@
|
|||
(uberjar proj)
|
||||
(let [uberjar-file (File. jarfile)]
|
||||
(is (= true (.exists uberjar-file))
|
||||
(format "File '%s' does not exist!" uberjar-file)))))
|
||||
(format "File '%s' does not exist!" uberjar-file)))))
|
||||
|
|
Loading…
Reference in a new issue