Skip to content

Commit

Permalink
refactor(reporter)!: Remove the unused config argument
Browse files Browse the repository at this point in the history
All reporters have been migrated to receive their configuration options
via the constructor, so remove the now unused `config` argument from the
`generateReport` function.

Signed-off-by: Martin Nonnenmacher <martin.nonnenmacher@bosch.com>
  • Loading branch information
mnonnenmacher committed Nov 9, 2024
1 parent 80b28c7 commit 4596888
Show file tree
Hide file tree
Showing 16 changed files with 42 additions and 117 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ class ReporterCommand : OrtCommand(
reporter to measureTimedValue {
val options = reportConfigMap[reporter.descriptor.id] ?: PluginConfiguration.EMPTY
reporter.create(PluginConfig(options.options, options.secrets))
.generateReport(input, outputDir, options)
.generateReport(input, outputDir)
}
}
}.awaitAll()
Expand Down
7 changes: 1 addition & 6 deletions plugins/reporters/aosd/src/main/kotlin/Aosd2Reporter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import org.ossreviewtoolkit.model.HashAlgorithm
import org.ossreviewtoolkit.model.Package
import org.ossreviewtoolkit.model.RemoteArtifact
import org.ossreviewtoolkit.model.RepositoryProvenance
import org.ossreviewtoolkit.model.config.PluginConfiguration
import org.ossreviewtoolkit.model.licenses.LicenseView
import org.ossreviewtoolkit.plugins.api.OrtPlugin
import org.ossreviewtoolkit.plugins.api.PluginDescriptor
Expand All @@ -44,11 +43,7 @@ import org.ossreviewtoolkit.utils.spdx.SpdxLicense
factory = ReporterFactory::class
)
class Aosd2Reporter(override val descriptor: PluginDescriptor = Aosd2ReporterFactory.descriptor) : Reporter {
override fun generateReport(
input: ReporterInput,
outputDir: File,
config: PluginConfiguration
): List<Result<File>> {
override fun generateReport(input: ReporterInput, outputDir: File): List<Result<File>> {
val reportFiles = input.ortResult.getProjects(omitExcluded = true).map { project ->
val directDependencies = input.ortResult.getDependencies(project.id, maxLevel = 1, omitExcluded = true)
.map { it.toCoordinates() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import org.asciidoctor.Attributes
import org.asciidoctor.Options
import org.asciidoctor.SafeMode

import org.ossreviewtoolkit.model.config.PluginConfiguration
import org.ossreviewtoolkit.plugins.api.OrtPluginOption
import org.ossreviewtoolkit.plugins.reporters.freemarker.FreemarkerTemplateProcessor
import org.ossreviewtoolkit.reporter.Reporter
Expand Down Expand Up @@ -85,11 +84,7 @@ abstract class AsciiDocTemplateReporter(private val config: AsciiDocTemplateRepo
*/
protected open fun generateAsciiDocAttributes(outputDir: File): Attributes = Attributes.builder().build()

final override fun generateReport(
input: ReporterInput,
outputDir: File,
config: PluginConfiguration
): List<Result<File>> {
final override fun generateReport(input: ReporterInput, outputDir: File): List<Result<File>> {
val asciiDocOutputDir = createOrtTempDir("asciidoc")

val asciidoctorAttributes = generateAsciiDocAttributes(asciiDocOutputDir)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import java.io.File
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.encodeToStream

import org.ossreviewtoolkit.model.config.PluginConfiguration
import org.ossreviewtoolkit.model.licenses.LicenseView
import org.ossreviewtoolkit.plugins.api.OrtPlugin
import org.ossreviewtoolkit.plugins.api.PluginDescriptor
Expand Down Expand Up @@ -53,11 +52,7 @@ class CtrlXAutomationReporter(override val descriptor: PluginDescriptor = CtrlXA
)
}

override fun generateReport(
input: ReporterInput,
outputDir: File,
config: PluginConfiguration
): List<Result<File>> {
override fun generateReport(input: ReporterInput, outputDir: File): List<Result<File>> {
val packages = input.ortResult.getPackages(omitExcluded = true)
val components = packages.mapTo(mutableListOf()) { (pkg, _) ->
val qualifiedName = when (pkg.id.type) {
Expand Down
17 changes: 6 additions & 11 deletions plugins/reporters/cyclonedx/src/main/kotlin/CycloneDxReporter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ import org.ossreviewtoolkit.model.Identifier
import org.ossreviewtoolkit.model.LicenseSource
import org.ossreviewtoolkit.model.Package
import org.ossreviewtoolkit.model.Project
import org.ossreviewtoolkit.model.config.PluginConfiguration
import org.ossreviewtoolkit.model.licenses.ResolvedLicenseInfo
import org.ossreviewtoolkit.model.utils.toPurl
import org.ossreviewtoolkit.model.vulnerabilities.Vulnerability
Expand Down Expand Up @@ -171,21 +170,17 @@ class CycloneDxReporter(
}
}

override fun generateReport(
input: ReporterInput,
outputDir: File,
config: PluginConfiguration
): List<Result<File>> {
override fun generateReport(input: ReporterInput, outputDir: File): List<Result<File>> {
val reportFileResults = mutableListOf<Result<File>>()

val projects = input.ortResult.getProjects(omitExcluded = true).sortedBy { it.id }
val packages = input.ortResult.getPackages(omitExcluded = true).sortedBy { it.metadata.id }

val schemaVersion = Version.entries.find {
it.versionString == this.config.schemaVersion
} ?: throw IllegalArgumentException("Unsupported CycloneDX schema version '${this.config.schemaVersion}'.")
it.versionString == config.schemaVersion
} ?: throw IllegalArgumentException("Unsupported CycloneDX schema version '${config.schemaVersion}'.")

val outputFileExtensions = this.config.outputFileFormats.mapNotNullTo(mutableSetOf()) {
val outputFileExtensions = config.outputFileFormats.mapNotNullTo(mutableSetOf()) {
val extension = it.trim().lowercase()
extension.toFormat().alsoIfNull {
logger.warn { "No CycloneDX format supports the '$extension' extension." }
Expand All @@ -208,10 +203,10 @@ class CycloneDxReporter(
)
}

licenses = LicenseChoice().apply { expression = Expression(this@CycloneDxReporter.config.dataLicense) }
licenses = LicenseChoice().apply { expression = Expression(config.dataLicense) }
}

if (this.config.singleBom) {
if (config.singleBom) {
val bom = Bom().apply {
serialNumber = "urn:uuid:${UUID.randomUUID()}"
this.metadata = metadata
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ package org.ossreviewtoolkit.plugins.reporters.evaluatedmodel
import java.io.File

import org.ossreviewtoolkit.model.FileFormat
import org.ossreviewtoolkit.model.config.PluginConfiguration
import org.ossreviewtoolkit.plugins.api.OrtPlugin
import org.ossreviewtoolkit.plugins.api.OrtPluginOption
import org.ossreviewtoolkit.plugins.api.PluginDescriptor
Expand Down Expand Up @@ -67,14 +66,10 @@ class EvaluatedModelReporter(
const val OPTION_DEDUPLICATE_DEPENDENCY_TREE = "deduplicateDependencyTree"
}

override fun generateReport(
input: ReporterInput,
outputDir: File,
config: PluginConfiguration
): List<Result<File>> {
val evaluatedModel = EvaluatedModel.create(input, this.config.deduplicateDependencyTree)
override fun generateReport(input: ReporterInput, outputDir: File): List<Result<File>> {
val evaluatedModel = EvaluatedModel.create(input, config.deduplicateDependencyTree)

val outputFileFormats = this.config.outputFileFormats.map { FileFormat.forExtension(it) }
val outputFileFormats = config.outputFileFormats.map { FileFormat.forExtension(it) }

return outputFileFormats.map { fileFormat ->
runCatching {
Expand Down
17 changes: 6 additions & 11 deletions plugins/reporters/fossid/src/main/kotlin/FossIdReporter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import org.ossreviewtoolkit.clients.fossid.generateReport
import org.ossreviewtoolkit.clients.fossid.model.report.ReportType
import org.ossreviewtoolkit.clients.fossid.model.report.SelectionType
import org.ossreviewtoolkit.model.ScanResult
import org.ossreviewtoolkit.model.config.PluginConfiguration
import org.ossreviewtoolkit.plugins.api.OrtPlugin
import org.ossreviewtoolkit.plugins.api.OrtPluginOption
import org.ossreviewtoolkit.plugins.api.PluginDescriptor
Expand Down Expand Up @@ -93,16 +92,12 @@ class FossIdReporter(
const val SCAN_CODE_KEY = "scancode"
}

override fun generateReport(
input: ReporterInput,
outputDir: File,
config: PluginConfiguration
): List<Result<File>> {
val reportType = ReportType.valueOf(this.config.reportType)
val selectionType = SelectionType.valueOf(this.config.selectionType)
override fun generateReport(input: ReporterInput, outputDir: File): List<Result<File>> {
val reportType = ReportType.valueOf(config.reportType)
val selectionType = SelectionType.valueOf(config.selectionType)

return runBlocking(Dispatchers.IO) {
val service = FossIdRestService.create(this@FossIdReporter.config.serverUrl)
val service = FossIdRestService.create(config.serverUrl)
val scanResults = input.ortResult.getScanResults().values.flatten()
val scanCodes = scanResults.flatMapTo(mutableSetOf()) {
it.additionalData[SCAN_CODE_KEY]?.split(',').orEmpty()
Expand All @@ -113,8 +108,8 @@ class FossIdReporter(
logger.info { "Generating report for scan $scanCode." }

service.generateReport(
this@FossIdReporter.config.user.value,
this@FossIdReporter.config.apiKey.value,
config.user.value,
config.apiKey.value,
scanCode,
reportType,
selectionType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ package org.ossreviewtoolkit.plugins.reporters.fossid

import java.io.File

import org.ossreviewtoolkit.model.config.PluginConfiguration
import org.ossreviewtoolkit.plugins.api.OrtPlugin
import org.ossreviewtoolkit.plugins.api.PluginDescriptor
import org.ossreviewtoolkit.plugins.reporters.asciidoc.AsciiDocTemplateReporterConfig
Expand All @@ -44,11 +43,7 @@ class FossIdSnippetReporter(override val descriptor: PluginDescriptor = FossIdSn
)
}

override fun generateReport(
input: ReporterInput,
outputDir: File,
config: PluginConfiguration
): List<Result<File>> {
override fun generateReport(input: ReporterInput, outputDir: File): List<Result<File>> {
val hasFossIdResults = input.ortResult.scanner?.scanResults?.any { it.scanner.name == "FossId" } == true
require(hasFossIdResults) { "No FossID scan results have been found." }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ package org.ossreviewtoolkit.plugins.reporters.freemarker

import java.io.File

import org.ossreviewtoolkit.model.config.PluginConfiguration
import org.ossreviewtoolkit.plugins.api.OrtPlugin
import org.ossreviewtoolkit.plugins.api.OrtPluginOption
import org.ossreviewtoolkit.plugins.api.PluginDescriptor
Expand Down Expand Up @@ -75,12 +74,8 @@ class PlainTextTemplateReporter(

private val templateProcessor = FreemarkerTemplateProcessor(TEMPLATE_DIRECTORY)

override fun generateReport(
input: ReporterInput,
outputDir: File,
config: PluginConfiguration
): List<Result<File>> {
val actualConfig = this.config.takeIf {
override fun generateReport(input: ReporterInput, outputDir: File): List<Result<File>> {
val actualConfig = config.takeIf {
it.templateIds?.isNotEmpty() == true || it.templatePaths?.isNotEmpty() == true
} ?: PlainTextTemplateReporterConfig.DEFAULT

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.JsonNamingStrategy

import org.ossreviewtoolkit.model.config.PluginConfiguration
import org.ossreviewtoolkit.plugins.api.OrtPlugin
import org.ossreviewtoolkit.plugins.api.OrtPluginOption
import org.ossreviewtoolkit.plugins.api.PluginDescriptor
Expand Down Expand Up @@ -67,12 +66,8 @@ class GitLabLicenseModelReporter(

private val reportFilename = "gl-license-scanning-report.json"

override fun generateReport(
input: ReporterInput,
outputDir: File,
config: PluginConfiguration
): List<Result<File>> {
val licenseModel = GitLabLicenseModelMapper.map(input.ortResult, this.config.skipExcluded)
override fun generateReport(input: ReporterInput, outputDir: File): List<Result<File>> {
val licenseModel = GitLabLicenseModelMapper.map(input.ortResult, config.skipExcluded)

val reportFileResult = runCatching {
val licenseModelJson = JSON.encodeToString(licenseModel)
Expand Down
9 changes: 2 additions & 7 deletions plugins/reporters/opossum/src/main/kotlin/OpossumReporter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ import org.ossreviewtoolkit.model.Package
import org.ossreviewtoolkit.model.Project
import org.ossreviewtoolkit.model.ScanResult
import org.ossreviewtoolkit.model.VcsInfo
import org.ossreviewtoolkit.model.config.PluginConfiguration
import org.ossreviewtoolkit.model.utils.getPurlType
import org.ossreviewtoolkit.model.utils.toPurl
import org.ossreviewtoolkit.plugins.api.OrtPlugin
Expand Down Expand Up @@ -545,13 +544,9 @@ class OpossumReporter(
return opossumInput
}

override fun generateReport(
input: ReporterInput,
outputDir: File,
config: PluginConfiguration
): List<Result<File>> {
override fun generateReport(input: ReporterInput, outputDir: File): List<Result<File>> {
val reportFileResult = runCatching {
val opossumInput = generateOpossumInput(input, this.config.maxDepth)
val opossumInput = generateOpossumInput(input, config.maxDepth)

outputDir.resolve("report.opossum").also {
writeReport(it, opossumInput)
Expand Down
21 changes: 8 additions & 13 deletions plugins/reporters/spdx/src/main/kotlin/SpdxDocumentReporter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import java.io.File

import org.apache.logging.log4j.kotlin.logger

import org.ossreviewtoolkit.model.config.PluginConfiguration
import org.ossreviewtoolkit.plugins.api.OrtPlugin
import org.ossreviewtoolkit.plugins.api.OrtPluginOption
import org.ossreviewtoolkit.plugins.api.PluginDescriptor
Expand Down Expand Up @@ -98,21 +97,17 @@ class SpdxDocumentReporter(
const val REPORT_BASE_FILENAME = "bom.spdx"
}

override fun generateReport(
input: ReporterInput,
outputDir: File,
config: PluginConfiguration
): List<Result<File>> {
val outputFileFormats = this.config.outputFileFormats
override fun generateReport(input: ReporterInput, outputDir: File): List<Result<File>> {
val outputFileFormats = config.outputFileFormats
.mapTo(mutableSetOf()) { FileFormat.valueOf(it.uppercase()) }

val params = SpdxDocumentModelMapper.SpdxDocumentParams(
documentName = this.config.documentName,
documentComment = this.config.documentComment.orEmpty(),
creationInfoComment = this.config.creationInfoComment.orEmpty(),
creationInfoPerson = this.config.creationInfoPerson.orEmpty(),
creationInfoOrganization = this.config.creationInfoOrganization.orEmpty(),
fileInformationEnabled = this.config.fileInformationEnabled
documentName = config.documentName,
documentComment = config.documentComment.orEmpty(),
creationInfoComment = config.creationInfoComment.orEmpty(),
creationInfoPerson = config.creationInfoPerson.orEmpty(),
creationInfoOrganization = config.creationInfoOrganization.orEmpty(),
fileInformationEnabled = config.fileInformationEnabled
)

val spdxDocument = SpdxDocumentModelMapper.map(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ import org.ossreviewtoolkit.model.RepositoryProvenance
import org.ossreviewtoolkit.model.Severity
import org.ossreviewtoolkit.model.VcsInfo
import org.ossreviewtoolkit.model.config.PathExclude
import org.ossreviewtoolkit.model.config.PluginConfiguration
import org.ossreviewtoolkit.model.config.RepositoryConfiguration
import org.ossreviewtoolkit.model.config.ScopeExclude
import org.ossreviewtoolkit.model.licenses.ResolvedLicenseLocation
Expand Down Expand Up @@ -77,11 +76,7 @@ class StaticHtmlReporter(override val descriptor: PluginDescriptor = StaticHtmlR
private val css = javaClass.getResource("/static-html-reporter.css").readText()
private val licensesSha1 = mutableMapOf<String, String>()

override fun generateReport(
input: ReporterInput,
outputDir: File,
config: PluginConfiguration
): List<Result<File>> {
override fun generateReport(input: ReporterInput, outputDir: File): List<Result<File>> {
val tablesReport = TablesReportModelMapper.map(input)

val reportFileResult = runCatching {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import kotlinx.serialization.json.Json
import kotlinx.serialization.json.encodeToStream

import org.ossreviewtoolkit.model.DependencyNode
import org.ossreviewtoolkit.model.config.PluginConfiguration
import org.ossreviewtoolkit.model.licenses.LicenseView
import org.ossreviewtoolkit.plugins.api.OrtPlugin
import org.ossreviewtoolkit.plugins.api.PluginDescriptor
Expand All @@ -46,11 +45,7 @@ class TrustSourceReporter(override val descriptor: PluginDescriptor = TrustSourc

private val reportFilename = "trustsource-report.json"

override fun generateReport(
input: ReporterInput,
outputDir: File,
config: PluginConfiguration
): List<Result<File>> {
override fun generateReport(input: ReporterInput, outputDir: File): List<Result<File>> {
val outputFile = outputDir.resolve(reportFilename)

val nav = input.ortResult.dependencyNavigator
Expand Down
9 changes: 2 additions & 7 deletions plugins/reporters/web-app/src/main/kotlin/WebAppReporter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import kotlin.io.encoding.encodingWith
import org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream
import org.apache.commons.compress.compressors.gzip.GzipParameters

import org.ossreviewtoolkit.model.config.PluginConfiguration
import org.ossreviewtoolkit.plugins.api.OrtPlugin
import org.ossreviewtoolkit.plugins.api.OrtPluginOption
import org.ossreviewtoolkit.plugins.api.PluginDescriptor
Expand Down Expand Up @@ -62,13 +61,9 @@ class WebAppReporter(
) : Reporter {
private val reportFilename = "scan-report-web-app.html"

override fun generateReport(
input: ReporterInput,
outputDir: File,
config: PluginConfiguration
): List<Result<File>> {
override fun generateReport(input: ReporterInput, outputDir: File): List<Result<File>> {
val template = javaClass.getResource("/scan-report-template.html").readText()
val evaluatedModel = EvaluatedModel.create(input, this.config.deduplicateDependencyTree)
val evaluatedModel = EvaluatedModel.create(input, config.deduplicateDependencyTree)

val index = template.indexOf(PLACEHOLDER)
val prefix = template.substring(0, index)
Expand Down
Loading

0 comments on commit 4596888

Please sign in to comment.