From 9ece42c97e43ea8462a85b6fcab4d1eb8c61f353 Mon Sep 17 00:00:00 2001 From: Frank Viernau Date: Fri, 24 May 2024 18:03:20 +0200 Subject: [PATCH] refactor(model): Stop using `SortedSet` for `scopeRoots` Only sort on serialization for human readability and reproducibility. Also, remove the now unused comparator, which was used only by tests before. Signed-off-by: Frank Viernau --- analyzer/src/test/kotlin/AnalyzerResultBuilderTest.kt | 4 ++-- model/src/main/kotlin/DependencyGraph.kt | 11 ++--------- model/src/test/kotlin/DependencyGraphTest.kt | 10 +++++----- model/src/test/kotlin/ProjectTest.kt | 2 +- 4 files changed, 10 insertions(+), 17 deletions(-) diff --git a/analyzer/src/test/kotlin/AnalyzerResultBuilderTest.kt b/analyzer/src/test/kotlin/AnalyzerResultBuilderTest.kt index 4cda0e334d66d..7b2094b60c7a3 100644 --- a/analyzer/src/test/kotlin/AnalyzerResultBuilderTest.kt +++ b/analyzer/src/test/kotlin/AnalyzerResultBuilderTest.kt @@ -105,13 +105,13 @@ class AnalyzerResultBuilderTest : WordSpec() { private val graph1 = DependencyGraph( packages = dependencies1, - scopeRoots = sortedSetOf(DependencyGraph.DEPENDENCY_REFERENCE_COMPARATOR, depRef1, depRef2), + scopeRoots = setOf(depRef1, depRef2), scopes = scopeMapping1 ) private val graph2 = DependencyGraph( packages = dependencies2, - scopeRoots = sortedSetOf(DependencyGraph.DEPENDENCY_REFERENCE_COMPARATOR, depRef3), + scopeRoots = setOf(depRef3), scopes = scopeMapping2 ) diff --git a/model/src/main/kotlin/DependencyGraph.kt b/model/src/main/kotlin/DependencyGraph.kt index 2eec2456ca542..b073fa06ca3c5 100644 --- a/model/src/main/kotlin/DependencyGraph.kt +++ b/model/src/main/kotlin/DependencyGraph.kt @@ -23,8 +23,6 @@ import com.fasterxml.jackson.annotation.JsonIgnore import com.fasterxml.jackson.annotation.JsonInclude import com.fasterxml.jackson.databind.annotation.JsonSerialize -import java.util.SortedSet - import org.ossreviewtoolkit.model.utils.DependencyGraphEdgeSortedSetConverter import org.ossreviewtoolkit.model.utils.DependencyReferenceSortedSetConverter import org.ossreviewtoolkit.model.utils.PackageLinkageValueFilter @@ -86,7 +84,8 @@ data class DependencyGraph( * declared by scopes that cannot be reached via other paths in the dependency graph. Note that this property * exists for backwards compatibility only; it is replaced by the lists of nodes and edges. */ - val scopeRoots: SortedSet = sortedSetOf(), + @JsonSerialize(converter = DependencyReferenceSortedSetConverter::class) + val scopeRoots: Set = emptySet(), /** * A mapping from scope names to the direct dependencies of the scopes. Based on this information, the set of @@ -109,12 +108,6 @@ data class DependencyGraph( val edges: Set? = null ) { companion object { - /** - * A comparator for [DependencyReference] objects. Note that the concrete order does not really matter, it - * just has to be well-defined. - */ - val DEPENDENCY_REFERENCE_COMPARATOR = compareBy({ it.pkg }, { it.fragment }) - /** * Return a name for the given [scope][scopeName] that is qualified with parts of the identifier of the given * [project]. This is used to ensure that the scope names are unique when constructing a dependency graph from diff --git a/model/src/test/kotlin/DependencyGraphTest.kt b/model/src/test/kotlin/DependencyGraphTest.kt index 0144fbf67f5a1..030018cf7ec1e 100644 --- a/model/src/test/kotlin/DependencyGraphTest.kt +++ b/model/src/test/kotlin/DependencyGraphTest.kt @@ -35,7 +35,7 @@ class DependencyGraphTest : WordSpec({ id("org.apache.commons", "commons-collections4", "4.4"), id(group = "org.junit", artifact = "junit", version = "5") ) - val fragments = sortedSetOf( + val fragments = setOf( DependencyReference(0), DependencyReference(1), DependencyReference(2) @@ -62,7 +62,7 @@ class DependencyGraphTest : WordSpec({ id("org.apache.commons", "commons-collections4", "4.4"), id("org.junit", "junit", "5") ) - val fragments = sortedSetOf( + val fragments = setOf( DependencyReference(0), DependencyReference(1), DependencyReference(2) @@ -93,7 +93,7 @@ class DependencyGraphTest : WordSpec({ val refCollections = DependencyReference(1) val refConfig = DependencyReference(2, dependencies = setOf(refLang, refCollections)) val refCsv = DependencyReference(3, dependencies = setOf(refConfig)) - val fragments = sortedSetOf(DependencyGraph.DEPENDENCY_REFERENCE_COMPARATOR, refCsv) + val fragments = setOf(refCsv) val scopeMap = mapOf("s" to listOf(RootDependencyIndex(3))) val graph = DependencyGraph(ids, fragments, scopeMap) val scopes = graph.createScopes() @@ -115,7 +115,7 @@ class DependencyGraphTest : WordSpec({ val refConfig1 = DependencyReference(2, dependencies = setOf(refLang, refCollections1)) val refConfig2 = DependencyReference(2, fragment = 1, dependencies = setOf(refLang, refCollections2)) - val fragments = sortedSetOf(refConfig1, refConfig2) + val fragments = setOf(refConfig1, refConfig2) val scopeMap = mapOf( "s1" to listOf(RootDependencyIndex(2)), "s2" to listOf(RootDependencyIndex(2, fragment = 1)) @@ -174,7 +174,7 @@ class DependencyGraphTest : WordSpec({ val issue = Issue(source = "analyzer", message = "Could not analyze :-(") val refLang = DependencyReference(0, linkage = PackageLinkage.PROJECT_DYNAMIC) val refCol = DependencyReference(1, issues = listOf(issue), dependencies = setOf(refLang)) - val trees = sortedSetOf(refCol) + val trees = setOf(refCol) val scopeMap = mapOf("s" to listOf(RootDependencyIndex(1))) val graph = DependencyGraph(ids, trees, scopeMap) diff --git a/model/src/test/kotlin/ProjectTest.kt b/model/src/test/kotlin/ProjectTest.kt index ca0adf223c34c..a08feda73993a 100644 --- a/model/src/test/kotlin/ProjectTest.kt +++ b/model/src/test/kotlin/ProjectTest.kt @@ -79,7 +79,7 @@ private fun createDependencyGraph(qualified: Boolean = false): DependencyGraph { return DependencyGraph( packages = dependencies, - scopeRoots = sortedSetOf(exampleRef, csvRef), + scopeRoots = setOf(exampleRef, csvRef), scopes = scopeMapping ) }