-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move functions to OciVariantGraphPlatformSelection.kt
- Loading branch information
Showing
2 changed files
with
37 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
...in/io/github/sgtsilvio/gradle/oci/internal/resolution/OciVariantGraphPlatformSelection.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package io.github.sgtsilvio.gradle.oci.internal.resolution | ||
|
||
import io.github.sgtsilvio.gradle.oci.platform.Platform | ||
import io.github.sgtsilvio.gradle.oci.platform.PlatformSelector | ||
|
||
internal typealias OciVariantGraphWithSelectedPlatforms = List<Pair<OciVariantGraphRoot, Set<Platform>>> | ||
|
||
internal fun OciVariantGraph.selectPlatforms(platformSelector: PlatformSelector?): OciVariantGraphWithSelectedPlatforms { | ||
val selectedPlatformsGraph = ArrayList<Pair<OciVariantGraphRoot, Set<Platform>>>(size) | ||
val graphRootsWithEmptySelection = ArrayList<OciVariantGraphRoot>() | ||
for (graphRoot in this) { | ||
val supportedPlatforms = graphRoot.node.supportedPlatforms | ||
val platforms = platformSelector?.select(supportedPlatforms) ?: supportedPlatforms.set | ||
if (platforms.isEmpty()) { | ||
graphRootsWithEmptySelection += graphRoot | ||
} else { | ||
selectedPlatformsGraph += Pair(graphRoot, platforms) | ||
} | ||
} | ||
if (graphRootsWithEmptySelection.isNotEmpty()) { | ||
val errorMessage = graphRootsWithEmptySelection.joinToString("\n") { | ||
"no platforms can be selected for variant ${it.node.variant} (supported platforms: ${it.node.supportedPlatforms}, platform selector: $platformSelector)" | ||
} | ||
throw IllegalStateException(errorMessage) | ||
} | ||
return selectedPlatformsGraph | ||
} | ||
|
||
internal fun OciVariantGraphWithSelectedPlatforms.groupByPlatform(): Map<Platform, List<OciVariantGraphRoot>> { | ||
val platformToGraphRoots = HashMap<Platform, ArrayList<OciVariantGraphRoot>>() | ||
for ((graphRoot, platforms) in this) { | ||
for (platform in platforms) { | ||
platformToGraphRoots.getOrPut(platform) { ArrayList() } += graphRoot | ||
} | ||
} | ||
return platformToGraphRoots | ||
} |