Skip to content

Commit

Permalink
Added in "ExtraMetadata" for CodeReferences and changed CollectedStat…
Browse files Browse the repository at this point in the history
…Type -> DataType.
  • Loading branch information
handstandsam committed Sep 4, 2024
1 parent ce6ebca commit a1da1e1
Show file tree
Hide file tree
Showing 16 changed files with 194 additions and 136 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.squareup.invert

import java.io.File

data class ReportOutputConfig(
val invertReportDirectory: File
)
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.squareup.invert

import org.gradle.api.Named
import java.io.File


/**
Expand All @@ -21,6 +22,7 @@ interface StatCollector : Named {
* Compute [CollectedStat]s with the context of all collected information.
*/
fun aggregate(
reportOutputConfig: ReportOutputConfig,
invertAllCollectedDataRepo: InvertAllCollectedDataRepo,
): CollectedStatsAggregate = CollectedStatsAggregate(mapOf(), listOf())
}
): CollectedStatsAggregate? = CollectedStatsAggregate(mapOf(), listOf())
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ package com.squareup.invert.internal

import com.squareup.invert.CollectedStatsAggregate
import com.squareup.invert.InvertAllCollectedDataRepo
import com.squareup.invert.ReportOutputConfig
import com.squareup.invert.StatCollector
import com.squareup.invert.internal.models.CollectedStatsForProject
import com.squareup.invert.internal.models.InvertCombinedCollectedData
import com.squareup.invert.models.Stat
import com.squareup.invert.models.StatKey
import com.squareup.invert.models.StatMetadata
import com.squareup.invert.models.js.MetadataJsReportModel
import java.io.File

