Skip to content

Commit

Permalink
refactor(web-app): Use a plugin config class
Browse files Browse the repository at this point in the history
Add a config class for the reporter and use it instead of the options
passed to the `generateReport` function.

Signed-off-by: Martin Nonnenmacher <martin.nonnenmacher@bosch.com>
  • Loading branch information
mnonnenmacher committed Nov 7, 2024
1 parent 4c52f4c commit bd1d5e9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import io.kotest.matchers.longs.beInRange
import io.kotest.matchers.result.shouldBeSuccess
import io.kotest.matchers.should

import org.ossreviewtoolkit.plugins.api.PluginConfig
import org.ossreviewtoolkit.reporter.ReporterInput
import org.ossreviewtoolkit.utils.test.getAssetFile
import org.ossreviewtoolkit.utils.test.readOrtResult
Expand All @@ -36,7 +37,8 @@ class WebAppReporterFunTest : WordSpec({
val ortResult = readOrtResult(getAssetFile("scan-result-for-synthetic-gradle-lib.yml"))
val outputDir = tempdir()

val reportFileResults = WebAppReporter().generateReport(ReporterInput(ortResult), outputDir)
val reportFileResults = WebAppReporterFactory().create(PluginConfig())
.generateReport(ReporterInput(ortResult), outputDir)

reportFileResults.shouldBeSingleton {
it shouldBeSuccess { reportFile ->
Expand Down
27 changes: 14 additions & 13 deletions plugins/reporters/web-app/src/main/kotlin/WebAppReporter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ 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
import org.ossreviewtoolkit.plugins.reporters.evaluatedmodel.EvaluatedModel
import org.ossreviewtoolkit.reporter.Reporter
Expand All @@ -39,23 +40,26 @@ import org.ossreviewtoolkit.reporter.ReporterInput

private const val PLACEHOLDER = "ORT_REPORT_DATA_PLACEHOLDER"

data class WebAppReporterConfig(
/**
* If true, subtrees occurring multiple times in the dependency tree are stripped.
*/
@OrtPluginOption(defaultValue = "false")
val deduplicateDependencyTree: Boolean
)

/**
* A [Reporter] that generates a web application that allows browsing an ORT result interactively.
*
* This reporter supports the following options:
* - *deduplicateDependencyTree*: Controls whether subtrees occurring multiple times in the dependency tree are
* stripped.
*/
@OrtPlugin(
displayName = "WebApp Reporter",
description = "Generates a web application to browse an ORT result interactively.",
factory = ReporterFactory::class
)
class WebAppReporter(override val descriptor: PluginDescriptor = WebAppReporterFactory.descriptor) : Reporter {
companion object {
const val OPTION_DEDUPLICATE_DEPENDENCY_TREE = "deduplicateDependencyTree"
}

class WebAppReporter(

Check warning on line 59 in plugins/reporters/web-app/src/main/kotlin/WebAppReporter.kt

View workflow job for this annotation

GitHub Actions / qodana-scan

Unused symbol

Class "WebAppReporter" is never used

Check warning

Code scanning / QDJVMC

Unused symbol Warning

Class "WebAppReporter" is never used
override val descriptor: PluginDescriptor = WebAppReporterFactory.descriptor,
private val config: WebAppReporterConfig
) : Reporter {
private val reportFilename = "scan-report-web-app.html"

override fun generateReport(
Expand All @@ -64,10 +68,7 @@ class WebAppReporter(override val descriptor: PluginDescriptor = WebAppReporterF
config: PluginConfiguration
): List<Result<File>> {
val template = javaClass.getResource("/scan-report-template.html").readText()
val evaluatedModel = EvaluatedModel.create(
input,
config.options[OPTION_DEDUPLICATE_DEPENDENCY_TREE].toBoolean()
)
val evaluatedModel = EvaluatedModel.create(input, this.config.deduplicateDependencyTree)

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

0 comments on commit bd1d5e9

Please sign in to comment.