Fixed bug in jar/get-resources

This commit is contained in:
Clemens Geibel 2020-02-11 14:10:49 +01:00
parent 3b2d21ad96
commit 91e4c5a09a
6 changed files with 36 additions and 10 deletions

View file

View 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]

View file

@ -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)))

View file

@ -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}

View 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

View file

@ -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"])))))