From 3182421a5e00907844e4b13f1de6b2fa2df5ba7e Mon Sep 17 00:00:00 2001 From: Jan Krebs Date: Tue, 3 Dec 2019 18:11:30 +0100 Subject: [PATCH] "mob next [ci-skip]" --- src/cryogen_core/classpath_able_io.clj | 16 +++++++++++++--- test/cryogen_core/classpath_able_io_test.clj | 8 ++++---- 2 files changed, 17 insertions(+), 7 deletions(-) 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