From da9bfedfd8002bbc76d8c085d3aa406e9b16b796 Mon Sep 17 00:00:00 2001 From: jem Date: Fri, 10 Jan 2020 18:11:36 +0100 Subject: [PATCH] issue: loading from jar file is not working --- project.clj | 5 +++-- src/cryogen_core/classpath_able_io.clj | 13 ++++++------ test/cryogen_core/classpath_able_io_test.clj | 6 ++++++ test/cryogen_core/classpath_able_io_test.repl | 21 +++++++++++++++++++ 4 files changed, 37 insertions(+), 8 deletions(-) create mode 100644 test/cryogen_core/classpath_able_io_test.repl diff --git a/project.clj b/project.clj index d56e0a6..8ccae14 100644 --- a/project.clj +++ b/project.clj @@ -24,8 +24,9 @@ :resource-paths ["test-resources"] :dependencies [] :leiningen/reply - {:dependencies [[org.slf4j/jcl-over-slf4j "1.8.0-beta0"]] + {:dependencies [[org.slf4j/jcl-over-slf4j "1.8.0-beta0"] + [dda/dummy "0.1.0-SNAPSHOT"]] :exclusions [commons-logging]}} :test {:source-paths ["test"] :resource-paths ["test-resources"] - :dependencies []}}) + :dependencies [[dda/dummy "0.1.0-SNAPSHOT"]]}}) diff --git a/src/cryogen_core/classpath_able_io.clj b/src/cryogen_core/classpath_able_io.clj index 1af0f0e..2920a96 100644 --- a/src/cryogen_core/classpath_able_io.clj +++ b/src/cryogen_core/classpath_able_io.clj @@ -9,7 +9,8 @@ (ns cryogen-core.classpath-able-io (:require [clojure.java.io :as io] [clojure.string :as st] - [schema.core :as s])) + [schema.core :as s]) + (:import [java.nio.file FileSystems Paths Files])) (def SourceType (s/enum :classpath :filesystem)) @@ -73,12 +74,12 @@ (s/defn file-from-cp ; :- File [resource-path :- Path] - (let [file-from-cp (io/file (io/resource resource-path))] - (try + (try + (let [file-from-cp (io/file (io/resource resource-path))] (when (.exists file-from-cp) - file-from-cp) - (catch Exception e - nil)))) + file-from-cp)) + (catch Exception e + nil))) (s/defn file-from-fs ; :- File [fs-prefix :- Prefix diff --git a/test/cryogen_core/classpath_able_io_test.clj b/test/cryogen_core/classpath_able_io_test.clj index 300f5ce..7f120da 100644 --- a/test/cryogen_core/classpath_able_io_test.clj +++ b/test/cryogen_core/classpath_able_io_test.clj @@ -19,6 +19,12 @@ (def target "target/tmp") +; TODO: Fix this test! +(deftest test-file-from-cp + (is + (sut/file-from-cp + "dummy"))) + (deftest test-resource-from-cp-or-fs (is (.exists diff --git a/test/cryogen_core/classpath_able_io_test.repl b/test/cryogen_core/classpath_able_io_test.repl new file mode 100644 index 0000000..eab9791 --- /dev/null +++ b/test/cryogen_core/classpath_able_io_test.repl @@ -0,0 +1,21 @@ +TODO: to solve reading from jars: + 1. create fs + + +(FileSystems/newFileSystem + (java.net.URI. + "jar:file:/home/jem/.m2/repository/dda/dummy/0.1.0-SNAPSHOT/dummy-0.1.0-SNAPSHOT.jar") + {}) + + + 2. be able to use it + +(Files/exists + (.getPath + (FileSystems/getFileSystem + (java.net.URI. + "jar:file:/home/jem/.m2/repository/dda/dummy/0.1.0-SNAPSHOT/dummy-0.1.0-SNAPSHOT.jar")) + "dummy" + (into-array String '())) + (into-array java.nio.file.LinkOption {})) +