Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -198,19 +198,19 @@ private abstract class GraphDumpTask : DefaultTask() {
if (it.key.count { char -> char == ':' } > 1) it.key.substringBeforeLast(":") else ""
}

val groupIncomingCounts = dependencies.groupBy { it.dependency.substringBeforeLast(":") }
.mapValues { (group, groupDependencies) ->
groupDependencies.count { dep -> dep.project.substringBeforeLast(":") != group }
}
Comment on lines +201 to +204

Choose a reason for hiding this comment

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

medium

This pre-calculation is a great optimization. To further improve readability and reduce repetition, consider extracting the substringBeforeLast(":") logic into a helper. This logic to get a module's group is used multiple times here and elsewhere in the function.

For example, you could define a private extension property on String:

private val String.moduleGroup: String get() = substringBeforeLast(":")

// Then use it like this:
val groupIncomingCounts = dependencies.groupBy { it.dependency.moduleGroup }
    .mapValues { (group, groupDependencies) ->
        groupDependencies.count { dep -> dep.project.moduleGroup != group }
    }

This would make the code more declarative and easier to maintain. Since this change would be outside the modified lines, I'm leaving it as a suggestion for a potential follow-up.


orderedGroups.forEach { (outerGroup, innerGroups) ->
if (outerGroup.isNotEmpty()) {
appendLine(" subgraph $outerGroup")
appendLine(" direction TB")
}
innerGroups.sortedWith(
compareBy(
{ (group, _) ->
dependencies.filter { dep ->
val toGroup = dep.dependency.substringBeforeLast(":")
toGroup == group && dep.project.substringBeforeLast(":") != group
}.count()
},
{ (group, _) -> groupIncomingCounts[group] ?: 0 },
{ -it.value.size },
),
).forEach { (group, projects) ->
Expand Down
Loading