diff --git a/fs_root/dummy/dummy2/dummy2_from_fs b/fs_root/dummy/dummy2/dummy2_from_fs new file mode 100644 index 0000000..e69de29 diff --git a/src/cryogen_core/classpath_able_io.clj b/src/cryogen_core/classpath_able_io.clj index 8489412..be4a822 100644 --- a/src/cryogen_core/classpath_able_io.clj +++ b/src/cryogen_core/classpath_able_io.clj @@ -11,6 +11,7 @@ [clojure.string :as st] [cryogen-core.classpath-able-io.fs :as fs] [cryogen-core.classpath-able-io.jar :as jar] + [cryogen-core.classpath-able-io.cp :as cp] [cryogen-core.classpath-able-io.this :as this] [schema.core :as s]) (:import [java.net URI] @@ -194,7 +195,7 @@ :or {from-cp true from-fs true}}] (let [fs-resources (fs/get-resources fs-prefix base-path paths) - jar-resources (jar/get-resources base-path paths)]) + cp-resources (cp/get-resources base-path paths)]) ) (defn get-resource-paths-recursive ;:- [VirtualPath] diff --git a/src/cryogen_core/classpath_able_io/jar.clj b/src/cryogen_core/classpath_able_io/jar.clj index 3b082ed..942fcac 100644 --- a/src/cryogen_core/classpath_able_io/jar.clj +++ b/src/cryogen_core/classpath_able_io/jar.clj @@ -80,6 +80,13 @@ (not (= element norm-path-to-filter-for)))) elements-list)))) +(defn filter-and-remove-for-path + [path-to-filter-for + virtual-paths-list] + (filter + #(st/starts-with? % path-to-filter-for) + virtual-paths-list)) + (defn jar-file-for-resource [resource] (JarFile. @@ -116,9 +123,11 @@ (let [entry-list (flatten (map (fn [p] - (list-entries-for-dir - base-path - (create-resource p (path-if-exists base-path p)))) + (filter-and-remove-for-path + p + (list-entries-for-dir + base-path + (create-resource p (path-if-exists base-path p))))) paths))] (map (fn [entry] (create-resource entry (path-if-exists base-path entry))) diff --git a/test/cryogen_core/classpath_able_io/cp_test.clj b/test/cryogen_core/classpath_able_io/cp_test.clj index affb4e5..676f45f 100644 --- a/test/cryogen_core/classpath_able_io/cp_test.clj +++ b/test/cryogen_core/classpath_able_io/cp_test.clj @@ -30,6 +30,12 @@ [{:virtual-path "dummy_from_jar", :source-type :java-classpath-jar, :resource-type :file}] (map ftt/filter-object (sut/get-resources "dummy" ["dummy_from_jar"])))) + (is (= + [{:virtual-path "dummy2", :source-type :java-classpath-jar, :resource-type :dir} + {:virtual-path "dummy2/dummy_common", :source-type :java-classpath-jar, :resource-type :file} + {:virtual-path "dummy2/dummy2_from_jar", :source-type :java-classpath-jar, :resource-type :file}] + (map ftt/filter-object + (sut/get-resources "dummy" ["dummy2"])))) (is (= [{:virtual-path "test_pages/home" :source-type :java-classpath-filesystem :resource-type :dir} {:virtual-path "test_pages/home/.gitkeep" :source-type :java-classpath-filesystem :resource-type :file} diff --git a/test/cryogen_core/classpath_able_io/fs_test.clj b/test/cryogen_core/classpath_able_io/fs_test.clj index 396e765..2606c19 100644 --- a/test/cryogen_core/classpath_able_io/fs_test.clj +++ b/test/cryogen_core/classpath_able_io/fs_test.clj @@ -33,16 +33,20 @@ (deftest test-list-entries-for-dir (is (= ["dummy2" "dummy_from_fs"] - (seq - (sut/list-entries-for-dir - (sut/create-resource "dummy" (sut/path-if-exists fs-root "dummy") :filesytem)))))) + (sort + (seq + (sut/list-entries-for-dir + (sut/create-resource "dummy" (sut/path-if-exists fs-root "dummy") :filesytem))))))) +; TODO: sort output to get consistent tests on all systems. Yet, order of output maps can be different on different systems (deftest test-get-resources + ; TODO: base path should not be empty (is (= [{:virtual-path "dummy" :source-type :filesystem :resource-type :dir} - {:virtual-path "dummy/dummy_from_fs" :source-type :filesystem :resource-type :file} {:virtual-path "dummy/dummy2" :source-type :filesystem :resource-type :dir} - {:virtual-path "dummy/dummy2/dummy_common" :source-type :filesystem :resource-type :file}] + {:virtual-path "dummy/dummy2/dummy2_from_fs" :source-type :filesystem :resource-type :file} + {:virtual-path "dummy/dummy2/dummy_common" :source-type :filesystem :resource-type :file} + {:virtual-path "dummy/dummy_from_fs" :source-type :filesystem :resource-type :file}] (map ftt/filter-object (sut/get-resources fs-root "" ["dummy"])))) (is diff --git a/test/cryogen_core/classpath_able_io/jar_test.clj b/test/cryogen_core/classpath_able_io/jar_test.clj index 7abdec8..1e41993 100644 --- a/test/cryogen_core/classpath_able_io/jar_test.clj +++ b/test/cryogen_core/classpath_able_io/jar_test.clj @@ -30,4 +30,10 @@ (is (= [{:virtual-path "dummy_from_jar" :source-type :java-classpath-jar :resource-type :file}] (map ftt/filter-object - (sut/get-resources "dummy" ["dummy_from_jar"]))))) + (sut/get-resources "dummy" ["dummy_from_jar"])))) + (is + (= [{:virtual-path "dummy2", :source-type :java-classpath-jar, :resource-type :dir} + {:virtual-path "dummy2/dummy_common", :source-type :java-classpath-jar, :resource-type :file} + {:virtual-path "dummy2/dummy2_from_jar", :source-type :java-classpath-jar, :resource-type :file}] + (map ftt/filter-object + (sut/get-resources "dummy" ["dummy2"])))))