Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

model: Remove the remaining uses of SortedSet / SortedMap from classes which get serialized #8705

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
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 <frank_viernau@epam.com>
  • Loading branch information
fviernau committed Jun 18, 2024
commit a523522505c893df8cbdf356c8828a8c9de34df9
4 changes: 2 additions & 2 deletions analyzer/src/test/kotlin/AnalyzerResultBuilderTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down
11 changes: 2 additions & 9 deletions model/src/main/kotlin/DependencyGraph.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<DependencyReference> = sortedSetOf(),
@JsonSerialize(converter = DependencyReferenceSortedSetConverter::class)
val scopeRoots: Set<DependencyReference> = emptySet(),

/**
* A mapping from scope names to the direct dependencies of the scopes. Based on this information, the set of
Expand All @@ -109,12 +108,6 @@ data class DependencyGraph(
val edges: Set<DependencyGraphEdge>? = 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<DependencyReference>({ 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
Expand Down
10 changes: 5 additions & 5 deletions model/src/test/kotlin/DependencyGraphTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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()
Expand All @@ -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))
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion model/src/test/kotlin/ProjectTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
}
Expand Down
Loading