From e370ed23a080dce3fdf1f9f7baea98cec835faf3 Mon Sep 17 00:00:00 2001 From: bom Date: Fri, 31 Jan 2020 16:31:46 +0100 Subject: [PATCH] mob --- src/cryogen_core/classpath_able_io/fs.clj | 36 ++++++----------- src/cryogen_core/classpath_able_io/type.clj | 45 +++++++++++++++++++++ 2 files changed, 57 insertions(+), 24 deletions(-) create mode 100644 src/cryogen_core/classpath_able_io/type.clj diff --git a/src/cryogen_core/classpath_able_io/fs.clj b/src/cryogen_core/classpath_able_io/fs.clj index 6c84881..2112641 100644 --- a/src/cryogen_core/classpath_able_io/fs.clj +++ b/src/cryogen_core/classpath_able_io/fs.clj @@ -37,32 +37,20 @@ (when (Files/exists path-from-fs follow-link-option) path-from-fs))) -(defn create-resource - ([virtual-path - java-path] - {:virtual-path virtual-path - :java-uri (.toUri java-path) - :java-path java-path - :source-type :filesystem - :resource-type (cond - (Files/isDirectory java-path no-link-option) :dir - (Files/isRegularFile java-path no-link-option) :file - :else :unknown)})) +(defn source-type + [] + :filesystem) -; ------------------- infra --------------------------------- -(defn user-dir [] - (java.lang.System/getProperty "user.dir")) +(defn resource-type + [java-path] + (cond + (Files/isDirectory java-path follow-link-option) :dir + (Files/isRegularFile java-path follow-link-option) :file + :else :unknown)) -(defn path-from-fs - [full-path] - (let [path-from-fs (Paths/get (URI. (str "file://" full-path)))] ;fragile - (try - (when (Files/exists path-from-fs no-link-option) - path-from-fs) - (catch Exception e - nil)))) +; ------------------- infra --------------------------------- (defn list-entries-for-dir - [resource] - (.list (.toFile (:java-path resource)))) + [java-path] + (.list (.toFile java-path))) diff --git a/src/cryogen_core/classpath_able_io/type.clj b/src/cryogen_core/classpath_able_io/type.clj new file mode 100644 index 0000000..b4a65ce --- /dev/null +++ b/src/cryogen_core/classpath_able_io/type.clj @@ -0,0 +1,45 @@ +; Copyright (c) meissa. All rights reserved. +; The use and distribution terms for this software are covered by the +; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) +; which can be found in the file epl-v10.html at the root of this distribution. +; By using this software in any fashion, you are agreeing to be bound by +; the terms of this license. +; You must not remove this notice, or any other, from this software. + +(ns cryogen-core.classpath-able-io.type + (:require [clojure.java.io :as io] + [clojure.string :as st] + [schema.core :as s] + [cryogen-core.classpath-able-io.fs :as fs]) + (:import [java.net URI] + [java.util.jar JarFile JarEntry] + [java.nio.file FileSystems Paths Files LinkOption StandardCopyOption] + [java.nio.file.attribute FileAttribute])) + +; -------------------- Domain Definition ------------------------------ +(def SourceType (s/enum :java-classpath-filesystem :java-classpath-jar :filesystem)) +(def ResourceType (s/enum :file :dir :unknown)) +(def Prefix s/Str) +(def JavaUri s/Any) ; java.net.URI +(def VirtualPath s/Str) +(def JavaPath s/Any) ; java.nio.Path +(def Resource + {:virtual-path VirtualPath + :source-type SourceType + :resource-type ResourceType + :java-uri JavaUri + :java-path JavaPath}) + +(defn create-resource + ([virtual-path + java-path] + {:virtual-path virtual-path + :java-uri (.toUri java-path) + :java-path java-path + :source-type (fs/source-type) + :resource-type (fs/resource-type java-path)})) + +(defn + list-entries-for-dir + [resource] + (fs/list-entries-for-dir (:java-path resource))) \ No newline at end of file