diff --git a/src/main/kotlin/io/github/sgtsilvio/gradle/oci/dsl/OciImageDependencies.kt b/src/main/kotlin/io/github/sgtsilvio/gradle/oci/dsl/OciImageDependencies.kt new file mode 100644 index 00000000..6c60ee47 --- /dev/null +++ b/src/main/kotlin/io/github/sgtsilvio/gradle/oci/dsl/OciImageDependencies.kt @@ -0,0 +1,24 @@ +package io.github.sgtsilvio.gradle.oci.dsl + +import io.github.sgtsilvio.gradle.oci.OciImagesTask +import io.github.sgtsilvio.gradle.oci.platform.PlatformSelector +import org.gradle.api.Action +import org.gradle.api.Named +import org.gradle.api.provider.Provider + +/** + * @author Silvio Giebl + */ +interface OciImageDependencies : Named { + + val runtime: ReferencableOciImageDependencyCollector + + fun resolve(platformSelector: Provider): Provider> +} + +interface OciImageDependenciesWithScopes : OciImageDependencies, DependencyConstraintFactories { + + fun scope(name: String): OciImageDependencies + + fun scope(name: String, action: Action) +} diff --git a/src/main/kotlin/io/github/sgtsilvio/gradle/oci/dsl/OciImageDependenciesExtension.kt b/src/main/kotlin/io/github/sgtsilvio/gradle/oci/dsl/OciImageDependenciesExtension.kt index e382b552..fd55390c 100644 --- a/src/main/kotlin/io/github/sgtsilvio/gradle/oci/dsl/OciImageDependenciesExtension.kt +++ b/src/main/kotlin/io/github/sgtsilvio/gradle/oci/dsl/OciImageDependenciesExtension.kt @@ -1,11 +1,7 @@ package io.github.sgtsilvio.gradle.oci.dsl -import io.github.sgtsilvio.gradle.oci.OciImagesTask -import io.github.sgtsilvio.gradle.oci.platform.PlatformSelector import org.gradle.api.Action -import org.gradle.api.Named import org.gradle.api.plugins.jvm.JvmTestSuite -import org.gradle.api.provider.Provider import org.gradle.api.tasks.TaskProvider import org.gradle.api.tasks.testing.Test @@ -35,47 +31,3 @@ interface OciImageDependenciesExtension : DependencyConstraintFactories { // no dsl syntactic sugar for Test because it should not be used inside a lazy task configuration } - -interface OciImageDependencies : Named { // TODO move out to own file - -// val configuration: Configuration // TODO not in the one that is extended by the multi scope interface - - val runtime: ReferencableOciImageDependencyCollector - - fun resolve(platformSelector: Provider): Provider> -} - -interface OciImageDependenciesWithScopes : OciImageDependencies, DependencyConstraintFactories { - - fun scope(name: String): OciImageDependencies - - fun scope(name: String, action: Action) -} - -// TODO rename OciImageDependencies -> OciImageDependencyCollector -// rename ResolvableOciImageDependencies -> ResolvableOciImageDependencyCollector? weird -// -> OciImageDependencyWithReferenceCollector? slightly incorrect -// -> OciImageDependencyWithReferencesCollector? slightly incorrect -// -> OciImageDependencyWithReferenceSpecsCollector? correct but long -// -> OciImageReferenceDependencyCollector? -// -> ReferencedOciImageDependencyCollector? -// -> ReferencableOciImageDependencyCollector? <=== -// -> OciImageWithReferencesDependencyCollector? -// -> OciImageWithReferenceSpecsDependencyCollector? <== -// rename OciImageDependenciesForRuntimeScope -> OciImageDependenciesScope -// rename OciImageDependenciesForRuntime -> OciImageDependencies -// DependencyCollector: collector of dependencies -// OciImageDependencyCollector: collector of dependencies to OCI images -// OciImage...DependencyCollector: collector of dependencies to OCI images with reference specs - -/* -OciImageDependenciesForRuntime -OciImageDependenciesForRuntimeScope -OciImageDependencies -ResolvableOciImageDependencies - -OciImageDependencies -OciImageDependenciesScope -OciImageDependencyCollector -ReferencableOciImageDependencyCollector - */ diff --git a/src/main/kotlin/io/github/sgtsilvio/gradle/oci/internal/dsl/OciImageDependenciesExtensionImpl.kt b/src/main/kotlin/io/github/sgtsilvio/gradle/oci/internal/dsl/OciImageDependenciesExtensionImpl.kt index 4931654d..05adfa7c 100644 --- a/src/main/kotlin/io/github/sgtsilvio/gradle/oci/internal/dsl/OciImageDependenciesExtensionImpl.kt +++ b/src/main/kotlin/io/github/sgtsilvio/gradle/oci/internal/dsl/OciImageDependenciesExtensionImpl.kt @@ -1,27 +1,19 @@ package io.github.sgtsilvio.gradle.oci.internal.dsl -import io.github.sgtsilvio.gradle.oci.OciImagesTask import io.github.sgtsilvio.gradle.oci.OciRegistryDataTask import io.github.sgtsilvio.gradle.oci.TASK_GROUP_NAME -import io.github.sgtsilvio.gradle.oci.attributes.* -import io.github.sgtsilvio.gradle.oci.dsl.* -import io.github.sgtsilvio.gradle.oci.internal.resolution.resolveOciImageInputs -import io.github.sgtsilvio.gradle.oci.internal.string.concatCamelCase -import io.github.sgtsilvio.gradle.oci.platform.PlatformSelector -import org.gradle.api.Action -import org.gradle.api.artifacts.Configuration -import org.gradle.api.artifacts.ConfigurationContainer +import io.github.sgtsilvio.gradle.oci.dsl.OciExtension +import io.github.sgtsilvio.gradle.oci.dsl.OciImageDependenciesExtension import org.gradle.api.artifacts.dsl.DependencyConstraintHandler -import org.gradle.api.attributes.Bundling -import org.gradle.api.attributes.Category import org.gradle.api.file.ProjectLayout import org.gradle.api.model.ObjectFactory import org.gradle.api.plugins.jvm.JvmTestSuite -import org.gradle.api.provider.Provider import org.gradle.api.tasks.TaskContainer import org.gradle.api.tasks.TaskProvider import org.gradle.api.tasks.testing.Test -import org.gradle.kotlin.dsl.* +import org.gradle.kotlin.dsl.invoke +import org.gradle.kotlin.dsl.newInstance +import org.gradle.kotlin.dsl.register import javax.inject.Inject /** @@ -70,61 +62,3 @@ internal abstract class OciImageDependenciesExtensionImpl @Inject constructor( dependencies } } - -internal abstract class OciImageDependenciesImpl @Inject constructor( - private val name: String, - objectFactory: ObjectFactory, - configurationContainer: ConfigurationContainer, -) : OciImageDependencies { - - final override fun getName() = name - - final override val runtime: ReferencableOciImageDependencyCollector = - objectFactory.newInstance() - - private val configuration: Configuration = configurationContainer.create(name + "OciImages").apply { - description = "OCI image dependencies '$name'" - isCanBeConsumed = false - isCanBeResolved = true - attributes.apply { - attribute(Category.CATEGORY_ATTRIBUTE, objectFactory.named(DISTRIBUTION_CATEGORY)) - attribute(DISTRIBUTION_TYPE_ATTRIBUTE, OCI_IMAGE_DISTRIBUTION_TYPE) - attribute(Bundling.BUNDLING_ATTRIBUTE, objectFactory.named(Bundling.EXTERNAL)) - attribute(PLATFORM_ATTRIBUTE, MULTI_PLATFORM_ATTRIBUTE_VALUE) - } - dependencies.addAllLater(runtime.dependencies) - dependencyConstraints.addAllLater(runtime.dependencyConstraints) - } - - final override fun resolve(platformSelector: Provider) = - configuration.incoming.resolveOciImageInputs(platformSelector) -} - -internal abstract class OciImageDependenciesWithScopesImpl @Inject constructor( - private val name: String, - private val oci: OciExtension, - private val objectFactory: ObjectFactory, - dependencyConstraintHandler: DependencyConstraintHandler, -) : DependencyConstraintFactoriesImpl(dependencyConstraintHandler), OciImageDependenciesWithScopes { - - final override fun getName() = name - - // linked because it will be iterated - private val scopes = LinkedHashMap() - - final override val runtime = scope("").runtime - - final override fun resolve(platformSelector: Provider): Provider> { - val resolved = objectFactory.listProperty() - for (scope in scopes.values) { - resolved.addAll(scope.resolve(platformSelector)) - } - return resolved - } - - final override fun scope(name: String) = scopes.getOrPut(name) { - oci.imageDependencies.create(this.name.concatCamelCase(name)) - } - - final override fun scope(name: String, action: Action) = action.execute(scope(name)) -} diff --git a/src/main/kotlin/io/github/sgtsilvio/gradle/oci/internal/dsl/OciImageDependenciesImpl.kt b/src/main/kotlin/io/github/sgtsilvio/gradle/oci/internal/dsl/OciImageDependenciesImpl.kt new file mode 100644 index 00000000..fae52e19 --- /dev/null +++ b/src/main/kotlin/io/github/sgtsilvio/gradle/oci/internal/dsl/OciImageDependenciesImpl.kt @@ -0,0 +1,84 @@ +package io.github.sgtsilvio.gradle.oci.internal.dsl + +import io.github.sgtsilvio.gradle.oci.OciImagesTask +import io.github.sgtsilvio.gradle.oci.attributes.* +import io.github.sgtsilvio.gradle.oci.dsl.OciExtension +import io.github.sgtsilvio.gradle.oci.dsl.OciImageDependencies +import io.github.sgtsilvio.gradle.oci.dsl.OciImageDependenciesWithScopes +import io.github.sgtsilvio.gradle.oci.dsl.ReferencableOciImageDependencyCollector +import io.github.sgtsilvio.gradle.oci.internal.resolution.resolveOciImageInputs +import io.github.sgtsilvio.gradle.oci.internal.string.concatCamelCase +import io.github.sgtsilvio.gradle.oci.platform.PlatformSelector +import org.gradle.api.Action +import org.gradle.api.artifacts.Configuration +import org.gradle.api.artifacts.ConfigurationContainer +import org.gradle.api.artifacts.dsl.DependencyConstraintHandler +import org.gradle.api.attributes.Bundling +import org.gradle.api.attributes.Category +import org.gradle.api.model.ObjectFactory +import org.gradle.api.provider.Provider +import org.gradle.kotlin.dsl.listProperty +import org.gradle.kotlin.dsl.named +import org.gradle.kotlin.dsl.newInstance +import javax.inject.Inject + +/** + * @author Silvio Giebl + */ +internal abstract class OciImageDependenciesImpl @Inject constructor( + private val name: String, + objectFactory: ObjectFactory, + configurationContainer: ConfigurationContainer, +) : OciImageDependencies { + + final override fun getName() = name + + final override val runtime: ReferencableOciImageDependencyCollector = + objectFactory.newInstance() + + private val configuration: Configuration = configurationContainer.create(name + "OciImages").apply { + description = "OCI image dependencies '$name'" + isCanBeConsumed = false + isCanBeResolved = true + attributes.apply { + attribute(Category.CATEGORY_ATTRIBUTE, objectFactory.named(DISTRIBUTION_CATEGORY)) + attribute(DISTRIBUTION_TYPE_ATTRIBUTE, OCI_IMAGE_DISTRIBUTION_TYPE) + attribute(Bundling.BUNDLING_ATTRIBUTE, objectFactory.named(Bundling.EXTERNAL)) + attribute(PLATFORM_ATTRIBUTE, MULTI_PLATFORM_ATTRIBUTE_VALUE) + } + dependencies.addAllLater(runtime.dependencies) + dependencyConstraints.addAllLater(runtime.dependencyConstraints) + } + + final override fun resolve(platformSelector: Provider) = + configuration.incoming.resolveOciImageInputs(platformSelector) +} + +internal abstract class OciImageDependenciesWithScopesImpl @Inject constructor( + private val name: String, + private val oci: OciExtension, + private val objectFactory: ObjectFactory, + dependencyConstraintHandler: DependencyConstraintHandler, +) : DependencyConstraintFactoriesImpl(dependencyConstraintHandler), OciImageDependenciesWithScopes { + + final override fun getName() = name + + // linked because it will be iterated + private val scopes = LinkedHashMap() + + final override val runtime = scope("").runtime + + final override fun resolve(platformSelector: Provider): Provider> { + val resolved = objectFactory.listProperty() + for (scope in scopes.values) { + resolved.addAll(scope.resolve(platformSelector)) + } + return resolved + } + + final override fun scope(name: String) = scopes.getOrPut(name) { + oci.imageDependencies.create(this.name.concatCamelCase(name)) + } + + final override fun scope(name: String, action: Action) = action.execute(scope(name)) +}