Skip to content

Commit

Permalink
Cleanup OciImagesInputTask.kt and OciImagesInputResolution.kt
Browse files Browse the repository at this point in the history
Rename resolveOciImagesInput -> resolveOciImageInputs
  • Loading branch information
SgtSilvio committed Jul 11, 2024
1 parent 10e7fc2 commit c9bd2e3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 79 deletions.
32 changes: 16 additions & 16 deletions src/main/kotlin/io/github/sgtsilvio/gradle/oci/OciImagesInput.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<File>,
)

data class OciImageInput(
@get:Input val platform: Platform,
@get:Nested val variants: List<OciVariantInput>, // TODO document must not be empty
@get:Input val referenceSpecs: Set<OciImageReferenceSpec>,
)

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

data class OciImageReferenceSpec(val name: String?, val tag: String?) : Serializable {
override fun toString() = (name ?: "") + ":" + (tag ?: "")
}
Expand All @@ -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<OciLayer>,
internal class OciMultiArchImage(
val index: OciData,
val platformToImage: Map<Platform, OciImage>,
)

internal class OciImage(
Expand All @@ -55,9 +50,14 @@ internal class OciImage(
val variants: List<OciVariant>,
)

internal class OciMultiArchImage(
val index: OciData,
val platformToImage: Map<Platform, OciImage>,
internal class OciVariant(
val metadata: OciMetadata,
val layers: List<OciLayer>,
)

internal class OciLayer( // TODO internal?
val descriptor: OciMetadata.Layer.Descriptor,
val file: File,
)

abstract class OciImagesInputTask : DefaultTask() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<List<OciImageInput>> {
internal fun ResolvableDependencies.resolveOciImageInputs(): Provider<List<OciImageInput>> {
val rootComponentProvider = resolutionResult.rootComponent
val imageSpecsProvider = rootComponentProvider.map(::resolveOciImageSpecs)
val artifactResultsProvider = artifactView {
Expand All @@ -29,66 +29,6 @@ internal fun ResolvableDependencies.resolveOciImagesInput(): Provider<List<OciIm
val imageSpecs = imageSpecsProvider.get()
val variantDescriptorToInput = artifactResults.groupBy({ it.variant.toDescriptor() }) { it.file }
.mapValues { (_, files) -> OciVariantInput(files.first(), files.drop(1)) }

// val variantDescriptorToInput = HashMap<VariantDescriptor, OciVariantInput>()
// 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<File>()
// 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<VariantDescriptor, OciVariantInput>()
// val artifactResultsIterator = artifactResults.iterator()
// if (artifactResultsIterator.hasNext()) {
// val metadataArtifactResult = artifactResultsIterator.next()
// var variantResult = metadataArtifactResult.variant
// var metadataFile = metadataArtifactResult.file
// var layerFiles = ArrayList<File>()
// 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<VariantDescriptor, OciVariantInput>()
// var metadataArtifactResult: ResolvedArtifactResult? = null
// val layerFiles = ArrayList<File>()
// 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,
Expand Down

0 comments on commit c9bd2e3

Please sign in to comment.