Skip to content

Commit

Permalink
Upgrade Aether via new pomegranate; merge pedantic into leiningen-core.
Browse files Browse the repository at this point in the history
  • Loading branch information
technomancy committed May 26, 2017
1 parent 781195f commit c968fa5
Show file tree
Hide file tree
Showing 8 changed files with 292 additions and 128 deletions.
13 changes: 4 additions & 9 deletions leiningen-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,15 @@
<dependency>
<groupId>com.cemerick</groupId>
<artifactId>pomegranate</artifactId>
<version>0.3.1</version>
<version>0.4.0-alpha1</version>
<exclusions>
<exclusion>
<artifactId>dynapath</artifactId>
<groupId>org.tcrawley</groupId>
<artifactId>dynapath</artifactId>
</exclusion>
<exclusion>
<artifactId>plexus-utils</artifactId>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
</exclusion>
</exclusions>
</dependency>
Expand All @@ -113,8 +113,8 @@
<version>2.12</version>
<exclusions>
<exclusion>
<artifactId>wagon-provider-api</artifactId>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-provider-api</artifactId>
</exclusion>
</exclusions>
</dependency>
Expand All @@ -123,11 +123,6 @@
<artifactId>io</artifactId>
<version>0.3.1</version>
</dependency>
<dependency>
<groupId>pedantic</groupId>
<artifactId>pedantic</artifactId>
<version>0.2.0</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-nop</artifactId>
Expand Down
3 changes: 1 addition & 2 deletions leiningen-core/project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@
[bultitude "0.2.8" :exclusions [org.tcrawley/dynapath]]
[org.flatland/classlojure "0.7.1"]
[robert/hooke "1.3.0"]
[com.cemerick/pomegranate "0.3.1"
[com.cemerick/pomegranate "0.4.0-alpha1"
:exclusions [org.tcrawley/dynapath
org.codehaus.plexus/plexus-utils]]
[org.tcrawley/dynapath "0.2.5"]
[org.apache.maven.wagon/wagon-http "2.12"
:exclusions [org.apache.maven.wagon/wagon-provider-api]]
[com.hypirion/io "0.3.1"]
[pedantic "0.2.0"]
[org.slf4j/slf4j-nop "1.7.22"] ; wagon-http uses slf4j
;; we pull this in transitively but want a newer version
[org.clojure/tools.macro "0.1.5"]]
Expand Down
116 changes: 4 additions & 112 deletions leiningen-core/src/leiningen/core/classpath.clj
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@
[clojure.set :as set]
[leiningen.core.user :as user]
[leiningen.core.utils :as utils]
[pedantic.core :as pedantic])
[leiningen.core.pedantic :as pedantic])
(:import (java.util.jar JarFile)
(org.sonatype.aether.graph Exclusion)
(org.sonatype.aether.resolution DependencyResolutionException)))
(org.eclipse.aether.resolution DependencyResolutionException)))

(defn- warn [& args]
;; TODO: remove me once #1227 is merged
Expand Down Expand Up @@ -307,125 +306,18 @@
(get-dependencies-memoized dependencies-key (assoc project :offline? true))
(throw e))))))))

(defn- group-artifact [artifact]
(if (= (.getGroupId artifact)
(.getArtifactId artifact))
(.getGroupId artifact)
(str (.getGroupId artifact)
"/"
(.getArtifactId artifact))))

(defn- dependency-str [dependency & [version]]
(if-let [artifact (and dependency (.getArtifact dependency))]
(str "["
(group-artifact artifact)
" \"" (or version (.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 %) (.getVersionConstraint %)))
(remove nil?)
(interpose " -> ")
(apply str)))

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

(defn- exclusion-for-range [node parents]
(if-let [top-level (second parents)]
(let [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]}]
(str (message-for (conj parents node) :constraints) "\n"
"Consider using "
(exclusion-for-range node parents) "."))

(defn- exclusion-for-override [{:keys [node parents]}]
(exclusion-for-range node parents))

(defn- message-for-override [{:keys [accepted ignoreds ranges]}]
{:accepted (message-for-version accepted)
:ignoreds (map message-for-version ignoreds)
:ranges (map message-for-range ranges)
:exclusions (map exclusion-for-override ignoreds)})

(defn- pedantic-print-ranges [messages]
(when-not (empty? messages)
(warn "WARNING!!! version ranges found for:")
(doseq [dep-string messages]
(warn dep-string))
(warn)))

(defn- pedantic-print-overrides [messages]
(when-not (empty? messages)
(warn "Possibly confusing dependencies found:")
(doseq [{:keys [accepted ignoreds ranges exclusions]} messages]
(warn accepted)
(warn " overrides")
(doseq [ignored (interpose " and" ignoreds)]
(warn ignored))
(when-not (empty? ranges)
(warn " possibly due to a version range in")
(doseq [r ranges]
(warn r)))
(warn "\nConsider using these exclusions:")
(doseq [ex (distinct exclusions)]
(warn ex))
(warn))))

(alter-var-root #'pedantic-print-ranges memoize)
(alter-var-root #'pedantic-print-overrides memoize)

(defn- pedantic-do [pedantic-setting ranges overrides]
;; Need to turn everything into a string before calling
;; pedantic-print-*, otherwise we can't memoize due to bad equality
;; semantics on aether GraphEdge objects.
(let [key (keyword pedantic-setting)
abort-or-true (#{true :abort} key)]
(when (and key (not= key :overrides))
(pedantic-print-ranges (distinct (map message-for-range ranges))))
(when (and key (not= key :ranges))
(pedantic-print-overrides (map message-for-override overrides)))
(when (and abort-or-true
(not (empty? (concat ranges overrides))))
(require 'leiningen.core.main)
((resolve 'leiningen.core.main/abort) ; cyclic dependency =\
"Aborting due to :pedantic? :abort"))))

(defn- pedantic-session [project ranges overrides]
(if (:pedantic? project)
#(-> % aether/repository-session
(pedantic/use-transformer ranges overrides))))

(defn ^:internal get-dependencies [dependencies-key managed-dependencies-key
project & args]
(let [ranges (atom []), overrides (atom [])
session (pedantic-session project ranges overrides)
session (pedantic/session project ranges overrides)
args (assoc (apply hash-map args) :repository-session-fn session)
trimmed (select-keys project [dependencies-key managed-dependencies-key
:repositories :checksum :local-repo :offline?
:update :mirrors])
deps-result (get-dependencies-memoized dependencies-key
managed-dependencies-key
trimmed args)]
(pedantic-do (:pedantic? project) @ranges @overrides)
(pedantic/do (:pedantic? project) @ranges @overrides)
deps-result))

(defn- get-original-dependency
Expand Down

0 comments on commit c968fa5

Please sign in to comment.