diff --git a/CHANGELOG.md b/CHANGELOG.md index 4b6db7372..be9333f77 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ ### Bugs Fixed * [#123](https://github.com/clojure-emacs/orchard/pull/123): Fix info lookups from namespaces that don't yet exist +* [#125](https://github.com/clojure-emacs/orchard/pull/125): Don't fail if the classpath references a non-existing .jar ## 0.7.1 (2021-04-18) diff --git a/src/orchard/java/classpath.clj b/src/orchard/java/classpath.clj index 26c3865e3..6e76ad73c 100644 --- a/src/orchard/java/classpath.clj +++ b/src/orchard/java/classpath.clj @@ -84,10 +84,16 @@ as relative paths." [^URL url] (let [f (io/as-file url)] - (if (misc/archive? url) + (cond + (not (.exists f)) + [] + + (misc/archive? url) (->> (enumeration-seq (.entries (JarFile. f))) (filter #(not (.isDirectory ^JarEntry %))) (map #(.getName ^JarEntry %))) + + :else (->> (file-seq f) (filter #(not (.isDirectory ^File %))) (map #(.getPath (.relativize (.toURI url) (.toURI ^File %)))))))) diff --git a/test/orchard/java/classpath_test.clj b/test/orchard/java/classpath_test.clj index 16001eb39..b8abaa0ed 100644 --- a/test/orchard/java/classpath_test.clj +++ b/test/orchard/java/classpath_test.clj @@ -60,9 +60,32 @@ (deftest classpath-resources-test (testing "Iterating classpath resources" (testing "returns non-empty lists" - (doseq [entry (map cp/classpath-seq (cp/classpath))] - (is (seq entry) - (pr-str entry)))) + (let [dev-resources-path (-> "dev-resources" File. .getAbsolutePath) + the-classpath (cp/classpath) + corpus (->> the-classpath + (filter (fn [^URL u] + (let [f (-> u io/as-file)] + ;; filter out intentionally non-existing files + ;; (which we put in the :test classpath for reproducing certain bug) + (and (-> f .exists) + (not (= (.getAbsolutePath f) + ;; remove dev-resources, only present in the :dev profile: + dev-resources-path))))))) + ^File non-existing-jar (->> the-classpath + (filter (fn [u] + ;; Find the non-existing jar declared under the :test profile: + (-> u io/as-file str (.contains "does-not-exist.jar")))) + first)] + (assert (seq corpus) + "There's something to test") + (assert non-existing-jar + "The classpath includes he non-existing jar") + (is (not (.exists non-existing-jar)) + "Orchard will succeed even in presence of an entry in the classpath that refers to a non-existing.jar") + (doseq [item corpus + :let [entry (cp/classpath-seq item)]] + (is (seq entry) + (pr-str [item entry]))))) (testing "returns relative paths" (doseq [^String entry (mapcat cp/classpath-seq (cp/classpath))] (is (not (-> entry File. .isAbsolute))))))))