Skip to content

Commit

Permalink
Fix eager evaluation of image definition capabilities for OciPushSing…
Browse files Browse the repository at this point in the history
…leTask
  • Loading branch information
SgtSilvio committed Mar 16, 2024
1 parent 0a2fb43 commit c98362c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
8 changes: 1 addition & 7 deletions src/main/kotlin/io/github/sgtsilvio/gradle/oci/OciPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,7 @@ class OciPlugin : Plugin<Project> {
val pushName = "push".concatCamelCase(name.mainToEmpty())
val pushTask = project.tasks.register<OciPushSingleTask>(pushName.concatCamelCase("ociImage"))
val pushImageDependencies = extension.imageDependencies.create(pushName) {
add(project) {
capabilities {
for (capability in capabilities.set.get()) {
requireCapability("${capability.group}:${capability.name}")
}
}
}.name(pushTask.flatMap { it.imageName }).tag(pushTask.flatMap { it.imageTags })
add(dependency).name(pushTask.flatMap { it.imageName }).tag(pushTask.flatMap { it.imageTags })
}
pushTask {
group = TASK_GROUP_NAME
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import io.github.sgtsilvio.gradle.oci.platform.PlatformFilter
import org.gradle.api.Action
import org.gradle.api.Named
import org.gradle.api.NamedDomainObjectList
import org.gradle.api.artifacts.ProjectDependency
import org.gradle.api.capabilities.Capability
import org.gradle.api.provider.*
import org.gradle.api.tasks.TaskProvider
Expand All @@ -19,6 +20,7 @@ interface OciImageDefinition : Named {
val capabilities: Capabilities
val indexAnnotations: MapProperty<String, String>
val component: Provider<OciComponent>
val dependency: Provider<ProjectDependency>

fun capabilities(configuration: Action<in Capabilities>)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import org.gradle.api.Project
import org.gradle.api.artifacts.Configuration
import org.gradle.api.artifacts.ConfigurationContainer
import org.gradle.api.artifacts.ModuleDependency
import org.gradle.api.artifacts.ProjectDependency
import org.gradle.api.artifacts.dsl.DependencyHandler
import org.gradle.api.attributes.Bundling
import org.gradle.api.attributes.Category
Expand Down Expand Up @@ -65,6 +66,7 @@ internal abstract class OciImageDefinitionImpl @Inject constructor(
private var platformBundles: TreeMap<Platform, Bundle>? = null
final override val component = createComponent(providerFactory)
private val componentTask = createComponentTask(name, taskContainer, projectLayout)
final override val dependency = createDependency()

init {
registerArtifacts(objectFactory, providerFactory)
Expand Down Expand Up @@ -123,6 +125,16 @@ internal abstract class OciImageDefinitionImpl @Inject constructor(
classifier.set(createOciComponentClassifier(imageDefName))
}

private fun createDependency(): Provider<ProjectDependency> = capabilities.set.map { capabilities ->
val projectDependency = project.dependencies.create(project) as ProjectDependency
projectDependency.capabilities {
for (capability in capabilities) {
requireCapability("${capability.group}:${capability.name}")
}
}
projectDependency
}

private fun registerArtifacts(objectFactory: ObjectFactory, providerFactory: ProviderFactory) {
imageConfiguration.outgoing.addArtifacts(providerFactory.provider {
val layerTasks = LinkedHashMap<String, TaskProvider<OciLayerTask>>()
Expand Down

0 comments on commit c98362c

Please sign in to comment.