Browse files

Add conj-dependency function.

  • Loading branch information...
1 parent 28397ad commit 02e39e507ac4aa57d489f19eaee0dc4aca11cd33 @technomancy committed Mar 1, 2012
Showing with 24 additions and 5 deletions.
  1. +21 −1 leiningen-core/src/leiningen/core/project.clj
  2. +3 −4 todo.org
View
22 leiningen-core/src/leiningen/core/project.clj
@@ -67,8 +67,19 @@
(defn- dedupe-deps [deps]
(first (reduce dedupe-step [[] #{}] deps)))
+(defn- exclude [exclusions deps dep]
+ (let [exclusions-offset (.indexOf dep :exclusions)]
+ (conj deps (if (pos? exclusions-offset)
+ (update-in dep [(inc exclusions-offset)] into exclusions)
+ dep))))
+
+(defn- add-exclusions [deps exclusions]
+ (reduce (partial exclude exclusions) [] deps))
+
(defn normalize-deps [project]
- (update-in project [:dependencies] dedupe-deps))
+ (-> project
+ (update-in [:dependencies] dedupe-deps)
+ (update-in [:dependencies] add-exclusions (:exclusions project))))
(defn normalize-plugins [project]
(update-in project [:plugins] dedupe-deps))
@@ -194,6 +205,15 @@
(require (symbol m-ns)))
((resolve middleware-name) project))
+(defn conj-dependency
+ "Add a dependency into the project map if it's not already present. Warn the
+ user if it is. Plugins should use this rather than altering :dependencies."
+ [project dependency]
+ (if (some #(= (first %) (first dependency)) (:dependencies project))
+ (do (println "WARNING: Tried to add" dependency "but was already present.")
+ project)
+ (update-in project [:dependencies] conj dependency)))
+
(defn read
"Read project map out of file, which defaults to project.clj."
([file profiles]
View
7 todo.org
@@ -28,11 +28,10 @@ See also https://github.com/technomancy/leiningen/issues
- [X] Pass user-level repository auth settings on to pomegranate
- [X] Use ordered map for :dependencies and :repositories?
- [X] Project middleware
+ - [X] Top-level :exclusions
+ - [X] Better error messages for misformatted :dependencies/:repositories
+ - [X] Utility function for plugins to conditionally add dependencies
- [ ] Look for :java-cmd in project map
- - [ ] Better error messages for misformatted :dependencies/:repositories
- - [ ] Test top-level :exclusions
- - [ ] Utility function for plugins to add dependencies
- Needs to be a no-op if the dep is present, but warn
** Other stuff (post-preview)
- [ ] Offline mode
- [ ] Honor hooks declared in plugin jar metadata?

0 comments on commit 02e39e5

Please sign in to comment.