Skip to content

Commit

Permalink
Fix technomancy#742, explicit middleware load error
Browse files Browse the repository at this point in the history
Don't call set-profiles from leiningen.core.project/read because it
calls load-middleware, and we want to wait to do that for the first time
in init-project. To solve this, I added init-profiles which is called by
both read and set-profiles.

Also clean up init-project and move code duplicated in set-profiles into
activate-middleware. We now always load hooks and certificates when
activating middleware, and load-certificates is actually called twice in
the course of init-project. To make sure load-certificates is
idempotent, we memoized leiningen.core.ssl/register-scheme.
  • Loading branch information
ninjudd committed Aug 23, 2012
1 parent d7488b2 commit 99a7bfc
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 23 deletions.
51 changes: 33 additions & 18 deletions leiningen-core/src/leiningen/core/project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -318,11 +318,19 @@
(ssl/register-scheme (ssl/https-scheme context))
project))

(defn activate-middleware
"A helper funtction to apply middleware and then load certificates and hooks,
since we always do these three things together, at least so far."
[project]
(doto (apply-middleware project)
(load-certificates)
(load-hooks)))

;; # High-level profile operations

(defn set-profiles
"Compute a fresh version of the project map with middleware applied, including
and excluding the specified profiles."
(defn- init-profiles
"Compute a fresh version of the project map, including and excluding the
specified profiles."
[project include-profiles & [exclude-profiles]]
(let [without-profiles (:without-profiles (meta project) project)
profile-map (apply dissoc (read-profiles project) exclude-profiles)
Expand All @@ -332,10 +340,14 @@
(normalize)
(vary-meta merge {:without-profiles without-profiles
:included-profiles include-profiles
:excluded-profiles exclude-profiles})
(apply-middleware)
(load-certificates)
(load-hooks))))
:excluded-profiles exclude-profiles}))))

(defn set-profiles
"Compute a fresh version of the project map, with "
[project include-profiles & [exclude-profiles]]
(-> project
(init-profiles include-profiles exclude-profiles)
(activate-middleware)))

(defn merge-profiles
"Compute a fresh version of the project map with the given profiles merged
Expand All @@ -355,19 +367,22 @@
(remove (set profiles) included-profiles)
(concat excluded-profiles profiles))))

;; TODO: unify with set-profiles above?
(defn init-project
"Initializes a project: loads certificates, loads plugins, then applies
middleware, and finally loads hooks. Adds dependencies to Leiningen's
classpath if required."
(defn- init-lein-classpath
"Adds dependencies to Leiningen's classpath if required."
[project]
(load-certificates project)
(when (= :leiningen (:eval-in project))
(doseq [path (classpath/get-classpath project)]
(pomegranate/add-classpath path)))
(load-plugins project)
(doto (apply-middleware project)
(load-hooks)))
(pomegranate/add-classpath path))))

(defn init-project
"Initializes a project. This is called at startup with the default profiles."
[project]
(-> project
(doto
(load-certificates)
(init-lein-classpath)
(load-plugins))
(activate-middleware)))

(defn ^{:deprecated "2.0.0-preview3"} conj-dependency
"Add a dependency into the project map if it's not already present. Warn the
Expand Down Expand Up @@ -404,6 +419,6 @@
(throw (Exception. "project.clj must define project map.")))
;; return it to original state
(ns-unmap 'leiningen.core.project 'project)
(set-profiles @project profiles))))
(init-profiles @project profiles))))
([file] (read file [:default]))
([] (read "project.clj")))
10 changes: 5 additions & 5 deletions leiningen-core/src/leiningen/core/ssl.clj
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@
(let [factory (SSLSocketFactory. context (BrowserCompatHostnameVerifier.))]
(Scheme. "https" port factory))))

(defn register-scheme
(def register-scheme
"Register a scheme with the HTTP Wagon for use with Aether."
[scheme]
(-> (.getConnectionManager (HttpWagon.))
(.getSchemeRegistry)
(.register scheme)))
(memoize (fn [scheme]
(-> (.getConnectionManager (HttpWagon.))
(.getSchemeRegistry)
(.register scheme)))))

0 comments on commit 99a7bfc

Please sign in to comment.