Compare commits
No commits in common. "b11f3edd61351090ad45170e3a6188aeb73be370" and "f2925a2991a23034f1ce30a9f6ce61f2fe16b230" have entirely different histories.
b11f3edd61
...
f2925a2991
7 changed files with 28 additions and 58 deletions
|
@ -1,4 +1,4 @@
|
||||||
(defproject org.domaindrivenarchitecture/c4k-common-cljs "6.2.4-SNAPSHOT"
|
(defproject org.domaindrivenarchitecture/c4k-common-cljs "6.2.3-SNAPSHOT"
|
||||||
:description "Contains predicates and tools for c4k"
|
:description "Contains predicates and tools for c4k"
|
||||||
:url "https://domaindrivenarchitecture.org"
|
:url "https://domaindrivenarchitecture.org"
|
||||||
:license {:name "Apache License, Version 2.0"
|
:license {:name "Apache License, Version 2.0"
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
(defproject org.domaindrivenarchitecture/c4k-common-clj "6.2.4-SNAPSHOT"
|
(defproject org.domaindrivenarchitecture/c4k-common-clj "6.2.3-SNAPSHOT"
|
||||||
:description "Contains predicates and tools for c4k"
|
:description "Contains predicates and tools for c4k"
|
||||||
:url "https://domaindrivenarchitecture.org"
|
:url "https://domaindrivenarchitecture.org"
|
||||||
:license {:name "Apache License, Version 2.0"
|
:license {:name "Apache License, Version 2.0"
|
||||||
:url "https://www.apache.org/licenses/LICENSE-2.0.html"}
|
:url "https://www.apache.org/licenses/LICENSE-2.0.html"}
|
||||||
:dependencies [[org.clojure/clojure "1.11.2"]
|
:dependencies [[org.clojure/clojure "1.11.1" :scope "provided"]
|
||||||
[org.clojure/tools.reader "1.4.1"]
|
[org.clojure/tools.reader "1.4.0"]
|
||||||
[aero "1.1.6"]
|
[aero "1.1.6"]
|
||||||
[orchestra "2021.01.01-1"]
|
[orchestra "2021.01.01-1"]
|
||||||
[expound "0.9.0"]
|
[expound "0.9.0"]
|
||||||
|
@ -26,7 +26,7 @@
|
||||||
:main dda.c4k-common.uberjar
|
:main dda.c4k-common.uberjar
|
||||||
:uberjar-name "c4k-common-standalone.jar"
|
:uberjar-name "c4k-common-standalone.jar"
|
||||||
:dependencies [[org.clojure/tools.cli "1.1.230"]
|
:dependencies [[org.clojure/tools.cli "1.1.230"]
|
||||||
[ch.qos.logback/logback-classic "1.5.3"
|
[ch.qos.logback/logback-classic "1.5.1"
|
||||||
:exclusions [com.sun.mail/javax.mail]]
|
:exclusions [com.sun.mail/javax.mail]]
|
||||||
[org.slf4j/jcl-over-slf4j "2.0.12"]]}}
|
[org.slf4j/jcl-over-slf4j "2.0.12"]]}}
|
||||||
:release-tasks [["test"]
|
:release-tasks [["test"]
|
||||||
|
|
|
@ -1,34 +1,9 @@
|
||||||
(ns dda.c4k-common.macros
|
(ns dda.c4k-common.macros
|
||||||
(:require [clojure.java.io :as io]
|
(:require [clojure.java.io :as io]))
|
||||||
[clojure.string :as str])
|
|
||||||
(:import java.util.jar.JarFile))
|
|
||||||
|
|
||||||
(defn inline-resource-file [resource-url relative-resource-folder-path]
|
|
||||||
(let [files (.listFiles (io/file resource-url))
|
|
||||||
file-contents (map slurp files)
|
|
||||||
file-names (map #(str relative-resource-folder-path "/" (.getName %)) files)]
|
|
||||||
(zipmap file-names file-contents)))
|
|
||||||
|
|
||||||
(defn inline-resource-jar [resource-url]
|
|
||||||
(let [resource-url-string (.toString resource-url)
|
|
||||||
; Remove jar:file:
|
|
||||||
start-absolute (str/replace-first resource-url-string "jar:file:" "")
|
|
||||||
; Split path into jar base and search folder
|
|
||||||
jar-split (str/split start-absolute #"!/")
|
|
||||||
absolute-jar-path (first jar-split)
|
|
||||||
relative-file-path (second jar-split)
|
|
||||||
jar (JarFile. absolute-jar-path)
|
|
||||||
files (->> (enumeration-seq (.entries jar))
|
|
||||||
(filter #(str/starts-with? % relative-file-path))
|
|
||||||
(filter #(not (.isDirectory %))))
|
|
||||||
file-names (map #(.getName %) files)
|
|
||||||
file-contents (map #(slurp (.getInputStream jar %)) files)]
|
|
||||||
(zipmap file-names file-contents)))
|
|
||||||
|
|
||||||
(defmacro inline-resources [resource-path]
|
(defmacro inline-resources [resource-path]
|
||||||
(let [resource-url (io/resource resource-path)
|
(let [files (.listFiles (io/file (io/resource resource-path)))
|
||||||
resource-protocol (.getProtocol resource-url)]
|
file-contents (map slurp files)
|
||||||
(case resource-protocol
|
file-names (map #(str resource-path "/" (.getName %)) files)]
|
||||||
"file" (inline-resource-file resource-url resource-path)
|
(zipmap file-names file-contents))
|
||||||
"jar" (inline-resource-jar resource-url))))
|
)
|
||||||
|
|
||||||
|
|
|
@ -1,14 +1,18 @@
|
||||||
(ns dda.c4k-common.namespace.namespace-internal
|
(ns dda.c4k-common.namespace.namespace-internal
|
||||||
(:require
|
(:require
|
||||||
[clojure.spec.alpha :as s]
|
[clojure.spec.alpha :as s]
|
||||||
|
#?(:cljs [shadow.resource :as rc])
|
||||||
#?(:clj [orchestra.core :refer [defn-spec]]
|
#?(:clj [orchestra.core :refer [defn-spec]]
|
||||||
:cljs [orchestra.core :refer-macros [defn-spec]])
|
:cljs [orchestra.core :refer-macros [defn-spec]])
|
||||||
[dda.c4k-common.yaml :as yaml]
|
[dda.c4k-common.yaml :as yaml]))
|
||||||
#?(:cljs [dda.c4k-common.macros :refer-macros [inline-resources]])))
|
|
||||||
|
|
||||||
#?(:cljs
|
#?(:cljs
|
||||||
(defmethod yaml/load-resource :namespace [resource-name]
|
(defmethod yaml/load-resource :namespace [resource-name]
|
||||||
(get (inline-resources "namespace") resource-name)))
|
(case resource-name
|
||||||
|
"namespace/namespace.yaml" (rc/inline "namespace/namespace.yaml")
|
||||||
|
(throw (js/Error. (str "Undefined Resource: " resource-name))))))
|
||||||
|
|
||||||
|
|
||||||
(s/def ::namespace string?)
|
(s/def ::namespace string?)
|
||||||
|
|
||||||
|
|
|
@ -1,21 +1,13 @@
|
||||||
(ns dda.c4k-common.macros-test
|
(ns dda.c4k-common.macros-test
|
||||||
(:require
|
(:require
|
||||||
[clojure.test :refer [deftest is are testing run-tests]]
|
[clojure.test :refer [deftest is are testing run-tests]]
|
||||||
[dda.c4k-common.macros :as cut :refer [inline-resources]]))
|
[dda.c4k-common.macros :refer [inline-resources]]))
|
||||||
|
|
||||||
(deftest should-count-inline-resources
|
(deftest should-count-inline-resources
|
||||||
(is (= 3 (count (inline-resources "dda/c4k_common/inline_resources_test")))))
|
(is (= 3 (count (inline-resources "dda/c4k_common/inline_resources_test")))))
|
||||||
|
|
||||||
(deftest should-inline-resources
|
(deftest should-inline-resources
|
||||||
(let [resource-path (fn [name] (str "dda/c4k_common/inline_resources_test/" name))
|
(let [resource-path (fn [name] (str "dda/c4k_common/inline_resources_test/" name))]
|
||||||
inlined-resources (inline-resources "dda/c4k_common/inline_resources_test")]
|
(is (= "1" (get (inline-resources "dda/c4k_common/inline_resources_test") (resource-path "inline_resource_1.yaml"))))
|
||||||
(is (= "1" (get inlined-resources (resource-path "inline_resource_1.yaml"))))
|
(is (= "2" (get (inline-resources "dda/c4k_common/inline_resources_test") (resource-path "inline_resource_2.yaml"))))
|
||||||
(is (= "2" (get inlined-resources (resource-path "inline_resource_2.yaml"))))
|
(is (= "3" (get (inline-resources "dda/c4k_common/inline_resources_test") (resource-path "inline_resource_3.yaml"))))))
|
||||||
(is (= "3" (get inlined-resources (resource-path "inline_resource_3.yaml"))))))
|
|
||||||
|
|
||||||
(deftest should-inline-jar-resources
|
|
||||||
(let [jar-url (java.net.URL. "jar:file:./src/test/resources/dda/c4k_common/inline_jar_test/test.jar!/inline_resources_test/")
|
|
||||||
inlined-resources (cut/inline-resource-jar jar-url)]
|
|
||||||
(is (= "1" (get inlined-resources "inline_resources_test/inline_resource_1.yaml")))
|
|
||||||
(is (= "2" (get inlined-resources "inline_resources_test/inline_resource_2.yaml")))
|
|
||||||
(is (= "3" (get inlined-resources "inline_resources_test/inline_resource_3.yaml")))))
|
|
||||||
|
|
|
@ -7,8 +7,7 @@
|
||||||
(is (= 4 (count (inline-resources "ingress")))))
|
(is (= 4 (count (inline-resources "ingress")))))
|
||||||
|
|
||||||
(deftest should-inline-resources
|
(deftest should-inline-resources
|
||||||
(let [resource-path (fn [name] (str "dda/c4k_common/inline_resources_test/" name))
|
(let [resource-path (fn [name] (str "dda/c4k_common/inline_resources_test/" name))]
|
||||||
inlined-resources (inline-resources "dda/c4k_common/inline_resources_test")]
|
(is (= "1" (get (inline-resources "dda/c4k_common/inline_resources_test") (resource-path "inline_resource_1.yaml"))))
|
||||||
(is (= "1" (get inlined-resources (resource-path "inline_resource_1.yaml"))))
|
(is (= "2" (get (inline-resources "dda/c4k_common/inline_resources_test") (resource-path "inline_resource_2.yaml"))))
|
||||||
(is (= "2" (get inlined-resources (resource-path "inline_resource_2.yaml"))))
|
(is (= "3" (get (inline-resources "dda/c4k_common/inline_resources_test") (resource-path "inline_resource_3.yaml"))))))
|
||||||
(is (= "3" (get inlined-resources (resource-path "inline_resource_3.yaml"))))))
|
|
||||||
|
|
Binary file not shown.
Loading…
Reference in a new issue