diff --git a/example/project.clj b/example/project.clj index 1ad7c64..e55208d 100644 --- a/example/project.clj +++ b/example/project.clj @@ -12,11 +12,16 @@ {:unit (complement :integration) :integration :integration} + :test-paths ["test/unit" "test/integration"] + :monolith {:inherit [:test-selectors :env] + :inherit-raw + [:test-paths] + :inherit-leaky [:repositories :managed-dependencies] diff --git a/src/lein_monolith/config.clj b/src/lein_monolith/config.clj index 20c9843..0efb5e1 100644 --- a/src/lein_monolith/config.clj +++ b/src/lein_monolith/config.clj @@ -37,6 +37,9 @@ (cons file next-files) next-files))))) +(defn- add-raw + [monolith raw] + (assoc-in monolith [:monolith :raw] raw)) (defn find-monolith "Returns the loaded project map for the monolith metaproject, or nil if not @@ -47,13 +50,16 @@ are loaded to check for the `:monolith` entry." [project] (if (:monolith project) - project + (add-raw project (-> (:root project) + (io/file "project.clj") + str + project/read-raw)) (some (fn check-project [file] (lein/debug "Reading candidate project file" (str file)) (let [super (project/read-raw (str file))] (when (:monolith super) - super))) + (add-raw (project/init-project super) super)))) (find-up (:root project) "project.clj")))) diff --git a/src/lein_monolith/plugin.clj b/src/lein_monolith/plugin.clj index a3cfece..db7c70f 100644 --- a/src/lein_monolith/plugin.clj +++ b/src/lein_monolith/plugin.clj @@ -2,6 +2,7 @@ "This namespace runs inside of Leiningen on all projects and handles profile creation for `with-all` and `inherit` functionality." (:require + [clojure.string :as str] [lein-monolith.config :as config] [lein-monolith.dependency :as dep] [leiningen.core.main :as lein] @@ -46,27 +47,32 @@ "Constructs a profile map containing the inherited properties from a parent project map." [monolith inherit-key setting] - (when-let [base-properties (get-in monolith [:monolith inherit-key])] - (cond - ; Don't inherit anything - (not setting) - nil - - ; Inherit the base properties specified in the parent. - (true? setting) - (select-keys monolith base-properties) - - ; Provide additional properties to inherit, or replace if metadata is set. - (vector? setting) - (->> (if (:replace (meta setting)) - setting - (distinct (concat base-properties setting))) - (select-keys monolith)) - - :else - (throw (ex-info (str "Unknown value type for monolith inherit setting: " - (pr-str setting)) - {:inherit setting}))))) + (let [raw? (str/ends-with? (name inherit-key) "-raw") + source (if raw? + (get-in monolith [:monolith :raw]) + monolith) + base-properties (get-in source [:monolith inherit-key])] + (when base-properties + (cond + ; Don't inherit anything + (not setting) + nil + + ; Inherit the base properties specified in the parent. + (true? setting) + (select-keys source base-properties) + + ; Provide additional properties to inherit, or replace if metadata is set. + (vector? setting) + (->> (if (:replace (meta setting)) + setting + (distinct (concat base-properties setting))) + (select-keys source)) + + :else + (throw (ex-info (str "Unknown value type for monolith inherit setting: " + (pr-str setting)) + {:inherit setting})))))) (defn build-inherited-profiles @@ -75,12 +81,20 @@ (let [inherit-profile (inherited-profile monolith :inherit (:monolith/inherit subproject)) + inherit-raw-profile (inherited-profile + monolith :inherit-raw + (:monolith/inherit-raw subproject)) leaky-profile (inherited-profile monolith :inherit-leaky - (:monolith/leaky subproject (boolean (:monolith/inherit subproject))))] + (:monolith/leaky subproject (boolean (:monolith/inherit subproject)))) + leaky-raw-profile (inherited-profile + monolith :inherit-leaky-raw + (:monolith/leaky-raw subproject (boolean (:monolith/inherit-raw subproject))))] (cond-> nil inherit-profile (assoc :monolith/inherited inherit-profile) - leaky-profile (assoc :monolith/leaky (vary-meta leaky-profile assoc :leaky true))))) + inherit-raw-profile (assoc :monolith/inherited-raw inherit-raw-profile) + leaky-profile (assoc :monolith/leaky (vary-meta leaky-profile assoc :leaky true)) + leaky-raw-profile (assoc :monolith/leaky-raw (vary-meta leaky-raw-profile assoc :leaky true))))) diff --git a/src/lein_monolith/task/info.clj b/src/lein_monolith/task/info.clj index 4f951d1..03aebdb 100644 --- a/src/lein_monolith/task/info.clj +++ b/src/lein_monolith/task/info.clj @@ -20,8 +20,18 @@ (doseq [kw inherited] (println (colorize [:bold :yellow] kw))) (newline)) + (when-let [inherited (get-in monolith [:monolith :inherit-raw])] + (println "Inherited properties (raw):") + (doseq [kw inherited] + (println (colorize [:bold :yellow] kw))) + (newline)) (when-let [inherited (get-in monolith [:monolith :inherit-leaky])] - (println "Inherited (leaky) properties:") + (println "Inherited properties (leaky):") + (doseq [kw inherited] + (println (colorize [:bold :yellow] kw))) + (newline)) + (when-let [inherited (get-in monolith [:monolith :inherit-leaky-raw])] + (println "Inherited properties (leaky, raw):") (doseq [kw inherited] (println (colorize [:bold :yellow] kw))) (newline))