diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 31aa70d..40b77f8 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1,2 +1,3 @@ examples/jvm-with-anvil/ Anvil -examples/scopes/ @handstandsam \ No newline at end of file +examples/scopes/ @handstandsam +examples/app/ AppTeam \ No newline at end of file diff --git a/invert-gradle-plugin/src/main/kotlin/com/squareup/invert/internal/report/InvertReportWriter.kt b/invert-gradle-plugin/src/main/kotlin/com/squareup/invert/internal/report/InvertReportWriter.kt index ea9120b..d7f2ea8 100644 --- a/invert-gradle-plugin/src/main/kotlin/com/squareup/invert/internal/report/InvertReportWriter.kt +++ b/invert-gradle-plugin/src/main/kotlin/com/squareup/invert/internal/report/InvertReportWriter.kt @@ -6,7 +6,7 @@ import com.squareup.invert.internal.models.CollectedOwnershipForProject import com.squareup.invert.internal.models.CollectedPluginsForProject import com.squareup.invert.internal.models.CollectedStatsForProject import com.squareup.invert.internal.report.js.InvertJsReportUtils -import com.squareup.invert.internal.report.js.InvertJsReportUtils.computeGlobalStats +import com.squareup.invert.internal.report.js.InvertJsReportUtils.computeGlobalTotals import com.squareup.invert.internal.report.js.InvertJsReportWriter import com.squareup.invert.internal.report.json.InvertJsonReportWriter import com.squareup.invert.logging.InvertLogger @@ -40,7 +40,7 @@ class InvertReportWriter( invertedModulesList = invertedDependenciesJsReportModel.getAllModulePaths() ) - val globalStats = computeGlobalStats(allProjectsStatsData) + val globalStats = computeGlobalTotals(allProjectsStatsData, collectedOwnershipInfo) // JSON Report InvertJsonReportWriter(invertLogger, rootBuildReportsDir).createInvertJsonReport( diff --git a/invert-gradle-plugin/src/main/kotlin/com/squareup/invert/internal/report/js/InvertJsReportUtils.kt b/invert-gradle-plugin/src/main/kotlin/com/squareup/invert/internal/report/js/InvertJsReportUtils.kt index 36f5b71..4e0850d 100644 --- a/invert-gradle-plugin/src/main/kotlin/com/squareup/invert/internal/report/js/InvertJsReportUtils.kt +++ b/invert-gradle-plugin/src/main/kotlin/com/squareup/invert/internal/report/js/InvertJsReportUtils.kt @@ -9,6 +9,7 @@ import com.squareup.invert.models.ConfigurationName import com.squareup.invert.models.DependencyId import com.squareup.invert.models.GradlePluginId import com.squareup.invert.models.ModulePath +import com.squareup.invert.models.OwnerName import com.squareup.invert.models.Stat import com.squareup.invert.models.StatDataType import com.squareup.invert.models.StatKey @@ -42,8 +43,28 @@ object InvertJsReportUtils { ) } - fun computeGlobalStats(allProjectsStatsData: StatsJsReportModel): Map { - val globalStats: Map = allProjectsStatsData.statInfos.values + fun countFromStat(stat: Stat?): Int { + return when (stat) { + is Stat.NumericStat -> stat.value + is Stat.CodeReferencesStat -> stat.value.size + is Stat.BooleanStat -> if (stat.value) { + 1 + } else { + 0 + } + + else -> { + 0 // Default Value + } + } + } + + fun computeGlobalTotals( + allProjectsStatsData: StatsJsReportModel, + collectedOwnershipInfo: OwnershipJsReportModel + ): Map { + val moduleToOwnerMap = collectedOwnershipInfo.modules + val allStatMetadatas: List = allProjectsStatsData.statInfos.values .filter { statInfo -> when (statInfo.dataType) { StatDataType.BOOLEAN, @@ -55,26 +76,51 @@ object InvertJsReportUtils { } } } - .associateWith { statMetadata: StatMetadata -> - val statKey = statMetadata.key - allProjectsStatsData.statsByModule.values.sumOf { statsForModule: Map -> - val stat: Stat? = statsForModule[statKey] - when (stat) { - is Stat.NumericStat -> stat.value - is Stat.CodeReferencesStat -> stat.value.size - is Stat.BooleanStat -> if (stat.value) { - 1 - } else { - 0 - } - else -> { - 0 // Default Value - } + + val globalTotals: Map = allStatMetadatas.associate { statMetadata: StatMetadata -> + var totalCount = 0 // Total count of the stat across all modules + val totalByModule: Map = allProjectsStatsData.statsByModule.entries + .mapNotNull { (modulePath: ModulePath, statsForModule: Map) -> + val stat: Stat? = statsForModule[statMetadata.key] + if (stat != null) { + val countForStat = countFromStat(stat) + totalCount += countForStat + modulePath to countForStat + } else { + null } } - }.toMap() - return globalStats.entries.associate { it.key.key to StatTotalAndMetadata(it.key, it.value) } + .filter { it.second != 0 } // Drop all the `0` entries to avoid clutter in the JSON files + .toMap() + + val ownerToTotalCount: Map = totalByModule.entries + .groupBy { (modulePath, totalForModule) -> + val ownerName = moduleToOwnerMap[modulePath] + + ownerName + } + .map { (modulePath, entry) -> + modulePath to entry.sumOf { it.value } + } + .mapNotNull { (ownerName, totalCountForOwner) -> + if (ownerName == null) { + null + } else { + ownerName to totalCountForOwner + } + } + .toMap() + + statMetadata.key to StatTotalAndMetadata( + metadata = statMetadata, + total = totalCount, + totalByModule = totalByModule, + totalByOwner = ownerToTotalCount + ) + }.toMap() + + return globalTotals } /** diff --git a/invert-models/src/commonMain/kotlin/com/squareup/invert/models/js/CollectedStatTotalsJsReportModel.kt b/invert-models/src/commonMain/kotlin/com/squareup/invert/models/js/CollectedStatTotalsJsReportModel.kt index a1b1ecf..d5740af 100644 --- a/invert-models/src/commonMain/kotlin/com/squareup/invert/models/js/CollectedStatTotalsJsReportModel.kt +++ b/invert-models/src/commonMain/kotlin/com/squareup/invert/models/js/CollectedStatTotalsJsReportModel.kt @@ -1,5 +1,7 @@ package com.squareup.invert.models.js +import com.squareup.invert.models.ModulePath +import com.squareup.invert.models.OwnerName import com.squareup.invert.models.StatKey import com.squareup.invert.models.StatMetadata import kotlinx.serialization.Serializable @@ -13,4 +15,6 @@ data class CollectedStatTotalsJsReportModel( data class StatTotalAndMetadata( val metadata: StatMetadata, val total: Int, + val totalByModule: Map, + val totalByOwner: Map, )