Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

RepositoryProvenance: Remove the originalVcsInfo property #3927

Merged
merged 7 commits into from
May 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions cli/src/funTest/assets/semver4j-analyzer-result.yml
Original file line number Diff line number Diff line change
Expand Up @@ -198,11 +198,6 @@ scanner:
revision: "7653e418d610ffcd2811bcb55fd72d00d420950b"
resolved_revision: "7653e418d610ffcd2811bcb55fd72d00d420950b"
path: ""
original_vcs_info:
type: "Git"
url: "https://github.com/vdurmont/semver4j.git"
revision: "7653e418d610ffcd2811bcb55fd72d00d420950b"
path: ""
scanner:
name: "ScanCode"
version: "3.2.1-rc2"
Expand Down Expand Up @@ -249,11 +244,6 @@ scanner:
revision: "r4.12"
resolved_revision: "64155f8a9babcfcf4263cf4d08253a1556e75481"
path: ""
original_vcs_info:
type: "Git"
url: "https://github.com/junit-team/junit.git"
revision: "r4.12"
path: ""
scanner:
name: "ScanCode"
version: "3.2.1-rc2"
Expand Down
2 changes: 1 addition & 1 deletion downloader/src/funTest/kotlin/BeanUtilsFunTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class BeanUtilsFunTest : StringSpec() {
provenance.shouldBeTypeOf<RepositoryProvenance>().apply {
vcsInfo.type shouldBe VcsType.SUBVERSION
vcsInfo.url shouldBe vcsFromCuration.url
vcsInfo.revision shouldBe "928490"
vcsInfo.revision shouldBe ""
fviernau marked this conversation as resolved.
Show resolved Hide resolved
vcsInfo.resolvedRevision shouldBe "928490"
vcsInfo.path shouldBe vcsFromCuration.path
}
Expand Down
12 changes: 7 additions & 5 deletions downloader/src/main/kotlin/Downloader.kt
Original file line number Diff line number Diff line change
Expand Up @@ -262,19 +262,21 @@ class Downloader(private val config: DownloaderConfiguration) {
throw e
}
}
val revision = workingTree.getRevision()
val resolvedRevision = workingTree.getRevision()

log.info { "Finished downloading source code revision '$revision' to '${outputDirectory.absolutePath}'." }
log.info {
"Finished downloading source code revision '$resolvedRevision' to '${outputDirectory.absolutePath}'."
}

val vcsInfo = VcsInfo(
type = applicableVcs.type,
url = pkg.vcsProcessed.url,
revision = pkg.vcsProcessed.revision.takeIf { it.isNotBlank() } ?: revision,
resolvedRevision = revision,
revision = pkg.vcsProcessed.revision,
resolvedRevision = resolvedRevision,
path = pkg.vcsProcessed.path
)

