diff --git a/analyzer/src/main/kotlin/Analyzer.kt b/analyzer/src/main/kotlin/Analyzer.kt index 4b154fdaa7e63..4fd01f7e0ad75 100644 --- a/analyzer/src/main/kotlin/Analyzer.kt +++ b/analyzer/src/main/kotlin/Analyzer.kt @@ -42,6 +42,8 @@ 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.VcsInfo import org.ossreviewtoolkit.model.config.AnalyzerConfiguration import org.ossreviewtoolkit.model.config.Excludes import org.ossreviewtoolkit.model.config.RepositoryConfiguration @@ -143,11 +145,24 @@ class Analyzer(private val config: AnalyzerConfiguration, private val labels: Ma val workingTree = VersionControlSystem.forDirectory(info.absoluteProjectPath) val vcs = workingTree?.getInfo().orEmpty() + val resolvedRevision = 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 = if (vcs == VcsInfo.EMPTY || resolvedRevision.isEmpty()) { + Repository.EMPTY + } else { + Repository( + provenance = RepositoryProvenance( + vcsInfo = vcs.normalize(), + resolvedRevision = resolvedRevision + ), + nestedRepositories = nestedVcs, + config = info.repositoryConfiguration + ) + } val endTime = Instant.now() diff --git a/cli-helper/src/main/kotlin/commands/CreateAnalyzerResultFromPackageListCommand.kt b/cli-helper/src/main/kotlin/commands/CreateAnalyzerResultFromPackageListCommand.kt index ada2e96f0d401..7c2c7503fdbe8 100644 --- a/cli-helper/src/main/kotlin/commands/CreateAnalyzerResultFromPackageListCommand.kt +++ b/cli-helper/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 @@ -120,7 +121,12 @@ internal class CreateAnalyzerResultFromPackageListCommand : OrtHelperCommand( environment = Environment() ), repository = Repository( - vcs = projectVcs.normalize(), + provenance = projectVcs.normalize().let { + RepositoryProvenance( + vcsInfo = it, + resolvedRevision = it.revision + ) + }, config = RepositoryConfiguration( excludes = Excludes( scopes = listOf( diff --git a/cli-helper/src/main/kotlin/utils/Extensions.kt b/cli-helper/src/main/kotlin/utils/Extensions.kt index 8fbc70b787211..118047e8866d9 100644 --- a/cli-helper/src/main/kotlin/utils/Extensions.kt +++ b/cli-helper/src/main/kotlin/utils/Extensions.kt @@ -716,7 +716,7 @@ internal fun OrtResult.getScanResultFor(packageConfiguration: PackageConfigurati * tree. */ internal fun OrtResult.getRepositoryPaths(): Map> { - val result = mutableMapOf(repository.vcsProcessed.url to mutableSetOf("")) + val result = mutableMapOf(repository.provenance.vcsInfo.url to mutableSetOf("")) repository.nestedRepositories.mapValues { (path, vcsInfo) -> result.getOrPut(vcsInfo.url) { mutableSetOf() } += path diff --git a/evaluator/src/main/kotlin/ProjectSourceRule.kt b/evaluator/src/main/kotlin/ProjectSourceRule.kt index fc89f1729735e..3989fbac7fa31 100644 --- a/evaluator/src/main/kotlin/ProjectSourceRule.kt +++ b/evaluator/src/main/kotlin/ProjectSourceRule.kt @@ -93,7 +93,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.provenance.vcsInfo.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 d8fe06df95973..c34579a8d1dd0 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.provenance.vcsInfo ), 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 1b5b270536929..4cd601c3c8798 100644 --- a/evaluator/src/test/kotlin/ProjectSourceRuleTest.kt +++ b/evaluator/src/test/kotlin/ProjectSourceRuleTest.kt @@ -214,7 +214,12 @@ private fun createOrtResult( } return OrtResult.EMPTY.copy( - repository = Repository(vcsInfo), + repository = Repository( + provenance = RepositoryProvenance( + vcsInfo = vcsInfo, + resolvedRevision = vcsInfo.revision + ) + ), analyzer = AnalyzerRun.EMPTY.copy( result = AnalyzerResult.EMPTY.copy( projects = setOf( diff --git a/evaluator/src/testFixtures/kotlin/TestData.kt b/evaluator/src/testFixtures/kotlin/TestData.kt index 92b2878996923..38e6e9e630b4e 100644 --- a/evaluator/src/testFixtures/kotlin/TestData.kt +++ b/evaluator/src/testFixtures/kotlin/TestData.kt @@ -42,7 +42,6 @@ import org.ossreviewtoolkit.model.ScannerDetails import org.ossreviewtoolkit.model.Scope import org.ossreviewtoolkit.model.TextLocation import org.ossreviewtoolkit.model.UnknownProvenance -import org.ossreviewtoolkit.model.VcsInfo import org.ossreviewtoolkit.model.config.AdvisorConfiguration import org.ossreviewtoolkit.model.config.AnalyzerConfiguration import org.ossreviewtoolkit.model.config.Excludes @@ -179,7 +178,7 @@ val allProjects = setOf( val ortResult = OrtResult( repository = Repository( - vcs = VcsInfo.EMPTY, + provenance = Repository.EMPTY.provenance, config = RepositoryConfiguration( excludes = Excludes( paths = listOf( diff --git a/model/src/main/kotlin/Repository.kt b/model/src/main/kotlin/Repository.kt index 480cb869613bd..5c0c8315840b0 100644 --- a/model/src/main/kotlin/Repository.kt +++ b/model/src/main/kotlin/Repository.kt @@ -20,6 +20,12 @@ package org.ossreviewtoolkit.model import com.fasterxml.jackson.annotation.JsonInclude +import com.fasterxml.jackson.core.JsonParser +import com.fasterxml.jackson.databind.DeserializationContext +import com.fasterxml.jackson.databind.JsonNode +import com.fasterxml.jackson.databind.annotation.JsonDeserialize +import com.fasterxml.jackson.databind.deser.std.StdDeserializer +import com.fasterxml.jackson.module.kotlin.treeToValue import org.ossreviewtoolkit.model.config.RepositoryConfiguration import org.ossreviewtoolkit.utils.ort.ORT_REPO_CONFIG_FILENAME @@ -27,17 +33,12 @@ import org.ossreviewtoolkit.utils.ort.ORT_REPO_CONFIG_FILENAME /** * A description of the source code repository that was used as input for ORT. */ +@JsonDeserialize(using = RepositoryDeserializer::class) data class Repository( /** - * Original VCS-related information from the working tree containing the analyzer root. + * Provenance wrapper for original VCS information, if present. */ - 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: RepositoryProvenance, /** * A map of nested repositories, for example Git submodules or Git-Repo modules. The key is the path to the @@ -57,24 +58,75 @@ data class Repository( */ @JvmField val EMPTY = Repository( - vcs = VcsInfo.EMPTY, - vcsProcessed = VcsInfo.EMPTY, + provenance = RepositoryProvenance( + vcsInfo = VcsInfo.EMPTY, + resolvedRevision = HashAlgorithm.SHA1.emptyValue + ), nestedRepositories = emptyMap(), config = RepositoryConfiguration() ) } /** - * 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 [vcs] relative to [Repository.provenance], or null if [vcs] is neither [Repository.provenance] + * nor contained in [nestedRepositories]. */ fun getRelativePath(vcs: VcsInfo): String? { fun VcsInfo.matches(other: VcsInfo) = type == other.type && url == other.url && revision == other.revision val normalizedVcs = vcs.normalize() - if (vcsProcessed.matches(normalizedVcs)) return "" + if (provenance.vcsInfo.matches(normalizedVcs)) return "" return nestedRepositories.entries.find { (_, nestedVcs) -> nestedVcs.normalize().matches(normalizedVcs) }?.key } } + +/** + * A custom deserializer for [Repository] to support the legacy "vcs" and "vcsProcessed" attributes. + */ +private class RepositoryDeserializer : StdDeserializer(Repository::class.java) { + override fun deserialize(p: JsonParser, ctxt: DeserializationContext): Repository { + val node = p.codec.readTree(p) + val parsedProvenance = when { + node.has("vcs") -> { + // Parse [vcs] and [vcsProcessed] attributes. + val vcs = jsonMapper.treeToValue(node["vcs"]) + val vcsProcess = jsonMapper.treeToValue(node["vcs_processed"]) + + // Fall back to [vcsProcessed], if [vcs] is empty. + val vcsInfo = vcsProcess + + // Get the [vcs]'s revision. + // Fall back to [vcsProcessed], if [vcs] has empty revision. + val resolvedRevision = vcs.revision.ifEmpty { + vcsProcess.revision.ifEmpty { + HashAlgorithm.SHA1.emptyValue + } + } + + // Build a RepositoryProvenance from the parsed VcsInfo fields. + RepositoryProvenance(vcsInfo, resolvedRevision) + } + + else -> { + // Parse the [provenance], if no legacy fields are present. + jsonMapper.treeToValue(node["provenance"]) + } + } + + val nestedRepositories = if (node.has("nested_repositories")) { + jsonMapper.treeToValue>(node["nested_repositories"]) + } else { + emptyMap() + } + + val config = if (node.has("config")) { + jsonMapper.treeToValue(node["config"]) + } else { + RepositoryConfiguration() + } + + return Repository(provenance = parsedProvenance, nestedRepositories, config) + } +} diff --git a/model/src/test/kotlin/OrtResultTest.kt b/model/src/test/kotlin/OrtResultTest.kt index d07eed327347f..4331b7509573e 100644 --- a/model/src/test/kotlin/OrtResultTest.kt +++ b/model/src/test/kotlin/OrtResultTest.kt @@ -162,7 +162,12 @@ class OrtResultTest : WordSpec({ "getDefinitionFilePathRelativeToAnalyzerRoot()" should { "use the correct vcs" { - val vcs = VcsInfo(type = VcsType.GIT, url = "https://example.com/git", revision = "") + val vcs = VcsInfo( + type = VcsType.GIT, + url = "https://example.com/git", + revision = HashAlgorithm.SHA1.emptyValue + ) + val provenance = RepositoryProvenance(vcsInfo = vcs, resolvedRevision = vcs.revision) val nestedVcs1 = VcsInfo(type = VcsType.GIT, url = "https://example.com/git1", revision = "") val nestedVcs2 = VcsInfo(type = VcsType.GIT, url = "https://example.com/git2", revision = "") val project1 = Project.EMPTY.copy( @@ -185,7 +190,7 @@ class OrtResultTest : WordSpec({ ) val ortResult = OrtResult( Repository( - vcs = vcs, + provenance = provenance, nestedRepositories = mapOf( "path/1" to nestedVcs1, "path/2" to nestedVcs2 @@ -202,7 +207,12 @@ class OrtResultTest : WordSpec({ } "fail if no vcs matches" { - val vcs = VcsInfo(type = VcsType.GIT, url = "https://example.com/git", revision = "") + val vcs = VcsInfo( + type = VcsType.GIT, + url = "https://example.com/git", + revision = HashAlgorithm.SHA1.emptyValue + ) + val provenance = RepositoryProvenance(vcsInfo = vcs, resolvedRevision = vcs.revision) val nestedVcs1 = VcsInfo(type = VcsType.GIT, url = "https://example.com/git1", revision = "") val nestedVcs2 = VcsInfo(type = VcsType.GIT, url = "https://example.com/git2", revision = "") val project = Project.EMPTY.copy( @@ -213,7 +223,7 @@ class OrtResultTest : WordSpec({ ) val ortResult = OrtResult( Repository( - vcs = vcs, + provenance = provenance, nestedRepositories = mapOf( "path/1" to nestedVcs1 ) @@ -413,8 +423,10 @@ class OrtResultTest : WordSpec({ val ortResult = OrtResult.EMPTY.copy( repository = Repository.EMPTY.copy( - vcs = vcs, - vcsProcessed = vcs, + provenance = RepositoryProvenance( + vcsInfo = vcs, + resolvedRevision = vcs.revision + ), config = RepositoryConfiguration( excludes = Excludes( paths = listOf( diff --git a/model/src/testFixtures/kotlin/TestData.kt b/model/src/testFixtures/kotlin/TestData.kt index e1f6922424a96..c347a87730324 100644 --- a/model/src/testFixtures/kotlin/TestData.kt +++ b/model/src/testFixtures/kotlin/TestData.kt @@ -136,7 +136,7 @@ val scanResults = listOf( val ortResult = OrtResult( repository = Repository( - vcs = VcsInfo.EMPTY, + provenance = Repository.EMPTY.provenance, config = RepositoryConfiguration( excludes = Excludes( paths = listOf( diff --git a/plugins/reporters/ctrlx/src/funTest/kotlin/CtrlXAutomationReporterFunTest.kt b/plugins/reporters/ctrlx/src/funTest/kotlin/CtrlXAutomationReporterFunTest.kt index ed1efef626c99..a5fd0618e82ec 100644 --- a/plugins/reporters/ctrlx/src/funTest/kotlin/CtrlXAutomationReporterFunTest.kt +++ b/plugins/reporters/ctrlx/src/funTest/kotlin/CtrlXAutomationReporterFunTest.kt @@ -42,6 +42,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.RootDependencyIndex import org.ossreviewtoolkit.model.Scope import org.ossreviewtoolkit.model.VcsInfo @@ -165,8 +166,10 @@ private fun createReporterInput(): ReporterInput { return ReporterInput( OrtResult( repository = Repository( - vcs = analyzedVcs, - vcsProcessed = analyzedVcs + provenance = RepositoryProvenance( + vcsInfo = analyzedVcs, + resolvedRevision = analyzedVcs.revision + ) ), analyzer = AnalyzerRun.EMPTY.copy( result = AnalyzerResult( diff --git a/plugins/reporters/cyclonedx/src/main/kotlin/CycloneDxReporter.kt b/plugins/reporters/cyclonedx/src/main/kotlin/CycloneDxReporter.kt index b62a0cc07e71b..477c7a895d476 100644 --- a/plugins/reporters/cyclonedx/src/main/kotlin/CycloneDxReporter.kt +++ b/plugins/reporters/cyclonedx/src/main/kotlin/CycloneDxReporter.kt @@ -154,7 +154,7 @@ class CycloneDxReporter( // There is no component type for repositories. type = Component.Type.FILE - with(input.ortResult.repository.vcsProcessed) { + with(input.ortResult.repository.provenance.vcsInfo) { bomRef = "$url@$revision" name = url @@ -178,7 +178,7 @@ class CycloneDxReporter( // 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.provenance.vcsInfo bom.addExternalReference( ExternalReference.Type.VCS, vcs.url, diff --git a/plugins/reporters/evaluated-model/src/funTest/resources/evaluated-model-reporter-test-deduplicate-expected-output.yml b/plugins/reporters/evaluated-model/src/funTest/resources/evaluated-model-reporter-test-deduplicate-expected-output.yml index 32f1672d38deb..4b912feb13324 100644 --- a/plugins/reporters/evaluated-model/src/funTest/resources/evaluated-model-reporter-test-deduplicate-expected-output.yml +++ b/plugins/reporters/evaluated-model/src/funTest/resources/evaluated-model-reporter-test-deduplicate-expected-output.yml @@ -1166,16 +1166,13 @@ 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" + 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: "3dcca3e6ee0dea120922f90495bf04b4e09ae455" nested_repositories: sub/module: type: "Git" diff --git a/plugins/reporters/evaluated-model/src/funTest/resources/evaluated-model-reporter-test-expected-output.json b/plugins/reporters/evaluated-model/src/funTest/resources/evaluated-model-reporter-test-expected-output.json index 56e4e607635be..5ae1c997bb667 100644 --- a/plugins/reporters/evaluated-model/src/funTest/resources/evaluated-model-reporter-test-expected-output.json +++ b/plugins/reporters/evaluated-model/src/funTest/resources/evaluated-model-reporter-test-expected-output.json @@ -1261,17 +1261,14 @@ "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" : "3dcca3e6ee0dea120922f90495bf04b4e09ae455" }, "nested_repositories" : { "sub/module" : { diff --git a/plugins/reporters/evaluated-model/src/funTest/resources/evaluated-model-reporter-test-expected-output.yml b/plugins/reporters/evaluated-model/src/funTest/resources/evaluated-model-reporter-test-expected-output.yml index 32f1672d38deb..4b912feb13324 100644 --- a/plugins/reporters/evaluated-model/src/funTest/resources/evaluated-model-reporter-test-expected-output.yml +++ b/plugins/reporters/evaluated-model/src/funTest/resources/evaluated-model-reporter-test-expected-output.yml @@ -1166,16 +1166,13 @@ 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" + 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: "3dcca3e6ee0dea120922f90495bf04b4e09ae455" nested_repositories: sub/module: type: "Git" diff --git a/plugins/reporters/fossid/src/test/kotlin/FossIdReporterTest.kt b/plugins/reporters/fossid/src/test/kotlin/FossIdReporterTest.kt index b69e14e0d627f..f42f12f7563b2 100644 --- a/plugins/reporters/fossid/src/test/kotlin/FossIdReporterTest.kt +++ b/plugins/reporters/fossid/src/test/kotlin/FossIdReporterTest.kt @@ -42,6 +42,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 @@ -266,8 +267,10 @@ private fun createReporterInput(vararg scanCodes: String): ReporterInput { ) ) ), - vcs = analyzedVcs, - vcsProcessed = analyzedVcs + provenance = RepositoryProvenance( + vcsInfo = analyzedVcs, + resolvedRevision = analyzedVcs.revision + ) ), 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 38f706c484a67..ec9f4e4197aaf 100644 --- a/plugins/reporters/freemarker/src/test/kotlin/FreeMarkerTemplateProcessorTest.kt +++ b/plugins/reporters/freemarker/src/test/kotlin/FreeMarkerTemplateProcessorTest.kt @@ -97,6 +97,10 @@ private val PROJECT_ROOT_VCS_INFO = VcsInfo( private val PROJECT_SUB_VCS_INFO = PROJECT_ROOT_VCS_INFO.copy( path = "sub-dir" ) +private val PROJECT_PROVENANCE = RepositoryProvenance( + vcsInfo = PROJECT_ROOT_VCS_INFO, + resolvedRevision = PROJECT_ROOT_VCS_INFO.revision +) private val NESTED_VCS_INFO = VcsInfo( type = VcsType.GIT, url = "ssh://git@host/project/repo", @@ -110,7 +114,7 @@ private val idNestedProject = Identifier("SpdxDocumentFile:@ort:project-in-neste private val ORT_RESULT = OrtResult( repository = Repository( - vcs = PROJECT_ROOT_VCS_INFO, + provenance = PROJECT_PROVENANCE, config = RepositoryConfiguration(), nestedRepositories = mapOf("nested-vcs-dir" to NESTED_VCS_INFO) ), diff --git a/plugins/reporters/opossum/src/main/kotlin/OpossumReporter.kt b/plugins/reporters/opossum/src/main/kotlin/OpossumReporter.kt index 903daaf22c1c8..ce06ad6fe16cb 100644 --- a/plugins/reporters/opossum/src/main/kotlin/OpossumReporter.kt +++ b/plugins/reporters/opossum/src/main/kotlin/OpossumReporter.kt @@ -127,7 +127,7 @@ class OpossumReporter( private val externalAttributionSources: MutableMap = mutableMapOf() internal fun create(input: ReporterInput, maxDepth: Int = Int.MAX_VALUE): OpossumInput { - addBaseUrl("/", input.ortResult.repository.vcs) + addBaseUrl("/", input.ortResult.repository.provenance.vcsInfo) SpdxLicense.entries.forEach { val licenseText = input.licenseFactProvider.getLicenseText(it.id)?.text diff --git a/plugins/reporters/opossum/src/test/kotlin/OpossumReporterTest.kt b/plugins/reporters/opossum/src/test/kotlin/OpossumReporterTest.kt index 025df80de6712..8f526430e2ee2 100644 --- a/plugins/reporters/opossum/src/test/kotlin/OpossumReporterTest.kt +++ b/plugins/reporters/opossum/src/test/kotlin/OpossumReporterTest.kt @@ -244,8 +244,10 @@ private fun createOrtResult(): OrtResult { return OrtResult( repository = Repository( - vcs = analyzedVcs, - vcsProcessed = analyzedVcs + provenance = RepositoryProvenance( + vcsInfo = analyzedVcs, + resolvedRevision = analyzedVcs.revision + ) ), analyzer = AnalyzerRun.EMPTY.copy( config = AnalyzerConfiguration(allowDynamicVersions = true), diff --git a/plugins/reporters/spdx/src/testFixtures/kotlin/TestData.kt b/plugins/reporters/spdx/src/testFixtures/kotlin/TestData.kt index fcf3e2d830da2..741ddea3fd695 100644 --- a/plugins/reporters/spdx/src/testFixtures/kotlin/TestData.kt +++ b/plugins/reporters/spdx/src/testFixtures/kotlin/TestData.kt @@ -53,6 +53,11 @@ private val ANALYZED_VCS = VcsInfo( url = "https://github.com/path/proj1-repo.git" ) +private val ANALYZED_PROVENANCE = RepositoryProvenance( + vcsInfo = ANALYZED_VCS, + resolvedRevision = ANALYZED_VCS.revision +) + val ORT_RESULT = OrtResult( repository = Repository( config = RepositoryConfiguration( @@ -66,8 +71,7 @@ val ORT_RESULT = OrtResult( ) ) ), - vcs = ANALYZED_VCS, - vcsProcessed = ANALYZED_VCS + provenance = ANALYZED_PROVENANCE ), analyzer = AnalyzerRun.EMPTY.copy( result = AnalyzerResult( diff --git a/plugins/reporters/static-html/src/main/kotlin/TablesReportModelMapper.kt b/plugins/reporters/static-html/src/main/kotlin/TablesReportModelMapper.kt index abab130df40db..79b566085dae2 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.provenance.vcsInfo, input.ortResult.repository.config, ruleViolations, getAnalyzerIssueSummaryTable(input), diff --git a/reporter/src/testFixtures/kotlin/TestData.kt b/reporter/src/testFixtures/kotlin/TestData.kt index 751a96956af69..310f277d82880 100644 --- a/reporter/src/testFixtures/kotlin/TestData.kt +++ b/reporter/src/testFixtures/kotlin/TestData.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.ScanResult import org.ossreviewtoolkit.model.ScanSummary import org.ossreviewtoolkit.model.ScannerDetails @@ -66,10 +67,13 @@ 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( - type = VcsType.GIT, - url = "https://github.com/oss-review-toolkit/ort.git", - revision = "main" + provenance = RepositoryProvenance( + vcsInfo = VcsInfo( + type = VcsType.GIT, + url = "https://github.com/oss-review-toolkit/ort.git", + revision = "main" + ), + resolvedRevision = "main" ), config = RepositoryConfiguration( excludes = Excludes( diff --git a/scanner/src/funTest/kotlin/scanners/ScannerIntegrationFunTest.kt b/scanner/src/funTest/kotlin/scanners/ScannerIntegrationFunTest.kt index 526d89bba554e..8d029ade0cfac 100644 --- a/scanner/src/funTest/kotlin/scanners/ScannerIntegrationFunTest.kt +++ b/scanner/src/funTest/kotlin/scanners/ScannerIntegrationFunTest.kt @@ -28,6 +28,7 @@ import java.io.File import org.ossreviewtoolkit.downloader.DefaultWorkingTreeCache import org.ossreviewtoolkit.model.AnalyzerResult import org.ossreviewtoolkit.model.AnalyzerRun +import org.ossreviewtoolkit.model.HashAlgorithm import org.ossreviewtoolkit.model.Identifier import org.ossreviewtoolkit.model.LicenseFinding import org.ossreviewtoolkit.model.OrtResult @@ -36,6 +37,7 @@ import org.ossreviewtoolkit.model.PackageReference import org.ossreviewtoolkit.model.PackageType import org.ossreviewtoolkit.model.Project import org.ossreviewtoolkit.model.Repository +import org.ossreviewtoolkit.model.RepositoryProvenance import org.ossreviewtoolkit.model.ScanSummary import org.ossreviewtoolkit.model.Scope import org.ossreviewtoolkit.model.TextLocation @@ -164,11 +166,15 @@ private fun createAnalyzerResultWithProject(project: Project, vararg packages: P config = AnalyzerConfiguration(enabledPackageManagers = emptyList()) ) + val resolvedRevision = projectWithScope.vcs.revision.ifEmpty { HashAlgorithm.SHA1.emptyValue } + return OrtResult.EMPTY.copy( analyzer = analyzerRun, repository = Repository.EMPTY.copy( - vcsProcessed = projectWithScope.vcsProcessed, - vcs = projectWithScope.vcs + provenance = RepositoryProvenance( + vcsInfo = projectWithScope.vcs, + resolvedRevision = resolvedRevision + ) ) ) } diff --git a/scanner/src/funTest/resources/scanner-integration-all-pkgs-expected-ort-result.yml b/scanner/src/funTest/resources/scanner-integration-all-pkgs-expected-ort-result.yml index 07a38a800a5a7..df5fa3508ebff 100644 --- a/scanner/src/funTest/resources/scanner-integration-all-pkgs-expected-ort-result.yml +++ b/scanner/src/funTest/resources/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: "da39a3ee5e6b4b0d3255bfef95601890afd80709" config: {} analyzer: start_time: "1970-01-01T00:00:00Z" diff --git a/scanner/src/funTest/resources/scanner-integration-subset-pkgs-expected-ort-result.yml b/scanner/src/funTest/resources/scanner-integration-subset-pkgs-expected-ort-result.yml index 3ca86ec7cfbd8..03dbd276fa8a6 100644 --- a/scanner/src/funTest/resources/scanner-integration-subset-pkgs-expected-ort-result.yml +++ b/scanner/src/funTest/resources/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: "da39a3ee5e6b4b0d3255bfef95601890afd80709" config: {} analyzer: start_time: "1970-01-01T00:00:00Z"