object CollectedStatAggregator {

Expand All @@ -17,19 +19,21 @@ object CollectedStatAggregator {
*/
fun aggregate(
allCollectedData: InvertCombinedCollectedData,
reportOutputConfig: ReportOutputConfig,
reportMetadata: MetadataJsReportModel,
statCollectors: List<StatCollector>?
): InvertCombinedCollectedData {
val statMap: MutableMap<String, CollectedStatsForProject> =
allCollectedData.collectedStats.associateBy { it.path }.toMutableMap()
statCollectors?.forEach { statCollector: StatCollector ->
val result: CollectedStatsAggregate = statCollector.aggregate(
InvertAllCollectedDataRepo(
val result: CollectedStatsAggregate? = statCollector.aggregate(
reportOutputConfig = reportOutputConfig,
invertAllCollectedDataRepo = InvertAllCollectedDataRepo(
projectMetadata = reportMetadata,
allCollectedData = allCollectedData
)
),
)
result.projectStats.entries.forEach { (gradlePath, stats) ->
result?.projectStats?.entries?.forEach { (gradlePath, stats) ->
val curr: CollectedStatsForProject = statMap[gradlePath] ?: CollectedStatsForProject(
path = gradlePath,
statInfos = emptyMap(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import com.squareup.invert.internal.models.CollectedDependenciesForProject
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.models.CollectedStatType
import com.squareup.invert.models.ConfigurationName
import com.squareup.invert.models.DataType
import com.squareup.invert.models.DependencyId
import com.squareup.invert.models.GradlePath
import com.squareup.invert.models.GradlePluginId
Expand Down Expand Up @@ -44,10 +44,10 @@ object InvertJsReportUtils {
fun computeGlobalStats(allProjectsStatsData: StatsJsReportModel): Map<StatMetadata, Int> {
val globalStats: Map<StatMetadata, Int> = allProjectsStatsData.statInfos.values
.filter { statInfo ->
when (statInfo.statType) {
CollectedStatType.BOOLEAN,
CollectedStatType.NUMERIC,
CollectedStatType.CODE_REFERENCES -> true
when (statInfo.dataType) {
DataType.BOOLEAN,
DataType.NUMERIC,
DataType.CODE_REFERENCES -> true

else -> {
false
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.squareup.invert.internal.tasks

import com.squareup.invert.InvertExtension
import com.squareup.invert.ReportOutputConfig
import com.squareup.invert.StatCollector
import com.squareup.invert.internal.CollectedStatAggregator
import com.squareup.invert.internal.InvertFileUtils
Expand Down Expand Up @@ -63,6 +64,7 @@ abstract class InvertTask : DefaultTask() {
val datePatternFormat = "MMMM dd, yyyy[ 'at' HH:mm:ss]"
val mavenRepoUrls = this.mavenRepoUrls.get()
runBlocking {
val invertReportDir = rootBuildReportsDir.get().asFile

val reportMetadata = ProjectMetadataCollector.gatherProjectMetadata(
timeZoneId = timeZoneId,
Expand All @@ -78,12 +80,15 @@ abstract class InvertTask : DefaultTask() {
val allCollectedData = CollectedStatAggregator.aggregate(
allCollectedData = allCollectedDataOrig,
reportMetadata = reportMetadata,
statCollectors = statCollectors
statCollectors = statCollectors,
reportOutputConfig = ReportOutputConfig(
invertReportDirectory = invertReportDir,
)
)

InvertReportWriter(
invertLogger = invertLogger(),
rootBuildReportsDir = rootBuildReportsDir.get().asFile
rootBuildReportsDir = invertReportDir,
).writeProjectData(
reportMetadata = reportMetadata,
collectedOwners = allCollectedData.collectedOwners,
Expand Down
34 changes: 17 additions & 17 deletions invert-models/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
plugins {
kotlin("multiplatform")
kotlin("plugin.serialization")
alias(libs.plugins.dokka)
alias(libs.plugins.vanniktech.maven.publish)
kotlin("multiplatform")
kotlin("plugin.serialization")
alias(libs.plugins.dokka)
alias(libs.plugins.vanniktech.maven.publish)
}

kotlin {
js {
browser()
}
jvm {
withSourcesJar()
}
js {
browser()
}
jvm {
withSourcesJar()
}

sourceSets {
val commonMain by getting {
dependencies {
api(libs.kotlinx.serialization.core)
api(libs.kotlinx.serialization.json)
}
}
sourceSets {
val commonMain by getting {
dependencies {
api(libs.kotlinx.serialization.core)
api(libs.kotlinx.serialization.json)
}
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.squareup.invert.models

import kotlinx.serialization.Transient
import kotlin.reflect.KClass

enum class DataType(
@Transient val basicType: Basic?,
@Transient val backingType: KClass<*>
) {
BOOLEAN(Basic.BOOLEAN, Boolean::class),
NUMERIC(Basic.NUMERIC, Long::class),
STRING(Basic.STRING, String::class),
CODE_REFERENCES(null, Stat.CodeReferencesStat.CodeReference::class), // EXPLORE (CUSTOM)
DI_PROVIDES_AND_INJECTS(null, Stat.DiProvidesAndInjectsStat::class); // EXPLORE (CUSTOM)

companion object {
fun fromString(type: String?): DataType? {
return DataType.entries.firstOrNull { it.name == type }
}
}

enum class Basic {
BOOLEAN, NUMERIC, STRING
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ object InvertSerialization {
allowStructuredMapKeys = true
ignoreUnknownKeys = true
serializersModule = SerializersModule {
// Stat
polymorphic(
baseClass = Stat::class,
actualClass = Stat.BooleanStat::class,
Expand Down
136 changes: 68 additions & 68 deletions invert-models/src/commonMain/kotlin/com/squareup/invert/models/Stat.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,80 +10,80 @@ import kotlinx.serialization.Serializable
*/
sealed interface Stat {

@Serializable
@SerialName("numeric_stat")
data class NumericStat(
val value: Int,
val details: String? = null,
) : Stat

@Serializable
@SerialName("string_stat")
data class StringStat(
val value: String,
val details: String? = null,
) : Stat
@Serializable
@SerialName("numeric_stat")
data class NumericStat(
val value: Int,
val details: String? = null,
) : Stat

@Serializable
@SerialName("boolean_stat")
data class BooleanStat(
val value: Boolean,
val details: String? = null,
) : Stat
@Serializable
@SerialName("string_stat")
data class StringStat(
val value: String,
val details: String? = null,
) : Stat

@Serializable
@SerialName("code_reference")
data class CodeReferencesStat(
val value: List<CodeReference>,
) : Stat {
@Serializable
@SerialName("boolean_stat")
data class BooleanStat(
val value: Boolean,
val details: String? = null,
) : Stat

@Serializable
data class CodeReference(
val filePath: String,
val startLine: Int,
val endLine: Int,
val code: String? = null
)
}
@Serializable
@SerialName("code_reference")
data class CodeReferencesStat(
val value: List<CodeReference>,
) : Stat {

@Serializable
data class CodeReference(
val filePath: String,
val startLine: Int,
val endLine: Int,
val code: String? = null,
val extras: Map<ExtraKey, String> = emptyMap(),
)
}

@Serializable
@SerialName("di_provides_and_injects")
data class DiProvidesAndInjectsStat(
val value: List<ProvidesAndInjects>,
val details: String? = null,
) : Stat {
/**
* Represents the data in an Anvil ContributesBinding Annotation Usage
*/
@Serializable
@SerialName("di_provides_and_injects")
data class DiProvidesAndInjectsStat(
val value: List<ProvidesAndInjects>,
val details: String? = null,
) : Stat {
/**
* Represents the data in an Anvil ContributesBinding Annotation Usage
*/
@Serializable
data class DiContribution(
val annotation: String,
val scope: String,
val boundImplementation: String,
val boundType: String,
val replaces: List<String>,
)
data class DiContribution(
val annotation: String,
val scope: String,
val boundImplementation: String,
val boundType: String,
val replaces: List<String>,
)

/**
* Represents the data in an Anvil ContributesBinding Annotation Usage
*/
@Serializable
data class DiInjection(
val type: String,
val qualifierAnnotations: List<String>,
val startLine: Int,
val endLine: Int,
)
/**
* Represents the data in an Anvil ContributesBinding Annotation Usage
*/
@Serializable
data class DiInjection(
val type: String,
val qualifierAnnotations: List<String>,
val startLine: Int,
val endLine: Int,
)

@Serializable
data class ProvidesAndInjects(
val classFqName: String,
val contributions: List<DiContribution>,
val consumptions: List<DiInjection>,
val filePath: String,
val startLine: Int,
val endLine: Int,
)
}
@Serializable
data class ProvidesAndInjects(
val classFqName: String,
val contributions: List<DiContribution>,
val consumptions: List<DiInjection>,
val filePath: String,
val startLine: Int,
val endLine: Int,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,22 @@ package com.squareup.invert.models

import kotlinx.serialization.Serializable


@Serializable
data class ExtraMetadata(
val key: ExtraKey,
val type: DataType,
val description: String,
)

/**
* Information about a specific stat type.
*/
@Serializable
data class StatMetadata(
val key: StatKey,
val description: String,
val statType: CollectedStatType,
val category: String? = null,
val dataType: DataType,
val category: String = "Stats",
val extraMetadata: List<ExtraMetadata> = emptyList(),
)
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ typealias OwnerName = String
typealias GitSha = String
typealias GitBranch = String
typealias StatKey = String
typealias ExtraKey = String
Loading

0 comments on commit a1da1e1

Please sign in to comment.