diff --git a/src/main/kotlin/io/github/sgtsilvio/gradle/oci/internal/resolution/OciImageSpecResolution.kt b/src/main/kotlin/io/github/sgtsilvio/gradle/oci/internal/resolution/OciImageSpecResolution.kt index 785c6d42..72ea204d 100644 --- a/src/main/kotlin/io/github/sgtsilvio/gradle/oci/internal/resolution/OciImageSpecResolution.kt +++ b/src/main/kotlin/io/github/sgtsilvio/gradle/oci/internal/resolution/OciImageSpecResolution.kt @@ -6,49 +6,10 @@ import io.github.sgtsilvio.gradle.oci.internal.gradle.toVariantSelector import io.github.sgtsilvio.gradle.oci.metadata.DEFAULT_OCI_IMAGE_REFERENCE_SPEC import io.github.sgtsilvio.gradle.oci.metadata.OciImageReferenceSpec import io.github.sgtsilvio.gradle.oci.metadata.toOciImageReferenceSpec -import io.github.sgtsilvio.gradle.oci.platform.Platform -import io.github.sgtsilvio.gradle.oci.platform.PlatformSelector import org.gradle.api.artifacts.result.ResolvedComponentResult import org.gradle.api.artifacts.result.ResolvedDependencyResult import org.gradle.api.artifacts.result.ResolvedVariantResult -// TODO new file from here? - -internal fun OciVariantGraph.selectPlatforms( - platformSelector: PlatformSelector?, -): List>> { - val selectedPlatformsGraph = ArrayList>>(size) - val graphRootsWithEmptySelection = ArrayList() - 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 List>>.groupByPlatform(): Map> { - val platformToGraphRoots = HashMap>() - for ((graphRoot, platforms) in this) { - for (platform in platforms) { - platformToGraphRoots.getOrPut(platform) { ArrayList() } += graphRoot - } - } - return platformToGraphRoots -} - -// TODO new file from here? - internal class OciImageSpec(val variants: List, val selectors: Set) // TODO internal fun collectOciImageSpecs(rootComponent: ResolvedComponentResult): List { diff --git a/src/main/kotlin/io/github/sgtsilvio/gradle/oci/internal/resolution/OciVariantGraphPlatformSelection.kt b/src/main/kotlin/io/github/sgtsilvio/gradle/oci/internal/resolution/OciVariantGraphPlatformSelection.kt new file mode 100644 index 00000000..d75e088d --- /dev/null +++ b/src/main/kotlin/io/github/sgtsilvio/gradle/oci/internal/resolution/OciVariantGraphPlatformSelection.kt @@ -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>> + +internal fun OciVariantGraph.selectPlatforms(platformSelector: PlatformSelector?): OciVariantGraphWithSelectedPlatforms { + val selectedPlatformsGraph = ArrayList>>(size) + val graphRootsWithEmptySelection = ArrayList() + 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> { + val platformToGraphRoots = HashMap>() + for ((graphRoot, platforms) in this) { + for (platform in platforms) { + platformToGraphRoots.getOrPut(platform) { ArrayList() } += graphRoot + } + } + return platformToGraphRoots +}