Skip to content

Commit

Permalink
refactor(scanner)!: Align provenance storages on write instead of `…
Browse files Browse the repository at this point in the history
…put`

Say `write` instead of `put` to match `read` functions and to align with
the `ScanStorage` interfaces.

Signed-off-by: Sebastian Schuberth <[email protected]>
  • Loading branch information
sschuberth committed Feb 21, 2024
1 parent 90083ca commit c06467d
Show file tree
Hide file tree
Showing 12 changed files with 35 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ abstract class AbstractNestedProvenanceStorageFunTest(vararg listeners: TestList
val root = createRepositoryProvenance()
val result = NestedProvenanceResolutionResult(createNestedProvenance(root), true)

storage.putNestedProvenance(root, result)
storage.writeNestedProvenance(root, result)

storage.readNestedProvenance(root) shouldBe result
}
Expand All @@ -57,8 +57,8 @@ abstract class AbstractNestedProvenanceStorageFunTest(vararg listeners: TestList
)
val result2 = NestedProvenanceResolutionResult(createNestedProvenance(root), true)

storage.putNestedProvenance(root, result1)
storage.putNestedProvenance(root, result2)
storage.writeNestedProvenance(root, result1)
storage.writeNestedProvenance(root, result2)

storage.readNestedProvenance(root) shouldBe result2
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ abstract class AbstractPackageProvenanceStorageFunTest(vararg listeners: TestLis
val sourceArtifact = createRemoteArtifact()
val result = ResolvedArtifactProvenance(createArtifactProvenance(sourceArtifact))

storage.putProvenance(id, sourceArtifact, result)
storage.writeProvenance(id, sourceArtifact, result)

storage.readProvenance(id, sourceArtifact) shouldBe result
}
Expand All @@ -62,7 +62,7 @@ abstract class AbstractPackageProvenanceStorageFunTest(vararg listeners: TestLis
val vcs = createVcsInfo()
val result = ResolvedRepositoryProvenance(createRepositoryProvenance(vcs), vcs.revision, true)

storage.putProvenance(id, vcs, result)
storage.writeProvenance(id, vcs, result)

storage.readProvenance(id, vcs) shouldBe result
}
Expand All @@ -72,7 +72,7 @@ abstract class AbstractPackageProvenanceStorageFunTest(vararg listeners: TestLis
val vcs = createVcsInfo()
val result = UnresolvedPackageProvenance("message")

storage.putProvenance(id, vcs, result)
storage.writeProvenance(id, vcs, result)

storage.readProvenance(id, vcs) shouldBe result
}
Expand All @@ -83,8 +83,8 @@ abstract class AbstractPackageProvenanceStorageFunTest(vararg listeners: TestLis
val result1 = UnresolvedPackageProvenance("message")
val result2 = ResolvedRepositoryProvenance(createRepositoryProvenance(vcs), vcs.revision, true)

storage.putProvenance(id, vcs, result1)
storage.putProvenance(id, vcs, result2)
storage.writeProvenance(id, vcs, result1)
storage.writeProvenance(id, vcs, result2)

storage.readProvenance(id, vcs) shouldBe result2
}
Expand All @@ -96,11 +96,11 @@ abstract class AbstractPackageProvenanceStorageFunTest(vararg listeners: TestLis

val sourceArtifact = createRemoteArtifact()
val artifactResult = ResolvedArtifactProvenance(createArtifactProvenance(sourceArtifact))
storage.putProvenance(id, sourceArtifact, artifactResult)
storage.writeProvenance(id, sourceArtifact, artifactResult)

val vcs = createVcsInfo()
val vcsResult = ResolvedRepositoryProvenance(createRepositoryProvenance(vcs), vcs.revision, true)
storage.putProvenance(id, vcs, vcsResult)
storage.writeProvenance(id, vcs, vcsResult)

storage.readProvenances(id) should containExactlyInAnyOrder(artifactResult, vcsResult)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ class DefaultNestedProvenanceResolverFunTest : WordSpec() {

internal class DummyNestedProvenanceStorage : NestedProvenanceStorage {
override fun readNestedProvenance(root: RepositoryProvenance): NestedProvenanceResolutionResult? = null
override fun putNestedProvenance(root: RepositoryProvenance, result: NestedProvenanceResolutionResult) {
override fun writeNestedProvenance(root: RepositoryProvenance, result: NestedProvenanceResolutionResult) {
/** no-op */
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,11 @@ internal class DummyProvenanceStorage : PackageProvenanceStorage {

override fun readProvenances(id: Identifier): List<PackageProvenanceResolutionResult> = emptyList()

override fun putProvenance(id: Identifier, vcs: VcsInfo, result: PackageProvenanceResolutionResult) { /* no-op */ }
override fun writeProvenance(id: Identifier, vcs: VcsInfo, result: PackageProvenanceResolutionResult) {
/* no-op */
}

override fun putProvenance(
override fun writeProvenance(
id: Identifier,
sourceArtifact: RemoteArtifact,
result: PackageProvenanceResolutionResult
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class FileBasedNestedProvenanceStorage(private val backend: FileStorage) : Neste
}
}

override fun putNestedProvenance(root: RepositoryProvenance, result: NestedProvenanceResolutionResult) {
override fun writeNestedProvenance(root: RepositoryProvenance, result: NestedProvenanceResolutionResult) {
val results = readResults(root).toMutableList()
results.removeAll { it.nestedProvenance.root == root }
results += result
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,16 @@ class FileBasedPackageProvenanceStorage(val backend: FileStorage) : PackageProve
}
}

override fun putProvenance(
override fun writeProvenance(
id: Identifier,
sourceArtifact: RemoteArtifact,
result: PackageProvenanceResolutionResult
) = putProvenance(id, sourceArtifact, null, result)
) = writeProvenance(id, sourceArtifact, null, result)

Check warning on line 78 in scanner/src/main/kotlin/provenance/FileBasedPackageProvenanceStorage.kt

View check run for this annotation

Codecov / codecov/patch

scanner/src/main/kotlin/provenance/FileBasedPackageProvenanceStorage.kt#L78

Added line #L78 was not covered by tests

override fun putProvenance(id: Identifier, vcs: VcsInfo, result: PackageProvenanceResolutionResult) =
putProvenance(id, null, vcs, result)
override fun writeProvenance(id: Identifier, vcs: VcsInfo, result: PackageProvenanceResolutionResult) =
writeProvenance(id, null, vcs, result)

Check warning on line 81 in scanner/src/main/kotlin/provenance/FileBasedPackageProvenanceStorage.kt

View check run for this annotation

Codecov / codecov/patch

scanner/src/main/kotlin/provenance/FileBasedPackageProvenanceStorage.kt#L81

Added line #L81 was not covered by tests

private fun putProvenance(
private fun writeProvenance(
id: Identifier,
sourceArtifact: RemoteArtifact?,
vcs: VcsInfo?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class DefaultNestedProvenanceResolver(
// TODO: Find a way to figure out if the nested repository is configured with a fixed revision to
// correctly set `hasOnlyFixedRevisions`. For now always assume that they are fixed because that
// should be correct for most cases and otherwise the storage would have no effect.
storage.putNestedProvenance(
storage.writeNestedProvenance(

Check warning on line 96 in scanner/src/main/kotlin/provenance/NestedProvenanceResolver.kt

View check run for this annotation

Codecov / codecov/patch

scanner/src/main/kotlin/provenance/NestedProvenanceResolver.kt#L96

Added line #L96 was not covered by tests
provenance,
NestedProvenanceResolutionResult(nestedProvenance, hasOnlyFixedRevisions = true)
)
Expand Down
6 changes: 3 additions & 3 deletions scanner/src/main/kotlin/provenance/NestedProvenanceStorage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ interface NestedProvenanceStorage {
fun readNestedProvenance(root: RepositoryProvenance): NestedProvenanceResolutionResult?

/**
* Put the resolution [result] for the [root] provenance into the storage. If the storage already contains an entry
* for [root] it is overwritten.
* Write the resolution [result] for the [root] provenance into the storage. If the storage already contains an
* entry for [root] it is overwritten.
*/
fun putNestedProvenance(root: RepositoryProvenance, result: NestedProvenanceResolutionResult)
fun writeNestedProvenance(root: RepositoryProvenance, result: NestedProvenanceResolutionResult)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ class DefaultPackageProvenanceResolver(

if (responseCode == HttpURLConnection.HTTP_OK) {
val artifactProvenance = ArtifactProvenance(pkg.sourceArtifact)
storage.putProvenance(pkg.id, pkg.sourceArtifact, ResolvedArtifactProvenance(artifactProvenance))
storage.writeProvenance(pkg.id, pkg.sourceArtifact, ResolvedArtifactProvenance(artifactProvenance))

Check warning on line 145 in scanner/src/main/kotlin/provenance/PackageProvenanceResolver.kt

View check run for this annotation

Codecov / codecov/patch

scanner/src/main/kotlin/provenance/PackageProvenanceResolver.kt#L145

Added line #L145 was not covered by tests
return artifactProvenance
}

Expand Down Expand Up @@ -252,7 +252,7 @@ class DefaultPackageProvenanceResolver(
val repositoryProvenance = RepositoryProvenance(pkg.vcsProcessed, workingTree.getRevision())

vcs.isFixedRevision(workingTree, revision).onSuccess { isFixedRevision ->
storage.putProvenance(
storage.writeProvenance(

Check warning on line 255 in scanner/src/main/kotlin/provenance/PackageProvenanceResolver.kt

View check run for this annotation

Codecov / codecov/patch

scanner/src/main/kotlin/provenance/PackageProvenanceResolver.kt#L255

Added line #L255 was not covered by tests
pkg.id,
pkg.vcsProcessed,
ResolvedRepositoryProvenance(repositoryProvenance, revision, isFixedRevision)
Expand All @@ -265,7 +265,7 @@ class DefaultPackageProvenanceResolver(
val message = "Could not resolve revision for package '${pkg.id.toCoordinates()}' with " +
"${pkg.vcsProcessed}:\n${messages.joinToString("\n") { "\t$it" }}"

storage.putProvenance(pkg.id, pkg.vcsProcessed, UnresolvedPackageProvenance(message))
storage.writeProvenance(pkg.id, pkg.vcsProcessed, UnresolvedPackageProvenance(message))

Check warning on line 268 in scanner/src/main/kotlin/provenance/PackageProvenanceResolver.kt

View check run for this annotation

Codecov / codecov/patch

scanner/src/main/kotlin/provenance/PackageProvenanceResolver.kt#L268

Added line #L268 was not covered by tests

throw IOException(message)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,16 @@ interface PackageProvenanceStorage {
fun readProvenances(id: Identifier): List<PackageProvenanceResolutionResult>

/**
* Put the resolution [result] for the [id] and [sourceArtifact] into the storage. If the storage already contains
* Write the resolution [result] for the [id] and [sourceArtifact] into the storage. If the storage already contains
* an entry for [id] and [sourceArtifact] it is overwritten.
*/
fun putProvenance(id: Identifier, sourceArtifact: RemoteArtifact, result: PackageProvenanceResolutionResult)
fun writeProvenance(id: Identifier, sourceArtifact: RemoteArtifact, result: PackageProvenanceResolutionResult)

/**
* Put the resolution [result] for the [id] and [vcs] into the storage. If the storage already contains an entry
* Write the resolution [result] for the [id] and [vcs] into the storage. If the storage already contains an entry
* for [id] and [vcs] it is overwritten.
*/
fun putProvenance(id: Identifier, vcs: VcsInfo, result: PackageProvenanceResolutionResult)
fun writeProvenance(id: Identifier, vcs: VcsInfo, result: PackageProvenanceResolutionResult)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class PostgresNestedProvenanceStorage(
}.map { it[table.result] }.find { it.nestedProvenance.root == root }
}

override fun putNestedProvenance(root: RepositoryProvenance, result: NestedProvenanceResolutionResult) {
override fun writeNestedProvenance(root: RepositoryProvenance, result: NestedProvenanceResolutionResult) {
database.transaction {
val idsToRemove = table.selectAll().where {
table.vcsType eq root.vcsInfo.type.toString() and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class PostgresPackageProvenanceStorage(
}.map { it[table.result] }
}

override fun putProvenance(
override fun writeProvenance(
id: Identifier,
sourceArtifact: RemoteArtifact,
result: PackageProvenanceResolutionResult
Expand All @@ -114,7 +114,7 @@ class PostgresPackageProvenanceStorage(
}
}

override fun putProvenance(id: Identifier, vcs: VcsInfo, result: PackageProvenanceResolutionResult) {
override fun writeProvenance(id: Identifier, vcs: VcsInfo, result: PackageProvenanceResolutionResult) {
database.transaction {
table.deleteWhere {
table.identifier eq id.toCoordinates() and
Expand Down

0 comments on commit c06467d

Please sign in to comment.