Skip to content

Commit 9ece42c

Browse files
committed
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 <[email protected]>
1 parent 87fd707 commit 9ece42c

File tree

4 files changed

+10
-17
lines changed

4 files changed

+10
-17
lines changed

analyzer/src/test/kotlin/AnalyzerResultBuilderTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,13 @@ class AnalyzerResultBuilderTest : WordSpec() {
105105

106106
private val graph1 = DependencyGraph(
107107
packages = dependencies1,
108-
scopeRoots = sortedSetOf(DependencyGraph.DEPENDENCY_REFERENCE_COMPARATOR, depRef1, depRef2),
108+
scopeRoots = setOf(depRef1, depRef2),
109109
scopes = scopeMapping1
110110
)
111111

112112
private val graph2 = DependencyGraph(
113113
packages = dependencies2,
114-
scopeRoots = sortedSetOf(DependencyGraph.DEPENDENCY_REFERENCE_COMPARATOR, depRef3),
114+
scopeRoots = setOf(depRef3),
115115
scopes = scopeMapping2
116116
)
117117

model/src/main/kotlin/DependencyGraph.kt

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ import com.fasterxml.jackson.annotation.JsonIgnore
2323
import com.fasterxml.jackson.annotation.JsonInclude
2424
import com.fasterxml.jackson.databind.annotation.JsonSerialize
2525

26-
import java.util.SortedSet
27-
2826
import org.ossreviewtoolkit.model.utils.DependencyGraphEdgeSortedSetConverter
2927
import org.ossreviewtoolkit.model.utils.DependencyReferenceSortedSetConverter
3028
import org.ossreviewtoolkit.model.utils.PackageLinkageValueFilter
@@ -86,7 +84,8 @@ data class DependencyGraph(
8684
* declared by scopes that cannot be reached via other paths in the dependency graph. Note that this property
8785
* exists for backwards compatibility only; it is replaced by the lists of nodes and edges.
8886
*/
89-
val scopeRoots: SortedSet<DependencyReference> = sortedSetOf(),
87+
@JsonSerialize(converter = DependencyReferenceSortedSetConverter::class)
88+
val scopeRoots: Set<DependencyReference> = emptySet(),
9089

9190
/**
9291
* 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(
109108
val edges: Set<DependencyGraphEdge>? = null
110109
) {
111110
companion object {
112-
/**
113-
* A comparator for [DependencyReference] objects. Note that the concrete order does not really matter, it
114-
* just has to be well-defined.
115-
*/
116-
val DEPENDENCY_REFERENCE_COMPARATOR = compareBy<DependencyReference>({ it.pkg }, { it.fragment })
117-
118111
/**
119112
* Return a name for the given [scope][scopeName] that is qualified with parts of the identifier of the given
120113
* [project]. This is used to ensure that the scope names are unique when constructing a dependency graph from

model/src/test/kotlin/DependencyGraphTest.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class DependencyGraphTest : WordSpec({
3535
id("org.apache.commons", "commons-collections4", "4.4"),
3636
id(group = "org.junit", artifact = "junit", version = "5")
3737
)
38-
val fragments = sortedSetOf(
38+
val fragments = setOf(
3939
DependencyReference(0),
4040
DependencyReference(1),
4141
DependencyReference(2)
@@ -62,7 +62,7 @@ class DependencyGraphTest : WordSpec({
6262
id("org.apache.commons", "commons-collections4", "4.4"),
6363
id("org.junit", "junit", "5")
6464
)
65-
val fragments = sortedSetOf(
65+
val fragments = setOf(
6666
DependencyReference(0),
6767
DependencyReference(1),
6868
DependencyReference(2)
@@ -93,7 +93,7 @@ class DependencyGraphTest : WordSpec({
9393
val refCollections = DependencyReference(1)
9494
val refConfig = DependencyReference(2, dependencies = setOf(refLang, refCollections))
9595
val refCsv = DependencyReference(3, dependencies = setOf(refConfig))
96-
val fragments = sortedSetOf(DependencyGraph.DEPENDENCY_REFERENCE_COMPARATOR, refCsv)
96+
val fragments = setOf(refCsv)
9797
val scopeMap = mapOf("s" to listOf(RootDependencyIndex(3)))
9898
val graph = DependencyGraph(ids, fragments, scopeMap)
9999
val scopes = graph.createScopes()
@@ -115,7 +115,7 @@ class DependencyGraphTest : WordSpec({
115115
val refConfig1 = DependencyReference(2, dependencies = setOf(refLang, refCollections1))
116116
val refConfig2 =
117117
DependencyReference(2, fragment = 1, dependencies = setOf(refLang, refCollections2))
118-
val fragments = sortedSetOf(refConfig1, refConfig2)
118+
val fragments = setOf(refConfig1, refConfig2)
119119
val scopeMap = mapOf(
120120
"s1" to listOf(RootDependencyIndex(2)),
121121
"s2" to listOf(RootDependencyIndex(2, fragment = 1))
@@ -174,7 +174,7 @@ class DependencyGraphTest : WordSpec({
174174
val issue = Issue(source = "analyzer", message = "Could not analyze :-(")
175175
val refLang = DependencyReference(0, linkage = PackageLinkage.PROJECT_DYNAMIC)
176176
val refCol = DependencyReference(1, issues = listOf(issue), dependencies = setOf(refLang))
177-
val trees = sortedSetOf(refCol)
177+
val trees = setOf(refCol)
178178
val scopeMap = mapOf("s" to listOf(RootDependencyIndex(1)))
179179

180180
val graph = DependencyGraph(ids, trees, scopeMap)

model/src/test/kotlin/ProjectTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ private fun createDependencyGraph(qualified: Boolean = false): DependencyGraph {
7979

8080
return DependencyGraph(
8181
packages = dependencies,
82-
scopeRoots = sortedSetOf(exampleRef, csvRef),
82+
scopeRoots = setOf(exampleRef, csvRef),
8383
scopes = scopeMapping
8484
)
8585
}

0 commit comments

Comments
 (0)