Browse files

Fix #742, explicit middleware load error

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...
1 parent d7488b2 commit 99a7bfcea05859defd18daab9f0d6d214d832201 @ninjudd ninjudd committed Aug 23, 2012
Showing with 38 additions and 23 deletions.
  1. +33 −18 leiningen-core/src/leiningen/core/project.clj
  2. +5 −5 leiningen-core/src/leiningen/core/ssl.clj
View
51 leiningen-core/src/leiningen/core/project.clj
@@ -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)
@@ -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
@@ -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
@@ -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")))
View
10 leiningen-core/src/leiningen/core/ssl.clj
@@ -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.