From c9bd2e3bb0e252f3aa072c9015aa8be1259dd4ce Mon Sep 17 00:00:00 2001 From: Silvio Giebl Date: Thu, 11 Jul 2024 18:03:42 +0200 Subject: [PATCH] Cleanup OciImagesInputTask.kt and OciImagesInputResolution.kt Rename resolveOciImagesInput -> resolveOciImageInputs --- .../sgtsilvio/gradle/oci/OciImagesInput.kt | 32 +++++----- .../dsl/ResolvableOciImageDependenciesImpl.kt | 4 +- .../resolution/OciImagesInputResolution.kt | 62 +------------------ 3 files changed, 19 insertions(+), 79 deletions(-) diff --git a/src/main/kotlin/io/github/sgtsilvio/gradle/oci/OciImagesInput.kt b/src/main/kotlin/io/github/sgtsilvio/gradle/oci/OciImagesInput.kt index 701a2268..d96ac6e8 100644 --- a/src/main/kotlin/io/github/sgtsilvio/gradle/oci/OciImagesInput.kt +++ b/src/main/kotlin/io/github/sgtsilvio/gradle/oci/OciImagesInput.kt @@ -13,17 +13,17 @@ import java.io.Serializable /** * @author Silvio Giebl */ -data class OciVariantInput( - @get:InputFile @get:PathSensitive(PathSensitivity.NONE) val metadataFile: File, - @get:InputFiles @get:PathSensitive(PathSensitivity.NONE) val layerFiles: List, -) - data class OciImageInput( @get:Input val platform: Platform, @get:Nested val variants: List, // TODO document must not be empty @get:Input val referenceSpecs: Set, ) +data class OciVariantInput( + @get:InputFile @get:PathSensitive(PathSensitivity.NONE) val metadataFile: File, + @get:InputFiles @get:PathSensitive(PathSensitivity.NONE) val layerFiles: List, +) + data class OciImageReferenceSpec(val name: String?, val tag: String?) : Serializable { override fun toString() = (name ?: "") + ":" + (tag ?: "") } @@ -39,14 +39,9 @@ internal fun String.toOciImageReferenceSpec(): OciImageReferenceSpec { // TODO factory method for OciImageReferenceSpec that returns DEFAULT_OCI_REFERENCE_SPEC if both are null internal val DEFAULT_OCI_REFERENCE_SPEC = OciImageReferenceSpec(null, null) -internal class OciLayer( // TODO internal? - val descriptor: OciMetadata.Layer.Descriptor, - val file: File, -) - -internal class OciVariant( - val metadata: OciMetadata, - val layers: List, +internal class OciMultiArchImage( + val index: OciData, + val platformToImage: Map, ) internal class OciImage( @@ -55,9 +50,14 @@ internal class OciImage( val variants: List, ) -internal class OciMultiArchImage( - val index: OciData, - val platformToImage: Map, +internal class OciVariant( + val metadata: OciMetadata, + val layers: List, +) + +internal class OciLayer( // TODO internal? + val descriptor: OciMetadata.Layer.Descriptor, + val file: File, ) abstract class OciImagesInputTask : DefaultTask() { diff --git a/src/main/kotlin/io/github/sgtsilvio/gradle/oci/internal/dsl/ResolvableOciImageDependenciesImpl.kt b/src/main/kotlin/io/github/sgtsilvio/gradle/oci/internal/dsl/ResolvableOciImageDependenciesImpl.kt index bb8f0b99..d3dbd7cb 100644 --- a/src/main/kotlin/io/github/sgtsilvio/gradle/oci/internal/dsl/ResolvableOciImageDependenciesImpl.kt +++ b/src/main/kotlin/io/github/sgtsilvio/gradle/oci/internal/dsl/ResolvableOciImageDependenciesImpl.kt @@ -7,7 +7,7 @@ import io.github.sgtsilvio.gradle.oci.dsl.ResolvableOciImageDependencies.Nameabl import io.github.sgtsilvio.gradle.oci.dsl.ResolvableOciImageDependencies.Taggable import io.github.sgtsilvio.gradle.oci.internal.gradle.attribute import io.github.sgtsilvio.gradle.oci.internal.gradle.zipAbsentAsNull -import io.github.sgtsilvio.gradle.oci.internal.resolution.resolveOciImagesInput +import io.github.sgtsilvio.gradle.oci.internal.resolution.resolveOciImageInputs import org.gradle.api.artifacts.ConfigurationContainer import org.gradle.api.artifacts.ModuleDependency import org.gradle.api.artifacts.dsl.DependencyHandler @@ -43,7 +43,7 @@ internal abstract class ResolvableOciImageDependenciesImpl @Inject constructor( dependencyHandler, ), ResolvableOciImageDependencies { - final override fun asInput() = configuration.incoming.resolveOciImagesInput() + final override fun asInput() = configuration.incoming.resolveOciImageInputs() final override fun getName() = name diff --git a/src/main/kotlin/io/github/sgtsilvio/gradle/oci/internal/resolution/OciImagesInputResolution.kt b/src/main/kotlin/io/github/sgtsilvio/gradle/oci/internal/resolution/OciImagesInputResolution.kt index d65c5d84..b36638ea 100644 --- a/src/main/kotlin/io/github/sgtsilvio/gradle/oci/internal/resolution/OciImagesInputResolution.kt +++ b/src/main/kotlin/io/github/sgtsilvio/gradle/oci/internal/resolution/OciImagesInputResolution.kt @@ -10,7 +10,7 @@ import org.gradle.api.attributes.AttributeContainer import org.gradle.api.capabilities.Capability import org.gradle.api.provider.Provider -internal fun ResolvableDependencies.resolveOciImagesInput(): Provider> { +internal fun ResolvableDependencies.resolveOciImageInputs(): Provider> { val rootComponentProvider = resolutionResult.rootComponent val imageSpecsProvider = rootComponentProvider.map(::resolveOciImageSpecs) val artifactResultsProvider = artifactView { @@ -29,66 +29,6 @@ internal fun ResolvableDependencies.resolveOciImagesInput(): Provider OciVariantInput(files.first(), files.drop(1)) } - -// val variantDescriptorToInput = HashMap() -// val artifactResultsIterator = artifactResults.iterator() -// if (artifactResultsIterator.hasNext()) { -// var artifactResult = artifactResultsIterator.next() -// outer@ while (true) { -// val variantResult = artifactResult.variant -// val metadataFile = artifactResult.file -// val layerFiles = ArrayList() -// while (true) { -// if (!artifactResultsIterator.hasNext()) { -// break@outer -// } -// artifactResult = artifactResultsIterator.next() -// if (artifactResult.variant != variantResult) { -// break -// } -// layerFiles += artifactResult.file -// } -// variantDescriptorToInput[variantResult.toDescriptor()] = OciVariantInput(metadataFile, layerFiles) -// } -// } - -// val variantDescriptorToInput = HashMap() -// val artifactResultsIterator = artifactResults.iterator() -// if (artifactResultsIterator.hasNext()) { -// val metadataArtifactResult = artifactResultsIterator.next() -// var variantResult = metadataArtifactResult.variant -// var metadataFile = metadataArtifactResult.file -// var layerFiles = ArrayList() -// while (artifactResultsIterator.hasNext()) { -// val artifactResult = artifactResultsIterator.next() -// if (artifactResult.variant == variantResult) { -// layerFiles += artifactResult.file -// } else { -// variantDescriptorToInput[variantResult.toDescriptor()] = OciVariantInput(metadataFile, layerFiles) -// variantResult = artifactResult.variant -// metadataFile = artifactResult.file -// layerFiles = ArrayList() -// } -// } -// variantDescriptorToInput[variantResult.toDescriptor()] = OciVariantInput(metadataFile, layerFiles) -// } - -// val variantDescriptorToInput = HashMap() -// var metadataArtifactResult: ResolvedArtifactResult? = null -// val layerFiles = ArrayList() -// for (artifactResult in artifactResults) { -// if (artifactResult.variant == metadataArtifactResult?.variant) { -// layerFiles += artifactResult.file -// } else { -// if (metadataArtifactResult != null) { -// variantDescriptorToInput[metadataArtifactResult.variant.toDescriptor()] = -// OciVariantInput(metadataArtifactResult.file, layerFiles.toList()) -// } -// metadataArtifactResult = artifactResult -// layerFiles.clear() -// } -// } - val imageInputs = imageSpecs.map { imageSpec -> OciImageInput( imageSpec.platform,