Skip to content
Browse files

Tweaks for gh-48:

* change `classloader-resources` to return URLs instead of strings
* mapcat results of `resources`
* minimal tests for `resources`
  • Loading branch information...
1 parent 2ae9213 commit c0eee85a79fb044bcb61595a59ee568de0b8c6d4 @cemerick committed
Showing with 22 additions and 5 deletions.
  1. +3 −5 src/main/clojure/cemerick/pomegranate.clj
  2. +19 −0 src/test/clojure/cemerick/pomegranate_test.clj
View
8 src/main/clojure/cemerick/pomegranate.clj
@@ -100,10 +100,8 @@
what clojure.java.io/resource returns."
([classloaders resource-name]
(for [classloader (reverse classloaders)]
- [classloader
- (map str
- (enumeration-seq
- (.getResources ^ClassLoader classloader resource-name)))]))
+ [classloader (enumeration-seq
+ (.getResources ^ClassLoader classloader resource-name))]))
([resource-name] (classloader-resources (classloader-hierarchy) resource-name)))
(defn resources
@@ -113,5 +111,5 @@
circumstances, the first of the returned sequence will be the same
as what clojure.java.io/resource returns."
([classloaders resource-name]
- (distinct (map second (classloader-resources classloaders resource-name))))
+ (distinct (mapcat second (classloader-resources classloaders resource-name))))
([resource-name] (resources (classloader-hierarchy) resource-name)))
View
19 src/test/clojure/cemerick/pomegranate_test.clj
@@ -0,0 +1,19 @@
+(ns cemerick.pomegranate-test
+ (:require [cemerick.pomegranate :as p]
+ clojure.java.io)
+ (:use clojure.test))
+
+(deftest resources
+ (is (= (first (p/resources "META-INF/MANIFEST.MF"))
+ (clojure.java.io/resource "META-INF/MANIFEST.MF")))
+
+ ; the last classloader should be ext, for e.g. $JAVA_HOME/lib/ext/*
+ (is (->> (p/resources [(last (p/classloader-hierarchy))] "META-INF/MANIFEST.MF")
+ (map str)
+ (filter #(.contains % "clojure"))
+ empty?))
+
+ (is (->> (p/resources (butlast (p/classloader-hierarchy)) "META-INF/MANIFEST.MF")
+ (map str)
+ (filter #(.contains % "clojure"))
+ seq)))

0 comments on commit c0eee85

Please sign in to comment.
Something went wrong with that request. Please try again.