refactor type -> this
This commit is contained in:
parent
5359fdd996
commit
928950e9b2
5 changed files with 34 additions and 20 deletions
BIN
doc/classpath_able_io_dependencies.png
Executable file
BIN
doc/classpath_able_io_dependencies.png
Executable file
Binary file not shown.
After Width: | Height: | Size: 31 KiB |
|
@ -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)
|
||||
|
|
|
@ -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]))
|
||||
|
||||
|
|
|
@ -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)))
|
||||
|
||||
|
|
|
@ -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)))
|
||||
(= :dir (:resource-type resource)))
|
||||
|
||||
(s/defn virtual-path-from-elements :- VirtualPath
|
||||
[& path-elements ;:- VirtualPath
|
||||
]
|
||||
(st/join "/"
|
||||
(filter #(not (empty? %))
|
||||
path-elements)))
|
Loading…
Reference in a new issue