Skip to content
Merged
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 @@ -27,6 +27,38 @@ internal abstract class InspectionTask : BaseGraphInputTask() {
@get:Optional // By default we use the project that the task was run against
internal abstract var projectPath: String?

@get:Input
@set:Option(
option = "report-cycles",
description = "Include the dependency cycles report section (default: $DEFAULT_REPORT_CYCLES)"
)
@get:Optional
internal abstract var reportCycles: Boolean?

@get:Input
@set:Option(
option = "report-top-nodes",
description = "Include the top nodes report section (default: $DEFAULT_REPORT_TOP_NODES)"
)
@get:Optional
internal abstract var reportTopNodes: Boolean?

@get:Input
@set:Option(
option = "report-dep-tree",
description = "Include the dependency tree report section (default: $DEFAULT_REPORT_DEP_TREE)"
)
@get:Optional
internal abstract var reportDepTree: Boolean?

@get:Input
@set:Option(
option = "top",
description = "Number of top project nodes to include in the report (default: $DEFAULT_TOP_N)"
)
@get:Optional
internal abstract var topN: Int?

@get:OutputFile
internal abstract val outputFile: RegularFileProperty

Expand All @@ -40,12 +72,17 @@ internal abstract class InspectionTask : BaseGraphInputTask() {
appendLine("Project inspection report for: $targetProject ${selfInfo.attributes}")
appendLine()

dependencyCyclesReport(graph, selfInfo)
topNodesReport(graph, selfInfo)

append("Dependency tree:\n")
addDependency(graph = graph, indent = "", vertex = selfInfo)
append("* Indicates a vertex that has already been rendered\n")
if (reportCycles ?: DEFAULT_REPORT_CYCLES) {
dependencyCyclesReport(graph, selfInfo)
}
if (reportTopNodes ?: DEFAULT_REPORT_TOP_NODES) {
topNodesReport(graph, selfInfo)
}
if (reportDepTree ?: DEFAULT_REPORT_DEP_TREE) {
append("Dependency tree:\n")
addDependency(graph = graph, indent = "", vertex = selfInfo)
append("* Indicates a vertex that has already been rendered\n")
}
}.replace("\n", System.lineSeparator())

outputFile.asFile.get().writeText(report)
Expand Down Expand Up @@ -168,7 +205,7 @@ internal abstract class InspectionTask : BaseGraphInputTask() {
}.map { (key, _) -> key }.toSortedSet()

allNumericAttrNames.forEach { attrName ->
topNodesReportForMetric(allDependencies, attrName)
topNodesReportForMetric(allDependencies, attrName, topN ?: DEFAULT_TOP_N)
}
}

Expand All @@ -177,18 +214,19 @@ internal abstract class InspectionTask : BaseGraphInputTask() {
*/
private fun StringBuilder.topNodesReportForMetric(
allDependencies: Set<VertexInfo>,
attrName: String
attrName: String,
topN: Int,
) {
val metricValues = allDependencies.mapNotNull { node ->
node.attributes[attrName]?.value?.toDoubleOrNull()?.let {
Pair(node, it)
}
}.sortedByDescending { (_, value) ->
value
}.take(TOP_N).map { it.first }
}.take(topN).map { it.first }

if (metricValues.isNotEmpty()) {
appendLine("Top $TOP_N dependencies by '$attrName':")
appendLine("Top $topN dependencies by '$attrName':")
metricValues.forEachIndexed { index, node ->
appendLine("\t${index + 1}: ${node.attributes[attrName]} -- ${node.path} ${node.attributes}")
}
Expand Down Expand Up @@ -235,7 +273,10 @@ internal abstract class InspectionTask : BaseGraphInputTask() {
}

companion object {
private const val TOP_N = 10
private const val DEFAULT_TOP_N = 10
private const val DEFAULT_REPORT_CYCLES = true
private const val DEFAULT_REPORT_TOP_NODES = true
private const val DEFAULT_REPORT_DEP_TREE = true
private val MAX_TRAVERSAL_DURATION = Duration.ofMinutes(5)
}
}