Skip to content

Commit

Permalink
Merge pull request #77 from amperity/fix-each-composite-profiles
Browse files Browse the repository at this point in the history
Fix each composite profiles
  • Loading branch information
greglook authored Sep 29, 2020
2 parents 3c5c6ac + 1364f79 commit 353e050
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 29 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,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)
- When `each` is used with `:parallel`, task aliases are now correctly resolved
before iteration starts.
[#36](https://github.com/amperity/lein-monolith/issues/36)
Expand Down
15 changes: 10 additions & 5 deletions example/apps/app-a/project.clj
Original file line number Diff line number Diff line change
@@ -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 ["bench"]}
:dev [:shared {:dependencies [[clj-stacktrace "0.2.8"]]}]
:uberjar [:shared {:dependencies [[commons-net "3.6"]]}]})
4 changes: 2 additions & 2 deletions example/libs/lib-a/project.clj
Original file line number Diff line number Diff line change
@@ -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"]])
6 changes: 3 additions & 3 deletions example/libs/lib-b/project.clj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(defproject example/lib-b "0.2.0"
(defproject example/lib-b "MONOLITH-SNAPSHOT"
:description "Example lib depending on lib-a."
:monolith/inherit [:aliases]

:dependencies
[[example/lib-a "1.0.0"]
[org.clojure/clojure "1.8.0"]])
[[org.clojure/clojure "1.10.1"]
[example/lib-a "MONOLITH-SNAPSHOT"]])
3 changes: 3 additions & 0 deletions example/project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
:dependencies
[[org.clojure/clojure "1.10.1"]]

:managed-dependencies
[[amperity/greenlight "0.6.0"]]

:test-selectors
{:unit (complement :integration)
:integration :integration}
Expand Down
10 changes: 10 additions & 0 deletions src/lein_monolith/plugin.clj
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,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 conj []) mw-sym))))
32 changes: 13 additions & 19 deletions src/lein_monolith/task/each.clj
Original file line number Diff line number Diff line change
Expand Up @@ -202,27 +202,21 @@

(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)))))))
[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 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)]
Expand All @@ -236,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"
Expand Down Expand Up @@ -296,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"
Expand Down

0 comments on commit 353e050

Please sign in to comment.