Skip to content

Commit

Permalink
Merge pull request #21 from square/module-path
Browse files Browse the repository at this point in the history
gradlePath -> modulePath
  • Loading branch information
handstandsam authored Sep 4, 2024
2 parents fce1a13 + 83831e5 commit ff9e078
Show file tree
Hide file tree
Showing 42 changed files with 177 additions and 177 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.squareup.invert

import com.squareup.invert.models.GradlePath
import com.squareup.invert.models.ModulePath

data class CollectedStatsAggregate(
val aggregatedStatsByProject: Map<GradlePath, List<CollectedStat>>,
val aggregatedStatsByProject: Map<ModulePath, List<CollectedStat>>,
val globalStats: List<CollectedStat>
)
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.squareup.invert

import com.squareup.invert.models.GradlePath
import com.squareup.invert.models.ModulePath
import java.io.File

/**
* Information sent to a [StatCollector] for a specific project/module.
*/
class InvertAllCollectedData(
val rootProjectDir: File,
val projectPath: GradlePath,
val projectPath: ModulePath,
val projectDir: File,
)
Original file line number Diff line number Diff line change
Expand Up @@ -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.models.InvertCombinedCollectedData
import com.squareup.invert.models.GradlePath
import com.squareup.invert.models.ModulePath
import com.squareup.invert.models.OwnerInfo
import com.squareup.invert.models.Stat
import com.squareup.invert.models.js.MetadataJsReportModel
Expand All @@ -23,46 +23,46 @@ class InvertAllCollectedDataRepo(

val mavenRepoUrls = projectMetadata.mavenRepoUrls

val projectPaths: Set<GradlePath> by lazy {
val projectPaths: Set<ModulePath> by lazy {
mutableSetOf<String>().apply {
allCollectedData.apply {
collectedDependencies.forEach { add(it.path) }
collectedConfigurations.forEach { add(it.path) }
collectedConfigurations.forEach { add(it.modulePath) }
collectedOwners.forEach { add(it.path) }
collectedStats.forEach { add(it.path) }
collectedPlugins.forEach { add(it.path) }
}
}
}

fun getProject(gradlePath: GradlePath): AllCollectedDataForProject? {
fun getProject(modulePath: ModulePath): AllCollectedDataForProject? {
return AllCollectedDataForProject(
collectedDependencies = allCollectedData.collectedDependencies.firstOrNull { it.path == gradlePath }
collectedDependencies = allCollectedData.collectedDependencies.firstOrNull { it.path == modulePath }
?: CollectedDependenciesForProject(
path = gradlePath,
path = modulePath,
emptyMap(),
emptyMap()
),
collectedConfigurations = allCollectedData.collectedConfigurations.firstOrNull { it.path == gradlePath }
collectedConfigurations = allCollectedData.collectedConfigurations.firstOrNull { it.modulePath == modulePath }
?: CollectedConfigurationsForProject(
path = gradlePath,
modulePath = modulePath,
emptySet(),
emptySet()
),
collectedOwners = allCollectedData.collectedOwners.firstOrNull { it.path == gradlePath }
collectedOwners = allCollectedData.collectedOwners.firstOrNull { it.path == modulePath }
?: CollectedOwnershipForProject(
path = gradlePath,
path = modulePath,
ownerInfo = OwnerInfo("None"),
),
collectedStats = allCollectedData.collectedStats.firstOrNull { it.path == gradlePath }
collectedStats = allCollectedData.collectedStats.firstOrNull { it.path == modulePath }
?: CollectedStatsForProject(
path = gradlePath,
path = modulePath,
emptyMap(),
emptyMap()
),
collectedPlugins = allCollectedData.collectedPlugins.firstOrNull { it.path == gradlePath }
collectedPlugins = allCollectedData.collectedPlugins.firstOrNull { it.path == modulePath }
?: CollectedPluginsForProject(
path = gradlePath,
path = modulePath,
emptyList()
),
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.squareup.invert

import com.squareup.invert.models.GradlePath
import com.squareup.invert.models.ModulePath
import com.squareup.invert.models.OwnerInfo

/**
Expand All @@ -9,6 +9,6 @@ import com.squareup.invert.models.OwnerInfo
interface InvertOwnershipCollector {
fun collect(
rootProjectDir: String,
gradlePath: GradlePath
modulePath: ModulePath
): OwnerInfo?
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.squareup.invert

import com.squareup.invert.models.GradlePath
import com.squareup.invert.models.ModulePath
import java.io.File


class InvertProjectData(
val rootProjectDir: File,
val projectPath: GradlePath,
val projectPath: ModulePath,
val projectDir: File,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import com.squareup.invert.internal.models.InvertCombinedCollectedData
import com.squareup.invert.internal.report.json.InvertJsonReportWriter
import com.squareup.invert.models.ExtraDataType
import com.squareup.invert.models.ExtraMetadata
import com.squareup.invert.models.GradlePath
import com.squareup.invert.models.ModulePath
import com.squareup.invert.models.Stat
import com.squareup.invert.models.StatKey
import com.squareup.invert.models.StatMetadata
Expand All @@ -25,10 +25,10 @@ data class AggregatedCodeReferences(

object CollectedStatAggregator {

private val PROJECT_EXTRA_METADATA = ExtraMetadata(
key = "project",
private val MODULE_EXTRA_METADATA = ExtraMetadata(
key = "module_path",
type = ExtraDataType.STRING,
description = "Project"
description = "Module Path"
)

private fun exportFullListOfCodeReferences(
Expand All @@ -52,7 +52,7 @@ object CollectedStatAggregator {
collectedCodeReferenceStat.value.map { codeReference: Stat.CodeReferencesStat.CodeReference ->
// Adding addition "extra" field named "project"
codeReference.copy(
extras = codeReference.extras.plus(PROJECT_EXTRA_METADATA.key to collectedStatsForProject.path)
extras = codeReference.extras.plus(MODULE_EXTRA_METADATA.key to collectedStatsForProject.path)
)
}
)
Expand All @@ -69,7 +69,7 @@ object CollectedStatAggregator {
),
serializer = AggregatedCodeReferences.serializer(),
value = AggregatedCodeReferences(
metadata = statMetadata.copy(extras = statMetadata.extras.plus(PROJECT_EXTRA_METADATA)),
metadata = statMetadata.copy(extras = statMetadata.extras.plus(MODULE_EXTRA_METADATA)),
values = allCodeReferencesForStatWithProjectPathExtra
)
)
Expand All @@ -85,7 +85,7 @@ object CollectedStatAggregator {
reportMetadata: MetadataJsReportModel,
statCollectorsForAggregation: List<StatCollector>?
): InvertCombinedCollectedData {
val projectPathToCollectedStatsForProject: MutableMap<GradlePath, CollectedStatsForProject> =
val projectPathToCollectedStatsForProject: MutableMap<ModulePath, CollectedStatsForProject> =
origAllCollectedData.collectedStats
.associateBy { it.path }
.toMutableMap()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.squareup.invert.internal

import com.squareup.invert.InvertOwnershipCollector
import com.squareup.invert.models.GradlePath
import com.squareup.invert.models.ModulePath
import com.squareup.invert.models.OwnerInfo

/**
Expand All @@ -10,6 +10,6 @@ import com.squareup.invert.models.OwnerInfo
object NoOpOwnershipCollector : InvertOwnershipCollector {
override fun collect(
rootProjectDir: String,
gradlePath: GradlePath
modulePath: ModulePath
): OwnerInfo? = null
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.squareup.invert.internal.models
import com.squareup.invert.models.ConfigurationName
import com.squareup.invert.models.GradlePath
import com.squareup.invert.models.ModulePath
import kotlinx.serialization.Serializable

/**
Expand All @@ -10,7 +10,7 @@ import kotlinx.serialization.Serializable
*/
@Serializable
data class CollectedConfigurationsForProject(
val path: GradlePath,
val modulePath: ModulePath,
/** All Available Configurations */
val allConfigurationNames: Set<ConfigurationName>,
/** Configurations that were analyzed */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.squareup.invert.internal.models
import com.squareup.invert.models.ConfigurationName
import com.squareup.invert.models.DependencyId
import com.squareup.invert.models.GradlePath
import com.squareup.invert.models.ModulePath
import kotlinx.serialization.Serializable

/**
Expand All @@ -11,7 +11,7 @@ import kotlinx.serialization.Serializable
*/
@Serializable
data class CollectedDependenciesForProject(
val path: GradlePath,
val path: ModulePath,
val dependencies: Map<DependencyId, Set<ConfigurationName>>,
val directDependencies: Map<ConfigurationName, Set<DependencyId>>,
)
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.squareup.invert.internal.models

import com.squareup.invert.models.GradlePath
import com.squareup.invert.models.ModulePath
import com.squareup.invert.models.OwnerInfo
import kotlinx.serialization.Serializable

Expand All @@ -11,6 +11,6 @@ import kotlinx.serialization.Serializable
*/
@Serializable
data class CollectedOwnershipForProject(
val path: GradlePath,
val path: ModulePath,
val ownerInfo: OwnerInfo,
)
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.squareup.invert.internal.models

import com.squareup.invert.models.GradlePath
import com.squareup.invert.models.ModulePath
import com.squareup.invert.models.GradlePluginId
import kotlinx.serialization.Serializable

Expand All @@ -9,6 +9,6 @@ import kotlinx.serialization.Serializable
*/
@Serializable
data class CollectedPluginsForProject(
val path: GradlePath,
val path: ModulePath,
val plugins: List<GradlePluginId>,
)
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.squareup.invert.internal.models

import com.squareup.invert.models.GradlePath
import com.squareup.invert.models.ModulePath
import com.squareup.invert.models.Stat
import com.squareup.invert.models.StatKey
import com.squareup.invert.models.StatMetadata
Expand All @@ -11,7 +11,7 @@ import kotlinx.serialization.Serializable
*/
@Serializable
data class CollectedStatsForProject(
val path: GradlePath,
val path: ModulePath,
val statInfos: Map<StatKey, StatMetadata>,
val stats: Map<StatKey, Stat>
)
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import com.squareup.invert.internal.report.js.InvertJsReportWriter
import com.squareup.invert.internal.report.json.InvertJsonReportWriter
import com.squareup.invert.logging.InvertLogger
import com.squareup.invert.models.DependencyId
import com.squareup.invert.models.GradlePath
import com.squareup.invert.models.ModulePath
import com.squareup.invert.models.js.CollectedStatTotalsJsReportModel
import com.squareup.invert.models.js.MetadataJsReportModel
import java.io.File
Expand Down Expand Up @@ -75,7 +75,7 @@ class InvertReportWriter(
*/
private fun assertModuleMatch(
logger: InvertLogger,
modulesList: List<GradlePath>,
modulesList: List<ModulePath>,
invertedModulesList: List<DependencyId>
) {
if (!invertedModulesList.containsAll(modulesList)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import com.squareup.invert.internal.models.CollectedStatsForProject
import com.squareup.invert.models.ConfigurationName
import com.squareup.invert.models.StatDataType
import com.squareup.invert.models.DependencyId
import com.squareup.invert.models.GradlePath
import com.squareup.invert.models.ModulePath
import com.squareup.invert.models.GradlePluginId
import com.squareup.invert.models.Stat
import com.squareup.invert.models.StatKey
Expand Down Expand Up @@ -88,7 +88,7 @@ object InvertJsReportUtils {
}
.associateBy { it.key }

val statData = mutableMapOf<GradlePath, Map<StatKey, Stat>>()
val statData = mutableMapOf<ModulePath, Map<StatKey, Stat>>()
collectedStats.forEach { collectedStatForProject: CollectedStatsForProject ->
statData[collectedStatForProject.path] = collectedStatForProject.stats
}
Expand All @@ -104,7 +104,7 @@ object InvertJsReportUtils {
*/
fun toCollectedPlugins(allPlugins: List<CollectedPluginsForProject>): PluginsJsReportModel {
return PluginsJsReportModel(
plugins = mutableMapOf<GradlePluginId, MutableList<GradlePath>>()
plugins = mutableMapOf<GradlePluginId, MutableList<ModulePath>>()
.also { resultingDepIdToModuleUsageInfo ->
allPlugins.forEach { collectedDataFromModule ->
collectedDataFromModule.plugins.forEach { pluginId ->
Expand All @@ -114,7 +114,7 @@ object InvertJsReportUtils {
}
}
},
modules = mutableMapOf<GradlePath, List<GradlePluginId>>()
modules = mutableMapOf<ModulePath, List<GradlePluginId>>()
.also { map ->
allPlugins.forEach { collectedDataFromModule ->
collectedDataFromModule.plugins.onEach {
Expand All @@ -132,12 +132,12 @@ object InvertJsReportUtils {
collectedDependenciesForProjects: List<CollectedDependenciesForProject>
): DependenciesJsReportModel {
return DependenciesJsReportModel(
mutableMapOf<DependencyId, MutableMap<GradlePath, MutableList<ConfigurationName>>>()
mutableMapOf<DependencyId, MutableMap<ModulePath, MutableList<ConfigurationName>>>()
.also { resultingDepIdToModuleUsageInfo ->
collectedDependenciesForProjects.forEach { collectedDataFromModule ->
val collectedDataFromModuleGradlePath = collectedDataFromModule.path
collectedDataFromModule.dependencies.forEach { (dependencyId, usedInConfigurationNames) ->
val currDataForDepName: MutableMap<GradlePath, MutableList<ConfigurationName>> =
val currDataForDepName: MutableMap<ModulePath, MutableList<ConfigurationName>> =
resultingDepIdToModuleUsageInfo[dependencyId] ?: mutableMapOf()
val currConfigsForPath: MutableList<ConfigurationName> =
currDataForDepName[collectedDataFromModuleGradlePath] ?: mutableListOf()
Expand All @@ -154,20 +154,20 @@ object InvertJsReportUtils {
allProjectsConfigurationsData: List<CollectedConfigurationsForProject>
): ConfigurationsJsReportModel {
val allConfigurationNames = mutableSetOf<String>()
val moduleToAllConfigurationNames = mutableMapOf<GradlePath, Set<ConfigurationName>>()
val moduleToAnalyzedConfigurationNames = mutableMapOf<GradlePath, Set<ConfigurationName>>()
val analyzedConfigurationNameToModules = mutableMapOf<ConfigurationName, MutableSet<GradlePath>>()
val moduleToAllConfigurationNames = mutableMapOf<ModulePath, Set<ConfigurationName>>()
val moduleToAnalyzedConfigurationNames = mutableMapOf<ModulePath, Set<ConfigurationName>>()
val analyzedConfigurationNameToModules = mutableMapOf<ConfigurationName, MutableSet<ModulePath>>()

allProjectsConfigurationsData.forEach { projectConfigurationsData ->
allConfigurationNames.addAll(projectConfigurationsData.allConfigurationNames)
moduleToAllConfigurationNames[projectConfigurationsData.path] =
moduleToAllConfigurationNames[projectConfigurationsData.modulePath] =
projectConfigurationsData.allConfigurationNames
moduleToAnalyzedConfigurationNames[projectConfigurationsData.path] =
moduleToAnalyzedConfigurationNames[projectConfigurationsData.modulePath] =
projectConfigurationsData.analyzedConfigurationNames
projectConfigurationsData.analyzedConfigurationNames.forEach { analyzedConfigurationName ->
val modules =
analyzedConfigurationNameToModules[analyzedConfigurationName] ?: mutableSetOf()
modules.add(projectConfigurationsData.path)
modules.add(projectConfigurationsData.modulePath)
analyzedConfigurationNameToModules[analyzedConfigurationName] = modules
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ internal abstract class InvertCollectDependenciesTask : DefaultTask() {
.toTransitiveDeps(),
)
val collectedConfigurations = CollectedConfigurationsForProject(
path = projectPath.get(),
modulePath = projectPath.get(),
allConfigurationNames = allConfigurationNames.get(),
analyzedConfigurationNames = analyzedConfigurationNames.get(),
)
Expand Down
Loading

0 comments on commit ff9e078

Please sign in to comment.