Skip to content

Commit

Permalink
feat(Repository): Use KnownProvenance instead of VcsInfo
Browse files Browse the repository at this point in the history
In order to allow source artifacts as well as local source code to
be scanned, a more generalized `Repository` class is required, which
allows any type of `KnownProvenance`. While the signature of the
`Repository` class is set to allow any `KnownProvenance` object,
this commit focuses on accommodating `RepositoryProvenance` as the
main input for now.

Therefore `VcsInfo` is wrapped within `RepositoryProvenance`, whenever
it is used as input, and unwraped, when it is produced as output.
This results in a faster update of the now deprecated code, without
the necessity to support all `KnownProvenance` types from the get go.

Any related tests are also updated, mostly the expected `OrtResults`,
but also some `Repository` definitions and calls.

To avoid having `vcs` and `vcsProcessed` appear in the `OrtResult`
output, getter properties were created and marked as `@JsonIgnore`.

Signed-off-by: Jens Keim <jens.keim@forvia.com>
  • Loading branch information
pepper-jk committed Jul 1, 2024
1 parent 7969f0b commit ba2a2a2
Show file tree
Hide file tree
Showing 40 changed files with 261 additions and 319 deletions.
8 changes: 7 additions & 1 deletion analyzer/src/main/kotlin/Analyzer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -135,11 +136,16 @@ 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,
config = info.repositoryConfiguration
)

val endTime = Instant.now()

Expand Down
17 changes: 7 additions & 10 deletions cli/src/funTest/assets/git-repo-expected-output.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
---
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"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
---
repository:
vcs:
type: "Git"
url: "<REPLACE_URL>"
revision: "<REPLACE_REVISION>"
path: "plugins/package-managers/gradle/src/funTest/assets/projects/synthetic/gradle"
vcs_processed:
type: "Git"
url: "<REPLACE_URL_PROCESSED>"
revision: "<REPLACE_REVISION>"
path: "plugins/package-managers/gradle/src/funTest/assets/projects/synthetic/gradle"
provenance:
vcs_info:
type: "Git"
url: "<REPLACE_URL>"
revision: "<REPLACE_REVISION>"
path: "plugins/package-managers/gradle/src/funTest/assets/projects/synthetic/gradle"
resolved_revision: "<REPLACE_REVISION>"
config:
excludes:
paths:
Expand Down
17 changes: 7 additions & 10 deletions cli/src/funTest/assets/semver4j-ort-result.yml
Original file line number Diff line number Diff line change
@@ -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:
excludes:
scopes:
Expand Down
2 changes: 1 addition & 1 deletion evaluator/src/test/kotlin/ProjectSourceRuleTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,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(
Expand Down
3 changes: 2 additions & 1 deletion evaluator/src/test/kotlin/TestData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
32 changes: 21 additions & 11 deletions model/src/main/kotlin/Repository.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package org.ossreviewtoolkit.model

import com.fasterxml.jackson.annotation.JsonIgnore
import com.fasterxml.jackson.annotation.JsonInclude

import org.ossreviewtoolkit.model.config.RepositoryConfiguration
Expand All @@ -31,13 +32,7 @@ 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
Expand All @@ -57,18 +52,33 @@ data class Repository(
*/
@JvmField
val EMPTY = Repository(
vcs = VcsInfo.EMPTY,
vcsProcessed = VcsInfo.EMPTY,
provenance = RepositoryProvenance(VcsInfo.EMPTY, ""),
nestedRepositories = emptyMap(),
config = RepositoryConfiguration()
)
}

@JsonIgnore
val vcs = if (provenance is RepositoryProvenance) {
provenance.vcsInfo
} else {
VcsInfo.EMPTY
}

@JsonIgnore
val vcsProcessed = if (provenance is RepositoryProvenance) {
provenance.vcsInfo.normalize()
} else {
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 [vcs] relative to [Repository.provenance], or null if [vcs] is neither
* [Repository.provenance] nor contained in [nestedRepositories].
*/
fun getRelativePath(vcs: VcsInfo): String? {
if (this.provenance !is RepositoryProvenance) return null

val normalizedVcs = vcs.normalize()

if (vcsProcessed.equalsDisregardingPath(normalizedVcs)) return ""
Expand Down
17 changes: 7 additions & 10 deletions model/src/test/assets/analyzer-result-with-dependency-graph.yml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
17 changes: 7 additions & 10 deletions model/src/test/assets/gradle-all-dependencies-expected-result.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
17 changes: 7 additions & 10 deletions model/src/test/assets/result-with-issues-graph-old.yml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
17 changes: 7 additions & 10 deletions model/src/test/assets/result-with-issues-graph.yml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
17 changes: 7 additions & 10 deletions model/src/test/assets/result-with-issues-scopes.yml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
17 changes: 7 additions & 10 deletions model/src/test/assets/sbt-multi-project-example-graph-old.yml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
Loading

0 comments on commit ba2a2a2

Please sign in to comment.