Fixed bug in jar/get-resources
This commit is contained in:
parent
3b2d21ad96
commit
91e4c5a09a
6 changed files with 36 additions and 10 deletions
0
fs_root/dummy/dummy2/dummy2_from_fs
Normal file
0
fs_root/dummy/dummy2/dummy2_from_fs
Normal file
|
@ -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]
|
||||
|
|
|
@ -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)))
|
||||
|
|
|
@ -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}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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"])))))
|
||||
|
|
Loading…
Reference in a new issue