From b6d59b2f79aa981b7f710330a4db4276418dddb2 Mon Sep 17 00:00:00 2001 From: Jens Keim Date: Thu, 13 Jun 2024 16:32:47 +0200 Subject: [PATCH] feat(Repository): Use `KnownProvenance` instead of `VcsInfo` In order to allow source artifacts as well as local source code to be scanned, we require a more generallized Repository, which allows any type of `KnownProvenance`. While we still set the signature of `Repository` to allow `KnownProvenance`s, this commit focuses on accomidateing `RepositoryProvenance` as then main input for now. Therefore we wrap `VcsInfo` with `RepositoryProvenance`, whenever it is used as input, and unwrap it, when it is produced as output. This gives us a quick update of the now depreacted code, without the necessity to support all `KnownProvenance` types from the get go. We also update any realted tests, mostly the expected `OrtResults`, but also some `Repository` definitions and calls. To avoid having `vcs` and `vcsProcessed` appear in the `OrtResult` output, we change them to be a method (fun) instead of a variable (val). This is still a soft refactor, to keep the widely used `vcsProcessed` available for now. We might still remove it later. Signed-off-by: Jens Keim --- analyzer/src/main/kotlin/Analyzer.kt | 10 ++- .../assets/git-repo-expected-output.yml | 77 +++++++++++-------- ...dencies-expected-result-with-curations.yml | 17 ++-- .../funTest/assets/semver4j-ort-result.yml | 17 ++-- .../src/main/kotlin/ProjectSourceRule.kt | 2 +- evaluator/src/main/kotlin/RuleSet.kt | 2 +- .../src/test/kotlin/ProjectSourceRuleTest.kt | 2 +- evaluator/src/test/kotlin/TestData.kt | 3 +- ...r-result-from-pkg-list-expected-output.yml | 17 ++-- ...ateAnalyzerResultFromPackageListCommand.kt | 3 +- .../src/main/kotlin/utils/Extensions.kt | 10 +-- helper-cli/src/main/kotlin/utils/Utils.kt | 43 +++++++---- model/src/main/kotlin/OrtResult.kt | 4 +- model/src/main/kotlin/Repository.kt | 38 ++++----- .../licenses/DefaultLicenseInfoProvider.kt | 5 +- model/src/main/kotlin/licenses/LicenseInfo.kt | 2 - .../main/kotlin/utils/OrtResultExtensions.kt | 7 +- .../analyzer-result-with-dependency-graph.yml | 17 ++-- ...radle-all-dependencies-expected-result.yml | 17 ++-- .../assets/result-with-issues-graph-old.yml | 17 ++-- .../test/assets/result-with-issues-graph.yml | 17 ++-- .../test/assets/result-with-issues-scopes.yml | 17 ++-- ...-multi-project-example-expected-output.yml | 17 ++-- .../sbt-multi-project-example-graph-old.yml | 17 ++-- .../sbt-multi-project-example-graph.yml | 17 ++-- model/src/test/kotlin/OrtResultTest.kt | 13 ++-- model/src/test/kotlin/licenses/TestData.kt | 3 +- .../src/test/assets/ort-analyzer-result.yml | 17 ++-- .../assets/semver4j-analyzer-result-linux.yml | 17 ++-- .../semver4j-analyzer-result-windows.yml | 17 ++-- .../pnpm-workspaces-expected-output.yml | 17 ++-- ...-multi-project-example-expected-output.yml | 17 ++-- .../sbt-http4s-template-expected-output.yml | 17 ++-- .../src/main/kotlin/CycloneDxReporter.kt | 2 +- ...orter-test-deduplicate-expected-output.yml | 27 ++++--- ...d-model-reporter-test-expected-output.json | 30 ++++---- ...ed-model-reporter-test-expected-output.yml | 27 ++++--- .../funTest/assets/reporter-test-input.yml | 27 ++++--- .../src/main/kotlin/EvaluatedModelMapper.kt | 4 - .../src/test/kotlin/FossIdReporterTest.kt | 19 +++-- .../kotlin/FreeMarkerTemplateProcessorTest.kt | 11 +-- .../funTest/assets/reporter-test-input.yml | 27 ++++--- .../src/main/kotlin/OpossumReporter.kt | 2 +- .../src/test/kotlin/OpossumReporterTest.kt | 7 +- .../kotlin/SpdxDocumentReporterFunTest.kt | 7 +- .../funTest/assets/reporter-test-input.yml | 27 ++++--- .../main/kotlin/TablesReportModelMapper.kt | 2 +- .../scan-result-for-synthetic-gradle-lib.yml | 17 ++-- .../src/main/kotlin/StatisticsCalculator.kt | 2 - reporter/src/testFixtures/kotlin/TestData.kt | 3 +- ...tegration-all-pkgs-expected-ort-result.yml | 17 ++-- ...ration-subset-pkgs-expected-ort-result.yml | 17 ++-- website/docs/getting-started/tutorial.md | 17 ++-- 53 files changed, 386 insertions(+), 419 deletions(-) diff --git a/analyzer/src/main/kotlin/Analyzer.kt b/analyzer/src/main/kotlin/Analyzer.kt index 03f447568d64b..e7fa651f8ef11 100644 --- a/analyzer/src/main/kotlin/Analyzer.kt +++ b/analyzer/src/main/kotlin/Analyzer.kt @@ -42,6 +42,7 @@ import org.ossreviewtoolkit.model.AnalyzerResult import org.ossreviewtoolkit.model.AnalyzerRun import org.ossreviewtoolkit.model.OrtResult import org.ossreviewtoolkit.model.Repository +import org.ossreviewtoolkit.model.RepositoryProvenance import org.ossreviewtoolkit.model.config.AnalyzerConfiguration import org.ossreviewtoolkit.model.config.Excludes import org.ossreviewtoolkit.model.config.RepositoryConfiguration @@ -135,11 +136,18 @@ class Analyzer(private val config: AnalyzerConfiguration, private val labels: Ma val workingTree = VersionControlSystem.forDirectory(info.absoluteProjectPath) val vcs = workingTree?.getInfo().orEmpty() + val revision = workingTree?.getRevision().orEmpty() val nestedVcs = workingTree?.getNested()?.filter { (path, _) -> // Only include nested VCS if they are part of the analyzed directory. workingTree.getRootPath().resolve(path).startsWith(info.absoluteProjectPath) }.orEmpty() - val repository = Repository(vcs = vcs, nestedRepositories = nestedVcs, config = info.repositoryConfiguration) + val repository = Repository( + provenance = RepositoryProvenance(vcs, revision), + nestedRepositories = nestedVcs.map { + it.key to RepositoryProvenance(it.value, it.value.revision) + }.toMap(), + config = info.repositoryConfiguration + ) val endTime = Instant.now() diff --git a/cli/src/funTest/assets/git-repo-expected-output.yml b/cli/src/funTest/assets/git-repo-expected-output.yml index 3b6f280282408..5a62c0d8e471d 100644 --- a/cli/src/funTest/assets/git-repo-expected-output.yml +++ b/cli/src/funTest/assets/git-repo-expected-output.yml @@ -1,46 +1,55 @@ --- repository: - vcs: - type: "GitRepo" - url: "https://github.com/oss-review-toolkit/ort-test-data-git-repo?manifest=manifest.xml" - revision: "31588aa8f8555474e1c3c66a359ec99e4cd4b1fa" - path: "" - vcs_processed: - type: "GitRepo" - url: "https://github.com/oss-review-toolkit/ort-test-data-git-repo.git?manifest=manifest.xml" - revision: "31588aa8f8555474e1c3c66a359ec99e4cd4b1fa" - path: "" + provenance: + vcs_info: + type: "GitRepo" + url: "https://github.com/oss-review-toolkit/ort-test-data-git-repo?manifest=manifest.xml" + revision: "31588aa8f8555474e1c3c66a359ec99e4cd4b1fa" + path: "" + resolved_revision: "31588aa8f8555474e1c3c66a359ec99e4cd4b1fa" nested_repositories: spdx-tools: - type: "Git" - url: "https://github.com/spdx/tools" - revision: "e179fae47590eccedc46186ea0ce20cbade5fda7" - path: "" + vcs_info: + type: "Git" + url: "https://github.com/spdx/tools" + revision: "e179fae47590eccedc46186ea0ce20cbade5fda7" + path: "" + resolved_revision: "e179fae47590eccedc46186ea0ce20cbade5fda7" submodules: - type: "Git" - url: "https://github.com/oss-review-toolkit/ort-test-data-git-submodules" - revision: "fcea94bab5835172e826afddb9f6427274c983b9" - path: "" + vcs_info: + type: "Git" + url: "https://github.com/oss-review-toolkit/ort-test-data-git-submodules" + revision: "fcea94bab5835172e826afddb9f6427274c983b9" + path: "" + resolved_revision: "fcea94bab5835172e826afddb9f6427274c983b9" submodules/commons-text: - type: "Git" - url: "https://github.com/apache/commons-text.git" - revision: "7643b12421100d29fd2b78053e77bcb04a251b2e" - path: "" + vcs_info: + type: "Git" + url: "https://github.com/apache/commons-text.git" + revision: "7643b12421100d29fd2b78053e77bcb04a251b2e" + path: "" + resolved_revision: "7643b12421100d29fd2b78053e77bcb04a251b2e" submodules/test-data-npm: - type: "Git" - url: "https://github.com/oss-review-toolkit/ort-test-data-npm.git" - revision: "ad0367b7b9920144a47b8d30cc0c84cea102b821" - path: "" + vcs_info: + type: "Git" + url: "https://github.com/oss-review-toolkit/ort-test-data-npm.git" + revision: "ad0367b7b9920144a47b8d30cc0c84cea102b821" + path: "" + resolved_revision: "ad0367b7b9920144a47b8d30cc0c84cea102b821" submodules/test-data-npm/isarray: - type: "Git" - url: "https://github.com/juliangruber/isarray.git" - revision: "63ea4ca0a0d6b0574d6a470ebd26880c3026db4a" - path: "" + vcs_info: + type: "Git" + url: "https://github.com/juliangruber/isarray.git" + revision: "63ea4ca0a0d6b0574d6a470ebd26880c3026db4a" + path: "" + resolved_revision: "63ea4ca0a0d6b0574d6a470ebd26880c3026db4a" submodules/test-data-npm/long.js: - type: "Git" - url: "https://github.com/dcodeIO/long.js.git" - revision: "941c5c62471168b5d18153755c2a7b38d2560e58" - path: "" + vcs_info: + type: "Git" + url: "https://github.com/dcodeIO/long.js.git" + revision: "941c5c62471168b5d18153755c2a7b38d2560e58" + path: "" + resolved_revision: "941c5c62471168b5d18153755c2a7b38d2560e58" config: {} analyzer: start_time: "1970-01-01T00:00:00Z" diff --git a/cli/src/funTest/assets/gradle-all-dependencies-expected-result-with-curations.yml b/cli/src/funTest/assets/gradle-all-dependencies-expected-result-with-curations.yml index 5ead4c4f0d4e3..5e92476d47954 100644 --- a/cli/src/funTest/assets/gradle-all-dependencies-expected-result-with-curations.yml +++ b/cli/src/funTest/assets/gradle-all-dependencies-expected-result-with-curations.yml @@ -1,15 +1,12 @@ --- repository: - vcs: - type: "Git" - url: "" - revision: "" - path: "plugins/package-managers/gradle/src/funTest/assets/projects/synthetic/gradle" - vcs_processed: - type: "Git" - url: "" - revision: "" - path: "plugins/package-managers/gradle/src/funTest/assets/projects/synthetic/gradle" + provenance: + vcs_info: + type: "Git" + url: "" + revision: "" + path: "plugins/package-managers/gradle/src/funTest/assets/projects/synthetic/gradle" + resolved_revision: "" config: excludes: paths: diff --git a/cli/src/funTest/assets/semver4j-ort-result.yml b/cli/src/funTest/assets/semver4j-ort-result.yml index 7f06ecc1c2915..695a666fe83f4 100644 --- a/cli/src/funTest/assets/semver4j-ort-result.yml +++ b/cli/src/funTest/assets/semver4j-ort-result.yml @@ -1,15 +1,12 @@ --- repository: - vcs: - type: "Git" - url: "https://github.com/vdurmont/semver4j.git" - revision: "7653e418d610ffcd2811bcb55fd72d00d420950b" - path: "" - vcs_processed: - type: "Git" - url: "https://github.com/vdurmont/semver4j.git" - revision: "7653e418d610ffcd2811bcb55fd72d00d420950b" - path: "" + provenance: + vcs_info: + type: "Git" + url: "https://github.com/vdurmont/semver4j.git" + revision: "7653e418d610ffcd2811bcb55fd72d00d420950b" + path: "" + resolved_revision: "" config: excludes: scopes: diff --git a/evaluator/src/main/kotlin/ProjectSourceRule.kt b/evaluator/src/main/kotlin/ProjectSourceRule.kt index e390cb0835218..de06cd9e3a692 100644 --- a/evaluator/src/main/kotlin/ProjectSourceRule.kt +++ b/evaluator/src/main/kotlin/ProjectSourceRule.kt @@ -91,7 +91,7 @@ open class ProjectSourceRule( /** * Return the [VcsType] of the project's code repository. */ - fun projectSourceGetVcsType(): VcsType = ortResult.repository.vcsProcessed.type + fun projectSourceGetVcsType(): VcsType = ortResult.repository.vcsProcessed().type /** * Return the file paths matching any of the given [glob expressions][patterns] with its file content matching diff --git a/evaluator/src/main/kotlin/RuleSet.kt b/evaluator/src/main/kotlin/RuleSet.kt index d90f3f2991a5d..259559489840d 100644 --- a/evaluator/src/main/kotlin/RuleSet.kt +++ b/evaluator/src/main/kotlin/RuleSet.kt @@ -159,7 +159,7 @@ fun ruleSet( licenseInfoResolver: LicenseInfoResolver = ortResult.createLicenseInfoResolver(), resolutionProvider: ResolutionProvider = DefaultResolutionProvider.create(), projectSourceResolver: SourceTreeResolver = SourceTreeResolver.forRemoteRepository( - ortResult.repository.vcsProcessed + ortResult.repository.vcsProcessed() ), configure: RuleSet.() -> Unit = { } ) = RuleSet(ortResult, licenseInfoResolver, resolutionProvider, projectSourceResolver).apply(configure) diff --git a/evaluator/src/test/kotlin/ProjectSourceRuleTest.kt b/evaluator/src/test/kotlin/ProjectSourceRuleTest.kt index 7f834823f684e..80d620eb17af7 100644 --- a/evaluator/src/test/kotlin/ProjectSourceRuleTest.kt +++ b/evaluator/src/test/kotlin/ProjectSourceRuleTest.kt @@ -208,7 +208,7 @@ private fun createOrtResult( } return OrtResult.EMPTY.copy( - repository = Repository(vcsInfo), + repository = Repository(RepositoryProvenance(vcsInfo, vcsInfo.revision)), analyzer = AnalyzerRun.EMPTY.copy( result = AnalyzerResult.EMPTY.copy( projects = setOf( diff --git a/evaluator/src/test/kotlin/TestData.kt b/evaluator/src/test/kotlin/TestData.kt index 45d72b0c61b56..a9f22e0924273 100644 --- a/evaluator/src/test/kotlin/TestData.kt +++ b/evaluator/src/test/kotlin/TestData.kt @@ -37,6 +37,7 @@ import org.ossreviewtoolkit.model.Package import org.ossreviewtoolkit.model.PackageLinkage import org.ossreviewtoolkit.model.Project import org.ossreviewtoolkit.model.Repository +import org.ossreviewtoolkit.model.RepositoryProvenance import org.ossreviewtoolkit.model.ScanResult import org.ossreviewtoolkit.model.ScanSummary import org.ossreviewtoolkit.model.ScannerDetails @@ -180,7 +181,7 @@ val allProjects = setOf( val ortResult = OrtResult( repository = Repository( - vcs = VcsInfo.EMPTY, + provenance = RepositoryProvenance(VcsInfo.EMPTY, ""), config = RepositoryConfiguration( excludes = Excludes( paths = listOf( diff --git a/helper-cli/src/funTest/assets/create-analyzer-result-from-pkg-list-expected-output.yml b/helper-cli/src/funTest/assets/create-analyzer-result-from-pkg-list-expected-output.yml index 69d7709bb6a00..cdb580b567c65 100644 --- a/helper-cli/src/funTest/assets/create-analyzer-result-from-pkg-list-expected-output.yml +++ b/helper-cli/src/funTest/assets/create-analyzer-result-from-pkg-list-expected-output.yml @@ -1,15 +1,12 @@ --- repository: - vcs: - type: "Git" - url: "https://github.com/example/project.git" - revision: "2222222222222222222222222222222222222222" - path: "vcs-path/project" - vcs_processed: - type: "Git" - url: "https://github.com/example/project.git" - revision: "2222222222222222222222222222222222222222" - path: "vcs-path/project" + provenance: + vcs_info: + type: "Git" + url: "https://github.com/example/project.git" + revision: "2222222222222222222222222222222222222222" + path: "vcs-path/project" + resolved_revision: "2222222222222222222222222222222222222222" config: excludes: scopes: diff --git a/helper-cli/src/main/kotlin/commands/CreateAnalyzerResultFromPackageListCommand.kt b/helper-cli/src/main/kotlin/commands/CreateAnalyzerResultFromPackageListCommand.kt index 7921112313610..dd7007486e075 100644 --- a/helper-cli/src/main/kotlin/commands/CreateAnalyzerResultFromPackageListCommand.kt +++ b/helper-cli/src/main/kotlin/commands/CreateAnalyzerResultFromPackageListCommand.kt @@ -41,6 +41,7 @@ import org.ossreviewtoolkit.model.PackageReference import org.ossreviewtoolkit.model.Project import org.ossreviewtoolkit.model.RemoteArtifact import org.ossreviewtoolkit.model.Repository +import org.ossreviewtoolkit.model.RepositoryProvenance import org.ossreviewtoolkit.model.Scope import org.ossreviewtoolkit.model.VcsInfo import org.ossreviewtoolkit.model.VcsType @@ -118,7 +119,7 @@ internal class CreateAnalyzerResultFromPackageListCommand : CliktCommand( environment = Environment() ), repository = Repository( - vcs = projectVcs.normalize(), + provenance = RepositoryProvenance(projectVcs.normalize(), projectVcs.revision), config = RepositoryConfiguration( excludes = Excludes( scopes = listOf( diff --git a/helper-cli/src/main/kotlin/utils/Extensions.kt b/helper-cli/src/main/kotlin/utils/Extensions.kt index 061e3fcca4633..ae53c448a0834 100644 --- a/helper-cli/src/main/kotlin/utils/Extensions.kt +++ b/helper-cli/src/main/kotlin/utils/Extensions.kt @@ -38,9 +38,7 @@ import org.ossreviewtoolkit.model.OrtResult import org.ossreviewtoolkit.model.PackageCuration import org.ossreviewtoolkit.model.Project import org.ossreviewtoolkit.model.Provenance -import org.ossreviewtoolkit.model.Repository import org.ossreviewtoolkit.model.RepositoryProvenance -import org.ossreviewtoolkit.model.RuleViolation import org.ossreviewtoolkit.model.ScanResult import org.ossreviewtoolkit.model.Severity import org.ossreviewtoolkit.model.SourceCodeOrigin @@ -691,10 +689,12 @@ internal fun OrtResult.getScanResultFor(packageConfiguration: PackageConfigurati * tree. */ internal fun OrtResult.getRepositoryPaths(): Map> { - val result = mutableMapOf(repository.vcsProcessed.url to mutableSetOf("")) + val result = mutableMapOf(repository.vcsProcessed().url to mutableSetOf("")) - repository.nestedRepositories.mapValues { (path, vcsInfo) -> - result.getOrPut(vcsInfo.url) { mutableSetOf() } += path + repository.nestedRepositories.mapValues { (path, provenance) -> + if (provenance is RepositoryProvenance) { + result.getOrPut(provenance.vcsInfo.url) { mutableSetOf() } += path + } } // For some Git-repo projects `OrtResult.repository.nestedRepositories´ misses some nested repositories for Git diff --git a/helper-cli/src/main/kotlin/utils/Utils.kt b/helper-cli/src/main/kotlin/utils/Utils.kt index 555277d595bef..4dd3d444ef511 100644 --- a/helper-cli/src/main/kotlin/utils/Utils.kt +++ b/helper-cli/src/main/kotlin/utils/Utils.kt @@ -25,8 +25,10 @@ import java.io.File import org.ossreviewtoolkit.downloader.VersionControlSystem import org.ossreviewtoolkit.model.Identifier +import org.ossreviewtoolkit.model.KnownProvenance import org.ossreviewtoolkit.model.OrtResult import org.ossreviewtoolkit.model.PackageCuration +import org.ossreviewtoolkit.model.RepositoryProvenance import org.ossreviewtoolkit.model.VcsInfo import org.ossreviewtoolkit.model.config.LicenseFindingCuration import org.ossreviewtoolkit.model.config.PathExclude @@ -68,8 +70,10 @@ internal fun findRepositoryPaths(directory: File): Map> { val result = mutableMapOf>() - findRepositories(directory).forEach { (path, vcs) -> - result.getOrPut(vcs.url.replaceCredentialsInUri()) { mutableSetOf() } += path + findRepositories(directory).forEach { (path, provenance) -> + if (provenance is RepositoryProvenance) { + result.getOrPut(provenance.vcsInfo.url.replaceCredentialsInUri()) { mutableSetOf() } += path + } } return result @@ -79,14 +83,17 @@ internal fun findRepositoryPaths(directory: File): Map> { * Search the given [directory] for repositories and return a mapping from paths where each respective repository was * found to the corresponding [VcsInfo]. */ -internal fun findRepositories(directory: File): Map { +internal fun findRepositories(directory: File): Map { require(directory.isDirectory) val workingTree = VersionControlSystem.forDirectory(directory) - return workingTree?.getNested()?.filter { (path, _) -> + val nestedVcs = workingTree?.getNested()?.filter { (path, _) -> // Only include nested VCS if they are part of the analyzed directory. workingTree.getRootPath().resolve(path).startsWith(directory) }.orEmpty() + return nestedVcs.map { + it.key to RepositoryProvenance(it.value, it.value.revision) + }.toMap() } /** @@ -166,15 +173,17 @@ internal data class ProcessedCopyrightStatement( */ internal fun getLicenseFindingCurationsByRepository( curations: Collection, - nestedRepositories: Map + nestedRepositories: Map ): RepositoryLicenseFindingCurations { val result = mutableMapOf>() - nestedRepositories.forEach { (path, vcs) -> - val pathExcludesForRepository = result.getOrPut(vcs.url) { mutableListOf() } - curations.forEach { curation -> - curation.path.withoutPrefix("$path/")?.let { - pathExcludesForRepository += curation.copy(path = it) + nestedRepositories.forEach { (path, provenance) -> + if (provenance is RepositoryProvenance) { + val pathExcludesForRepository = result.getOrPut(provenance.vcsInfo.url) { mutableListOf() } + curations.forEach { curation -> + curation.path.withoutPrefix("$path/")?.let { + pathExcludesForRepository += curation.copy(path = it) + } } } } @@ -187,15 +196,17 @@ internal fun getLicenseFindingCurationsByRepository( */ internal fun getPathExcludesByRepository( pathExcludes: Collection, - nestedRepositories: Map + nestedRepositories: Map ): RepositoryPathExcludes { val result = mutableMapOf>() - nestedRepositories.forEach { (path, vcs) -> - val pathExcludesForRepository = result.getOrPut(vcs.url) { mutableListOf() } - pathExcludes.forEach { pathExclude -> - pathExclude.pattern.withoutPrefix("$path/")?.let { - pathExcludesForRepository += pathExclude.copy(pattern = it) + nestedRepositories.forEach { (path, provenance) -> + if (provenance is RepositoryProvenance) { + val pathExcludesForRepository = result.getOrPut(provenance.vcsInfo.url) { mutableListOf() } + pathExcludes.forEach { pathExclude -> + pathExclude.pattern.withoutPrefix("$path/")?.let { + pathExcludesForRepository += pathExclude.copy(pattern = it) + } } } } diff --git a/model/src/main/kotlin/OrtResult.kt b/model/src/main/kotlin/OrtResult.kt index 85ccd06d2e3f4..3457448774ed7 100644 --- a/model/src/main/kotlin/OrtResult.kt +++ b/model/src/main/kotlin/OrtResult.kt @@ -194,7 +194,9 @@ data class OrtResult( } private val relativeProjectVcsPath: Map by lazy { - getProjects().associateBy({ it.id }, { repository.getRelativePath(it.vcsProcessed) }) + getProjects().associateBy({ it.id }, { + repository.getRelativePath(RepositoryProvenance(it.vcsProcessed, it.vcsProcessed.revision)) + }) } /** diff --git a/model/src/main/kotlin/Repository.kt b/model/src/main/kotlin/Repository.kt index 1fcf4562b9d77..93110aac6f4b6 100644 --- a/model/src/main/kotlin/Repository.kt +++ b/model/src/main/kotlin/Repository.kt @@ -22,7 +22,6 @@ package org.ossreviewtoolkit.model import com.fasterxml.jackson.annotation.JsonInclude import org.ossreviewtoolkit.model.config.RepositoryConfiguration -import org.ossreviewtoolkit.utils.ort.ORT_REPO_CONFIG_FILENAME /** * A description of the source code repository that was used as input for ORT. @@ -31,20 +30,14 @@ data class Repository( /** * Original VCS-related information from the working tree containing the analyzer root. */ - val vcs: VcsInfo, - - /** - * Processed VCS-related information from the working tree containing the analyzer root that has e.g. common - * mistakes corrected. - */ - val vcsProcessed: VcsInfo = vcs.normalize(), + val provenance: KnownProvenance, /** * A map of nested repositories, for example Git submodules or Git-Repo modules. The key is the path to the * nested repository relative to the root of the main repository. */ @JsonInclude(JsonInclude.Include.NON_EMPTY) - val nestedRepositories: Map = emptyMap(), + val nestedRepositories: Map = emptyMap(), /** * The configuration of the repository, parsed from [ORT_REPO_CONFIG_FILENAME]. @@ -52,27 +45,36 @@ data class Repository( val config: RepositoryConfiguration = RepositoryConfiguration() ) { companion object { + const val DEFAULT_REVISION = "" + /** * A constant for a [Repository] where all properties are empty strings. */ @JvmField val EMPTY = Repository( - vcs = VcsInfo.EMPTY, - vcsProcessed = VcsInfo.EMPTY, + provenance = RepositoryProvenance(VcsInfo.EMPTY, DEFAULT_REVISION), nestedRepositories = emptyMap(), config = RepositoryConfiguration() ) } + fun vcs(): VcsInfo { + if (provenance is RepositoryProvenance) { return provenance.vcsInfo } + return VcsInfo.EMPTY + } + + fun vcsProcessed(): VcsInfo { + if (provenance is RepositoryProvenance) { return provenance.vcsInfo.normalize() } + return VcsInfo.EMPTY + } + /** - * Return the path of [vcs] relative to [Repository.vcs], or null if [vcs] is neither [Repository.vcs] nor contained - * in [nestedRepositories]. + * Return the path of [provenance] relative to [Repository.provenance], or null if [provenance] is neither + * [Repository.provenance] nor contained in [nestedRepositories]. */ - fun getRelativePath(vcs: VcsInfo): String? { - val normalizedVcs = vcs.normalize() - - if (vcsProcessed.matches(normalizedVcs)) return "" + fun getRelativePath(provenance: KnownProvenance): String? { + if (this.provenance.matches(provenance)) return "" - return nestedRepositories.entries.find { (_, nestedVcs) -> nestedVcs.normalize().matches(normalizedVcs) }?.key + return nestedRepositories.entries.find { (_, nestedProvenance) -> nestedProvenance.matches(provenance) }?.key } } diff --git a/model/src/main/kotlin/licenses/DefaultLicenseInfoProvider.kt b/model/src/main/kotlin/licenses/DefaultLicenseInfoProvider.kt index 71a72b9c36aa5..136ecc26d4c27 100644 --- a/model/src/main/kotlin/licenses/DefaultLicenseInfoProvider.kt +++ b/model/src/main/kotlin/licenses/DefaultLicenseInfoProvider.kt @@ -25,6 +25,7 @@ import java.util.concurrent.ConcurrentMap import org.ossreviewtoolkit.model.Identifier import org.ossreviewtoolkit.model.OrtResult import org.ossreviewtoolkit.model.Provenance +import org.ossreviewtoolkit.model.RepositoryProvenance import org.ossreviewtoolkit.model.config.LicenseFindingCuration import org.ossreviewtoolkit.model.config.PathExclude import org.ossreviewtoolkit.model.utils.filterByVcsPath @@ -106,7 +107,9 @@ class DefaultLicenseInfoProvider(val ortResult: OrtResult) : LicenseInfoProvider Configuration( ortResult.repository.config.curations.licenseFindings, ortResult.repository.config.excludes.paths, - ortResult.repository.getRelativePath(project.vcsProcessed).orEmpty() + ortResult.repository.getRelativePath( + RepositoryProvenance(project.vcsProcessed, project.vcsProcessed.revision) + ).orEmpty() ) } ?: ortResult.getPackageConfigurations(id, provenance).let { packageConfigurations -> Configuration( diff --git a/model/src/main/kotlin/licenses/LicenseInfo.kt b/model/src/main/kotlin/licenses/LicenseInfo.kt index 5f5b95bc70c5f..149a28b225076 100644 --- a/model/src/main/kotlin/licenses/LicenseInfo.kt +++ b/model/src/main/kotlin/licenses/LicenseInfo.kt @@ -24,10 +24,8 @@ import org.ossreviewtoolkit.model.Identifier import org.ossreviewtoolkit.model.LicenseFinding import org.ossreviewtoolkit.model.PackageCurationResult import org.ossreviewtoolkit.model.Provenance -import org.ossreviewtoolkit.model.Repository import org.ossreviewtoolkit.model.config.LicenseFindingCuration import org.ossreviewtoolkit.model.config.PathExclude -import org.ossreviewtoolkit.model.config.RepositoryConfiguration import org.ossreviewtoolkit.utils.ort.ProcessedDeclaredLicense import org.ossreviewtoolkit.utils.spdx.SpdxExpression diff --git a/model/src/main/kotlin/utils/OrtResultExtensions.kt b/model/src/main/kotlin/utils/OrtResultExtensions.kt index b167908c90911..68f24dc67adc9 100644 --- a/model/src/main/kotlin/utils/OrtResultExtensions.kt +++ b/model/src/main/kotlin/utils/OrtResultExtensions.kt @@ -85,11 +85,8 @@ fun OrtResult.createLicenseInfoResolver( * 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 - ) { + repository.nestedRepositories.forEach { (path, nestedProvenance) -> + if (nestedProvenance is RepositoryProvenance && nestedProvenance == provenance) { return "/$path/" } } diff --git a/model/src/test/assets/analyzer-result-with-dependency-graph.yml b/model/src/test/assets/analyzer-result-with-dependency-graph.yml index 15c739d4f11c4..4e834102b83c5 100644 --- a/model/src/test/assets/analyzer-result-with-dependency-graph.yml +++ b/model/src/test/assets/analyzer-result-with-dependency-graph.yml @@ -1,15 +1,12 @@ --- repository: - vcs: - type: "Git" - url: "https://github.com/vdurmont/semver4j.git" - revision: "7653e418d610ffcd2811bcb55fd72d00d420950b" - path: "" - vcs_processed: - type: "Git" - url: "https://github.com/vdurmont/semver4j.git" - revision: "7653e418d610ffcd2811bcb55fd72d00d420950b" - path: "" + provenance: + vcs_info: + type: "Git" + url: "https://github.com/vdurmont/semver4j.git" + revision: "7653e418d610ffcd2811bcb55fd72d00d420950b" + path: "" + resolved_revision: "7653e418d610ffcd2811bcb55fd72d00d420950b" config: {} analyzer: start_time: "2021-04-26T05:48:05.390356Z" diff --git a/model/src/test/assets/gradle-all-dependencies-expected-result.yml b/model/src/test/assets/gradle-all-dependencies-expected-result.yml index 5812c291755e4..e963b68f268c3 100644 --- a/model/src/test/assets/gradle-all-dependencies-expected-result.yml +++ b/model/src/test/assets/gradle-all-dependencies-expected-result.yml @@ -1,15 +1,12 @@ --- repository: - vcs: - type: "Git" - url: "https://github.com/oss-review-toolkit/ort.git" - revision: "d27a886818b8ebba8e97e914133ec3cc650a534b" - path: "analyzer/src/funTest/assets/projects/synthetic/gradle" - vcs_processed: - type: "Git" - url: "https://github.com/oss-review-toolkit/ort.git" - revision: "d27a886818b8ebba8e97e914133ec3cc650a534b" - path: "analyzer/src/funTest/assets/projects/synthetic/gradle" + provenance: + vcs_info: + type: "Git" + url: "https://github.com/oss-review-toolkit/ort.git" + revision: "d27a886818b8ebba8e97e914133ec3cc650a534b" + path: "analyzer/src/funTest/assets/projects/synthetic/gradle" + resolved_revision: "d27a886818b8ebba8e97e914133ec3cc650a534b" config: excludes: paths: diff --git a/model/src/test/assets/result-with-issues-graph-old.yml b/model/src/test/assets/result-with-issues-graph-old.yml index 813f1a184b827..d6a8838443b02 100644 --- a/model/src/test/assets/result-with-issues-graph-old.yml +++ b/model/src/test/assets/result-with-issues-graph-old.yml @@ -1,15 +1,12 @@ --- repository: - vcs: - type: "Git" - url: "https://github.com/pbassiner/sbt-multi-project-example.git" - revision: "31687c099ea6d645e819ef9d6ac9fc4c757a96bc" - path: "" - vcs_processed: - type: "Git" - url: "https://github.com/pbassiner/sbt-multi-project-example.git" - revision: "31687c099ea6d645e819ef9d6ac9fc4c757a96bc" - path: "" + provenance: + vcs_info: + type: "Git" + url: "https://github.com/pbassiner/sbt-multi-project-example.git" + revision: "31687c099ea6d645e819ef9d6ac9fc4c757a96bc" + path: "" + resolved_revision: "31687c099ea6d645e819ef9d6ac9fc4c757a96bc" config: {} analyzer: start_time: "1970-01-01T00:00:00Z" diff --git a/model/src/test/assets/result-with-issues-graph.yml b/model/src/test/assets/result-with-issues-graph.yml index 383a2a8ba0cad..72c30a85caa1b 100644 --- a/model/src/test/assets/result-with-issues-graph.yml +++ b/model/src/test/assets/result-with-issues-graph.yml @@ -1,15 +1,12 @@ --- repository: - vcs: - type: "Git" - url: "https://github.com/pbassiner/sbt-multi-project-example.git" - revision: "31687c099ea6d645e819ef9d6ac9fc4c757a96bc" - path: "" - vcs_processed: - type: "Git" - url: "https://github.com/pbassiner/sbt-multi-project-example.git" - revision: "31687c099ea6d645e819ef9d6ac9fc4c757a96bc" - path: "" + provenance: + vcs_info: + type: "Git" + url: "https://github.com/pbassiner/sbt-multi-project-example.git" + revision: "31687c099ea6d645e819ef9d6ac9fc4c757a96bc" + path: "" + resolved_revision: "31687c099ea6d645e819ef9d6ac9fc4c757a96bc" config: {} analyzer: start_time: "1970-01-01T00:00:00Z" diff --git a/model/src/test/assets/result-with-issues-scopes.yml b/model/src/test/assets/result-with-issues-scopes.yml index e48882fd41e74..79dee3ede4e0d 100644 --- a/model/src/test/assets/result-with-issues-scopes.yml +++ b/model/src/test/assets/result-with-issues-scopes.yml @@ -1,15 +1,12 @@ --- repository: - vcs: - type: "Git" - url: "https://github.com/pbassiner/sbt-multi-project-example.git" - revision: "31687c099ea6d645e819ef9d6ac9fc4c757a96bc" - path: "" - vcs_processed: - type: "Git" - url: "https://github.com/pbassiner/sbt-multi-project-example.git" - revision: "31687c099ea6d645e819ef9d6ac9fc4c757a96bc" - path: "" + provenance: + vcs_info: + type: "Git" + url: "https://github.com/pbassiner/sbt-multi-project-example.git" + revision: "31687c099ea6d645e819ef9d6ac9fc4c757a96bc" + path: "" + resolved_revision: "31687c099ea6d645e819ef9d6ac9fc4c757a96bc" config: {} analyzer: start_time: "1970-01-01T00:00:00Z" diff --git a/model/src/test/assets/sbt-multi-project-example-expected-output.yml b/model/src/test/assets/sbt-multi-project-example-expected-output.yml index 61689dfc575bd..4cc4f7d256c3b 100644 --- a/model/src/test/assets/sbt-multi-project-example-expected-output.yml +++ b/model/src/test/assets/sbt-multi-project-example-expected-output.yml @@ -1,15 +1,12 @@ --- repository: - vcs: - type: "Git" - url: "https://github.com/oss-review-toolkit/sbt-multi-project-example.git" - revision: "3c4e434b241b1f1addc97794932043b86afc2548" - path: "" - vcs_processed: - type: "Git" - url: "https://github.com/oss-review-toolkit/sbt-multi-project-example.git" - revision: "3c4e434b241b1f1addc97794932043b86afc2548" - path: "" + provenance: + vcs_info: + type: "Git" + url: "https://github.com/oss-review-toolkit/sbt-multi-project-example.git" + revision: "3c4e434b241b1f1addc97794932043b86afc2548" + path: "" + resolved_revision: "3c4e434b241b1f1addc97794932043b86afc2548" config: {} analyzer: start_time: "1970-01-01T00:00:00Z" diff --git a/model/src/test/assets/sbt-multi-project-example-graph-old.yml b/model/src/test/assets/sbt-multi-project-example-graph-old.yml index 75faa6da133a5..059d8e2b571bb 100644 --- a/model/src/test/assets/sbt-multi-project-example-graph-old.yml +++ b/model/src/test/assets/sbt-multi-project-example-graph-old.yml @@ -1,15 +1,12 @@ --- repository: - vcs: - type: "Git" - url: "https://github.com/oss-review-toolkit/sbt-multi-project-example.git" - revision: "3c4e434b241b1f1addc97794932043b86afc2548" - path: "" - vcs_processed: - type: "Git" - url: "https://github.com/oss-review-toolkit/sbt-multi-project-example.git" - revision: "3c4e434b241b1f1addc97794932043b86afc2548" - path: "" + provenance: + vcs_info: + type: "Git" + url: "https://github.com/oss-review-toolkit/sbt-multi-project-example.git" + revision: "3c4e434b241b1f1addc97794932043b86afc2548" + path: "" + resolved_revision: "3c4e434b241b1f1addc97794932043b86afc2548" config: {} analyzer: start_time: "1970-01-01T00:00:00Z" diff --git a/model/src/test/assets/sbt-multi-project-example-graph.yml b/model/src/test/assets/sbt-multi-project-example-graph.yml index 53969a4d0d20d..270723cc2ec23 100644 --- a/model/src/test/assets/sbt-multi-project-example-graph.yml +++ b/model/src/test/assets/sbt-multi-project-example-graph.yml @@ -1,15 +1,12 @@ --- repository: - vcs: - type: "Git" - url: "https://github.com/oss-review-toolkit/sbt-multi-project-example.git" - revision: "3c4e434b241b1f1addc97794932043b86afc2548" - path: "" - vcs_processed: - type: "Git" - url: "https://github.com/oss-review-toolkit/sbt-multi-project-example.git" - revision: "3c4e434b241b1f1addc97794932043b86afc2548" - path: "" + provenance: + vcs_info: + type: "Git" + url: "https://github.com/oss-review-toolkit/sbt-multi-project-example.git" + revision: "3c4e434b241b1f1addc97794932043b86afc2548" + path: "" + resolved_revision: "3c4e434b241b1f1addc97794932043b86afc2548" config: {} analyzer: start_time: "1970-01-01T00:00:00Z" diff --git a/model/src/test/kotlin/OrtResultTest.kt b/model/src/test/kotlin/OrtResultTest.kt index a514d4e351908..aba5123b748df 100644 --- a/model/src/test/kotlin/OrtResultTest.kt +++ b/model/src/test/kotlin/OrtResultTest.kt @@ -106,10 +106,10 @@ class OrtResultTest : WordSpec({ ) val ortResult = OrtResult( Repository( - vcs = vcs, + provenance = RepositoryProvenance(vcs, vcs.revision), nestedRepositories = mapOf( - "path/1" to nestedVcs1, - "path/2" to nestedVcs2 + "path/1" to RepositoryProvenance(nestedVcs1, nestedVcs1.revision), + "path/2" to RepositoryProvenance(nestedVcs2, nestedVcs2.revision) ) ), AnalyzerRun.EMPTY.copy( @@ -134,9 +134,9 @@ class OrtResultTest : WordSpec({ ) val ortResult = OrtResult( Repository( - vcs = vcs, + provenance = RepositoryProvenance(vcs, vcs.revision), nestedRepositories = mapOf( - "path/1" to nestedVcs1 + "path/1" to RepositoryProvenance(nestedVcs1, nestedVcs1.revision) ) ), AnalyzerRun.EMPTY.copy( @@ -260,8 +260,7 @@ class OrtResultTest : WordSpec({ val ortResult = OrtResult.EMPTY.copy( repository = Repository.EMPTY.copy( - vcs = vcs, - vcsProcessed = vcs, + provenance = RepositoryProvenance(vcs, vcs.revision), config = RepositoryConfiguration( excludes = Excludes( paths = listOf( diff --git a/model/src/test/kotlin/licenses/TestData.kt b/model/src/test/kotlin/licenses/TestData.kt index ab2f144071a4b..5edd4bdfa5a2f 100644 --- a/model/src/test/kotlin/licenses/TestData.kt +++ b/model/src/test/kotlin/licenses/TestData.kt @@ -27,6 +27,7 @@ import org.ossreviewtoolkit.model.OrtResult import org.ossreviewtoolkit.model.Package import org.ossreviewtoolkit.model.Project import org.ossreviewtoolkit.model.Repository +import org.ossreviewtoolkit.model.RepositoryProvenance import org.ossreviewtoolkit.model.ScanResult import org.ossreviewtoolkit.model.ScanSummary import org.ossreviewtoolkit.model.ScannerDetails @@ -151,7 +152,7 @@ val scanResults = listOf( val ortResult = OrtResult( repository = Repository( - vcs = VcsInfo.EMPTY, + provenance = RepositoryProvenance(VcsInfo.EMPTY, ""), config = RepositoryConfiguration( excludes = Excludes( paths = listOf( diff --git a/plugins/advisors/vulnerable-code/src/test/assets/ort-analyzer-result.yml b/plugins/advisors/vulnerable-code/src/test/assets/ort-analyzer-result.yml index 0b916212007b5..c18db71099cd4 100644 --- a/plugins/advisors/vulnerable-code/src/test/assets/ort-analyzer-result.yml +++ b/plugins/advisors/vulnerable-code/src/test/assets/ort-analyzer-result.yml @@ -1,15 +1,12 @@ --- repository: - vcs: - type: "Git" - url: "https://github.com/tests/test-project.git" - revision: "1234567890" - path: "analyzer/src/funTest/assets/projects/synthetic/gradle" - vcs_processed: - type: "Git" - url: "https://github.com/tests/test-project.git" - revision: "1234567890" - path: "analyzer/src/funTest/assets/projects/synthetic/gradle" + provenance: + vcs_info: + type: "Git" + url: "https://github.com/tests/test-project.git" + revision: "1234567890" + path: "analyzer/src/funTest/assets/projects/synthetic/gradle" + resolved_revision: "1234567890" config: excludes: paths: diff --git a/plugins/commands/compare/src/funTest/assets/semver4j-analyzer-result-linux.yml b/plugins/commands/compare/src/funTest/assets/semver4j-analyzer-result-linux.yml index 9bf93dc29067c..540c883c9bbaa 100644 --- a/plugins/commands/compare/src/funTest/assets/semver4j-analyzer-result-linux.yml +++ b/plugins/commands/compare/src/funTest/assets/semver4j-analyzer-result-linux.yml @@ -1,15 +1,12 @@ --- repository: - vcs: - type: "Git" - url: "https://github.com/vdurmont/semver4j.git" - revision: "7653e418d610ffcd2811bcb55fd72d00d420950b" - path: "" - vcs_processed: - type: "Git" - url: "https://github.com/vdurmont/semver4j.git" - revision: "7653e418d610ffcd2811bcb55fd72d00d420950b" - path: "" + provenance: + vcs_info: + type: "Git" + url: "https://github.com/vdurmont/semver4j.git" + revision: "7653e418d610ffcd2811bcb55fd72d00d420950b" + path: "" + resolved_revision: "7653e418d610ffcd2811bcb55fd72d00d420950b" config: {} analyzer: start_time: "2023-11-22T08:58:09.135241769Z" diff --git a/plugins/commands/compare/src/funTest/assets/semver4j-analyzer-result-windows.yml b/plugins/commands/compare/src/funTest/assets/semver4j-analyzer-result-windows.yml index 22ce0306e48d9..6aecc69c90fcd 100644 --- a/plugins/commands/compare/src/funTest/assets/semver4j-analyzer-result-windows.yml +++ b/plugins/commands/compare/src/funTest/assets/semver4j-analyzer-result-windows.yml @@ -1,15 +1,12 @@ --- repository: - vcs: - type: "Git" - url: "https://github.com/vdurmont/semver4j.git" - revision: "7653e418d610ffcd2811bcb55fd72d00d420950b" - path: "" - vcs_processed: - type: "Git" - url: "https://github.com/vdurmont/semver4j.git" - revision: "7653e418d610ffcd2811bcb55fd72d00d420950b" - path: "" + provenance: + vcs_info: + type: "Git" + url: "https://github.com/vdurmont/semver4j.git" + revision: "7653e418d610ffcd2811bcb55fd72d00d420950b" + path: "" + resolved_revision: "7653e418d610ffcd2811bcb55fd72d00d420950b" config: {} analyzer: start_time: "2023-11-28T18:19:25.524660Z" diff --git a/plugins/package-managers/node/src/funTest/assets/projects/synthetic/pnpm-workspaces-expected-output.yml b/plugins/package-managers/node/src/funTest/assets/projects/synthetic/pnpm-workspaces-expected-output.yml index b1fb99c19128e..ec8d44bcd44ae 100644 --- a/plugins/package-managers/node/src/funTest/assets/projects/synthetic/pnpm-workspaces-expected-output.yml +++ b/plugins/package-managers/node/src/funTest/assets/projects/synthetic/pnpm-workspaces-expected-output.yml @@ -1,15 +1,12 @@ --- repository: - vcs: - type: "Git" - url: "" - revision: "" - path: "plugins/package-managers/node/src/funTest/assets/projects/synthetic/pnpm-workspaces" - vcs_processed: - type: "Git" - url: "" - revision: "" - path: "" + provenance: + vcs_info: + type: "Git" + url: "" + revision: "" + path: "plugins/package-managers/node/src/funTest/assets/projects/synthetic/pnpm-workspaces" + resolved_revision: "" config: {} analyzer: start_time: "1970-01-01T00:00:00Z" diff --git a/plugins/package-managers/sbt/src/funTest/assets/projects/external/sbt-multi-project-example-expected-output.yml b/plugins/package-managers/sbt/src/funTest/assets/projects/external/sbt-multi-project-example-expected-output.yml index 61689dfc575bd..4cc4f7d256c3b 100644 --- a/plugins/package-managers/sbt/src/funTest/assets/projects/external/sbt-multi-project-example-expected-output.yml +++ b/plugins/package-managers/sbt/src/funTest/assets/projects/external/sbt-multi-project-example-expected-output.yml @@ -1,15 +1,12 @@ --- repository: - vcs: - type: "Git" - url: "https://github.com/oss-review-toolkit/sbt-multi-project-example.git" - revision: "3c4e434b241b1f1addc97794932043b86afc2548" - path: "" - vcs_processed: - type: "Git" - url: "https://github.com/oss-review-toolkit/sbt-multi-project-example.git" - revision: "3c4e434b241b1f1addc97794932043b86afc2548" - path: "" + provenance: + vcs_info: + type: "Git" + url: "https://github.com/oss-review-toolkit/sbt-multi-project-example.git" + revision: "3c4e434b241b1f1addc97794932043b86afc2548" + path: "" + resolved_revision: "3c4e434b241b1f1addc97794932043b86afc2548" config: {} analyzer: start_time: "1970-01-01T00:00:00Z" diff --git a/plugins/package-managers/sbt/src/funTest/assets/projects/synthetic/sbt-http4s-template-expected-output.yml b/plugins/package-managers/sbt/src/funTest/assets/projects/synthetic/sbt-http4s-template-expected-output.yml index e024c4d9dbada..8df93f67572bc 100644 --- a/plugins/package-managers/sbt/src/funTest/assets/projects/synthetic/sbt-http4s-template-expected-output.yml +++ b/plugins/package-managers/sbt/src/funTest/assets/projects/synthetic/sbt-http4s-template-expected-output.yml @@ -1,15 +1,12 @@ --- repository: - vcs: - type: "Git" - url: "" - revision: "" - path: "plugins/package-managers/sbt/src/funTest/assets/projects/synthetic/sbt-http4s-template" - vcs_processed: - type: "Git" - url: "" - revision: "" - path: "plugins/package-managers/sbt/src/funTest/assets/projects/synthetic/sbt-http4s-template" + provenance: + vcs_info: + type: "Git" + url: "" + revision: "" + path: "plugins/package-managers/sbt/src/funTest/assets/projects/synthetic/sbt-http4s-template" + resolved_revision: "" config: {} analyzer: start_time: "1970-01-01T00:00:00Z" diff --git a/plugins/reporters/cyclonedx/src/main/kotlin/CycloneDxReporter.kt b/plugins/reporters/cyclonedx/src/main/kotlin/CycloneDxReporter.kt index 575262be12551..c98d7332bf601 100644 --- a/plugins/reporters/cyclonedx/src/main/kotlin/CycloneDxReporter.kt +++ b/plugins/reporters/cyclonedx/src/main/kotlin/CycloneDxReporter.kt @@ -186,7 +186,7 @@ class CycloneDxReporter : Reporter { // distributable), just create a single BOM for all projects in that case for now. As there also is no // single correct project to pick for adding external references in that case, simply only use the global // repository VCS information here. - val vcs = input.ortResult.repository.vcsProcessed + val vcs = input.ortResult.repository.vcsProcessed() bom.addExternalReference( ExternalReference.Type.VCS, vcs.url, diff --git a/plugins/reporters/evaluated-model/src/funTest/assets/evaluated-model-reporter-test-deduplicate-expected-output.yml b/plugins/reporters/evaluated-model/src/funTest/assets/evaluated-model-reporter-test-deduplicate-expected-output.yml index 1d0483d199459..9b2e2e6122540 100644 --- a/plugins/reporters/evaluated-model/src/funTest/assets/evaluated-model-reporter-test-deduplicate-expected-output.yml +++ b/plugins/reporters/evaluated-model/src/funTest/assets/evaluated-model-reporter-test-deduplicate-expected-output.yml @@ -1159,22 +1159,21 @@ statistics: MIT: 1 execution_duration_in_seconds: 3125 repository: - vcs: - type: "" - url: "" - revision: "" - path: "" - vcs_processed: - type: "Git" - url: "https://github.com/oss-review-toolkit/ort.git" - revision: "master" - path: "analyzer/src/funTest/assets/projects/synthetic/gradle/lib" - nested_repositories: - sub/module: + provenance: + vcs_info: type: "Git" - url: "https://example.com/git" + url: "https://github.com/oss-review-toolkit/ort.git" revision: "master" - path: "" + path: "analyzer/src/funTest/assets/projects/synthetic/gradle/lib" + resolved_revision: "master" + nested_repositories: + sub/module: + vcs_info: + type: "Git" + url: "https://example.com/git" + revision: "master" + path: "" + resolved_revision: "master" config: excludes: paths: diff --git a/plugins/reporters/evaluated-model/src/funTest/assets/evaluated-model-reporter-test-expected-output.json b/plugins/reporters/evaluated-model/src/funTest/assets/evaluated-model-reporter-test-expected-output.json index 1ec5d8c80740c..593779a494b40 100644 --- a/plugins/reporters/evaluated-model/src/funTest/assets/evaluated-model-reporter-test-expected-output.json +++ b/plugins/reporters/evaluated-model/src/funTest/assets/evaluated-model-reporter-test-expected-output.json @@ -1256,24 +1256,24 @@ "execution_duration_in_seconds" : 3125 }, "repository" : { - "vcs" : { - "type" : "", - "url" : "", - "revision" : "", - "path" : "" - }, - "vcs_processed" : { - "type" : "Git", - "url" : "https://github.com/oss-review-toolkit/ort.git", - "revision" : "master", - "path" : "analyzer/src/funTest/assets/projects/synthetic/gradle/lib" + "provenance" : { + "vcs_info" : { + "type" : "Git", + "url" : "https://github.com/oss-review-toolkit/ort.git", + "revision" : "master", + "path" : "analyzer/src/funTest/assets/projects/synthetic/gradle/lib" + }, + "resolved_revision" : "master" }, "nested_repositories" : { "sub/module" : { - "type" : "Git", - "url" : "https://example.com/git", - "revision" : "master", - "path" : "" + "vcs_info" : { + "type" : "Git", + "url" : "https://example.com/git", + "revision" : "master", + "path" : "" + }, + "resolved_revision" : "master" } }, "config" : { diff --git a/plugins/reporters/evaluated-model/src/funTest/assets/evaluated-model-reporter-test-expected-output.yml b/plugins/reporters/evaluated-model/src/funTest/assets/evaluated-model-reporter-test-expected-output.yml index 1d0483d199459..9b2e2e6122540 100644 --- a/plugins/reporters/evaluated-model/src/funTest/assets/evaluated-model-reporter-test-expected-output.yml +++ b/plugins/reporters/evaluated-model/src/funTest/assets/evaluated-model-reporter-test-expected-output.yml @@ -1159,22 +1159,21 @@ statistics: MIT: 1 execution_duration_in_seconds: 3125 repository: - vcs: - type: "" - url: "" - revision: "" - path: "" - vcs_processed: - type: "Git" - url: "https://github.com/oss-review-toolkit/ort.git" - revision: "master" - path: "analyzer/src/funTest/assets/projects/synthetic/gradle/lib" - nested_repositories: - sub/module: + provenance: + vcs_info: type: "Git" - url: "https://example.com/git" + url: "https://github.com/oss-review-toolkit/ort.git" revision: "master" - path: "" + path: "analyzer/src/funTest/assets/projects/synthetic/gradle/lib" + resolved_revision: "master" + nested_repositories: + sub/module: + vcs_info: + type: "Git" + url: "https://example.com/git" + revision: "master" + path: "" + resolved_revision: "master" config: excludes: paths: diff --git a/plugins/reporters/evaluated-model/src/funTest/assets/reporter-test-input.yml b/plugins/reporters/evaluated-model/src/funTest/assets/reporter-test-input.yml index 0c9d1923ccd06..c12ea44cf5665 100644 --- a/plugins/reporters/evaluated-model/src/funTest/assets/reporter-test-input.yml +++ b/plugins/reporters/evaluated-model/src/funTest/assets/reporter-test-input.yml @@ -1,21 +1,20 @@ --- repository: - vcs: - type: "" - url: "" - revision: "" - path: "" - vcs_processed: - type: "Git" - url: "https://github.com/oss-review-toolkit/ort.git" - revision: "master" - path: "analyzer/src/funTest/assets/projects/synthetic/gradle/lib" - nested_repositories: - sub/module: + provenance: + vcs_info: type: "Git" - url: "https://example.com/git" + url: "https://github.com/oss-review-toolkit/ort.git" revision: "master" - path: "" + path: "analyzer/src/funTest/assets/projects/synthetic/gradle/lib" + resolved_revision: "master" + nested_repositories: + sub/module: + vcs_info: + type: "Git" + url: "https://example.com/git" + revision: "master" + path: "" + resolved_revision: "master" config: excludes: paths: diff --git a/plugins/reporters/evaluated-model/src/main/kotlin/EvaluatedModelMapper.kt b/plugins/reporters/evaluated-model/src/main/kotlin/EvaluatedModelMapper.kt index e0f4843811e8b..495ac15725282 100644 --- a/plugins/reporters/evaluated-model/src/main/kotlin/EvaluatedModelMapper.kt +++ b/plugins/reporters/evaluated-model/src/main/kotlin/EvaluatedModelMapper.kt @@ -30,17 +30,13 @@ import org.ossreviewtoolkit.model.Project import org.ossreviewtoolkit.model.Provenance import org.ossreviewtoolkit.model.RemoteArtifact import org.ossreviewtoolkit.model.Repository -import org.ossreviewtoolkit.model.ResolvedConfiguration import org.ossreviewtoolkit.model.RuleViolation import org.ossreviewtoolkit.model.ScanResult import org.ossreviewtoolkit.model.TextLocation import org.ossreviewtoolkit.model.VcsInfo -import org.ossreviewtoolkit.model.config.Excludes import org.ossreviewtoolkit.model.config.IssueResolution import org.ossreviewtoolkit.model.config.LicenseFindingCuration import org.ossreviewtoolkit.model.config.PathExclude -import org.ossreviewtoolkit.model.config.RepositoryConfiguration -import org.ossreviewtoolkit.model.config.Resolutions import org.ossreviewtoolkit.model.config.RuleViolationResolution import org.ossreviewtoolkit.model.config.ScopeExclude import org.ossreviewtoolkit.model.config.VulnerabilityResolution diff --git a/plugins/reporters/fossid/src/test/kotlin/FossIdReporterTest.kt b/plugins/reporters/fossid/src/test/kotlin/FossIdReporterTest.kt index 99daf6e814e73..c79d688409b1d 100644 --- a/plugins/reporters/fossid/src/test/kotlin/FossIdReporterTest.kt +++ b/plugins/reporters/fossid/src/test/kotlin/FossIdReporterTest.kt @@ -44,6 +44,7 @@ import org.ossreviewtoolkit.clients.fossid.model.report.SelectionType import org.ossreviewtoolkit.model.Identifier import org.ossreviewtoolkit.model.OrtResult import org.ossreviewtoolkit.model.Repository +import org.ossreviewtoolkit.model.RepositoryProvenance import org.ossreviewtoolkit.model.ScanResult import org.ossreviewtoolkit.model.ScanSummary import org.ossreviewtoolkit.model.ScannerDetails @@ -276,11 +277,14 @@ private fun createReporterMock(): Pair { } private fun createReporterInput(vararg scanCodes: String): ReporterInput { - val analyzedVcs = VcsInfo( - type = VcsType.GIT, - revision = "master", - url = "https://github.com/path/first-project.git", - path = "sub/path" + val analyzedProvenance = RepositoryProvenance( + VcsInfo( + type = VcsType.GIT, + revision = "master", + url = "https://github.com/path/first-project.git", + path = "sub/path" + ), + resolvedRevision = "master" ) val results = scanCodes.associateByTo( @@ -299,6 +303,7 @@ private fun createReporterInput(vararg scanCodes: String): ReporterInput { return ReporterInput( OrtResult( repository = Repository( + provenance = analyzedProvenance, config = RepositoryConfiguration( excludes = Excludes( scopes = listOf( @@ -309,9 +314,7 @@ private fun createReporterInput(vararg scanCodes: String): ReporterInput { ) ) ) - ), - vcs = analyzedVcs, - vcsProcessed = analyzedVcs + ) ), scanner = scannerRunOf(*results.toList().toTypedArray()) ) diff --git a/plugins/reporters/freemarker/src/test/kotlin/FreeMarkerTemplateProcessorTest.kt b/plugins/reporters/freemarker/src/test/kotlin/FreeMarkerTemplateProcessorTest.kt index ec1b097ff68cf..271e00977261c 100644 --- a/plugins/reporters/freemarker/src/test/kotlin/FreeMarkerTemplateProcessorTest.kt +++ b/plugins/reporters/freemarker/src/test/kotlin/FreeMarkerTemplateProcessorTest.kt @@ -90,16 +90,18 @@ private fun scanResults(vcsInfo: VcsInfo, findingsPaths: Collection): Li ) } +private const val PROJECT_REVISION = "deadbeaf44444444333333332222222211111111" private val PROJECT_VCS_INFO = VcsInfo( type = VcsType.GIT_REPO, url = "ssh://git@host/manifests/repo?manifest=path/to/manifest.xml", - revision = "deadbeaf44444444333333332222222211111111" + revision = PROJECT_REVISION ) +private const val NESTED_REVISION = "0000000000000000000000000000000000000000" private val NESTED_VCS_INFO = VcsInfo( type = VcsType.GIT, url = "ssh://git@host/project/repo", path = "", - revision = "0000000000000000000000000000000000000000" + revision = NESTED_REVISION ) private val idRootProject = Identifier("NPM:@ort:project-in-root-dir:1.0") @@ -108,9 +110,8 @@ private val idNestedProject = Identifier("SpdxDocumentFile:@ort:project-in-neste private val ORT_RESULT = OrtResult( repository = Repository( - vcs = PROJECT_VCS_INFO, - config = RepositoryConfiguration(), - nestedRepositories = mapOf("nested-vcs-dir" to NESTED_VCS_INFO) + provenance = RepositoryProvenance(PROJECT_VCS_INFO, PROJECT_REVISION), + nestedRepositories = mapOf("nested-vcs-dir" to RepositoryProvenance(NESTED_VCS_INFO, NESTED_REVISION)) ), analyzer = AnalyzerRun.EMPTY.copy( result = AnalyzerResult.EMPTY.copy( diff --git a/plugins/reporters/opossum/src/funTest/assets/reporter-test-input.yml b/plugins/reporters/opossum/src/funTest/assets/reporter-test-input.yml index 0c9d1923ccd06..c12ea44cf5665 100644 --- a/plugins/reporters/opossum/src/funTest/assets/reporter-test-input.yml +++ b/plugins/reporters/opossum/src/funTest/assets/reporter-test-input.yml @@ -1,21 +1,20 @@ --- repository: - vcs: - type: "" - url: "" - revision: "" - path: "" - vcs_processed: - type: "Git" - url: "https://github.com/oss-review-toolkit/ort.git" - revision: "master" - path: "analyzer/src/funTest/assets/projects/synthetic/gradle/lib" - nested_repositories: - sub/module: + provenance: + vcs_info: type: "Git" - url: "https://example.com/git" + url: "https://github.com/oss-review-toolkit/ort.git" revision: "master" - path: "" + path: "analyzer/src/funTest/assets/projects/synthetic/gradle/lib" + resolved_revision: "master" + nested_repositories: + sub/module: + vcs_info: + type: "Git" + url: "https://example.com/git" + revision: "master" + path: "" + resolved_revision: "master" config: excludes: paths: diff --git a/plugins/reporters/opossum/src/main/kotlin/OpossumReporter.kt b/plugins/reporters/opossum/src/main/kotlin/OpossumReporter.kt index a89dfc699f5ca..d3b1521827e79 100644 --- a/plugins/reporters/opossum/src/main/kotlin/OpossumReporter.kt +++ b/plugins/reporters/opossum/src/main/kotlin/OpossumReporter.kt @@ -499,7 +499,7 @@ class OpossumReporter : Reporter { internal fun generateOpossumInput(input: ReporterInput, maxDepth: Int = Int.MAX_VALUE): OpossumInput { val opossumInput = OpossumInput() - opossumInput.addBaseUrl("/", input.ortResult.repository.vcs) + opossumInput.addBaseUrl("/", input.ortResult.repository.vcs()) SpdxLicense.entries.forEach { val licenseText = input.licenseTextProvider.getLicenseText(it.id) diff --git a/plugins/reporters/opossum/src/test/kotlin/OpossumReporterTest.kt b/plugins/reporters/opossum/src/test/kotlin/OpossumReporterTest.kt index 2ef18843f3596..b1797ca38f955 100644 --- a/plugins/reporters/opossum/src/test/kotlin/OpossumReporterTest.kt +++ b/plugins/reporters/opossum/src/test/kotlin/OpossumReporterTest.kt @@ -251,11 +251,14 @@ private fun createOrtResult(): OrtResult { url = "https://github.com/path/first-project.git", path = "sub/path" ) + val analyzedProvenance = RepositoryProvenance( + analyzedVcs, + "master" + ) return OrtResult( repository = Repository( - vcs = analyzedVcs, - vcsProcessed = analyzedVcs + provenance = analyzedProvenance ), analyzer = AnalyzerRun.EMPTY.copy( config = AnalyzerConfiguration(allowDynamicVersions = true), diff --git a/plugins/reporters/spdx/src/funTest/kotlin/SpdxDocumentReporterFunTest.kt b/plugins/reporters/spdx/src/funTest/kotlin/SpdxDocumentReporterFunTest.kt index 7de4ab07a5287..59be8092e7739 100644 --- a/plugins/reporters/spdx/src/funTest/kotlin/SpdxDocumentReporterFunTest.kt +++ b/plugins/reporters/spdx/src/funTest/kotlin/SpdxDocumentReporterFunTest.kt @@ -158,8 +158,11 @@ private val analyzedVcs = VcsInfo( path = "" ) +private val analyzedProvenance = RepositoryProvenance(analyzedVcs, "master") + private val ortResult = OrtResult( repository = Repository( + provenance = analyzedProvenance, config = RepositoryConfiguration( excludes = Excludes( scopes = listOf( @@ -170,9 +173,7 @@ private val ortResult = OrtResult( ) ) ) - ), - vcs = analyzedVcs, - vcsProcessed = analyzedVcs + ) ), analyzer = AnalyzerRun.EMPTY.copy( result = AnalyzerResult( diff --git a/plugins/reporters/static-html/src/funTest/assets/reporter-test-input.yml b/plugins/reporters/static-html/src/funTest/assets/reporter-test-input.yml index 0c9d1923ccd06..c12ea44cf5665 100644 --- a/plugins/reporters/static-html/src/funTest/assets/reporter-test-input.yml +++ b/plugins/reporters/static-html/src/funTest/assets/reporter-test-input.yml @@ -1,21 +1,20 @@ --- repository: - vcs: - type: "" - url: "" - revision: "" - path: "" - vcs_processed: - type: "Git" - url: "https://github.com/oss-review-toolkit/ort.git" - revision: "master" - path: "analyzer/src/funTest/assets/projects/synthetic/gradle/lib" - nested_repositories: - sub/module: + provenance: + vcs_info: type: "Git" - url: "https://example.com/git" + url: "https://github.com/oss-review-toolkit/ort.git" revision: "master" - path: "" + path: "analyzer/src/funTest/assets/projects/synthetic/gradle/lib" + resolved_revision: "master" + nested_repositories: + sub/module: + vcs_info: + type: "Git" + url: "https://example.com/git" + revision: "master" + path: "" + resolved_revision: "master" config: excludes: paths: diff --git a/plugins/reporters/static-html/src/main/kotlin/TablesReportModelMapper.kt b/plugins/reporters/static-html/src/main/kotlin/TablesReportModelMapper.kt index bcb13dc0c0b7a..da98cdb496203 100644 --- a/plugins/reporters/static-html/src/main/kotlin/TablesReportModelMapper.kt +++ b/plugins/reporters/static-html/src/main/kotlin/TablesReportModelMapper.kt @@ -48,7 +48,7 @@ internal object TablesReportModelMapper { .sortedBy { it.id } return TablesReport( - input.ortResult.repository.vcsProcessed, + input.ortResult.repository.vcsProcessed(), input.ortResult.repository.config, ruleViolations, getAnalyzerIssueSummaryTable(input), diff --git a/plugins/reporters/web-app/src/funTest/assets/scan-result-for-synthetic-gradle-lib.yml b/plugins/reporters/web-app/src/funTest/assets/scan-result-for-synthetic-gradle-lib.yml index 7226d7d26b56a..de371e9aa6b93 100644 --- a/plugins/reporters/web-app/src/funTest/assets/scan-result-for-synthetic-gradle-lib.yml +++ b/plugins/reporters/web-app/src/funTest/assets/scan-result-for-synthetic-gradle-lib.yml @@ -1,15 +1,12 @@ --- repository: - vcs: - type: "" - url: "" - revision: "" - path: "" - vcs_processed: - type: "Git" - url: "" - revision: "" - path: "analyzer/src/funTest/assets/projects/synthetic/gradle/lib" + provenance: + vcs_info: + type: "Git" + url: "" + revision: "" + path: "analyzer/src/funTest/assets/projects/synthetic/gradle/lib" + resolved_revision: "" config: {} analyzer: start_time: "1970-01-01T00:00:00Z" diff --git a/reporter/src/main/kotlin/StatisticsCalculator.kt b/reporter/src/main/kotlin/StatisticsCalculator.kt index 700d08f39c24b..b37efc9cf0c29 100644 --- a/reporter/src/main/kotlin/StatisticsCalculator.kt +++ b/reporter/src/main/kotlin/StatisticsCalculator.kt @@ -27,9 +27,7 @@ import kotlin.time.toKotlinDuration import org.ossreviewtoolkit.model.Identifier import org.ossreviewtoolkit.model.OrtResult import org.ossreviewtoolkit.model.Severity -import org.ossreviewtoolkit.model.config.IssueResolution import org.ossreviewtoolkit.model.config.OrtConfiguration -import org.ossreviewtoolkit.model.config.RuleViolationResolution import org.ossreviewtoolkit.model.licenses.LicenseInfoResolver import org.ossreviewtoolkit.model.licenses.LicenseView import org.ossreviewtoolkit.model.licenses.ResolvedLicenseInfo diff --git a/reporter/src/testFixtures/kotlin/TestData.kt b/reporter/src/testFixtures/kotlin/TestData.kt index 52fea88318446..34c91bff2b0ff 100644 --- a/reporter/src/testFixtures/kotlin/TestData.kt +++ b/reporter/src/testFixtures/kotlin/TestData.kt @@ -42,6 +42,7 @@ import org.ossreviewtoolkit.model.PackageReference import org.ossreviewtoolkit.model.Project import org.ossreviewtoolkit.model.RemoteArtifact import org.ossreviewtoolkit.model.Repository +import org.ossreviewtoolkit.model.RepositoryProvenance import org.ossreviewtoolkit.model.ScanResult import org.ossreviewtoolkit.model.ScanSummary import org.ossreviewtoolkit.model.ScannerDetails @@ -66,7 +67,7 @@ import org.ossreviewtoolkit.utils.test.scannerRunOf // TODO: Create a way to reduce the code required to prepare an OrtResult for testing. val ORT_RESULT = OrtResult( repository = Repository( - vcs = VcsInfo.EMPTY, + provenance = RepositoryProvenance(VcsInfo.EMPTY, ""), config = RepositoryConfiguration( excludes = Excludes( paths = listOf( diff --git a/scanner/src/funTest/assets/scanner-integration-all-pkgs-expected-ort-result.yml b/scanner/src/funTest/assets/scanner-integration-all-pkgs-expected-ort-result.yml index 6b163eccd77e2..b8cb63ff5fc16 100644 --- a/scanner/src/funTest/assets/scanner-integration-all-pkgs-expected-ort-result.yml +++ b/scanner/src/funTest/assets/scanner-integration-all-pkgs-expected-ort-result.yml @@ -1,15 +1,12 @@ --- repository: - vcs: - type: "" - url: "" - revision: "" - path: "" - vcs_processed: - type: "" - url: "" - revision: "" - path: "" + provenance: + vcs_info: + type: "" + url: "" + revision: "" + path: "" + resolved_revision: "" config: {} analyzer: start_time: "1970-01-01T00:00:00Z" diff --git a/scanner/src/funTest/assets/scanner-integration-subset-pkgs-expected-ort-result.yml b/scanner/src/funTest/assets/scanner-integration-subset-pkgs-expected-ort-result.yml index f1627ba9c618e..625fd9c4f1d9e 100644 --- a/scanner/src/funTest/assets/scanner-integration-subset-pkgs-expected-ort-result.yml +++ b/scanner/src/funTest/assets/scanner-integration-subset-pkgs-expected-ort-result.yml @@ -1,15 +1,12 @@ --- repository: - vcs: - type: "" - url: "" - revision: "" - path: "" - vcs_processed: - type: "" - url: "" - revision: "" - path: "" + provenance: + vcs_info: + type: "" + url: "" + revision: "" + path: "" + resolved_revision: "" config: {} analyzer: start_time: "1970-01-01T00:00:00Z" diff --git a/website/docs/getting-started/tutorial.md b/website/docs/getting-started/tutorial.md index 5746053d2095a..3dfa28db9936e 100644 --- a/website/docs/getting-started/tutorial.md +++ b/website/docs/getting-started/tutorial.md @@ -136,16 +136,13 @@ Following is an overview of the structure of the `analyzer-result.yml` file (com ```yaml # VCS information about the input directory. repository: - vcs: - type: "Git" - url: "https://github.com/jshttp/mime-types.git" - revision: "7c4ce23d7354fbf64c69d7b7be8413c4ba2add78" - path: "" - vcs_processed: - type: "Git" - url: "https://github.com/jshttp/mime-types.git" - revision: "7c4ce23d7354fbf64c69d7b7be8413c4ba2add78" - path: "" + provenance: + vcs_info: + type: "Git" + url: "https://github.com/jshttp/mime-types.git" + revision: "7c4ce23d7354fbf64c69d7b7be8413c4ba2add78" + path: "" + resolved_revision: "7c4ce23d7354fbf64c69d7b7be8413c4ba2add78" # Will only be present if an '.ort.yml' configuration file with scope excludes was provided. Otherwise, this is an empty object. config: excludes: