Skip to content

Commit

Permalink
Add exclusion suggestions for version ranges.
Browse files Browse the repository at this point in the history
  • Loading branch information
technomancy committed Nov 16, 2013
1 parent a45e8a5 commit e78ebb6
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 20 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## 2.3.4 / ???

* Suggest `:exclusions` to possibly confusing `:pedantic?` dependencies. (Nelson Morris, Phil Hagelberg)
* Optionally look for snapshot templates in `new` task. (Travis Vachon)
* Allow task chains to be declared without commas in project.clj. (Jean Niklas L'orange)
* Support extra configurability in `:pom-plugins`. (Dominik Dziedzic)
* Fix a bug where implicit :aot warning triggered incorrectly. (Jean Niklas L'orange)
Expand Down
71 changes: 52 additions & 19 deletions leiningen-core/src/leiningen/core/classpath.clj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
[leiningen.core.utils :as utils]
[pedantic.core :as pedantic])
(:import (java.util.jar JarFile)
(org.sonatype.aether.graph Exclusion)
(org.sonatype.aether.resolution DependencyResolutionException)))

;; Basically just for re-throwing a more comprehensible error.
Expand Down Expand Up @@ -184,29 +185,59 @@
(get-dependencies-memoized dependencies-key (assoc project :offline? true))
(throw e)))))))

(defn- message-for [get-version path]
(str (->> path
(map #(if-let [dependency (.getDependency %)]
(if-let [artifact (.getArtifact dependency)]
(str "["
(if (= (.getGroupId artifact)
(.getArtifactId artifact))
(.getGroupId artifact)
(str (.getGroupId artifact)
"/"
(.getArtifactId artifact)))
" \""
(get-version %)
"\"]"))))
(remove nil?)
(interpose " -> ")
(apply str))))
(defn- group-artifact [artifact]
(if (= (.getGroupId artifact)
(.getArtifactId artifact))
(.getGroupId artifact)
(str (.getGroupId artifact)
"/"
(.getArtifactId artifact))))

(defn- dependency-str [dependency & [edge]]
(if-let [artifact (and dependency (.getArtifact dependency))]
(str "["
(group-artifact artifact)
" \""
;; TODO: this is bad; using an optional arg as a flag and a value
(if edge
(.getVersionConstraint edge)
(.getVersion artifact))
"\""
(if-let [classifier (.getClassifier artifact)]
(if (not (empty? classifier))
(str " :classifier \"" classifier "\"")))
(if-let [extension (.getExtension artifact)]
(if (not= extension "jar")
(str " :extension \"" extension "\"")))
(if-let [exclusions (seq (.getExclusions dependency))]
(str " :exclusions " (mapv (comp symbol group-artifact)
exclusions)))
"]")))

(defn- message-for [path & [show-constraint?]]
(->> path
(map #(dependency-str (.getDependency %) %))
(remove nil?)
(interpose " -> ")
(apply str)))

(defn- message-for-version [{:keys [node parents]}]
(message-for #(.getVersion %) (conj parents node)))
(message-for (conj parents node)))

(defn- exclusion-for-range [node parents]
(let [top-level (second parents)
excluded-artifact (.getArtifact (.getDependency node))
exclusion (Exclusion. (.getGroupId excluded-artifact)
(.getArtifactId excluded-artifact) "*" "*")
exclusion-set (into #{exclusion} (.getExclusions
(.getDependency top-level)))
with-exclusion (.setExclusions (.getDependency top-level) exclusion-set)]
(dependency-str with-exclusion)))

(defn- message-for-range [{:keys [node parents]}]
(message-for #(.getVersionConstraint %) (conj parents node)))
(str (message-for (conj parents node) :constraints) "\n"
"Consider using "
(exclusion-for-range node parents) "."))

(defn- message-for-override [{:keys [accepted ignoreds ranges]}]
{:accepted (message-for-version accepted)
Expand Down Expand Up @@ -255,6 +286,8 @@
#(-> % aether/repository-session
(pedantic/use-transformer ranges overrides))))

;; Exclusion(groupId, artifactId, classifier, extension)

(defn ^:internal get-dependencies [dependencies-key project & args]
(let [ranges (atom []), overrides (atom [])
session (pedantic-session project ranges overrides)
Expand Down
2 changes: 1 addition & 1 deletion leiningen-core/test/leiningen/core/test/classpath.clj
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
(dependency-hierarchy :dependencies project))))

(def directories
(vec (map lthelper/pathify
(vec (map lthelper/pathify
["/tmp/lein-sample-project/test"
"/tmp/lein-sample-project/src"
"/tmp/lein-sample-project/resources"])))
Expand Down

0 comments on commit e78ebb6

Please sign in to comment.