Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wip: replace pomegranate with alembic #224

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function check_result {
fi
}

lein do clean, source-deps :prefix-exclusions "[\"classlojure\"]"
lein do clean, source-deps
check_result
lein with-profile +plugin.mranderson/config test
check_result
Expand Down
20 changes: 11 additions & 9 deletions project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/tools.nrepl "0.2.13"]
^:source-dep [http-kit "2.2.0"]
^:source-dep [http-kit "2.3.0"]
^:source-dep [cheshire "5.8.0"]
^:source-dep [alembic "0.3.2"]
^:source-dep [com.cemerick/pomegranate "1.0.0"]
^:source-dep [commons-codec "1.10"]
^:source-dep [org.apache.httpcomponents/httpclient "4.5.3"]
^:source-dep [org.slf4j/jcl-over-slf4j "1.7.22"]
^:source-dep [org.clojure/tools.analyzer.jvm "0.7.1"]
^:source-dep [org.clojure/tools.namespace "0.3.0-alpha3"]
^:source-dep [org.clojure/tools.reader "1.1.1"]
^:source-dep [org.clojure/tools.namespace "0.3.0-alpha4"]
^:source-dep [org.clojure/tools.reader "1.3.0-alpha3"]
^:source-dep [cider/orchard "0.2.0"]
^:source-dep [lein-cljfmt "0.3.0"]
^:source-dep [me.raynes/fs "1.4.6"]
Expand All @@ -19,21 +22,20 @@
:plugins [[thomasa/mranderson "0.4.8"]]
:filespecs [{:type :bytes :path "refactor-nrepl/refactor-nrepl/project.clj" :bytes ~(slurp "project.clj")}]
:profiles {:provided {:dependencies [[cider/cider-nrepl "0.14.0"]
[org.clojure/clojure "1.7.0"]]}
[org.clojure/clojure "1.8.0"]]}
:test {:dependencies [[print-foo "1.0.2"]]
:src-paths ["test/resources"]}
:1.8 {:dependencies [[org.clojure/clojure "1.8.0"]]}
:1.9 {:dependencies [[org.clojure/clojure "1.9.0"]
[org.clojure/clojurescript "1.9.908"]]}
:dev {:plugins [[jonase/eastwood "0.2.0"]]
:global-vars {*warn-on-reflection* true}
:dependencies [[org.clojure/clojurescript "1.9.89"]
[com.cemerick/piggieback "0.2.2"]
:dependencies [[org.clojure/clojurescript "1.10.238"]
[cider/piggieback "0.2.3"]
Copy link
Member

@bbatsov bbatsov Jun 8, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That should be 0.3.6.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and cemerick.piggieback needs to be updated in refactor-nrepl.ns.resolve-missing-test

there are still failures and errors when tests are run but it compiles after the above changes

[leiningen-core "2.7.1"]
[commons-io/commons-io "2.6"]]
:repl-options {:nrepl-middleware [cemerick.piggieback/wrap-cljs-repl]}
:java-source-paths ["test/java"]
:resource-paths ["test/resources"
"test/resources/testproject/src"]
:repositories [["snapshots" "http://oss.sonatype.org/content/repositories/snapshots"]]}}
:repositories [["snapshots" "https://oss.sonatype.org/content/repositories/snapshots"]]}}
:jvm-opts ["-Djava.net.preferIPv4Stack=true"])
31 changes: 22 additions & 9 deletions src/refactor_nrepl/artifacts.clj
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
(ns refactor-nrepl.artifacts
(:require [alembic.still :as alembic]
(:require [cemerick.pomegranate :as pomegranate]
[cemerick.pomegranate.aether :as aether]
[cheshire.core :as json]
[clojure
[edn :as edn]
Expand All @@ -10,7 +11,8 @@
[refactor-nrepl.ns.slam.hound.search :as slamhound]
[refactor-nrepl.ns.slam.hound.regrow :as slamhound-regrow]
[version-clj.core :as versions])
(:import java.util.Date
(:import clojure.lang.DynamicClassLoader
java.util.Date
java.util.jar.JarFile))

;; structure here is {"prismatic/schem" ["0.1.1" "0.2.0" ...]}
Expand All @@ -29,7 +31,7 @@
"Returns a vector of [[some/lib \"0.1\"]...]."
[]
(try
(->> "https://clojars.org/repo/all-jars.clj"
(->> "https://repo.clojars.org/all-jars.clj"
java.net.URL.
io/reader
line-seq
Expand Down Expand Up @@ -116,9 +118,10 @@
"Once the deps are available on cp we still have to load them and
reset slamhound's cache to make resolve-missing work."
[coords repos]
(let [dep (->> (alembic/resolve-dependencies alembic/the-still coords repos nil)
(some (fn [dep] (when (= (:coords dep) (first coords)) dep))))
jarfile (JarFile. (:jar dep))]
(let [dep (->> (aether/resolve-dependencies :coordinates coords
:repositories repos)
(some (fn [dep] (when (= (key dep) (first coords)) dep))))
jarfile (JarFile. (-> dep first meta :file))]
(doseq [namespace (find/find-namespaces-in-jarfile jarfile)]
(try
(require namespace)
Expand Down Expand Up @@ -148,16 +151,26 @@
(throw (IllegalArgumentException. (str "Can't find artifact '"
(first coords) "'"))))))

(defn get-classloader []
"Returns the highest level DynamicClassLoader."
(loop [loader (.getContextClassLoader (Thread/currentThread))]
(let [parent (.getParent loader)]
(if (instance? DynamicClassLoader parent)
(recur parent)
loader))))

(defn distill [coords repos]
;; Just so we can mock this out during testing
(alembic/distill coords :repositories repos))
(pomegranate/add-dependencies :classloader (get-classloader)
:coordinates coords
:repositories repos))

(defn hotload-dependency
[{:keys [coordinates]}]
(let [dependency-vector (edn/read-string coordinates)
coords [(->> dependency-vector (take 2) vec)]
repos {"clojars" "http://clojars.org/repo"
"central" "http://repo1.maven.org/maven2/"}]
repos (merge aether/maven-central
{"clojars" "https://repo.clojars.org/"})]
(ensure-quality-coordinates coordinates)
(distill coords repos)
(make-resolve-missing-aware-of-new-deps coords repos)
Expand Down