return RepositoryProvenance(vcsInfo, pkg.vcsProcessed.takeIf { it != vcsInfo })
return RepositoryProvenance(vcsInfo)
fviernau marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Expand Down
24 changes: 7 additions & 17 deletions model/src/main/kotlin/Provenance.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

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
Expand Down Expand Up @@ -63,26 +62,15 @@ data class RepositoryProvenance(
/**
* The VCS repository that was downloaded.
*/
val vcsInfo: VcsInfo,

/**
* The original [VcsInfo] that was used to download the source code. It can be different to [vcsInfo] if any
* automatic detection took place. For example if the original [VcsInfo] does not contain any revision and the
* revision was automatically detected by searching for a tag that matches the version of the package there
* would be no way to match the package to the [Provenance] without downloading the source code and searching
* for the tag again.
*/
@JsonInclude(JsonInclude.Include.NON_NULL)
val originalVcsInfo: VcsInfo? = null
val vcsInfo: VcsInfo
) : KnownProvenance() {
override fun matches(pkg: Package): Boolean {
// If no VCS information is present either, or it does not have a resolved revision, there is no way of
// verifying matching provenance.
if (vcsInfo.resolvedRevision == null) return false

// If pkg.vcsProcessed equals originalVcsInfo or vcsInfo this provenance was definitely created when
// downloading this package.
if (pkg.vcsProcessed == originalVcsInfo || pkg.vcsProcessed == vcsInfo) return true
// This provenance was definitely created when downloading this package.
if (pkg.vcsProcessed.equalsIgnoreResolvedRevision(vcsInfo)) return true

return listOf(pkg.vcs, pkg.vcsProcessed).any {
if (it.resolvedRevision != null) {
Expand All @@ -107,10 +95,12 @@ private class ProvenanceDeserializer : StdDeserializer<Provenance>(Provenance::c
}
node.has("vcs_info") -> {
val vcsInfo = jsonMapper.treeToValue<VcsInfo>(node["vcs_info"])!!
val originalVcsInfo = node["original_vcs_info"]?.let { jsonMapper.treeToValue<VcsInfo>(it)!! }
RepositoryProvenance(vcsInfo, originalVcsInfo)
RepositoryProvenance(vcsInfo)
}
else -> UnknownProvenance
}
}
}

private fun VcsInfo.equalsIgnoreResolvedRevision(other: VcsInfo): Boolean =
copy(resolvedRevision = "") == other.copy(resolvedRevision = "")
26 changes: 10 additions & 16 deletions model/src/main/kotlin/ScanResult.kt
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,16 @@ data class ScanResult(
* Filter all detected licenses and copyrights from the [summary] which are underneath [path], and set the [path]
* for [provenance]. Findings which [RootLicenseMatcher] assigns as root license files for [path] are also kept.
*/
fun filterByPath(path: String): ScanResult {
if (path.isBlank()) return this

val summary = summary.filterByPath(path)

return if (provenance is RepositoryProvenance) {
val vcsProvenance = provenance.copy(
vcsInfo = provenance.vcsInfo.copy(path = path),
originalVcsInfo = provenance.originalVcsInfo?.copy(path = path)
)

ScanResult(vcsProvenance, scanner, summary)
} else {
ScanResult(provenance, scanner, summary)
}
}
fun filterByPath(path: String): ScanResult =
takeIf { path.isBlank() } ?: ScanResult(
provenance = if (provenance is RepositoryProvenance) {
provenance.copy(vcsInfo = provenance.vcsInfo.copy(path = path))
} else {
provenance
},
scanner = scanner,
summary = summary.filterByPath(path),
)

/**
* Return a [ScanResult] whose [summary] contains only findings from the [provenance]'s [VcsInfo.path].
Expand Down
15 changes: 0 additions & 15 deletions model/src/test/assets/advisor-result-initial.yml
Original file line number Diff line number Diff line change
Expand Up @@ -240,11 +240,6 @@ scanner:
revision: "7653e418d610ffcd2811bcb55fd72d00d420950b"
resolved_revision: "7653e418d610ffcd2811bcb55fd72d00d420950b"
path: ""
original_vcs_info:
type: "Git"
url: "https://github.com/vdurmont/semver4j.git"
revision: "7653e418d610ffcd2811bcb55fd72d00d420950b"
path: ""
scanner:
name: "ScanCode"
version: "3.2.1-rc2"
Expand Down Expand Up @@ -290,11 +285,6 @@ scanner:
revision: "r4.12"
resolved_revision: "64155f8a9babcfcf4263cf4d08253a1556e75481"
path: ""
original_vcs_info:
type: "Git"
url: "https://github.com/junit-team/junit4.git"
revision: "r4.12"
path: ""
scanner:
name: "ScanCode"
version: "3.2.1-rc2"
Expand Down Expand Up @@ -365,11 +355,6 @@ scanner:
revision: "36d525e1e425006939a77aec5183aecd7c775b05"
resolved_revision: "36d525e1e425006939a77aec5183aecd7c775b05"
path: ""
original_vcs_info:
type: "Git"
url: "ssh://git@github.com/hamcrest/JavaHamcrest.git"
revision: ""
path: ""
scanner:
name: "ScanCode"
version: "3.2.1-rc2"
Expand Down
15 changes: 0 additions & 15 deletions model/src/test/assets/advisor-result-vulnerability-refs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -274,11 +274,6 @@ scanner:
revision: "7653e418d610ffcd2811bcb55fd72d00d420950b"
resolved_revision: "7653e418d610ffcd2811bcb55fd72d00d420950b"
path: ""
original_vcs_info:
type: "Git"
url: "https://github.com/vdurmont/semver4j.git"
revision: "7653e418d610ffcd2811bcb55fd72d00d420950b"
path: ""
scanner:
name: "ScanCode"
version: "3.2.1-rc2"
Expand Down Expand Up @@ -324,11 +319,6 @@ scanner:
revision: "r4.12"
resolved_revision: "64155f8a9babcfcf4263cf4d08253a1556e75481"
path: ""
original_vcs_info:
type: "Git"
url: "https://github.com/junit-team/junit4.git"
revision: "r4.12"
path: ""
scanner:
name: "ScanCode"
version: "3.2.1-rc2"
Expand Down Expand Up @@ -399,11 +389,6 @@ scanner:
revision: "36d525e1e425006939a77aec5183aecd7c775b05"
resolved_revision: "36d525e1e425006939a77aec5183aecd7c775b05"
path: ""
original_vcs_info:
type: "Git"
url: "ssh://git@github.com/hamcrest/JavaHamcrest.git"
revision: ""
path: ""
scanner:
name: "ScanCode"
version: "3.2.1-rc2"
Expand Down
12 changes: 0 additions & 12 deletions model/src/test/kotlin/ProvenanceTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,6 @@ class ProvenanceTest : WordSpec({
revision = "revision",
resolvedRevision = "resolvedRevision",
path = "path"
),
originalVcsInfo = VcsInfo(
type = VcsType.UNKNOWN,
url = "originalUrl",
revision = "originalRevision",
path = "originalPath"
)
)

Expand All @@ -109,12 +103,6 @@ class ProvenanceTest : WordSpec({
"revision" : "revision",
"resolved_revision" : "resolvedRevision",
"path" : "path"
},
"original_vcs_info" : {
"type" : "",
"url" : "originalUrl",
"revision" : "originalRevision",
"path" : "originalPath"
}
}
""".trimIndent()
Expand Down
Loading