From 5d2fb19944757b1dbb9856fffc7ab9e60ae1c5c2 Mon Sep 17 00:00:00 2001 From: Frank Viernau Date: Fri, 24 Nov 2023 08:12:25 +0100 Subject: [PATCH] refactor(reporter): Make `map()` take `ReporterInput` as param Enable splitting up this function in a following change without the need to pass around too many parameters. Signed-off-by: Frank Viernau --- .../src/main/kotlin/ReportTableModelMapper.kt | 51 +++++++++---------- .../src/main/kotlin/StaticHtmlReporter.kt | 7 +-- 2 files changed, 25 insertions(+), 33 deletions(-) diff --git a/plugins/reporters/static-html/src/main/kotlin/ReportTableModelMapper.kt b/plugins/reporters/static-html/src/main/kotlin/ReportTableModelMapper.kt index 2364e12df4d86..ecbcda44de09c 100644 --- a/plugins/reporters/static-html/src/main/kotlin/ReportTableModelMapper.kt +++ b/plugins/reporters/static-html/src/main/kotlin/ReportTableModelMapper.kt @@ -28,7 +28,6 @@ import org.ossreviewtoolkit.model.Project import org.ossreviewtoolkit.model.RuleViolation import org.ossreviewtoolkit.model.config.Excludes import org.ossreviewtoolkit.model.config.ScopeExclude -import org.ossreviewtoolkit.model.licenses.LicenseInfoResolver import org.ossreviewtoolkit.model.licenses.LicenseView import org.ossreviewtoolkit.model.orEmpty import org.ossreviewtoolkit.model.utils.ResolutionProvider @@ -39,34 +38,30 @@ import org.ossreviewtoolkit.plugins.reporters.statichtml.ReportTableModel.Projec import org.ossreviewtoolkit.plugins.reporters.statichtml.ReportTableModel.ResolvableIssue import org.ossreviewtoolkit.plugins.reporters.statichtml.ReportTableModel.ResolvableViolation import org.ossreviewtoolkit.reporter.HowToFixTextProvider +import org.ossreviewtoolkit.reporter.ReporterInput /** * A mapper which converts an [OrtResult] to a [ReportTableModel]. */ internal object ReportTableModelMapper { - fun map( - ortResult: OrtResult, - licenseInfoResolver: LicenseInfoResolver, - resolutionProvider: ResolutionProvider, - howToFixTextProvider: HowToFixTextProvider - ): ReportTableModel { + fun map(input: ReporterInput): ReportTableModel { val issueSummaryRows = mutableMapOf() - val analyzerResult = ortResult.analyzer?.result - val excludes = ortResult.getExcludes() + val analyzerResult = input.ortResult.analyzer?.result + val excludes = input.ortResult.getExcludes() val projectTables = analyzerResult?.projects?.associateWith { project -> - val scopesForDependencies = project.getScopesForDependencies(excludes, ortResult.dependencyNavigator) - val pathExcludes = excludes.findPathExcludes(project, ortResult) + val scopesForDependencies = project.getScopesForDependencies(excludes, input.ortResult.dependencyNavigator) + val pathExcludes = excludes.findPathExcludes(project, input.ortResult) val allIds = sortedSetOf(project.id) - allIds += ortResult.dependencyNavigator.projectDependencies(project) + allIds += input.ortResult.dependencyNavigator.projectDependencies(project) - val projectIssues = ortResult.dependencyNavigator.projectIssues(project) + val projectIssues = input.ortResult.dependencyNavigator.projectIssues(project) val tableRows = allIds.map { id -> - val scanResults = ortResult.getScanResultsForId(id) + val scanResults = input.ortResult.getScanResultsForId(id) - val resolvedLicenseInfo = licenseInfoResolver.resolveLicenseInfo(id) + val resolvedLicenseInfo = input.licenseInfoResolver.resolveLicenseInfo(id) val concludedLicense = resolvedLicenseInfo.licenseInfo.concludedLicenseInfo.concludedLicense val declaredLicenses = resolvedLicenseInfo.filter { LicenseSource.DECLARED in it.sources } @@ -80,7 +75,7 @@ internal object ReportTableModelMapper { it.summary.issues } - val pkg = ortResult.getPackageOrProject(id)?.metadata + val pkg = input.ortResult.getPackageOrProject(id)?.metadata val row = DependencyRow( id = id, @@ -92,16 +87,18 @@ internal object ReportTableModelMapper { detectedLicenses = detectedLicenses, effectiveLicense = resolvedLicenseInfo.filterExcluded().effectiveLicense( LicenseView.CONCLUDED_OR_DECLARED_AND_DETECTED, - ortResult.getPackageLicenseChoices(id), - ortResult.getRepositoryLicenseChoices() + input.ortResult.getPackageLicenseChoices(id), + input.ortResult.getRepositoryLicenseChoices() )?.sorted(), analyzerIssues = analyzerIssues.map { - it.toResolvableIssue(resolutionProvider, howToFixTextProvider) + it.toResolvableIssue(input.resolutionProvider, input.howToFixTextProvider) }, - scanIssues = scanIssues.map { it.toResolvableIssue(resolutionProvider, howToFixTextProvider) } + scanIssues = scanIssues.map { + it.toResolvableIssue(input.resolutionProvider, input.howToFixTextProvider) + } ) - val isRowExcluded = ortResult.isExcluded(row.id) + val isRowExcluded = input.ortResult.isExcluded(row.id) val unresolvedAnalyzerIssues = row.analyzerIssues.filterUnresolved() val unresolvedScanIssues = row.scanIssues.filterUnresolved() @@ -130,7 +127,7 @@ internal object ReportTableModelMapper { ProjectTable( tableRows, - ortResult.getDefinitionFilePathRelativeToAnalyzerRoot(project), + input.ortResult.getDefinitionFilePathRelativeToAnalyzerRoot(project), pathExcludes ) }.orEmpty().toSortedMap(compareBy { it.id }) @@ -139,15 +136,15 @@ internal object ReportTableModelMapper { // TODO: Use the prefixes up until the first '.' (which below get discarded) for some visual grouping in the // report. - val labels = ortResult.labels.mapKeys { it.key.substringAfter(".") } + val labels = input.ortResult.labels.mapKeys { it.key.substringAfter(".") } - val ruleViolations = ortResult.getRuleViolations() - .map { it.toResolvableViolation(resolutionProvider) } + val ruleViolations = input.ortResult.getRuleViolations() + .map { it.toResolvableViolation(input.resolutionProvider) } .sortedWith(VIOLATION_COMPARATOR) return ReportTableModel( - ortResult.repository.vcsProcessed, - ortResult.repository.config, + input.ortResult.repository.vcsProcessed, + input.ortResult.repository.config, ruleViolations, issueSummaryTable, projectTables, diff --git a/plugins/reporters/static-html/src/main/kotlin/StaticHtmlReporter.kt b/plugins/reporters/static-html/src/main/kotlin/StaticHtmlReporter.kt index c949b72416f3d..861c3f3cd04b6 100644 --- a/plugins/reporters/static-html/src/main/kotlin/StaticHtmlReporter.kt +++ b/plugins/reporters/static-html/src/main/kotlin/StaticHtmlReporter.kt @@ -73,12 +73,7 @@ class StaticHtmlReporter : Reporter { private val licensesSha1 = mutableMapOf() override fun generateReport(input: ReporterInput, outputDir: File, config: PluginConfiguration): List { - val reportTableModel = ReportTableModelMapper.map( - input.ortResult, - input.licenseInfoResolver, - input.resolutionProvider, - input.howToFixTextProvider - ) + val reportTableModel = ReportTableModelMapper.map(input) val html = renderHtml(reportTableModel) val outputFile = outputDir.resolve(reportFilename)