Skip to content

Commit 5a6ed95

Browse files
fix: bundleTraces is a sortedSet and BundleTrace is Comparable.
1 parent 6c1f78a commit 5a6ed95

File tree

2 files changed

+47
-7
lines changed

2 files changed

+47
-7
lines changed

src/main/kotlin/com/autonomousapps/model/internal/intermediates/BundleTrace.kt

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,48 @@ import dev.zacsweers.moshix.sealed.annotations.TypeLabel
1111
internal sealed class BundleTrace(
1212
val top: Coordinates,
1313
val bottom: Coordinates
14-
) {
14+
) : Comparable<BundleTrace> {
15+
16+
override fun compareTo(other: BundleTrace): Int {
17+
return when (this) {
18+
is DeclaredParent -> {
19+
when (other) {
20+
is DeclaredParent -> {
21+
compareBy(DeclaredParent::parent)
22+
.thenBy(DeclaredParent::child)
23+
.compare(this, other)
24+
}
25+
26+
else -> 1
27+
}
28+
}
29+
30+
is UsedChild -> {
31+
when (other) {
32+
is UsedChild -> {
33+
compareBy(UsedChild::parent)
34+
.thenBy(UsedChild::child)
35+
.compare(this, other)
36+
}
37+
38+
is DeclaredParent -> -1
39+
else -> 1
40+
}
41+
}
42+
43+
is PrimaryMap -> {
44+
when (other) {
45+
is PrimaryMap -> {
46+
compareBy(PrimaryMap::primary)
47+
.thenBy(PrimaryMap::subordinate)
48+
.compare(this, other)
49+
}
50+
51+
else -> -1
52+
}
53+
}
54+
}
55+
}
1556

1657
@TypeLabel("parent")
1758
@JsonClass(generateAdapter = false)
@@ -34,4 +75,3 @@ internal sealed class BundleTrace(
3475
val subordinate: Coordinates
3576
) : BundleTrace(primary, subordinate)
3677
}
37-

src/main/kotlin/com/autonomousapps/tasks/ComputeAdviceTask.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ internal class DependencyAdviceBuilder(
282282
val advice: Set<Advice>
283283

284284
/** Dependencies that are removed from [advice] because they match a bundle rule. Used by **Reason**. */
285-
val bundledTraces = mutableSetOf<BundleTrace>()
285+
val bundledTraces: MutableSet<BundleTrace> = sortedSetOf()
286286

287287
init {
288288
advice = computeDependencyAdvice(projectPath)
@@ -333,29 +333,29 @@ internal class DependencyAdviceBuilder(
333333

334334
advice.isAdd() && bundles.hasParentInBundle(originalCoordinates) -> {
335335
val parent = bundles.findParentInBundle(originalCoordinates)!!
336-
bundledTraces += BundleTrace.DeclaredParent(parent = parent, child = originalCoordinates)
336+
bundledTraces.add(BundleTrace.DeclaredParent(parent = parent, child = originalCoordinates))
337337
null
338338
}
339339

340340
// Optionally map given advice to "primary" advice, if bundle has a primary
341341
advice.isAdd() -> {
342342
val p = bundles.maybePrimary(advice, originalCoordinates)
343343
if (p != advice) {
344-
bundledTraces += BundleTrace.PrimaryMap(primary = p.coordinates, subordinate = originalCoordinates)
344+
bundledTraces.add(BundleTrace.PrimaryMap(primary = p.coordinates, subordinate = originalCoordinates))
345345
}
346346
p
347347
}
348348

349349
advice.isRemove() && bundles.hasUsedChild(originalCoordinates) -> {
350350
val child = bundles.findUsedChild(originalCoordinates)!!
351-
bundledTraces += BundleTrace.UsedChild(parent = originalCoordinates, child = child)
351+
bundledTraces.add(BundleTrace.UsedChild(parent = originalCoordinates, child = child))
352352
null
353353
}
354354

355355
// If the advice has a used child, don't change it
356356
advice.isAnyChange() && bundles.hasUsedChild(originalCoordinates) -> {
357357
val child = bundles.findUsedChild(originalCoordinates)!!
358-
bundledTraces += BundleTrace.UsedChild(parent = originalCoordinates, child = child)
358+
bundledTraces.add(BundleTrace.UsedChild(parent = originalCoordinates, child = child))
359359
null
360360
}
361361

0 commit comments

Comments
 (0)