Unmemoize in order to fix tests.

This commit is contained in:
Phil Hagelberg 2017-06-04 09:38:00 -07:00
parent ad6c4bd290
commit 63305fcccd
6 changed files with 77 additions and 67 deletions

View file

@ -252,70 +252,71 @@
(def ^:private ^:dynamic *dependencies-session* (def ^:private ^:dynamic *dependencies-session*
"This is dynamic in order to avoid memoization issues.") "This is dynamic in order to avoid memoization issues.")
(def ^:private get-dependencies-memoized (defn- get-dependencies*
(memoize [dependencies-key managed-dependencies-key
(fn [dependencies-key managed-dependencies-key {:keys [repositories local-repo offline? update
{:keys [repositories local-repo offline? update checksum mirrors] :as project}
checksum mirrors] :as project} {:keys [add-classpath?] :as args}]
{:keys [add-classpath?] :as args}] {:pre [(every? vector? (get project dependencies-key))
{:pre [(every? vector? (get project dependencies-key)) (every? vector? (get project managed-dependencies-key))]}
(every? vector? (get project managed-dependencies-key))]} (try
(try ((if add-classpath?
((if add-classpath? pomegranate/add-dependencies
pomegranate/add-dependencies aether/resolve-dependencies)
aether/resolve-dependencies) :repository-session-fn *dependencies-session*
:repository-session-fn *dependencies-session* :local-repo local-repo
:local-repo local-repo :offline? offline?
:offline? offline? :repositories (->> repositories
:repositories (->> repositories (map add-repo-auth)
(map add-repo-auth) (map (partial update-policies update checksum)))
(map (partial update-policies update checksum))) :managed-coordinates (get project managed-dependencies-key)
:managed-coordinates (get project managed-dependencies-key) :coordinates (get project dependencies-key)
:coordinates (get project dependencies-key) :mirrors (->> mirrors
:mirrors (->> mirrors (map add-repo-auth)
(map add-repo-auth) (map (partial update-policies update checksum)))
(map (partial update-policies update checksum))) :transfer-listener
:transfer-listener (bound-fn [e]
(bound-fn [e] (let [{:keys [type resource error]} e]
(let [{:keys [type resource error]} e] (let [{:keys [repository name size trace]} resource]
(let [{:keys [repository name size trace]} resource] (let [aether-repos (if trace (.getRepositories (.getData trace)))]
(let [aether-repos (if trace (.getRepositories (.getData trace)))] (case type
(case type :started
:started (if-let [repo (first (filter
(if-let [repo (first (filter #(or (= (.getUrl %) repository)
#(or (= (.getUrl %) repository) ;; sometimes the "base" url
;; sometimes the "base" url ;; doesn't have a slash on it
;; doesn't have a slash on it (= (str (.getUrl %) "/") repository))
(= (str (.getUrl %) "/") repository)) aether-repos))]
aether-repos))] (locking *err*
(locking *err* (warn "Retrieving" name "from" (.getId repo)))
(warn "Retrieving" name "from" (.getId repo))) ;; else case happens for metadata files
;; else case happens for metadata files )
) nil)))))
nil))))) :proxy (get-proxy-settings))
:proxy (get-proxy-settings)) (catch DependencyResolutionException e
(catch DependencyResolutionException e ;; Cannot recur from catch/finally so have to put this in its own defn
;; Cannot recur from catch/finally so have to put this in its own defn (print-failures e)
(print-failures e) (warn "This could be due to a typo in :dependencies, file system permissions, or network issues.")
(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.")
(warn "If you are behind a proxy, try setting the 'http_proxy' environment variable.") (throw (ex-info "Could not resolve dependencies" {:suppress-msg true
(throw (ex-info "Could not resolve dependencies" {:suppress-msg true :exit-code 1} e)))
:exit-code 1} e))) (catch Exception e
(catch Exception e (let [exception-cause (root-cause e)]
(let [exception-cause (root-cause e)] (if (and (or (instance? java.net.UnknownHostException exception-cause)
(if (and (or (instance? java.net.UnknownHostException exception-cause) (instance? java.net.NoRouteToHostException exception-cause))
(instance? java.net.NoRouteToHostException exception-cause)) (not offline?))
(not offline?)) (get-dependencies* dependencies-key managed-dependencies-key
(get-dependencies-memoized dependencies-key managed-dependencies-key (assoc project :offline? true) args)
(assoc project :offline? true) args) (throw e))))))
(throw e))))))))
(def ^:private get-dependencies-memoized (memoize get-dependencies*))
(defn ^:internal get-dependencies [dependencies-key managed-dependencies-key (defn ^:internal get-dependencies [dependencies-key managed-dependencies-key
project & args] project & args]
(let [ranges (atom []), overrides (atom []) (let [ranges (atom []), overrides (atom [])
trimmed (select-keys project [dependencies-key managed-dependencies-key trimmed (select-keys project [dependencies-key managed-dependencies-key
:repositories :checksum :local-repo :repositories :checksum :local-repo
:offline? :update :mirrors]) :offline? :update :mirrors :memoize-buster])
deps-result (binding [*dependencies-session* (pedantic/session deps-result (binding [*dependencies-session* (pedantic/session
project ranges overrides)] project ranges overrides)]
(get-dependencies-memoized dependencies-key (get-dependencies-memoized dependencies-key

View file

@ -96,8 +96,8 @@
;; :plugins and will also be available to deploy to. ;; :plugins and will also be available to deploy to.
;; Add ^:replace (:repositories ^:replace [...]) to only use repositories you ;; Add ^:replace (:repositories ^:replace [...]) to only use repositories you
;; list below. ;; list below.
:repositories [["java.net" "http://download.java.net/maven/2"] :repositories [["java.net" "https://download.java.net/maven/2"]
["sonatype" {:url "http://oss.sonatype.org/content/repositories/releases" ["sonatype" {:url "https://oss.sonatype.org/content/repositories/releases"
;; If a repository contains releases only setting ;; If a repository contains releases only setting
;; :snapshots to false will speed up dependencies. ;; :snapshots to false will speed up dependencies.
:snapshots false :snapshots false
@ -117,8 +117,8 @@
;; Credentials for repositories should *not* be stored ;; Credentials for repositories should *not* be stored
;; in project.clj but in ~/.lein/credentials.clj.gpg instead, ;; in project.clj but in ~/.lein/credentials.clj.gpg instead,
;; see `lein help deploying` under "Authentication". ;; see `lein help deploying` under "Authentication".
["snapshots" "http://blueant.com/archiva/snapshots"] ["snapshots" "https://blueant.com/archiva/snapshots"]
["releases" {:url "http://blueant.com/archiva/internal" ["releases" {:url "https://blueant.com/archiva/internal"
;; Using :env as a value here will cause an ;; Using :env as a value here will cause an
;; environment variable to be used based on ;; environment variable to be used based on
;; the key; in this case LEIN_PASSWORD. ;; the key; in this case LEIN_PASSWORD.

View file

@ -136,3 +136,6 @@
(def #^{:macro true} with-system-out-str #'utils/with-system-out-str) (def #^{:macro true} with-system-out-str #'utils/with-system-out-str)
(def #^{:macro true} with-system-err-str #'utils/with-system-err-str) (def #^{:macro true} with-system-err-str #'utils/with-system-err-str)
(defn unmemoize [v underlying]
(alter-var-root v (constantly underlying)))

View file

@ -6,12 +6,12 @@
[clojure.java.io :only [file]])) [clojure.java.io :only [file]]))
(deftest ^:online test-install (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) (delete-file-recursively (m2-dir "nomnomnom" "0.5.0-SNAPSHOT") true)
(install sample-project) (install sample-project)
(is (not (empty? (.listFiles (m2-dir "nomnomnom" "0.5.0-SNAPSHOT")))))) (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")) (def tricky-m2-dir (file local-repo "org" "domain" "tricky-name" "1.0"))
(deftest ^:online test-tricky-name-install (deftest ^:online test-tricky-name-install

View file

@ -5,7 +5,8 @@
[leiningen.core.utils :refer [platform-nullsink]] [leiningen.core.utils :refer [platform-nullsink]]
[leiningen.test.helper :as helper] [leiningen.test.helper :as helper]
[robert.hooke :as hooke] [robert.hooke :as hooke]
[leiningen.javac :as javac]) [leiningen.javac :as javac]
[leiningen.test.helper :refer [unmemoize]])
(:use [clojure.test] (:use [clojure.test]
[leiningen.jar])) [leiningen.jar]))
@ -92,6 +93,8 @@
"jar produces two jar files"))) "jar produces two jar files")))
(deftest ^:online test-no-deps-jar (deftest ^:online test-no-deps-jar
(unmemoize #'leiningen.core.classpath/get-dependencies-memoized
#'leiningen.core.classpath/get-dependencies*)
(let [[coord jar-file] (first (let [[coord jar-file] (first
(jar (dissoc helper/sample-project (jar (dissoc helper/sample-project
:dependencies :main)))] :dependencies :main)))]

View file

@ -4,7 +4,8 @@
[clojure.java.io :refer [delete-file]] [clojure.java.io :refer [delete-file]]
[clojure.java.shell :refer [sh]] [clojure.java.shell :refer [sh]]
[clojure.xml :as xml] [clojure.xml :as xml]
[leiningen.test.helper :refer [sample-no-aot-project [leiningen.test.helper :refer [unmemoize
sample-no-aot-project
uberjar-merging-project uberjar-merging-project
provided-project provided-project
managed-deps-project managed-deps-project
@ -68,6 +69,8 @@
(is (= 0 (:exit (sh "java" bootclasspath "-jar" filename)))))) (is (= 0 (:exit (sh "java" bootclasspath "-jar" filename))))))
(deftest test-uberjar-managed-dependencies (deftest test-uberjar-managed-dependencies
(unmemoize #'leiningen.core.classpath/get-dependencies-memoized
#'leiningen.core.classpath/get-dependencies*)
(doseq [[proj jarfile] [[managed-deps-snapshot-project (doseq [[proj jarfile] [[managed-deps-snapshot-project
(str "test_projects/managed-deps-snapshot/target/" (str "test_projects/managed-deps-snapshot/target/"
"mgmt-0.99.0-SNAPSHOT-standalone.jar")] "mgmt-0.99.0-SNAPSHOT-standalone.jar")]
@ -77,4 +80,4 @@
(uberjar proj) (uberjar proj)
(let [uberjar-file (File. jarfile)] (let [uberjar-file (File. jarfile)]
(is (= true (.exists uberjar-file)) (is (= true (.exists uberjar-file))
(format "File '%s' does not exist!" uberjar-file))))) (format "File '%s' does not exist!" uberjar-file)))))