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

Fix crash in lein-monolith graph when root and cluster name are equal #31

Merged
merged 2 commits into from
Aug 18, 2017
Merged
Changes from 1 commit
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
10 changes: 7 additions & 3 deletions src/lein_monolith/task/graph.clj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@

(def image-name "project-hierarchy.png")

(defn cluster->descriptor
[monolith-root subdirectory]
(when-not (= monolith-root subdirectory)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style: I have a minor preference for (when (not= ... here. Please preserve the two-line spacing between top-level vars as well.

Copy link
Contributor Author

@MatthewDarling MatthewDarling Aug 18, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While I was writing it, I debated whether to use not= - seems I picked wrong, haha.

I've corrected the spacing, as well.

{:label (subs (str subdirectory)
(inc (count monolith-root)))}))

(defn graph
"Generate a graph of subprojects and their interdependencies."
Expand All @@ -17,8 +22,7 @@
(let [visualize! (ns-resolve 'rhizome.viz 'save-graph)
[monolith subprojects] (u/load-monolith! project)
dependencies (dep/dependency-map subprojects)
graph-file (io/file (:target-path monolith) image-name)
path-prefix (inc (count (:root monolith)))]
graph-file (io/file (:target-path monolith) image-name)]
(.mkdir (.getParentFile graph-file))
(visualize!
(keys dependencies)
Expand All @@ -28,6 +32,6 @@
:node->cluster (fn [id]
(when-let [root (get-in subprojects [id :root])]
(str/join "/" (butlast (str/split root #"/")))))
:cluster->descriptor #(array-map :label (subs (str %) path-prefix))
:cluster->descriptor (partial cluster->descriptor (:root monolith))
:filename (str graph-file))
(lein/info "Generated dependency graph in" (str graph-file))))