diff --git a/CHANGELOG.md b/CHANGELOG.md index 8985f673..b964782f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## master (unreleased) +* [#285](https://github.com/clojure-emacs/orchard/issues/285): **BREAKING:** Remove special handling of Boot classpath. + ## 0.26.3 (2024-08-14) * [#282](https://github.com/clojure-emacs/orchard/issues/282): Inspector: don't crash when inspecting internal classes. diff --git a/src/orchard/info.clj b/src/orchard/info.clj index 1bfe3ea9..9a8b474b 100644 --- a/src/orchard/info.clj +++ b/src/orchard/info.clj @@ -5,7 +5,6 @@ [orchard.cljs.analysis :as cljs-ana] [orchard.cljs.meta :as cljs-meta] [orchard.java :as java] - [orchard.java.classpath :as cp] [orchard.java.resource :as resource] [orchard.meta :as m] [orchard.misc :as misc])) @@ -158,8 +157,7 @@ meta (merge (when-let [file-path (:file meta)] - {:file (cond-> file-path - (misc/boot-project?) cp/classpath-file-relative-path)}))))) + {:file file-path}))))) (defn info "Provide the info map for the input ns and sym. diff --git a/src/orchard/java/classpath.clj b/src/orchard/java/classpath.clj index 4bebbbc2..9124ad4b 100644 --- a/src/orchard/java/classpath.clj +++ b/src/orchard/java/classpath.clj @@ -1,17 +1,13 @@ (ns orchard.java.classpath "Classpath access and modification utilities. - Provides an alternative to the java.classpath contrib library. - The library is Boot-aware, meaning it takes into account the - classpath manipulation magic, performed by the Boot build tool." + Provides an alternative to the java.classpath contrib library." (:require [clojure.java.io :as io] - [clojure.string :as string] [orchard.misc :as misc]) (:import (java.io File) - (java.net URI URL URLClassLoader) - (java.nio.file Paths) + (java.net URL URLClassLoader) (java.util.jar JarEntry JarFile))) ;;; Classloaders @@ -97,48 +93,3 @@ (file-seq f)) (filter #(not (.isDirectory ^File %))) (map #(.getPath (.relativize (.toURI url) (.toURI ^File %))))))))) - -;;; Boot support - previously part of cider-nrepl -;; -;; The Boot build tool stores files in a temporary directory, so -;; we have to do a bit of work to figure out where the real resources are. - -(defn boot-classloader - "Creates a class-loader that knows original source files paths in Boot project." - [] - (let [class-path (System/getProperty "fake.class.path") - dir-separator (System/getProperty "file.separator") - paths (string/split class-path (re-pattern (System/getProperty "path.separator"))) - urls (map - (fn [path] - (let [url (if (re-find #".jar$" path) - (str "file:" path) - (str "file:" path dir-separator))] - (.toURL (URI. url)))) - paths)] - ;; TODO: Figure out how to add the JDK sources here - (new java.net.URLClassLoader (into-array java.net.URL urls)))) - -(defn boot-aware-classloader - [] - (if (misc/boot-project?) - (boot-classloader) - (context-classloader))) - -(defn classpath-file-relative-path - "Boot stores files in a temporary directory & ClojureScript stores - the :file metadata location absolutely instead of relatively to the - classpath. This means when doing jump to source in Boot & - ClojureScript, you end up at the temp file. This code attempts to - find the classpath-relative location of the file, so that it can be - opened correctly." - [s] - (let [path (Paths/get s (into-array String [])) - path-count (.getNameCount path)] - (or (first - (sequence - (comp (map #(.subpath path % path-count)) - (map str) - (filter io/resource)) - (range path-count))) - s))) diff --git a/src/orchard/java/resource.clj b/src/orchard/java/resource.clj index 4622365a..1dd79be2 100644 --- a/src/orchard/java/resource.clj +++ b/src/orchard/java/resource.clj @@ -37,10 +37,10 @@ :url (io/as-url file)}))) (remove #(.startsWith ^String (:relpath %) "META-INF/")) (remove #(re-matches #".*\.(clj[cs]?|java|class)" (:relpath %))))) - (filter (memfn ^File isDirectory) (map io/as-file (cp/classpath (cp/boot-aware-classloader)))))) + (filter (memfn ^File isDirectory) (map io/as-file (cp/classpath (cp/context-classloader)))))) (defn resource-full-path ^URL [relative-path] - (io/resource relative-path (cp/boot-aware-classloader))) + (io/resource relative-path (cp/context-classloader))) (defn resource-path-tuple "If it's a resource, return a tuple of the relative path and the full diff --git a/src/orchard/misc.clj b/src/orchard/misc.clj index c7b10a98..5066ca62 100644 --- a/src/orchard/misc.clj +++ b/src/orchard/misc.clj @@ -9,20 +9,6 @@ (defn os-windows? [] (.startsWith (System/getProperty "os.name") "Windows")) -(defn boot-fake-classpath - "Retrieve Boot's fake classpath. - When using Boot, fake.class.path contains the original directories with source - files, which makes it way more useful than the real classpath. - See https://github.com/boot-clj/boot/issues/249 for details." - [] - (System/getProperty "fake.class.path")) - -(defn boot-project? - "Check whether we're dealing with a Boot project. - We figure this by checking for the presence of Boot's fake classpath." - [] - (not (nil? (boot-fake-classpath)))) - (defn url? "Check whether the argument is an url" [u] diff --git a/test/orchard/info_test.clj b/test/orchard/info_test.clj index c2728cc8..2f8ccc38 100644 --- a/test/orchard/info_test.clj +++ b/test/orchard/info_test.clj @@ -454,17 +454,10 @@ :doc "catch-clause => (catch classname name expr*)\n finally-clause => (finally expr*)\n\n Catches and handles Java exceptions.", :name finally, :special-form true, - :url "https://clojure.org/special_forms#finally"}] - (testing "- boot project" - (with-redefs [orchard.misc/boot-project? (constantly true)] - (let [i (info/info* params)] - (is (= expected (select-keys i [:ns :name :doc :forms :special-form :url]))) - (is (nil? (:file i)))))) - - (testing "- no boot project" - (let [i (info/info* params)] - (is (= expected (select-keys i [:ns :name :doc :forms :special-form :url]))) - (is (nil? (:file i)))))))) + :url "https://clojure.org/special_forms#finally"} + i (info/info* params)] + (is (= expected (select-keys i [:ns :name :doc :forms :special-form :url]))) + (is (nil? (:file i)))))) (deftest file-resolution-no-defs-issue-75-test (testing "File resolves, issue #75" @@ -721,20 +714,6 @@ (info/normalize-params) (select-keys [:ns :unqualified-sym])))))) -(deftest boot-file-resolution-test - ;; this checks the files on the classpath soo you need the test-resources - ;; and specifically test-resources/orchard/test_ns.cljc - ;; - ;; Note that :file in :meta is left untouched - (when cljs-available? - (with-redefs [orchard.misc/boot-project? (constantly true)] - (is (= '{:ns orchard.test-ns - :name x - :file "orchard/test_ns.cljc"} - (-> (merge @*cljs-params* '{:ns orchard.test-ns :sym x}) - (info/info*) - (select-keys [:ns :name :file]))))))) - (deftest indirect-vars-cljs (when cljs-available? (testing "Uses logic from `merge-meta-for-indirect-var-cljs`"