|
17 | 17 | package com.rubensousa.projectguard.plugin.internal.report |
18 | 18 |
|
19 | 19 | import com.rubensousa.projectguard.plugin.internal.DependencyConfiguration |
| 20 | +import com.rubensousa.projectguard.plugin.internal.ReportSpec |
20 | 21 | import com.rubensousa.projectguard.plugin.internal.SuppressionMap |
21 | 22 |
|
22 | 23 | internal class VerificationReportBuilder( |
23 | 24 | private val suppressionMap: SuppressionMap, |
| 25 | + private val reportSpec: ReportSpec, |
24 | 26 | ) { |
25 | 27 |
|
26 | 28 | fun build( |
27 | 29 | dependencyGraphDump: DependencyGraphDump, |
28 | 30 | restrictionDump: RestrictionDump, |
29 | 31 | ): VerificationReport { |
| 32 | + return VerificationReport( |
| 33 | + modules = buildVerificationReports(restrictionDump), |
| 34 | + dependencyGraph = buildDependencyGraph(dependencyGraphDump) |
| 35 | + ) |
| 36 | + } |
| 37 | + |
| 38 | + private fun buildVerificationReports( |
| 39 | + restrictionDump: RestrictionDump, |
| 40 | + ): List<VerificationModuleReport> { |
30 | 41 | val totalFatalMatches = mutableMapOf<String, MutableList<FatalMatch>>() |
31 | 42 | val totalSuppressedMatches = mutableMapOf<String, MutableList<SuppressedMatch>>() |
32 | 43 | val reports = mutableSetOf<String>() |
@@ -63,30 +74,39 @@ internal class VerificationReportBuilder( |
63 | 74 | reports.add(moduleReport.module) |
64 | 75 | } |
65 | 76 | } |
66 | | - val sortedReports = reports.sortedBy { it } |
| 77 | + return reports.sorted() |
67 | 78 | .map { moduleId -> |
68 | 79 | VerificationModuleReport( |
69 | 80 | module = moduleId, |
70 | 81 | fatal = totalFatalMatches[moduleId]?.sortedBy { it.dependency } ?: emptyList(), |
71 | 82 | suppressed = totalSuppressedMatches[moduleId]?.sortedBy { it.dependency } ?: emptyList(), |
72 | 83 | ) |
73 | 84 | } |
| 85 | + } |
| 86 | + |
| 87 | + private fun buildDependencyGraph( |
| 88 | + dependencyGraphDump: DependencyGraphDump, |
| 89 | + ): Map<String, List<DependencyReferenceDump>> { |
74 | 90 | val graph = mutableMapOf<String, MutableSet<DependencyReferenceDump>>() |
75 | 91 | dependencyGraphDump.modules.forEach { report -> |
76 | 92 | report.configurations.forEach { configuration -> |
77 | 93 | // TODO: Until https://github.com/rubensousa/ProjectGuard/issues/3 is clarified, |
78 | 94 | // filter out test dependencies from the graph reports |
79 | 95 | val moduleDependencies = graph.getOrPut(report.module) { mutableSetOf() } |
80 | 96 | if (DependencyConfiguration.isReleaseConfiguration(configuration.id)) { |
81 | | - moduleDependencies.addAll(configuration.dependencies.map { dependency -> |
82 | | - DependencyReferenceDump(dependency.id, dependency.isLibrary) |
| 97 | + moduleDependencies.addAll(configuration.dependencies.mapNotNull { dependency -> |
| 98 | + if (reportSpec.showLibrariesInGraph || !dependency.isLibrary) { |
| 99 | + DependencyReferenceDump(dependency.id, dependency.isLibrary) |
| 100 | + } else { |
| 101 | + null |
| 102 | + } |
83 | 103 | }) |
84 | 104 | } |
85 | 105 | } |
86 | 106 | } |
87 | | - return VerificationReport(sortedReports, graph.mapValues { entry -> |
| 107 | + return graph.mapValues { entry -> |
88 | 108 | entry.value.sortedBy { it.id } |
89 | | - }) |
| 109 | + } |
90 | 110 | } |
91 | 111 |
|
92 | 112 | } |
0 commit comments