Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recursive project search #85

Merged
merged 2 commits into from
Dec 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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!"))
4 changes: 2 additions & 2 deletions example/project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@
:unstable #(= (first (:version %)) \0)}

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

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

;; ## Subproject Configuration

(defn- project-dir?
"Given a directory returns true if it contains a `project.clj` file"
[dir]
(.exists (io/file dir "project.clj")))


(defn- all-projects
"Given a directory recursively search for all sub directories that contain
a `project.clj` file and return that list."
[dir]
(let [subdirs (->> (.listFiles dir)
(filter #(.isDirectory ^File %)))
grouped (group-by 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 +117,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))))