Skip to content

Commit

Permalink
Move OciImage/VariantInput -> OciImagesTask.Image/VariantInput
Browse files Browse the repository at this point in the history
  • Loading branch information
SgtSilvio committed Jul 16, 2024
1 parent 9aba070 commit 4c21cf7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 25 deletions.
40 changes: 20 additions & 20 deletions src/main/kotlin/io/github/sgtsilvio/gradle/oci/OciImagesTask.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,6 @@ import java.io.File
/**
* @author Silvio Giebl
*/
data class OciImageInput(
@get:Input val platform: Platform,
@get:Nested val variants: List<OciVariantInput>,
@get:Input val referenceSpecs: Set<OciImageReferenceSpec>,
) {
init {
require(variants.isNotEmpty()) { "variants must not be empty" }
}
}

data class OciVariantInput(
@get:InputFile @get:PathSensitive(PathSensitivity.NONE) val metadataFile: File,
@get:InputFiles @get:PathSensitive(PathSensitivity.NONE) val layerFiles: List<File>,
)

class OciMultiPlatformImage(
val index: OciData,
val platformToImage: Map<Platform, OciImage>,
Expand Down Expand Up @@ -57,7 +42,22 @@ class OciLayer(
abstract class OciImagesTask : DefaultTask() {

@get:Nested
val images = project.objects.setProperty<OciImageInput>()
val images = project.objects.setProperty<ImageInput>()

data class ImageInput(
@get:Input val platform: Platform,
@get:Nested val variants: List<VariantInput>,
@get:Input val referenceSpecs: Set<OciImageReferenceSpec>,
) {
init {
require(variants.isNotEmpty()) { "variants must not be empty" }
}
}

data class VariantInput(
@get:InputFile @get:PathSensitive(PathSensitivity.NONE) val metadataFile: File,
@get:InputFiles @get:PathSensitive(PathSensitivity.NONE) val layerFiles: List<File>,
)

init {
@Suppress("LeakingThis")
Expand All @@ -69,7 +69,7 @@ abstract class OciImagesTask : DefaultTask() {

@TaskAction
protected fun run() {
val imageInputs: Set<OciImageInput> = images.get()
val imageInputs: Set<ImageInput> = images.get()
val imageAndReferencesPairs = createImageAndReferencesPairs(imageInputs)
val multiPlatformImageAndReferencesPairs = createMultiPlatformImageAndReferencesPairs(imageAndReferencesPairs)
val images = imageAndReferencesPairs.map { it.first }
Expand All @@ -84,9 +84,9 @@ abstract class OciImagesTask : DefaultTask() {
)

private fun createImageAndReferencesPairs(
imageInputs: Iterable<OciImageInput>,
imageInputs: Iterable<ImageInput>,
): List<Pair<OciImage, Set<OciImageReference>>> {
val variantInputToVariant = HashMap<OciVariantInput, OciVariant>()
val variantInputToVariant = HashMap<VariantInput, OciVariant>()
return imageInputs.map { imageInput ->
val variants = imageInput.variants.map { variantInput ->
variantInputToVariant.getOrPut(variantInput) { variantInput.toVariant() }
Expand All @@ -105,7 +105,7 @@ abstract class OciImagesTask : DefaultTask() {
}
}

private fun OciVariantInput.toVariant(): OciVariant {
private fun VariantInput.toVariant(): OciVariant {
val metadata = metadataFile.readText().decodeAsJsonToOciMetadata()
val layerFiles = layerFiles
val layers = ArrayList<OciLayer>(layerFiles.size)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.github.sgtsilvio.gradle.oci.internal.resolution

import io.github.sgtsilvio.gradle.oci.OciImageInput
import io.github.sgtsilvio.gradle.oci.OciVariantInput
import io.github.sgtsilvio.gradle.oci.OciImagesTask
import io.github.sgtsilvio.gradle.oci.internal.gradle.ArtifactViewVariantFilter
import org.gradle.api.artifacts.ResolvableDependencies
import org.gradle.api.artifacts.component.ComponentIdentifier
Expand All @@ -10,7 +9,7 @@ import org.gradle.api.attributes.AttributeContainer
import org.gradle.api.capabilities.Capability
import org.gradle.api.provider.Provider

internal fun ResolvableDependencies.resolveOciImageInputs(): Provider<List<OciImageInput>> {
internal fun ResolvableDependencies.resolveOciImageInputs(): Provider<List<OciImagesTask.ImageInput>> {
val rootComponentProvider = resolutionResult.rootComponent
val imageSpecsProvider = rootComponentProvider.map(::resolveOciImageSpecs)
val artifactResultsProvider = artifactView {
Expand All @@ -28,9 +27,9 @@ internal fun ResolvableDependencies.resolveOciImageInputs(): Provider<List<OciIm
return artifactResultsProvider.flatMap { artifactResults ->
val imageSpecs = imageSpecsProvider.get()
val variantDescriptorToInput = artifactResults.groupBy({ it.variant.toDescriptor() }) { it.file }
.mapValues { (_, files) -> OciVariantInput(files.first(), files.drop(1)) }
.mapValues { (_, files) -> OciImagesTask.VariantInput(files.first(), files.drop(1)) }
val imageInputs = imageSpecs.map { imageSpec ->
OciImageInput(
OciImagesTask.ImageInput(
imageSpec.platform,
imageSpec.variants.mapNotNull { variant -> variantDescriptorToInput[variant.toDescriptor()] },
imageSpec.referenceSpecs,
Expand Down

0 comments on commit 4c21cf7

Please sign in to comment.