diff --git a/src/main/kotlin/io/github/sgtsilvio/gradle/oci/dsl/Capability.kt b/src/main/kotlin/io/github/sgtsilvio/gradle/oci/dsl/Capability.kt new file mode 100644 index 00000000..998902c1 --- /dev/null +++ b/src/main/kotlin/io/github/sgtsilvio/gradle/oci/dsl/Capability.kt @@ -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) +} diff --git a/src/main/kotlin/io/github/sgtsilvio/gradle/oci/dsl/OciImageDefinition.kt b/src/main/kotlin/io/github/sgtsilvio/gradle/oci/dsl/OciImageDefinition.kt index c53019ef..a6f878a5 100644 --- a/src/main/kotlin/io/github/sgtsilvio/gradle/oci/dsl/OciImageDefinition.kt +++ b/src/main/kotlin/io/github/sgtsilvio/gradle/oci/dsl/OciImageDefinition.kt @@ -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 val imageTag: Property - val capabilities: SetProperty + val capabilities: SetProperty val indexAnnotations: MapProperty val dependency: Provider diff --git a/src/main/kotlin/io/github/sgtsilvio/gradle/oci/internal/dsl/OciImageDefinitionImpl.kt b/src/main/kotlin/io/github/sgtsilvio/gradle/oci/internal/dsl/OciImageDefinitionImpl.kt index f2a2ca7d..34d31e7e 100644 --- a/src/main/kotlin/io/github/sgtsilvio/gradle/oci/internal/dsl/OciImageDefinitionImpl.kt +++ b/src/main/kotlin/io/github/sgtsilvio/gradle/oci/internal/dsl/OciImageDefinitionImpl.kt @@ -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 @@ -51,7 +53,7 @@ internal abstract class OciImageDefinitionImpl @Inject constructor( project.version.toString().concatKebabCase(name.mainToEmpty().kebabCase()) }) val imageReference: Provider = imageName.zip(imageTag, ::OciImageReference) - final override val capabilities = objectFactory.setProperty() + final override val capabilities = objectFactory.setProperty() private val variants = objectFactory.domainObjectSet(Variant::class) private var allPlatformVariantScope: VariantScope? = null private var platformVariantScopes: HashMap? = null @@ -62,7 +64,7 @@ internal abstract class OciImageDefinitionImpl @Inject constructor( capabilities.map { capabilities -> capabilities { for (capability in capabilities) { - requireCapability(capability) + requireCapability(capability.toMapNotation()) } } this @@ -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 { @@ -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()) } } }