Skip to content

Commit

Permalink
feat: reason works for multi capabilities (#1170)
Browse files Browse the repository at this point in the history
  • Loading branch information
seregamorph committed May 7, 2024
1 parent 731bef1 commit 71cf517
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
10 changes: 10 additions & 0 deletions src/main/kotlin/com/autonomousapps/internal/utils/collections.kt
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,16 @@ internal inline fun <T, R : Any> Iterable<T>.mapNotNullToOrderedSet(transform: (
return mapNotNullTo(TreeSet(), transform)
}

/**
* Sort elements keeping Comparable-equal elements (stable sorting).
* This method has different semantics with standard toSortedSet(Comparator).
*/
internal fun <T> Collection<T>.softSortedSet(comparator: Comparator<in T>): Set<T> {
val list = ArrayList(this)
list.sortWith(comparator)
return LinkedHashSet(list)
}

internal inline fun <T> Iterable<T>.mutPartitionOf(
predicate1: (T) -> Boolean,
predicate2: (T) -> Boolean,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ import com.autonomousapps.model.Coordinates
import com.autonomousapps.model.IncludedBuildCoordinates
import com.autonomousapps.model.intermediates.Usage

internal fun Map<Coordinates, Set<Usage>>.toStringCoordinates(buildPath: String): Map<String, Set<Usage>> =
map { (key, value) ->
toCoordinatesKey(key, buildPath) to value
}.toMap()
internal fun Map<Coordinates, Set<Usage>>.toStringCoordinates(buildPath: String): Map<String, Set<Usage>> {
val result = mutableMapOf<String, MutableSet<Usage>>()
forEach { (coordinates, usages) ->
result.computeIfAbsent(toCoordinatesKey(coordinates, buildPath)) { mutableSetOf() }.addAll(usages)
}
return result
}

internal fun toCoordinatesKey(coordinates: Coordinates, buildPath: String) =
coordinates.gav() + when {
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/com/autonomousapps/tasks/ReasonTask.kt
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,8 @@ abstract class ReasonTask @Inject constructor(
}

private fun getUsageFor(id: String): Set<Usage> {
return dependencyUsages.entries.find(id::equalsKey)?.value?.toSortedSet(Usage.BY_VARIANT)
?: annotationProcessorUsages.entries.find(id::equalsKey)?.value?.toSortedSet(Usage.BY_VARIANT)
return dependencyUsages.entries.find(id::equalsKey)?.value?.softSortedSet(Usage.BY_VARIANT)
?: annotationProcessorUsages.entries.find(id::equalsKey)?.value?.softSortedSet(Usage.BY_VARIANT)
// Will be empty for runtimeOnly dependencies (no detected usages)
?: emptySet()
}
Expand Down

0 comments on commit 71cf517

Please sign in to comment.