diff --git a/doc/classpath_able_io_dependencies.png b/doc/classpath_able_io_dependencies.png new file mode 100755 index 0000000..625cc8c Binary files /dev/null and b/doc/classpath_able_io_dependencies.png differ diff --git a/src/cryogen_core/classpath_able_io.clj b/src/cryogen_core/classpath_able_io.clj index 00071cc..8489412 100644 --- a/src/cryogen_core/classpath_able_io.clj +++ b/src/cryogen_core/classpath_able_io.clj @@ -11,16 +11,24 @@ [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.type :as type] + [cryogen-core.classpath-able-io.this :as this] [schema.core :as s]) (:import [java.net URI] [java.util.jar JarFile JarEntry] [java.nio.file FileSystems Paths Files LinkOption StandardCopyOption] [java.nio.file.attribute FileAttribute])) -(s/defn create-fs-resource :- type/Resource - ([virtual-path :- type/VirtualPath - java-path :- type/JavaPath] +(def SourceType this/SourceType) +(def ResourceType this/ResourceType) +(def Prefix this/Prefix) +(def JavaUri this/JavaUri) ; java.net.URI +(def VirtualPath this/VirtualPath) +(def JavaPath this/JavaPath) ; java.nio.Path +(def Resource this/Resource) + +(s/defn create-fs-resource :- this/Resource + ([virtual-path :- this/VirtualPath + java-path :- this/JavaPath] {:virtual-path virtual-path :java-uri (.toUri java-path) :java-path java-path @@ -31,9 +39,9 @@ :else :unknown)})) -(s/defn create-cp-resource :- type/Resource - ([virtual-path :- type/VirtualPath - java-path :- type/JavaPath] +(s/defn create-cp-resource :- this/Resource + ([virtual-path :- this/VirtualPath + java-path :- this/JavaPath] (let [java-uri (.toUri java-path)] {:virtual-path virtual-path :java-uri java-uri @@ -63,7 +71,7 @@ ; contains either a jar or a file (s/defn path-from-cp ;:- JavaPath - [resource-path :- type/VirtualPath] + [resource-path :- this/VirtualPath] (try (let [resource-uri (.toURI (io/resource resource-path))] (when (jar/is-from-classpath-jar? resource-uri) @@ -74,7 +82,7 @@ nil))) (s/defn path-from-fs ;:- JavaPath - [full-path :- type/VirtualPath] + [full-path :- this/VirtualPath] (let [path-from-fs (Paths/get (URI. (str "file://" full-path)))] ;fragile (try (when (Files/exists path-from-fs fs/no-link-option) @@ -133,7 +141,7 @@ (s/defn list-entries-for-dir ;:- [VirtualPath] - [resource :- type/Resource] + [resource :- this/Resource] (if (= :java-classpath-jar (:source-type resource)) (filter-and-remove-for-dir (:virtual-path resource) @@ -167,7 +175,7 @@ ; (println (:java-path resource-to-work-with)) (cond (nil? resource-to-work-with) [] - (type/is-file? resource-to-work-with) + (this/is-file? resource-to-work-with) (recur (drop 1 paths) result) :else (recur (into (drop 1 paths) diff --git a/src/cryogen_core/classpath_able_io/fs.clj b/src/cryogen_core/classpath_able_io/fs.clj index 108f88b..deb61ff 100644 --- a/src/cryogen_core/classpath_able_io/fs.clj +++ b/src/cryogen_core/classpath_able_io/fs.clj @@ -7,7 +7,7 @@ ; You must not remove this notice, or any other, from this software. (ns cryogen-core.classpath-able-io.fs - (:require [cryogen-core.classpath-able-io.type :as type]) + (:require [cryogen-core.classpath-able-io.this :as type]) (:import [java.net URI] [java.nio.file Paths Files LinkOption])) diff --git a/src/cryogen_core/classpath_able_io/jar.clj b/src/cryogen_core/classpath_able_io/jar.clj index 4443cd7..4f5eb33 100644 --- a/src/cryogen_core/classpath_able_io/jar.clj +++ b/src/cryogen_core/classpath_able_io/jar.clj @@ -9,7 +9,7 @@ (ns cryogen-core.classpath-able-io.jar (:require [clojure.java.io :as io] [clojure.string :as st] - [cryogen-core.classpath-able-io.type :as type] + [cryogen-core.classpath-able-io.this :as this] [cryogen-core.classpath-able-io.fs :as fs]) (:import [java.net URI] [java.util.jar JarFile JarEntry] @@ -61,10 +61,10 @@ (filter #(not (empty? %)) path-elements))))] (when (is-from-classpath-jar? resource-uri) - (init-file-system resource-uri)) - ;; TODO: hier steckt auch eine "from-fs-cp" funktionalität drinne - (when (Files/exists (Paths/get resource-uri) fs/no-link-option) - (Paths/get resource-uri))) + (do + (init-file-system resource-uri) + (when (Files/exists (Paths/get resource-uri) fs/no-link-option) + (Paths/get resource-uri))))) (catch Exception e nil))) diff --git a/src/cryogen_core/classpath_able_io/type.clj b/src/cryogen_core/classpath_able_io/this.clj similarity index 81% rename from src/cryogen_core/classpath_able_io/type.clj rename to src/cryogen_core/classpath_able_io/this.clj index 602711a..1a08fb4 100644 --- a/src/cryogen_core/classpath_able_io/type.clj +++ b/src/cryogen_core/classpath_able_io/this.clj @@ -6,12 +6,11 @@ ; the terms of this license. ; You must not remove this notice, or any other, from this software. -(ns cryogen-core.classpath-able-io.type +(ns cryogen-core.classpath-able-io.this (:require [clojure.java.io :as io] [clojure.string :as st] [schema.core :as s])) -; -------------------- Domain Definition ------------------------------ (def SourceType (s/enum :java-classpath-filesystem :java-classpath-jar :filesystem)) (def ResourceType (s/enum :file :dir :unknown)) (def Prefix s/Str) @@ -31,4 +30,11 @@ (s/defn is-dir? :- s/Bool [resource :- Resource] - (= :dir (:resource-type resource))) \ No newline at end of file + (= :dir (:resource-type resource))) + +(s/defn virtual-path-from-elements :- VirtualPath + [& path-elements ;:- VirtualPath + ] + (st/join "/" + (filter #(not (empty? %)) + path-elements)))