Skip to content

Commit

Permalink
OciImageDefinition.capabilities SetProperty<String> -> <Capability>
Browse files Browse the repository at this point in the history
  • Loading branch information
SgtSilvio committed Dec 1, 2024
1 parent ff85cc5 commit 6053316
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
18 changes: 18 additions & 0 deletions src/main/kotlin/io/github/sgtsilvio/gradle/oci/dsl/Capability.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package io.github.sgtsilvio.gradle.oci.dsl

/**
* @author Silvio Giebl
*/
data class Capability(val group: String, val name: String, val version: String) {
init {
require(group.isNotEmpty()) { "capability group must not be empty" }
require(name.isNotEmpty()) { "capability name must not be empty" }
require(version.isNotEmpty()) { "capability version must not be empty" }
}
}

internal fun Capability.toMapNotation() = mapOf("group" to group, "name" to name, "version" to version)

interface CapabilityFactories {
fun capability(group: String, name: String, version: String) = Capability(group, name, version)
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ import org.gradle.api.provider.*
import org.gradle.api.tasks.TaskProvider
import java.time.Instant

interface OciImageDefinition : Named {
interface OciImageDefinition : Named, CapabilityFactories {
val imageName: Property<String>
val imageTag: Property<String>
val capabilities: SetProperty<String>
val capabilities: SetProperty<Capability>
val indexAnnotations: MapProperty<String, String>

val dependency: Provider<ProjectDependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import io.github.sgtsilvio.gradle.oci.OciLayerTask
import io.github.sgtsilvio.gradle.oci.OciMetadataTask
import io.github.sgtsilvio.gradle.oci.TASK_GROUP_NAME
import io.github.sgtsilvio.gradle.oci.attributes.*
import io.github.sgtsilvio.gradle.oci.dsl.Capability
import io.github.sgtsilvio.gradle.oci.dsl.OciImageDefinition
import io.github.sgtsilvio.gradle.oci.dsl.toMapNotation
import io.github.sgtsilvio.gradle.oci.internal.*
import io.github.sgtsilvio.gradle.oci.internal.gradle.*
import io.github.sgtsilvio.gradle.oci.internal.string.camelCase
Expand Down Expand Up @@ -51,7 +53,7 @@ internal abstract class OciImageDefinitionImpl @Inject constructor(
project.version.toString().concatKebabCase(name.mainToEmpty().kebabCase())
})
val imageReference: Provider<OciImageReference> = imageName.zip(imageTag, ::OciImageReference)
final override val capabilities = objectFactory.setProperty<String>()
final override val capabilities = objectFactory.setProperty<Capability>()
private val variants = objectFactory.domainObjectSet(Variant::class)
private var allPlatformVariantScope: VariantScope? = null
private var platformVariantScopes: HashMap<PlatformFilter, VariantScope>? = null
Expand All @@ -62,7 +64,7 @@ internal abstract class OciImageDefinitionImpl @Inject constructor(
capabilities.map { capabilities ->
capabilities {
for (capability in capabilities) {
requireCapability(capability)
requireCapability(capability.toMapNotation())
}
}
this
Expand All @@ -72,7 +74,13 @@ internal abstract class OciImageDefinitionImpl @Inject constructor(
init {
if (name != MAIN_NAME) {
capabilities.convention(providerFactory.provider {
listOf("${project.group}:${project.name.concatKebabCase(name.kebabCase())}:${project.version}")
listOf(
Capability(
project.group.toString(),
project.name.concatKebabCase(name.kebabCase()),
project.version.toString(),
)
)
})
}
project.afterEvaluate {
Expand All @@ -86,13 +94,13 @@ internal abstract class OciImageDefinitionImpl @Inject constructor(
for (variant in variants) {
val configurationPublications = variant.configuration.outgoing
for (capability in capabilities) {
configurationPublications.capability(capability)
configurationPublications.capability(capability.toMapNotation())
}
}
indexConfiguration?.let { indexConfiguration ->
val configurationPublications = indexConfiguration.outgoing
for (capability in capabilities) {
configurationPublications.capability(capability)
configurationPublications.capability(capability.toMapNotation())
}
}
}
Expand Down

0 comments on commit 6053316

Please sign in to comment.