This commit is contained in:
bom 2020-01-31 16:31:46 +01:00
parent a9a58b0a25
commit e370ed23a0
2 changed files with 57 additions and 24 deletions

View file

@ -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)
(defn resource-type
[java-path]
(cond
(Files/isDirectory java-path follow-link-option) :dir
(Files/isRegularFile java-path follow-link-option) :file
:else :unknown))
; ------------------- infra ---------------------------------
(defn user-dir []
(java.lang.System/getProperty "user.dir"))
(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))))
(defn
list-entries-for-dir
[resource]
(.list (.toFile (:java-path resource))))
[java-path]
(.list (.toFile java-path)))

View file

@ -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)))