Skip to content
Permalink
Browse files

Slightly refactor the signature of Reporter.generateReport()

Introduce more default arguments and make them go last for making easy
use of them without named arguments.

Signed-off-by: Sebastian Schuberth <sebastian.schuberth@bosch-si.com>
  • Loading branch information...
sschuberth committed Sep 2, 2019
1 parent 959b888 commit 1b98e8b2bc56f8f58226b609305b01ffd0a255de
@@ -155,11 +155,11 @@ object ReporterCommand : CommandWithHelp() {
@Suppress("TooGenericExceptionCaught")
try {
reporter.generateReport(
file.outputStream(),
ortResult,
resolutionProvider,
DefaultLicenseTextProvider(customLicenseTextsDir),
copyrightGarbage,
file.outputStream(),
postProcessingScript?.expandTilde()?.readText()
)

@@ -21,8 +21,6 @@ package com.here.ort.reporter.reporters

import bad.robot.excel.matchers.WorkbookMatcher.sameWorkbook

import com.here.ort.model.config.CopyrightGarbage
import com.here.ort.reporter.DefaultResolutionProvider
import com.here.ort.utils.test.readOrtResult

import io.kotlintest.specs.WordSpec
@@ -39,11 +37,8 @@ class ExcelReporterTest : WordSpec({
"successfully export to an Excel sheet".config(enabled = false) {
val outputStream = ByteArrayOutputStream()
ExcelReporter().generateReport(
readOrtResult("../scanner/src/funTest/assets/file-counter-expected-output-for-analyzer-result.yml"),
DefaultResolutionProvider(),
DefaultLicenseTextProvider(),
CopyrightGarbage(),
outputStream
outputStream,
readOrtResult("../scanner/src/funTest/assets/file-counter-expected-output-for-analyzer-result.yml")
)
val actualWorkbook = WorkbookFactory.create(outputStream.toByteArray().inputStream())

@@ -21,7 +21,6 @@ package com.here.ort.reporter.reporters

import com.here.ort.model.OrtResult
import com.here.ort.model.config.CopyrightGarbage
import com.here.ort.reporter.DefaultResolutionProvider
import com.here.ort.utils.test.readOrtResult

import io.kotlintest.matchers.string.shouldContain
@@ -128,12 +127,10 @@ class NoticeReporterTest : WordSpec() {
) =
ByteArrayOutputStream().also { outputStream ->
NoticeReporter().generateReport(
ortResult,
DefaultResolutionProvider(),
DefaultLicenseTextProvider(),
copyrightGarbage,
outputStream,
postProcessingScript
ortResult,
copyrightGarbage = copyrightGarbage,
postProcessingScript = postProcessingScript
)
}.toString("UTF-8")
}
@@ -21,7 +21,6 @@ package com.here.ort.reporter.reporters

import com.here.ort.model.Environment
import com.here.ort.model.OrtResult
import com.here.ort.model.config.CopyrightGarbage
import com.here.ort.reporter.DefaultResolutionProvider
import com.here.ort.utils.test.patchExpectedResult
import com.here.ort.utils.test.readOrtResult
@@ -64,11 +63,9 @@ class StaticHtmlReporterTest : WordSpec() {
ortResult.repository.config.resolutions?.let { resolutionProvider.add(it) }

StaticHtmlReporter().generateReport(
outputStream,
ortResult,
resolutionProvider,
DefaultLicenseTextProvider(),
CopyrightGarbage(),
outputStream
resolutionProvider
)
}.toString("UTF-8")
}
@@ -19,8 +19,6 @@

package com.here.ort.reporter.reporters

import com.here.ort.model.config.CopyrightGarbage
import com.here.ort.reporter.DefaultResolutionProvider
import com.here.ort.utils.test.readOrtResult

import io.kotlintest.shouldNotBe
@@ -33,11 +31,8 @@ class WebAppReporterTest : WordSpec({
"successfully export to a web application" {
val outputStream = ByteArrayOutputStream()
WebAppReporter().generateReport(
readOrtResult("../scanner/src/funTest/assets/file-counter-expected-output-for-analyzer-result.yml"),
DefaultResolutionProvider(),
DefaultLicenseTextProvider(),
CopyrightGarbage(),
outputStream
outputStream,
readOrtResult("../scanner/src/funTest/assets/file-counter-expected-output-for-analyzer-result.yml")
)
outputStream.size() shouldNotBe 0
}
@@ -23,6 +23,7 @@ import com.here.ort.model.AnalyzerResult
import com.here.ort.model.OrtResult
import com.here.ort.model.ScanRecord
import com.here.ort.model.config.CopyrightGarbage
import com.here.ort.reporter.reporters.DefaultLicenseTextProvider

import java.io.OutputStream
import java.util.ServiceLoader
@@ -53,15 +54,15 @@ abstract class Reporter {

/**
* Generate a report for the [ortResult], taking into account any issue resolutions provided by [resolutionProvider]
* and the given known [copyrightGarbage]. The report may be post-processed by a [postProcessingScript] before it is
* written to [outputStream].
* and any license text provided by [LicenseTextProvider]. Copyright statements are cleaned from [copyrightGarbage].
* The report may be post-processed by a [postProcessingScript] before it is written to [outputStream].
*/
abstract fun generateReport(
ortResult: OrtResult,
resolutionProvider: ResolutionProvider,
licenseTextProvider: LicenseTextProvider,
copyrightGarbage: CopyrightGarbage,
outputStream: OutputStream,
ortResult: OrtResult,
resolutionProvider: ResolutionProvider = DefaultResolutionProvider(),
licenseTextProvider: LicenseTextProvider = DefaultLicenseTextProvider(),
copyrightGarbage: CopyrightGarbage = CopyrightGarbage(),
postProcessingScript: String? = null
)
}
@@ -84,11 +84,11 @@ class ExcelReporter : Reporter() {
override val defaultFilename = "scan-report.xlsx"

override fun generateReport(
outputStream: OutputStream,
ortResult: OrtResult,
resolutionProvider: ResolutionProvider,
licenseTextProvider: LicenseTextProvider,
copyrightGarbage: CopyrightGarbage,
outputStream: OutputStream,
postProcessingScript: String?
) {
val tabularScanRecord = ReportTableModelMapper(resolutionProvider).mapToReportTableModel(ortResult)
@@ -79,11 +79,11 @@ class NoticeReporter : Reporter() {
override val defaultFilename = "NOTICE"

override fun generateReport(
outputStream: OutputStream,
ortResult: OrtResult,
resolutionProvider: ResolutionProvider,
licenseTextProvider: LicenseTextProvider,
copyrightGarbage: CopyrightGarbage,
outputStream: OutputStream,
postProcessingScript: String?
) {
requireNotNull(ortResult.scanner) {
@@ -53,11 +53,11 @@ class StaticHtmlReporter : Reporter() {
override val defaultFilename = "scan-report.html"

override fun generateReport(
outputStream: OutputStream,
ortResult: OrtResult,
resolutionProvider: ResolutionProvider,
licenseTextProvider: LicenseTextProvider,
copyrightGarbage: CopyrightGarbage,
outputStream: OutputStream,
postProcessingScript: String?
) {
val tabularScanRecord = ReportTableModelMapper(resolutionProvider).mapToReportTableModel(ortResult)
@@ -33,11 +33,11 @@ class WebAppReporter : Reporter() {
override val defaultFilename = "scan-report-web-app.html"

override fun generateReport(
outputStream: OutputStream,
ortResult: OrtResult,
resolutionProvider: ResolutionProvider,
licenseTextProvider: LicenseTextProvider,
copyrightGarbage: CopyrightGarbage,
outputStream: OutputStream,
postProcessingScript: String?
) {
val template = javaClass.classLoader.getResource("scan-report-template.html").readText()

0 comments on commit 1b98e8b

Please sign in to comment.
You can’t perform that action at this time.