Skip to content

Commit

Permalink
Recursive project search
Browse files Browse the repository at this point in the history
  • Loading branch information
yogsototh committed Dec 14, 2020
1 parent 7f54fdf commit 8243fb2
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 2 deletions.
2 changes: 2 additions & 0 deletions doc/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ direct subproject directory (containing a `project.clj` file) such as
`apps/app-a`, or end with a wildcard `*` to indicate that all child directories
should be searched for projects, like `libs/*`. Note that this only works with a
single level of wildcard matching at the end of the path.
If you would like to search recursively you can indicate that using `lib/**`
and it will search for all subdirectories containing a `project.clj` file.

## Config Inheritance

Expand Down
9 changes: 9 additions & 0 deletions example/libs/subdir/lib-c/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/target
/classes
/checkouts
pom.xml
pom.xml.asc
*.jar
*.class
/.lein-*
/.nrepl-port
7 changes: 7 additions & 0 deletions example/libs/subdir/lib-c/project.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
(defproject lein-monolith.example/lib-c "MONOLITH-SNAPSHOT"
:description "Example lib depending on lib-a."
:monolith/inherit [:aliases]

:dependencies
[[org.clojure/clojure "1.10.1"]
[lein-monolith.example/lib-a "MONOLITH-SNAPSHOT"]])
7 changes: 7 additions & 0 deletions example/libs/subdir/lib-c/src/lib_c/core.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
(ns lib-c.core)


(defn foo
"I don't do a whole lot."
[x]
(println x "Hello, World!"))
9 changes: 9 additions & 0 deletions example/libs/subdir/lib-c/src/lib_c/lib_b/core_test.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
(ns lib-c.core-test
(:require
[clojure.test :refer :all]
[lib-c.core :refer :all]))


(deftest b-code-test
(testing "FIXME, I fail."
(is false)))
2 changes: 1 addition & 1 deletion example/project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@

:project-dirs
["apps/app-a"
"libs/*"
"libs/**"
"not-found"]}

:env
Expand Down
22 changes: 21 additions & 1 deletion src/lein_monolith/config.clj
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,28 @@

;; ## Subproject Configuration

(defn- is-project-dir?
[dir]
(.exists (io/file dir "project.clj")))


(defn- all-projects
[dir]
(let [subdirs (->> (.listFiles dir)
(filter #(.isDirectory ^File %)))
grouped (group-by is-project-dir? subdirs)
top-projects (get grouped true)
all-subdir-project (mapcat all-projects (get grouped false))]
(concat top-projects all-subdir-project)))


(defn- pick-directories
"Given a path, use it to find directories. If the path names a directory,
return a vector containing it. If the path ends in `/*` and the parent is a
directory, return a sequence of directories which are children of the parent.
Otherwise, returns nil."
If the path end in `/**` and the parent is a directory, returns a sequence
of directories searched recursively which are project (contains project.clj
file). Otherwise, returns nil."
[^File file]
(cond
(.isDirectory file)
Expand All @@ -97,6 +114,9 @@
(.listFiles)
(filter #(.isDirectory ^File %)))

(and (= "**" (.getName file)) (.isDirectory (.getParentFile file)))
(all-projects (.getParentFile file))

:else nil))


Expand Down
1 change: 1 addition & 0 deletions test/example-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ test_monolith lint
test_monolith deps
test_monolith deps-of app-a
test_monolith deps-on lib-a
test_monolith deps-of lib-c
test_monolith with-all pprint :dependencies :source-paths :test-paths
test_monolith each pprint :version
test_monolith each :in lib-a pprint :root :compile-path
Expand Down
4 changes: 4 additions & 0 deletions test/lein_monolith/monolith_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,14 @@
"dev-resources"
"libs/lib-a/resources"
"libs/lib-b/resources"
"libs/subdir/lib-c/resources"
"resources"]
(relativize-pprint-output :resource-paths)))

(is (= ["apps/app-a/src"
"libs/lib-a/src"
"libs/lib-b/src"
"libs/subdir/lib-c/src"
"src"]
(relativize-pprint-output :source-paths)))

Expand All @@ -60,6 +62,8 @@
"libs/lib-a/test/unit"
"libs/lib-b/test/integration"
"libs/lib-b/test/unit"
"libs/subdir/lib-c/test/integration"
"libs/subdir/lib-c/test/unit"
"test/integration"
"test/unit"]
(relativize-pprint-output :test-paths))))

0 comments on commit 8243fb2

Please sign in to comment.