Skip to content

Commit 6d06fcc

Browse files
committed
feat(utils): Make provenance matchers optional
Signed-off-by: Nicolas Nobelis <[email protected]>
1 parent 02fb740 commit 6d06fcc

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

model/src/main/kotlin/config/PackageConfiguration.kt

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import org.ossreviewtoolkit.model.Project
2828
import org.ossreviewtoolkit.model.Provenance
2929
import org.ossreviewtoolkit.model.RepositoryProvenance
3030
import org.ossreviewtoolkit.model.SourceCodeOrigin
31-
import org.ossreviewtoolkit.model.UnknownProvenance
3231
import org.ossreviewtoolkit.model.VcsInfo
3332
import org.ossreviewtoolkit.model.VcsType
3433
import org.ossreviewtoolkit.utils.common.replaceCredentialsInUri
@@ -77,9 +76,9 @@ data class PackageConfiguration(
7776
) {
7877
init {
7978
require(
80-
listOfNotNull(sourceArtifactUrl, vcs, sourceCodeOrigin).size == 1
79+
listOfNotNull(sourceArtifactUrl, vcs, sourceCodeOrigin).size <= 1
8180
) {
82-
"A package configuration must set exactly one of 'sourceArtifactUrl', 'vcs' or 'sourceCodeOrigin'."
81+
"A package configuration must contain at most one of 'sourceArtifactUrl', 'vcs' or 'sourceCodeOrigin'."
8382
}
8483
}
8584

@@ -100,11 +99,15 @@ data class PackageConfiguration(
10099
}
101100
}
102101

103-
return when (provenance) {
104-
is UnknownProvenance -> false
105-
is ArtifactProvenance -> sourceArtifactUrl != null && sourceArtifactUrl == provenance.sourceArtifact.url
106-
is RepositoryProvenance -> vcs != null && vcs.matches(provenance)
102+
if (sourceArtifactUrl != null) {
103+
return provenance is ArtifactProvenance && sourceArtifactUrl == provenance.sourceArtifact.url
107104
}
105+
106+
if (vcs != null) {
107+
return provenance is RepositoryProvenance && vcs.matches(provenance)
108+
}
109+
110+
return true
108111
}
109112
}
110113

model/src/test/kotlin/config/PackageConfigurationTest.kt

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
package org.ossreviewtoolkit.model.config
2121

22-
import io.kotest.assertions.throwables.shouldThrow
2322
import io.kotest.core.spec.style.WordSpec
2423
import io.kotest.matchers.shouldBe
2524

@@ -215,10 +214,16 @@ class PackageConfigurationTest : WordSpec({
215214
) shouldBe false
216215
}
217216

218-
"fail if the package configuration has only an identifier" {
219-
shouldThrow<IllegalArgumentException> {
220-
PackageConfiguration(id = Identifier.EMPTY.copy(name = "some-name"))
221-
}
217+
"return true if the package configuration contains only the identifier and the latter matches" {
218+
val config = PackageConfiguration(id = Identifier.EMPTY.copy(name = "some-name"))
219+
220+
config.matches(
221+
config.id,
222+
RepositoryProvenance(
223+
vcsInfo = VcsInfo.EMPTY,
224+
resolvedRevision = "12345678"
225+
)
226+
) shouldBe true
222227
}
223228
}
224229
})

0 commit comments

Comments
 (0)