Skip to content

Commit

Permalink
Cleanup OciImagesTask
Browse files Browse the repository at this point in the history
  • Loading branch information
SgtSilvio committed Jul 18, 2024
1 parent b5f14f8 commit 8ae62d6
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions src/main/kotlin/io/github/sgtsilvio/gradle/oci/OciImagesTask.kt
Original file line number Diff line number Diff line change
Expand Up @@ -97,17 +97,17 @@ abstract class OciImagesTask : DefaultTask() {
val metadata = metadataFile.readText().decodeAsJsonToOciMetadata()
val layerFiles = layerFiles
val layers = ArrayList<OciLayer>(layerFiles.size)
var layerFileIndex = 0
var layerFilesIndex = 0
for (layer in metadata.layers) {
val layerDescriptor = layer.descriptor ?: continue
if (layerFileIndex >= layerFiles.size) {
throw IllegalStateException("count of layer descriptors (${layerFileIndex + 1}+) and layer files (${layerFiles.size}) do not match")
if (layerFilesIndex >= layerFiles.size) {
throw IllegalStateException("count of layer descriptors (${layerFilesIndex + 1}+) and layer files (${layerFiles.size}) do not match")
}
val layerFile = layerFiles[layerFileIndex++]
val layerFile = layerFiles[layerFilesIndex++]
layers += OciLayer(layerDescriptor, layerFile)
}
if (layerFileIndex < layerFiles.size) {
throw IllegalStateException("count of layer descriptors ($layerFileIndex) and layer files (${layerFiles.size}) do not match")
if (layerFilesIndex < layerFiles.size) {
throw IllegalStateException("count of layer descriptors ($layerFilesIndex) and layer files (${layerFiles.size}) do not match")
}
return OciVariant(metadata, layers)
}
Expand All @@ -116,7 +116,6 @@ abstract class OciImagesTask : DefaultTask() {
imageAndReferencesPairs: Iterable<Pair<OciImage, Set<OciImageReference>>>,
): List<Pair<OciMultiPlatformImage, List<OciImageReference>>> {
// referenceToPlatformToImage map is linked because it will be iterated
// platformToImage map is linked to preserve the platform order
val referenceToPlatformToImage = LinkedHashMap<OciImageReference, LinkedHashMap<Platform, OciImage>>()
for ((image, imageReferences) in imageAndReferencesPairs) {
for (imageReference in imageReferences) {
Expand All @@ -130,12 +129,12 @@ abstract class OciImagesTask : DefaultTask() {
}
// multiPlatformImageAndReferencesPairMap is linked because it will be iterated
val multiPlatformImageAndReferencesPairMap =
LinkedHashMap<Map<Platform, OciImage>, Pair<OciMultiPlatformImage, ArrayList<OciImageReference>>>() // TODO reference non multi arch images?
LinkedHashMap<Map<Platform, OciImage>, Pair<OciMultiPlatformImage, ArrayList<OciImageReference>>>()
for ((reference, platformToImage) in referenceToPlatformToImage) {
var multiPlatformImageAndReferencesPair = multiPlatformImageAndReferencesPairMap[platformToImage]
if (multiPlatformImageAndReferencesPair == null) {
val index = createIndex(platformToImage)
multiPlatformImageAndReferencesPair = Pair(OciMultiPlatformImage(index, platformToImage), ArrayList()) // TODO ArrayList
multiPlatformImageAndReferencesPair = Pair(OciMultiPlatformImage(index, platformToImage), ArrayList())
multiPlatformImageAndReferencesPairMap[platformToImage] = multiPlatformImageAndReferencesPair
}
multiPlatformImageAndReferencesPair.second += reference
Expand Down

0 comments on commit 8ae62d6

Please sign in to comment.