From 016530478571b1b9b52494d1d31b3c3ed130838e Mon Sep 17 00:00:00 2001 From: Silvio Giebl Date: Sun, 28 Jul 2024 14:14:36 +0200 Subject: [PATCH] Add OciRegistries.exclusiveContent and OciRegistry.content --- .../sgtsilvio/gradle/oci/dsl/OciRegistries.kt | 5 +++++ .../gradle/oci/internal/dsl/OciRegistriesImpl.kt | 13 +++++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/main/kotlin/io/github/sgtsilvio/gradle/oci/dsl/OciRegistries.kt b/src/main/kotlin/io/github/sgtsilvio/gradle/oci/dsl/OciRegistries.kt index 5386f4ff..7eec9643 100644 --- a/src/main/kotlin/io/github/sgtsilvio/gradle/oci/dsl/OciRegistries.kt +++ b/src/main/kotlin/io/github/sgtsilvio/gradle/oci/dsl/OciRegistries.kt @@ -3,7 +3,9 @@ package io.github.sgtsilvio.gradle.oci.dsl import org.gradle.api.Action import org.gradle.api.Named import org.gradle.api.NamedDomainObjectList +import org.gradle.api.artifacts.repositories.InclusiveRepositoryContentDescriptor import org.gradle.api.artifacts.repositories.IvyArtifactRepository +import org.gradle.api.artifacts.repositories.RepositoryContentDescriptor import org.gradle.api.credentials.PasswordCredentials import org.gradle.api.provider.Property import org.gradle.api.provider.Provider @@ -19,6 +21,8 @@ interface OciRegistries { fun registry(name: String, configuration: Action): OciRegistry fun dockerHub(configuration: Action): OciRegistry fun gitHubContainerRegistry(configuration: Action): OciRegistry + + fun OciRegistry.exclusiveContent(configuration: Action) } interface OciRegistry : Named { @@ -29,4 +33,5 @@ interface OciRegistry : Named { fun credentials() fun optionalCredentials() + fun content(configuration: Action) } diff --git a/src/main/kotlin/io/github/sgtsilvio/gradle/oci/internal/dsl/OciRegistriesImpl.kt b/src/main/kotlin/io/github/sgtsilvio/gradle/oci/internal/dsl/OciRegistriesImpl.kt index 2b180970..17bbd867 100644 --- a/src/main/kotlin/io/github/sgtsilvio/gradle/oci/internal/dsl/OciRegistriesImpl.kt +++ b/src/main/kotlin/io/github/sgtsilvio/gradle/oci/internal/dsl/OciRegistriesImpl.kt @@ -19,6 +19,8 @@ import org.gradle.api.Project import org.gradle.api.artifacts.ConfigurationContainer import org.gradle.api.artifacts.ResolvableDependencies import org.gradle.api.artifacts.dsl.RepositoryHandler +import org.gradle.api.artifacts.repositories.InclusiveRepositoryContentDescriptor +import org.gradle.api.artifacts.repositories.RepositoryContentDescriptor import org.gradle.api.credentials.HttpHeaderCredentials import org.gradle.api.credentials.PasswordCredentials import org.gradle.api.model.ObjectFactory @@ -47,6 +49,7 @@ import javax.inject.Inject internal abstract class OciRegistriesImpl @Inject constructor( private val imageMapping: OciImageMappingImpl, private val objectFactory: ObjectFactory, + private val repositoryHandler: RepositoryHandler, configurationContainer: ConfigurationContainer, buildServiceRegistry: BuildServiceRegistry, project: Project, @@ -101,6 +104,13 @@ internal abstract class OciRegistriesImpl @Inject constructor( return registry } + final override fun OciRegistry.exclusiveContent(configuration: Action) { + repositoryHandler.exclusiveContent { + forRepository { repository } + filter(configuration) + } + } + private fun ResolvableDependencies.resolvesOciImages() = attributes.getAttribute(DISTRIBUTION_TYPE_ATTRIBUTE) == OCI_IMAGE_DISTRIBUTION_TYPE @@ -150,6 +160,9 @@ internal abstract class OciRegistryImpl @Inject constructor( final override fun credentials() = credentials.set(providerFactory.passwordCredentials(name)) final override fun optionalCredentials() = credentials.set(providerFactory.optionalPasswordCredentials(name)) + + final override fun content(configuration: Action) = + repository.content(configuration) } private const val PORT_HTTP_HEADER_NAME = "port"