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] [clojure.string :as st]
[cryogen-core.classpath-able-io.fs :as fs] [cryogen-core.classpath-able-io.fs :as fs]
[cryogen-core.classpath-able-io.jar :as jar] [cryogen-core.classpath-able-io.jar :as jar]
[cryogen-core.classpath-able-io.cp :as cp]
[cryogen-core.classpath-able-io.this :as this] [cryogen-core.classpath-able-io.this :as this]
[schema.core :as s]) [schema.core :as s])
(:import [java.net URI] (:import [java.net URI]
@ -194,7 +195,7 @@
:or {from-cp true :or {from-cp true
from-fs true}}] from-fs true}}]
(let [fs-resources (fs/get-resources fs-prefix base-path paths) (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] (defn get-resource-paths-recursive ;:- [VirtualPath]

View file

@ -80,6 +80,13 @@
(not (= element norm-path-to-filter-for)))) (not (= element norm-path-to-filter-for))))
elements-list)))) 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 (defn jar-file-for-resource
[resource] [resource]
(JarFile. (JarFile.
@ -116,9 +123,11 @@
(let [entry-list (flatten (let [entry-list (flatten
(map (map
(fn [p] (fn [p]
(list-entries-for-dir (filter-and-remove-for-path
base-path p
(create-resource p (path-if-exists base-path p)))) (list-entries-for-dir
base-path
(create-resource p (path-if-exists base-path p)))))
paths))] paths))]
(map (fn [entry] (map (fn [entry]
(create-resource entry (path-if-exists base-path 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}] [{:virtual-path "dummy_from_jar", :source-type :java-classpath-jar, :resource-type :file}]
(map ftt/filter-object (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"]))))
(is (= (is (=
[{:virtual-path "test_pages/home" :source-type :java-classpath-filesystem :resource-type :dir} [{: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} {: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 (deftest test-list-entries-for-dir
(is (is
(= ["dummy2" "dummy_from_fs"] (= ["dummy2" "dummy_from_fs"]
(seq (sort
(sut/list-entries-for-dir (seq
(sut/create-resource "dummy" (sut/path-if-exists fs-root "dummy") :filesytem)))))) (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 (deftest test-get-resources
; TODO: base path should not be empty
(is (is
(= [{:virtual-path "dummy" :source-type :filesystem :resource-type :dir} (= [{: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" :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 (map ftt/filter-object
(sut/get-resources fs-root "" ["dummy"])))) (sut/get-resources fs-root "" ["dummy"]))))
(is (is

View file

@ -30,4 +30,10 @@
(is (is
(= [{:virtual-path "dummy_from_jar" :source-type :java-classpath-jar :resource-type :file}] (= [{:virtual-path "dummy_from_jar" :source-type :java-classpath-jar :resource-type :file}]
(map ftt/filter-object (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"])))))