diff --git a/src/cryogen_core/classpath_able_io.clj b/src/cryogen_core/classpath_able_io.clj index 3dfb4c5..ec5a67b 100644 --- a/src/cryogen_core/classpath_able_io.clj +++ b/src/cryogen_core/classpath_able_io.clj @@ -2,11 +2,21 @@ (:require [clojure.java.io :as io] [clojure.string :as s])) +; TODO: loading from cpasspath results in nil even if file exists (defn file-from-cp-or-filesystem [fs-prefix resource-path] - (let [file-from-cp (io/file (io/resource "templates/themes/bootstrap4-test/js")) - file-from-fs (io/file "./test-resources/templates/themes/bootstrap4-test/js")] - file-from-cp)) + (let [file-from-cp (io/file (io/resource resource-path)) + file-from-fs (io/file (str fs-prefix resource-path))] + (try + (when (.exists file-from-fs) + file-from-fs) + (catch Exception e + (try (when (.exists file-from-cp) + file-from-cp) + (catch Exception e + (throw (IllegalArgumentException. + (str "resource " resource-path " neither found on classpath nor filesystem"))) + )))))) (defn copy-dir [source-path target-path ignored-files] diff --git a/test/cryogen_core/classpath_able_io_test.clj b/test/cryogen_core/classpath_able_io_test.clj index 2bcb3ea..e64eb67 100644 --- a/test/cryogen_core/classpath_able_io_test.clj +++ b/test/cryogen_core/classpath_able_io_test.clj @@ -16,10 +16,10 @@ (.isDirectory (io/file path)))) (deftest test-file-from-cp-or-filesystem - (is (do - (sut/copy-resources-from-theme theme target) - (and (verify-dir-exists (str target "/js")) - (verify-file-exists (str target "/js/dummy.js")))))) + (is + (.exists (sut/file-from-cp-or-filesystem "./test-resources" "templates/themes/bootstrap4-test/js"))) + (is + (.exists (sut/file-from-cp-or-filesystem "./" ".gitignore")))) (deftest test-copy-resources-from-theme (is (do