From f441abbb9fe9e2c53a0d02665199e0843a87d5e8 Mon Sep 17 00:00:00 2001 From: Jens Keim Date: Tue, 18 Jun 2024 16:29:07 +0200 Subject: [PATCH] refactor(Provenance): Allow blank `resolvedRevision` for `VcsInfo.EMPTY` This will allow tests using `Repository` objects using `VcsInfo.EMPTY` to continue to function, even though `RepositoryProvenance` does not usually allow blank revisions. By restricting the exception to `VcsInfo.EMPTY` any other bahaviour of `RepositoryProvenance` should be retained. Some unrelated `OrtResultTest`s had to be given non-blank revisions: Both `fail if no vcs matches` and `use the correct vcs` don't hinge on the given blank revision, so to assure they do not fail for unrelated reasons, we just add the default git revision "main" to these example repos. Signed-off-by: Jens Keim --- model/src/main/kotlin/Provenance.kt | 4 +++- model/src/test/kotlin/OrtResultTest.kt | 12 ++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/model/src/main/kotlin/Provenance.kt b/model/src/main/kotlin/Provenance.kt index 983a9558f964c..2ea6acafff79c 100644 --- a/model/src/main/kotlin/Provenance.kt +++ b/model/src/main/kotlin/Provenance.kt @@ -80,7 +80,9 @@ data class RepositoryProvenance( val resolvedRevision: String ) : KnownProvenance { init { - require(resolvedRevision.isNotBlank()) { "The resolved revision must not be blank." } + require(vcsInfo == VcsInfo.EMPTY || resolvedRevision.isNotBlank()) { + "The resolved revision must not be blank." + } } /** diff --git a/model/src/test/kotlin/OrtResultTest.kt b/model/src/test/kotlin/OrtResultTest.kt index c5065a38cd65a..a514d4e351908 100644 --- a/model/src/test/kotlin/OrtResultTest.kt +++ b/model/src/test/kotlin/OrtResultTest.kt @@ -83,9 +83,9 @@ class OrtResultTest : WordSpec({ "getDefinitionFilePathRelativeToAnalyzerRoot()" should { "use the correct vcs" { - val vcs = VcsInfo(type = VcsType.GIT, url = "https://example.com/git", 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 vcs = VcsInfo(type = VcsType.GIT, url = "https://example.com/git", revision = "main") + val nestedVcs1 = VcsInfo(type = VcsType.GIT, url = "https://example.com/git1", revision = "main") + val nestedVcs2 = VcsInfo(type = VcsType.GIT, url = "https://example.com/git2", revision = "main") val project1 = Project.EMPTY.copy( id = Identifier("Gradle:org.ossreviewtoolkit:project1:1.0"), definitionFilePath = "project1/build.gradle", @@ -123,9 +123,9 @@ class OrtResultTest : WordSpec({ } "fail if no vcs matches" { - val vcs = VcsInfo(type = VcsType.GIT, url = "https://example.com/git", 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 vcs = VcsInfo(type = VcsType.GIT, url = "https://example.com/git", revision = "main") + val nestedVcs1 = VcsInfo(type = VcsType.GIT, url = "https://example.com/git1", revision = "main") + val nestedVcs2 = VcsInfo(type = VcsType.GIT, url = "https://example.com/git2", revision = "main") val project = Project.EMPTY.copy( id = Identifier("Gradle:org.ossreviewtoolkit:project1:1.0"), definitionFilePath = "build.gradle",