issue: loading from jar file is not working

This commit is contained in:
jem 2020-01-10 18:11:36 +01:00
parent 090f784089
commit da9bfedfd8
4 changed files with 37 additions and 8 deletions

View file

@ -24,8 +24,9 @@
:resource-paths ["test-resources"] :resource-paths ["test-resources"]
:dependencies [] :dependencies []
:leiningen/reply :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]}} :exclusions [commons-logging]}}
:test {:source-paths ["test"] :test {:source-paths ["test"]
:resource-paths ["test-resources"] :resource-paths ["test-resources"]
:dependencies []}}) :dependencies [[dda/dummy "0.1.0-SNAPSHOT"]]}})

View file

@ -9,7 +9,8 @@
(ns cryogen-core.classpath-able-io (ns cryogen-core.classpath-able-io
(:require [clojure.java.io :as io] (:require [clojure.java.io :as io]
[clojure.string :as st] [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)) (def SourceType (s/enum :classpath :filesystem))
@ -73,12 +74,12 @@
(s/defn file-from-cp ; :- File (s/defn file-from-cp ; :- File
[resource-path :- Path] [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) (when (.exists file-from-cp)
file-from-cp) file-from-cp))
(catch Exception e (catch Exception e
nil)))) nil)))
(s/defn file-from-fs ; :- File (s/defn file-from-fs ; :- File
[fs-prefix :- Prefix [fs-prefix :- Prefix

View file

@ -19,6 +19,12 @@
(def target "target/tmp") (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 (deftest test-resource-from-cp-or-fs
(is (is
(.exists (.exists

View file

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