-
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.
Add OciExtension.platformSelector Add OciImagesTask.platformSelector Add OciImagesTask command line option --platform Use PlatformSelector in OciImageInput/SpecResolution.kt
- Loading branch information
Showing
7 changed files
with
152 additions
and
21 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
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
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
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
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
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
99 changes: 99 additions & 0 deletions
99
src/main/kotlin/io/github/sgtsilvio/gradle/oci/platform/PlatformSelector.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,99 @@ | ||
package io.github.sgtsilvio.gradle.oci.platform | ||
|
||
import io.github.sgtsilvio.gradle.oci.internal.resolution.PlatformSet | ||
|
||
/** | ||
* @author Silvio Giebl | ||
*/ | ||
sealed class PlatformSelector { | ||
|
||
fun and(other: PlatformSelector): PlatformSelector = AndPlatformSelector(this, other) | ||
|
||
fun or(other: PlatformSelector): PlatformSelector = OrPlatformSelector(this, other) | ||
|
||
internal abstract fun select(platformSet: PlatformSet): Set<Platform> | ||
// PlatformFilter as argument? | ||
// return nullable? null -> not fulfilled, empty -> fulfilled with empty | ||
} | ||
|
||
fun PlatformSelector(platform: Platform): PlatformSelector = SinglePlatformSelector(platform) | ||
|
||
fun PlatformSelector.and(platform: Platform) = and(PlatformSelector(platform)) | ||
|
||
fun PlatformSelector.or(platform: Platform) = or(PlatformSelector(platform)) | ||
|
||
private class SinglePlatformSelector(private val platform: Platform): PlatformSelector() { | ||
|
||
override fun select(platformSet: PlatformSet) = | ||
if (platformSet.isInfinite || (platform in platformSet.set)) setOf(platform) else emptySet() | ||
|
||
override fun toString() = platform.toString() | ||
} | ||
|
||
private class AndPlatformSelector( | ||
private val left: PlatformSelector, | ||
private val right: PlatformSelector, | ||
) : PlatformSelector() { | ||
|
||
override fun select(platformSet: PlatformSet): Set<Platform> { | ||
val leftResult = left.select(platformSet) | ||
if (leftResult.isEmpty()) { | ||
return emptySet() | ||
} | ||
val rightResult = right.select(platformSet) | ||
if (rightResult.isEmpty()) { | ||
return emptySet() | ||
} | ||
return leftResult + rightResult | ||
} | ||
|
||
override fun toString() = "($left and $right)" | ||
} | ||
|
||
private class OrPlatformSelector( | ||
private val left: PlatformSelector, | ||
private val right: PlatformSelector, | ||
) : PlatformSelector() { | ||
|
||
override fun select(platformSet: PlatformSet): Set<Platform> { | ||
val leftResult = left.select(platformSet) | ||
if (leftResult.isNotEmpty()) { | ||
return leftResult | ||
} | ||
val rightResult = right.select(platformSet) | ||
if (rightResult.isNotEmpty()) { | ||
return rightResult | ||
} | ||
return emptySet() | ||
} | ||
|
||
override fun toString() = "($left or $right)" | ||
} | ||
|
||
//PlatformFilterSelector? | ||
//MultiPlatformSelector instead of AndPlatformSelector and SinglePlatformSelector? | ||
|
||
/* | ||
fallback arch: | ||
linux,arm64 or linux,amd64 | ||
multiple arch, fallback for specific: | ||
linux,amd64 and optional(linux,arm64) | ||
=> linux,amd64 and (linux,arm64 or linux,amd64)? | ||
=> linux,amd64 and (linux,arm64 or empty)? | ||
all linux | ||
fallback arch, multiple os: | ||
(linux,arm64 or linux,amd64) and (windows,arm64 or windows,amd64) | ||
multiple arch, fallback for specific, multiple os: | ||
(linux,amd64 and (linux,arm64 or linux,amd64)) and (windows,amd64 and (windows,arm64 or windows,amd64)) | ||
=> linux,amd64 and (linux,arm64 or linux,amd64) and windows,amd64 and (windows,arm64 or windows,amd64) | ||
??? | ||
(linux,arm64 or (linux,amd64 and linux,arm)) and (windows,arm64 or (windows,amd64 and windows,arm)) | ||
(x or y) and z | ||
(x and z) or (y and z) | ||
*/ |