Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor preparations for the implementation of file checks #5750

Merged
merged 2 commits into from
Sep 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions cli/src/funTest/kotlin/ExamplesFunTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
}

Expand Down
17 changes: 17 additions & 0 deletions model/src/main/kotlin/utils/OrtResultExtensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -484,22 +485,6 @@ internal fun OrtResult.deduplicateProjectScanResults(targetProjects: Set<Identif
return replaceScanResults(scanResults)
}

/**
* Return the path where the repository given by [provenance] is linked into the source tree.
*/
private 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 "/"
}

/**
* Return a copy of this [OrtResult] with the scan results replaced by the given [scanResults].
*/
Expand Down