Skip to content
Merged
Show file tree
Hide file tree
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 @@ -39,7 +39,7 @@ class InvertReportWriter(
assertModuleMatch(
logger = invertLogger,
modulesList = collectedDependencies.map { it.path },
invertedModulesList = invertedDependenciesJsReportModel.getAllModulePaths()
invertedModulesList = invertedDependenciesJsReportModel.getAllModulePaths(reportMetadata.buildSystem)
)

val globalStats = computeGlobalTotals(allProjectsStatsData, collectedOwnershipInfo)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class InvertJsReportWriter(

val collectedDependencies = HomeJsReportModel(
modules = modulesList.sorted(),
artifacts = invertedDependencies.getAllArtifactIds().sorted(),
artifacts = invertedDependencies.getAllArtifactIds(reportMetadata.buildSystem).sorted(),
plugins = pluginsReport.plugins.keys.toList().sorted()
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.squareup.invert.models.js
import com.squareup.invert.models.ConfigurationName
import com.squareup.invert.models.DependencyId
import com.squareup.invert.models.ModulePath
import com.squareup.invert.models.utils.BuildSystemUtils
import kotlinx.serialization.Serializable

/**
Expand All @@ -11,16 +12,20 @@ import kotlinx.serialization.Serializable
@Serializable
data class DependenciesJsReportModel(
val invertedDependencies: Map<
DependencyId,
Map<ModulePath, List<ConfigurationName>>
>
DependencyId,
Map<ModulePath, List<ConfigurationName>>
>
) {

fun getAllModulePaths(): List<ModulePath> {
return invertedDependencies.keys.filter { it.startsWith(":") }.sorted()
fun getAllModulePaths(buildSystem: BuildSystem): List<ModulePath> {
return invertedDependencies.keys.filter {
BuildSystemUtils.isSourceModule(buildSystem, it)
}.sorted()
}

fun getAllArtifactIds(): List<DependencyId> {
return invertedDependencies.keys.filter { !it.startsWith(":") }.sorted()
fun getAllArtifactIds(buildSystem: BuildSystem): List<DependencyId> {
return invertedDependencies.keys.filter {
BuildSystemUtils.isArtifact(buildSystem, it)
}.sorted()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package com.squareup.invert.models.utils

import com.squareup.invert.models.DependencyId
import com.squareup.invert.models.ModulePath
import com.squareup.invert.models.js.BuildSystem

object BuildSystemUtils {

private enum class YesNoUnknown {
YES, NO, UNKNOWN
}

/**
* Returns whether the given module path is a source module for the given build system.
*
* We safely return everything when we aren't sure for the build system.
*/
private fun isSourceModuleInternal(buildSystem: BuildSystem, modulePath: ModulePath): YesNoUnknown {
val isSourceModuleForBuildSystem = when (buildSystem) {
BuildSystem.GRADLE -> modulePath.startsWith(":")
// We don't really know so we'll say yes
BuildSystem.OTHER -> null
}
return when (isSourceModuleForBuildSystem) {
true -> YesNoUnknown.YES
false -> YesNoUnknown.NO
null -> YesNoUnknown.UNKNOWN
}

}

/**
* Returns whether the given module path is an artifact for the given build system.
*
* We safely return everything when we aren't sure for the build system.
*/
fun isArtifact(buildSystem: BuildSystem, dependencyId: DependencyId): Boolean {
return when (isSourceModuleInternal(buildSystem, dependencyId)) {
YesNoUnknown.YES -> false
YesNoUnknown.NO,
YesNoUnknown.UNKNOWN -> true
}
}

/**
* Returns whether the given module path is a source module for the given build system.
*
* We safely return everything when we aren't sure for the build system.
*/
fun isSourceModule(buildSystem: BuildSystem, dependencyId: DependencyId): Boolean {
return when (isSourceModuleInternal(buildSystem, dependencyId)) {
YesNoUnknown.YES -> true
YesNoUnknown.NO,
YesNoUnknown.UNKNOWN -> false
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import com.squareup.invert.common.pages.AnnotationProcessorsReportPage
import com.squareup.invert.common.pages.ArtifactDetailNavRoute
import com.squareup.invert.common.pages.ArtifactsNavRoute
import com.squareup.invert.common.pages.ArtifactsReportPage
import com.squareup.invert.common.pages.OwnerBreakdownReportPage
import com.squareup.invert.common.pages.CodeReferencesReportPage
import com.squareup.invert.common.pages.ConfigurationDetailNavRoute
import com.squareup.invert.common.pages.ConfigurationsNavRoute
import com.squareup.invert.common.pages.DependencyDiffReportPage
Expand All @@ -22,22 +20,32 @@ import com.squareup.invert.common.pages.KotlinCompilerPluginsReportPage
import com.squareup.invert.common.pages.LeafModulesNavRoute
import com.squareup.invert.common.pages.ModuleDependencyGraphReportPage
import com.squareup.invert.common.pages.ModuleDetailNavRoute
import com.squareup.invert.common.pages.OwnerBreakdownReportPage
import com.squareup.invert.common.pages.OwnerDetailNavRoute
import com.squareup.invert.common.pages.OwnersNavRoute
import com.squareup.invert.common.pages.OwnersReportPage
import com.squareup.invert.common.pages.PluginDetailNavRoute
import com.squareup.invert.common.pages.UnusedModulesReportPage
import com.squareup.invert.models.js.BuildSystem
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.mapLatest

/**
* Source of truth for the current [NavPageGroup]s and [NavPage.NavItem]s
*/
class NavGroupsRepo(additionalGroups: Set<NavPageGroup>) {

private val _navGroups = MutableStateFlow(DefaultNavItems.ROOT_NAV_ITEMS.toSet() + additionalGroups)
private val _navGroups: MutableStateFlow<Set<NavPageGroup>> =
MutableStateFlow(DefaultNavItems.ROOT_NAV_ITEMS.toSet() + additionalGroups)

val navGroups: Flow<Set<NavPageGroup>> = _navGroups
@OptIn(ExperimentalCoroutinesApi::class)
fun navGroups(buildSystem: BuildSystem): Flow<Set<NavPageGroup>> = _navGroups.mapLatest { navGroups ->
navGroups.filter { navGroup ->
navGroup.buildSystem == null || buildSystem == navGroup.buildSystem
}.toSet()
}

fun add(item: NavPageGroup) {
this._navGroups.value = this._navGroups.value.plus(item)
Expand Down Expand Up @@ -75,17 +83,46 @@ object DefaultNavItems {
)
),
NavPageGroup(
"Insights", setOf(
groupTitle = "Gradle",
navItems = setOf(
GradlePluginsReportPage.navPage.toNavItem().copy(
matchesCurrentNavRoute = {
it is GradlePluginsNavRoute || it is PluginDetailNavRoute
},
destinationNavRoute = GradlePluginsNavRoute(null)
),
ArtifactsReportPage.navPage.toNavItem().copy(
matchesCurrentNavRoute = {
it is ArtifactsNavRoute || it is ArtifactDetailNavRoute
}
),
GradleRepositoriesReportPage.navPage.toNavItem(),
ConfigurationsNavRoute.navPage.toNavItem().copy(
matchesCurrentNavRoute = {
it is ConfigurationsNavRoute || it is ConfigurationDetailNavRoute
}
),
AnnotationProcessorsReportPage.navPage.toNavItem(),
KotlinCompilerPluginsReportPage.navPage.toNavItem(),
),
buildSystem = BuildSystem.GRADLE
),
NavPageGroup(
groupTitle = "Insights",
navItems = setOf(
LeafModulesNavRoute.navPage.toNavItem(),
UnusedModulesReportPage.navPage.toNavItem(),
)
),
buildSystem = BuildSystem.GRADLE
),
NavPageGroup(
"Explore", setOf(
groupTitle = "Explore",
navItems = setOf(
InvertedDependenciesReportPage.navPage.toNavItem(),
DependencyDiffReportPage.navPage.toNavItem(),
ModuleDependencyGraphReportPage.navPage.toNavItem(),
)
),
buildSystem = BuildSystem.GRADLE
)
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.squareup.invert.common.navigation

import com.squareup.invert.models.js.BuildSystem

data class NavPageGroup(
val groupTitle: String,
val navItems: Set<NavPage.NavItem>,
val buildSystem: BuildSystem? = null
)
Loading