import URI, fix uri construction with first

This commit is contained in:
jem 2020-01-17 19:21:02 +01:00
parent 02f9c57612
commit 9a4ab2bc0f
2 changed files with 7 additions and 10 deletions

View file

@ -10,7 +10,7 @@
(:require [clojure.java.io :as io]
[clojure.string :as st]
[schema.core :as s])
(:import [java.net Uri]
(:import [java.net URI]
[java.nio.file FileSystems Paths Files SimpleFileVisitor LinkOption StandardCopyOption]
[java.nio.file.attribute FileAttribute]))
@ -78,7 +78,7 @@
(s/defn init-file-system
[resource-uri :- ResourceUri]
(let [filesystem-uri (Uri. (pop (st/split (.toString resource-uri) #"!")))]
(let [filesystem-uri (URI. (first (st/split (.toString resource-uri) #"!")))]
(try
(FileSystems/getFileSystem filesystem-uri)
(catch Exception e
@ -89,7 +89,7 @@
[resource-path :- ShortPath]
(try
(let [resource-uri (.toURI (io/resource resource-path))] ; check if contains jar:
(when (st/starts-with? (.toString resource-uri) "jar:")
(when (= (.getScheme resource-uri) "jar")
(init-file-system resource-uri))
(when (Files/exists (Paths/get resource-uri) NoLinkOption)
(Paths/get resource-uri)))
@ -98,7 +98,7 @@
(s/defn path-from-fs ; :- JavaPath
[full-path :- ShortPath]
(let [path-from-fs (Paths/get (java.net.URI. (str "file://" full-path)))] ;fragile
(let [path-from-fs (Paths/get (URI. (str "file://" full-path)))] ;fragile
(try
(when (Files/exists path-from-fs NoLinkOption)
path-from-fs)
@ -205,7 +205,7 @@
[""]
:from-cp false))]
(doseq [resource-path resource-paths]
(Files/delete (Paths/get (java.net.URI. (str "file://" (java.lang.System/getProperty "user.dir") "/" short-path resource-path))))
(Files/delete (Paths/get (URI. (str "file://" (java.lang.System/getProperty "user.dir") "/" short-path resource-path))))
)))
; TODO: add ignore patterns filtering
@ -222,7 +222,7 @@
(throw (IllegalArgumentException. (str "resource " resource-paths ", "
source-paths " not found")))
(doseq [resource-path resource-paths]
(let [target-file (Paths/get (java.net.URI. (str "file://" (java.lang.System/getProperty "user.dir") "/" target-path "/" resource-path)))
(let [target-file (Paths/get (URI. (str "file://" (java.lang.System/getProperty "user.dir") "/" target-path "/" resource-path)))
source-file (path-from-cp-or-fs
fs-prefix
base-path

View file

@ -23,13 +23,10 @@
(def NoLinkOption (into-array [LinkOption/NOFOLLOW_LINKS]))
(sut/init-file-system (io/resource "dummy"))
; TODO: Fix this test!
(deftest test-file-from-cp
(is
(sut/path-from-cp
"dummy")))
(sut/path-from-cp "dummy")))
; TODO: one dummy from jar and one dummy from cp-filesystem and one from filesystem
; get resources and see all