From 44a6dc77ce14d464bb8de301584626c1eb3f38b7 Mon Sep 17 00:00:00 2001 From: Greg Look Date: Sun, 27 Sep 2020 23:08:08 -0700 Subject: [PATCH 1/5] Update example with some composite profiles. --- example/apps/app-a/project.clj | 15 ++++++++++----- example/libs/lib-a/project.clj | 4 ++-- example/libs/lib-b/project.clj | 6 +++--- example/project.clj | 3 +++ 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/example/apps/app-a/project.clj b/example/apps/app-a/project.clj index ace88a9..baf30bc 100644 --- a/example/apps/app-a/project.clj +++ b/example/apps/app-a/project.clj @@ -1,10 +1,15 @@ -(defproject example/app-a "0.5.0" +(defproject example/app-a "MONOLITH-SNAPSHOT" :description "Example project with internal and external dependencies." :monolith/inherit true :deployable true :dependencies - [[commons-io "2.5"] - [example/lib-a "1.0.0"] - [example/lib-b "0.2.0"] - [org.clojure/clojure "1.8.0"]]) + [[org.clojure/clojure "1.10.1"] + [commons-io "2.5"] + [example/lib-a "MONOLITH-SNAPSHOT"] + [example/lib-b "MONOLITH-SNAPSHOT"]] + + :profiles + {:shared {:source-paths ["/dev/null"]} + :dev [:shared {:dependencies [[clj-stacktrace "0.2.8"]]}] + :uberjar [:shared {:dependencies [[commons-net "3.6"]]}]}) diff --git a/example/libs/lib-a/project.clj b/example/libs/lib-a/project.clj index ff21a08..7f7dc43 100644 --- a/example/libs/lib-a/project.clj +++ b/example/libs/lib-a/project.clj @@ -1,8 +1,8 @@ -(defproject example/lib-a "1.0.0" +(defproject example/lib-a "MONOLITH-SNAPSHOT" :description "Example library with no internal dependencies." :monolith/inherit true :pedantic? :abort :dependencies - [[org.clojure/clojure "1.8.0"]]) + [[org.clojure/clojure "1.10.1"]]) diff --git a/example/libs/lib-b/project.clj b/example/libs/lib-b/project.clj index 71099ce..c61323f 100644 --- a/example/libs/lib-b/project.clj +++ b/example/libs/lib-b/project.clj @@ -1,6 +1,6 @@ -(defproject example/lib-b "0.2.0" +(defproject example/lib-b "MONOLITH-SNAPSHOT" :description "Example lib depending on lib-a." :dependencies - [[example/lib-a "1.0.0"] - [org.clojure/clojure "1.8.0"]]) + [[org.clojure/clojure "1.10.1"] + [example/lib-a "MONOLITH-SNAPSHOT"]]) diff --git a/example/project.clj b/example/project.clj index 1ad7c64..293cd2a 100644 --- a/example/project.clj +++ b/example/project.clj @@ -8,6 +8,9 @@ :dependencies [[org.clojure/clojure "1.10.1"]] + :managed-dependencies + [[amperity/greenlight "0.6.0"]] + :test-selectors {:unit (complement :integration) :integration :integration} From 1bea7888795112475a82dffca6a2c500fb717d91 Mon Sep 17 00:00:00 2001 From: Greg Look Date: Sun, 27 Sep 2020 23:08:39 -0700 Subject: [PATCH 2/5] Change how profiles are inherited in the each task. --- src/lein_monolith/plugin.clj | 10 ++++++++++ src/lein_monolith/task/each.clj | 21 ++++++++------------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/lein_monolith/plugin.clj b/src/lein_monolith/plugin.clj index a3cfece..7d0b0eb 100644 --- a/src/lein_monolith/plugin.clj +++ b/src/lein_monolith/plugin.clj @@ -139,3 +139,13 @@ (reduce-kv add-active-profile project profiles))) ; Normal project, don't activate. project)) + + +(defn add-middleware + "Update the given project to include the plugin middleware. Appends the + middleware symbol if it is not already present." + [project] + (let [mw-sym 'lein-monolith.plugin/middleware] + (if (some #{mw-sym} (:middleware project)) + project + (update project :middleware (fnil into []) [mw-sym])))) diff --git a/src/lein_monolith/task/each.clj b/src/lein_monolith/task/each.clj index 516abdd..d6ba280 100644 --- a/src/lein_monolith/task/each.clj +++ b/src/lein_monolith/task/each.clj @@ -203,19 +203,14 @@ (defn- apply-subproject-task "Applies the task to the given subproject." [monolith subproject task] - (binding [lein/*exit-process?* false] - (let [inherited (plugin/build-inherited-profiles monolith subproject)] - (as-> subproject - subproject - (reduce-kv - (fn inject-profile [p k v] (assoc-in p [:profiles k] v)) - subproject inherited) - (config/debug-profile "init-subproject" - (locking init-lock - (project/init-project subproject (cons :default (keys inherited))))) - (config/debug-profile "apply-task" - (binding [eval/*dir* (:root subproject)] - (lein/resolve-and-apply subproject task))))))) + (binding [lein/*exit-process?* false + eval/*dir* (:root subproject)] + (let [initialized (config/debug-profile "init-subproject" + (locking init-lock + (project/init-project + (plugin/add-middleware subproject))))] + (config/debug-profile "apply-task" + (lein/resolve-and-apply subproject task))))) (defn- apply-subproject-task-with-output From fc0ea0915fb1f015ff8c01c958568ada5ce9d16e Mon Sep 17 00:00:00 2001 From: Greg Look Date: Sun, 27 Sep 2020 23:17:31 -0700 Subject: [PATCH 3/5] Update CHANGELOG. --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 16d309d..99954c6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,9 @@ This project adheres to [Semantic Versioning](http://semver.org/). will be properly quoted for shells. [#27](https://github.com/amperity/lein-monolith/issues/27) [#72](https://github.com/amperity/lein-monolith/pull/72) +- The `each` task is now compatible with composite profiles. + [#29](https://github.com/amperity/lein-monolith/issues/29) + [#77](https://github.com/amperity/lein-monolith/pull/77) ## [1.5.0] - 2020-09-17 From 285993b16fea16acb9ea036a778781540ad731e8 Mon Sep 17 00:00:00 2001 From: Greg Look Date: Sun, 27 Sep 2020 23:21:12 -0700 Subject: [PATCH 4/5] Fix some lint problems. --- example/apps/app-a/project.clj | 2 +- src/lein_monolith/task/each.clj | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/example/apps/app-a/project.clj b/example/apps/app-a/project.clj index baf30bc..0bab203 100644 --- a/example/apps/app-a/project.clj +++ b/example/apps/app-a/project.clj @@ -10,6 +10,6 @@ [example/lib-b "MONOLITH-SNAPSHOT"]] :profiles - {:shared {:source-paths ["/dev/null"]} + {:shared {:source-paths ["bench"]} :dev [:shared {:dependencies [[clj-stacktrace "0.2.8"]]}] :uberjar [:shared {:dependencies [[commons-net "3.6"]]}]}) diff --git a/src/lein_monolith/task/each.clj b/src/lein_monolith/task/each.clj index d6ba280..8dc68d6 100644 --- a/src/lein_monolith/task/each.clj +++ b/src/lein_monolith/task/each.clj @@ -202,7 +202,7 @@ (defn- apply-subproject-task "Applies the task to the given subproject." - [monolith subproject task] + [subproject task] (binding [lein/*exit-process?* false eval/*dir* (:root subproject)] (let [initialized (config/debug-profile "init-subproject" @@ -210,13 +210,13 @@ (project/init-project (plugin/add-middleware subproject))))] (config/debug-profile "apply-task" - (lein/resolve-and-apply subproject task))))) + (lein/resolve-and-apply initialized task))))) (defn- apply-subproject-task-with-output "Applies the task to the given subproject, writing the task output to a file in the given directory." - [monolith subproject task out-dir results] + [subproject task out-dir results] (let [out-file (io/file out-dir (:group subproject) (str (:name subproject) ".txt"))] (io/make-parents out-file) (with-open [file-output-stream (io/output-stream out-file :append true)] @@ -230,7 +230,7 @@ (try ; Run task with output capturing. (binding [*task-file-output* file-output-stream] - (apply-subproject-task monolith subproject task)) + (apply-subproject-task subproject task)) (catch Exception ex (.write file-output-stream (.getBytes (format "\nERROR: %s\n%s" @@ -290,9 +290,9 @@ ""))) (if-let [out-dir (get-in ctx [:opts :output])] ; Capture output to file. - (apply-subproject-task-with-output (:monolith ctx) subproject (:task ctx) out-dir results) + (apply-subproject-task-with-output subproject (:task ctx) out-dir results) ; Run without output capturing. - (apply-subproject-task (:monolith ctx) subproject (:task ctx))) + (apply-subproject-task subproject (:task ctx))) (when (:refresh opts) (fingerprint/save! fprints marker target) (lein/info (format "Saved %s fingerprint for %s" From 712841497ca9e46eea1a78246b30c7eb84fc7668 Mon Sep 17 00:00:00 2001 From: Greg Look Date: Tue, 29 Sep 2020 12:51:31 -0700 Subject: [PATCH 5/5] Simplify middleware update. --- src/lein_monolith/plugin.clj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lein_monolith/plugin.clj b/src/lein_monolith/plugin.clj index 7d0b0eb..465e3e1 100644 --- a/src/lein_monolith/plugin.clj +++ b/src/lein_monolith/plugin.clj @@ -148,4 +148,4 @@ (let [mw-sym 'lein-monolith.plugin/middleware] (if (some #{mw-sym} (:middleware project)) project - (update project :middleware (fnil into []) [mw-sym])))) + (update project :middleware (fnil conj []) mw-sym))))