diff --git a/doc/config.md b/doc/config.md index 404cfd1..11c2c1b 100644 --- a/doc/config.md +++ b/doc/config.md @@ -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 diff --git a/example/libs/subdir/lib-c/.gitignore b/example/libs/subdir/lib-c/.gitignore new file mode 100644 index 0000000..e04714b --- /dev/null +++ b/example/libs/subdir/lib-c/.gitignore @@ -0,0 +1,9 @@ +/target +/classes +/checkouts +pom.xml +pom.xml.asc +*.jar +*.class +/.lein-* +/.nrepl-port diff --git a/example/libs/subdir/lib-c/project.clj b/example/libs/subdir/lib-c/project.clj new file mode 100644 index 0000000..0b9d421 --- /dev/null +++ b/example/libs/subdir/lib-c/project.clj @@ -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"]]) diff --git a/example/libs/subdir/lib-c/src/lib_c/core.clj b/example/libs/subdir/lib-c/src/lib_c/core.clj new file mode 100644 index 0000000..8f97582 --- /dev/null +++ b/example/libs/subdir/lib-c/src/lib_c/core.clj @@ -0,0 +1,7 @@ +(ns lib-c.core) + + +(defn foo + "I don't do a whole lot." + [x] + (println x "Hello, World!")) diff --git a/example/project.clj b/example/project.clj index 9f36cd9..c1cded4 100644 --- a/example/project.clj +++ b/example/project.clj @@ -47,8 +47,8 @@ :unstable #(= (first (:version %)) \0)} :project-dirs - ["apps/app-a" - "libs/*" + ["apps/*" + "libs/**" "not-found"]} :env diff --git a/src/lein_monolith/config.clj b/src/lein_monolith/config.clj index 6d59597..10e46d4 100644 --- a/src/lein_monolith/config.clj +++ b/src/lein_monolith/config.clj @@ -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) @@ -97,6 +117,9 @@ (.listFiles) (filter #(.isDirectory ^File %))) + (and (= "**" (.getName file)) (.isDirectory (.getParentFile file))) + (all-projects (.getParentFile file)) + :else nil)) diff --git a/test/example-tests.sh b/test/example-tests.sh index 7b65f2a..f67f55f 100755 --- a/test/example-tests.sh +++ b/test/example-tests.sh @@ -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 diff --git a/test/lein_monolith/monolith_test.clj b/test/lein_monolith/monolith_test.clj index c095311..c826088 100644 --- a/test/lein_monolith/monolith_test.clj +++ b/test/lein_monolith/monolith_test.clj @@ -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))) @@ -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))))