From d48ad68b94e66cc1bbc85001386fe05e784f1639 Mon Sep 17 00:00:00 2001 From: Frank Viernau Date: Mon, 1 Aug 2022 08:53:17 +0200 Subject: [PATCH 1/2] FreeMarkerTemplateProcesser: Extract `getRepositoryPath()` Move `getRepositoryPath()` to `OrtResultExtensions` to enable re-use in an upcoming change. Signed-off-by: Frank Viernau --- .../main/kotlin/utils/OrtResultExtensions.kt | 17 +++++++++++++++++ .../freemarker/FreemarkerTemplateProcessor.kt | 17 +---------------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/model/src/main/kotlin/utils/OrtResultExtensions.kt b/model/src/main/kotlin/utils/OrtResultExtensions.kt index 25357c95d3f13..de804b60d4d51 100644 --- a/model/src/main/kotlin/utils/OrtResultExtensions.kt +++ b/model/src/main/kotlin/utils/OrtResultExtensions.kt @@ -21,6 +21,7 @@ package org.ossreviewtoolkit.model.utils import org.ossreviewtoolkit.model.OrtResult +import org.ossreviewtoolkit.model.RepositoryProvenance import org.ossreviewtoolkit.model.config.CopyrightGarbage import org.ossreviewtoolkit.model.config.LicenseFilenamePatterns import org.ossreviewtoolkit.model.licenses.DefaultLicenseInfoProvider @@ -43,6 +44,22 @@ fun OrtResult.createLicenseInfoResolver( LicenseFilenamePatterns.getInstance() ) +/** + * Return the path where the repository given by [provenance] is linked into the source tree. + */ +fun OrtResult.getRepositoryPath(provenance: RepositoryProvenance): String { + repository.nestedRepositories.forEach { (path, vcsInfo) -> + if (vcsInfo.type == provenance.vcsInfo.type + && vcsInfo.url == provenance.vcsInfo.url + && vcsInfo.revision == provenance.resolvedRevision + ) { + return "/$path/" + } + } + + return "/" +} + /** * Copy this [OrtResult] and add all [labels] to the existing labels, overwriting existing labels on conflict. */ diff --git a/reporter/src/main/kotlin/reporters/freemarker/FreemarkerTemplateProcessor.kt b/reporter/src/main/kotlin/reporters/freemarker/FreemarkerTemplateProcessor.kt index 809efeca2e70b..325bf5b4c3f02 100644 --- a/reporter/src/main/kotlin/reporters/freemarker/FreemarkerTemplateProcessor.kt +++ b/reporter/src/main/kotlin/reporters/freemarker/FreemarkerTemplateProcessor.kt @@ -54,6 +54,7 @@ import org.ossreviewtoolkit.model.licenses.ResolvedLicense import org.ossreviewtoolkit.model.licenses.ResolvedLicenseFileInfo import org.ossreviewtoolkit.model.licenses.ResolvedLicenseInfo import org.ossreviewtoolkit.model.licenses.filterExcluded +import org.ossreviewtoolkit.model.utils.getRepositoryPath import org.ossreviewtoolkit.reporter.Reporter import org.ossreviewtoolkit.reporter.ReporterInput import org.ossreviewtoolkit.utils.common.expandTilde @@ -484,22 +485,6 @@ internal fun OrtResult.deduplicateProjectScanResults(targetProjects: Set - if (vcsInfo.type == provenance.vcsInfo.type - && vcsInfo.url == provenance.vcsInfo.url - && vcsInfo.revision == provenance.resolvedRevision - ) { - return "/$path/" - } - } - - return "/" -} - /** * Return a copy of this [OrtResult] with the scan results replaced by the given [scanResults]. */ From b76e8a24c935cbb55c076804d5c609c0c07980b4 Mon Sep 17 00:00:00 2001 From: Frank Viernau Date: Wed, 7 Sep 2022 09:02:19 +0200 Subject: [PATCH 2/2] ExamplesFunTest: Sort the list of expected violations alphabetically Prepare for extending the test case. Signed-off-by: Frank Viernau --- cli/src/funTest/kotlin/ExamplesFunTest.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cli/src/funTest/kotlin/ExamplesFunTest.kt b/cli/src/funTest/kotlin/ExamplesFunTest.kt index fb6b766dec90e..9fc8583f4496b 100644 --- a/cli/src/funTest/kotlin/ExamplesFunTest.kt +++ b/cli/src/funTest/kotlin/ExamplesFunTest.kt @@ -147,11 +147,11 @@ class ExamplesFunTest : StringSpec() { val result = evaluator.run(script) result.violations.map { it.rule } shouldContainExactlyInAnyOrder listOf( - "UNHANDLED_LICENSE", "COPYLEFT_LIMITED_IN_SOURCE", - "VULNERABILITY_IN_PACKAGE", + "DEPRECATED_SCOPE_EXCLUDE_REASON_IN_ORT_YML", "HIGH_SEVERITY_VULNERABILITY_IN_PACKAGE", - "DEPRECATED_SCOPE_EXCLUDE_REASON_IN_ORT_YML" + "UNHANDLED_LICENSE", + "VULNERABILITY_IN_PACKAGE" ) }