-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved metadata collection into the InvertTask itself and created a si…
…ngle entry point to write both the JS and JSON reports.
- Loading branch information
1 parent
0bd102c
commit 78baee1
Showing
9 changed files
with
320 additions
and
316 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
...plugin/src/main/kotlin/com/squareup/invert/internal/models/InvertCombinedCollectedData.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.squareup.invert.internal.models | ||
|
||
/** | ||
* A Combined view of all data collected for all projects. | ||
*/ | ||
data class InvertCombinedCollectedData( | ||
val collectedConfigurations: List<CollectedConfigurationsForProject>, | ||
val collectedDependencies: List<CollectedDependenciesForProject>, | ||
val collectedOwners: List<CollectedOwnershipForProject>, | ||
val collectedStats: List<CollectedStatsForProject>, | ||
val collectedPlugins: List<CollectedPluginsForProject>, | ||
) |
90 changes: 90 additions & 0 deletions
90
...ugin/src/main/kotlin/com/squareup/invert/internal/report/GradleProjectAnalysisCombiner.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package com.squareup.invert.internal.report | ||
|
||
import com.squareup.invert.internal.models.CollectedConfigurationsForProject | ||
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.internal.models.InvertCombinedCollectedData | ||
import com.squareup.invert.internal.models.InvertPluginFileKey | ||
import java.io.File | ||
|
||
/** | ||
* Reads from all the individual project reports and combines them. | ||
*/ | ||
object GradleProjectAnalysisCombiner { | ||
fun combineAnalysisResults(resultDirPaths: List<String>): InvertCombinedCollectedData { | ||
val collectedConfigurations = mutableListOf<CollectedConfigurationsForProject>() | ||
val collectedDependencies = mutableListOf<CollectedDependenciesForProject>() | ||
val collectedOwners = mutableListOf<CollectedOwnershipForProject>() | ||
val collectedStats = mutableListOf<CollectedStatsForProject>() | ||
val collectedPlugins = mutableListOf<CollectedPluginsForProject>() | ||
|
||
resultDirPaths | ||
.map { File(it) } | ||
.forEach { subprojectInvertReportDirFile -> | ||
if (subprojectInvertReportDirFile.exists()) { | ||
File( | ||
subprojectInvertReportDirFile, | ||
InvertPluginFileKey.DEPENDENCIES.filename | ||
).also { file -> | ||
if (file.exists()) { | ||
InvertReportFileUtils.buildModuleToFeaturesMap(file)?.let { | ||
collectedDependencies.add(it) | ||
} | ||
} | ||
} | ||
|
||
File( | ||
subprojectInvertReportDirFile, | ||
InvertPluginFileKey.CONFIGURATIONS.filename | ||
).also { file -> | ||
if (file.exists()) { | ||
InvertReportFileUtils.readCollectedConfigurationsForAllModules(file)?.let { | ||
collectedConfigurations.add(it) | ||
} | ||
} | ||
} | ||
|
||
File( | ||
subprojectInvertReportDirFile, | ||
InvertPluginFileKey.STATS.filename | ||
).also { file -> | ||
if (file.exists()) { | ||
InvertReportFileUtils.readCollectedStatsForAllProjectsFromDisk(file)?.let { | ||
collectedStats.add(it) | ||
} | ||
} | ||
} | ||
|
||
File( | ||
subprojectInvertReportDirFile, | ||
InvertPluginFileKey.OWNERS.filename | ||
).also { file -> | ||
InvertReportFileUtils.readCollectedOwnershipForAllProjectsFromDisk(file) | ||
?.let { collectedOwners.add(it) } | ||
} | ||
|
||
File( | ||
subprojectInvertReportDirFile, | ||
InvertPluginFileKey.PLUGINS.filename | ||
).also { file -> | ||
if (file.exists()) { | ||
InvertReportFileUtils.readCollectedPluginsForAllModules(file)?.let { | ||
synchronized(collectedPlugins) { | ||
collectedPlugins.add(it) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
return InvertCombinedCollectedData( | ||
collectedConfigurations = collectedConfigurations, | ||
collectedDependencies = collectedDependencies, | ||
collectedOwners = collectedOwners, | ||
collectedStats = collectedStats, | ||
collectedPlugins = collectedPlugins | ||
) | ||
} | ||
} |
98 changes: 98 additions & 0 deletions
98
...t-gradle-plugin/src/main/kotlin/com/squareup/invert/internal/report/InvertReportWriter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package com.squareup.invert.internal.report | ||
|
||
import com.squareup.invert.internal.models.CollectedConfigurationsForProject | ||
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.internal.report.js.InvertJsReportUtils | ||
import com.squareup.invert.internal.report.js.InvertJsReportUtils.computeGlobalStats | ||
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.js.CollectedStatTotalsJsReportModel | ||
import com.squareup.invert.models.js.MetadataJsReportModel | ||
import java.io.File | ||
|
||
class InvertReportWriter( | ||
private val invertLogger: InvertLogger, | ||
private val rootBuildReportsDir: File | ||
) { | ||
fun writeProjectData( | ||
reportMetadata: MetadataJsReportModel, | ||
collectedOwners: List<CollectedOwnershipForProject>, | ||
collectedStats: List<CollectedStatsForProject>, | ||
collectedDependencies: List<CollectedDependenciesForProject>, | ||
collectedConfigurations: List<CollectedConfigurationsForProject>, | ||
collectedPlugins: List<CollectedPluginsForProject>, | ||
) { | ||
val collectedOwnershipInfo = InvertJsReportUtils.buildModuleToOwnerMap(collectedOwners) | ||
val allProjectsStatsData = InvertJsReportUtils.buildModuleToStatsMap(collectedStats) | ||
val directDependenciesJsReportModel = InvertJsReportUtils.toDirectDependenciesJsReportModel(collectedDependencies) | ||
val invertedDependenciesJsReportModel = InvertJsReportUtils | ||
.toInvertedDependenciesJsReportModel(collectedDependencies) | ||
|
||
assertModuleMatch( | ||
logger = invertLogger, | ||
modulesList = collectedDependencies.map { it.path }, | ||
invertedModulesList = invertedDependenciesJsReportModel.getAllModulePaths() | ||
) | ||
|
||
val globalStats = computeGlobalStats(allProjectsStatsData) | ||
|
||
// JSON Report | ||
InvertJsonReportWriter(invertLogger, rootBuildReportsDir).createInvertJsonReport( | ||
reportMetadata = reportMetadata, | ||
allConfigurationsData = collectedConfigurations, | ||
allProjectsDependencyData = collectedDependencies, | ||
allProjectsStatsData = allProjectsStatsData, | ||
allPluginsData = collectedPlugins, | ||
allOwnersData = collectedOwners, | ||
globalStats = globalStats | ||
) | ||
|
||
// HTML/JS Report | ||
InvertJsReportWriter(invertLogger, rootBuildReportsDir).createInvertHtmlReport( | ||
reportMetadata = reportMetadata, | ||
allProjectsDependencyData = collectedDependencies, | ||
allProjectsStatsData = allProjectsStatsData, | ||
directDependencies = directDependenciesJsReportModel, | ||
invertedDependencies = invertedDependenciesJsReportModel, | ||
allPluginsData = collectedPlugins, | ||
collectedOwnershipInfo = collectedOwnershipInfo, | ||
allProjectsConfigurationsData = collectedConfigurations, | ||
globalStatTotals = CollectedStatTotalsJsReportModel(globalStats), | ||
) | ||
} | ||
|
||
|
||
/** | ||
* This provides a warning to the user to let them know that a module was found as a dependency | ||
* but was not scanned itself. In order to get a full picture of the project, all should | ||
* be scanned. | ||
*/ | ||
private fun assertModuleMatch( | ||
logger: InvertLogger, | ||
modulesList: List<GradlePath>, | ||
invertedModulesList: List<DependencyId> | ||
) { | ||
if (!invertedModulesList.containsAll(modulesList)) { | ||
val modulesMap = modulesList.groupBy { it } | ||
val invertedModulesMap = invertedModulesList.groupBy { it } | ||
val errorString = buildString { | ||
appendLine("WARNING: Module Mismatch...") | ||
appendLine("The following modules are dependencies, but were not scanned:") | ||
var idx = 1 | ||
invertedModulesMap.keys.sorted().forEach { path -> | ||
if (modulesMap[path] == null) { | ||
appendLine("${idx++}. $path") | ||
} | ||
} | ||
} | ||
|
||
logger.warn(errorString) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.