diff --git a/src/main/kotlin/io/github/sgtsilvio/gradle/oci/dsl/DependencyConstraintFactories.kt b/src/main/kotlin/io/github/sgtsilvio/gradle/oci/dsl/DependencyConstraintFactories.kt new file mode 100644 index 00000000..0f17c0b9 --- /dev/null +++ b/src/main/kotlin/io/github/sgtsilvio/gradle/oci/dsl/DependencyConstraintFactories.kt @@ -0,0 +1,22 @@ +package io.github.sgtsilvio.gradle.oci.dsl + +import org.gradle.api.Project +import org.gradle.api.artifacts.DependencyConstraint +import org.gradle.api.artifacts.MinimalExternalModuleDependency +import org.gradle.api.provider.Provider +import org.gradle.api.provider.ProviderConvertible + +/** + * @author Silvio Giebl + */ +interface DependencyConstraintFactories { + + fun constraint(dependencyConstraintNotation: CharSequence): DependencyConstraint + + fun constraint(project: Project): DependencyConstraint + + fun constraint(dependencyProvider: Provider): Provider + + fun constraint(dependencyProvider: ProviderConvertible) = + constraint(dependencyProvider.asProvider()) +} \ No newline at end of file diff --git a/src/main/kotlin/io/github/sgtsilvio/gradle/oci/dsl/OciDependenciesExtension.kt b/src/main/kotlin/io/github/sgtsilvio/gradle/oci/dsl/OciDependenciesExtension.kt index ca3f2ae0..85485a4b 100644 --- a/src/main/kotlin/io/github/sgtsilvio/gradle/oci/dsl/OciDependenciesExtension.kt +++ b/src/main/kotlin/io/github/sgtsilvio/gradle/oci/dsl/OciDependenciesExtension.kt @@ -1,19 +1,14 @@ package io.github.sgtsilvio.gradle.oci.dsl import org.gradle.api.Action -import org.gradle.api.Project -import org.gradle.api.artifacts.DependencyConstraint -import org.gradle.api.artifacts.MinimalExternalModuleDependency import org.gradle.api.plugins.jvm.JvmTestSuite -import org.gradle.api.provider.Provider -import org.gradle.api.provider.ProviderConvertible import org.gradle.api.tasks.TaskProvider import org.gradle.api.tasks.testing.Test /** * @author Silvio Giebl */ -interface OciDependenciesExtension { +interface OciDependenciesExtension : DependencyConstraintFactories { fun forTestSuite(testSuite: JvmTestSuite): OciDependencies @@ -24,38 +19,18 @@ interface OciDependenciesExtension { fun forTest(testTask: TaskProvider, action: Action) = action.execute(forTest(testTask)) - // constraint factories - - fun constraint(dependencyConstraintNotation: CharSequence): DependencyConstraint - - fun constraint(project: Project): DependencyConstraint - - fun constraint(dependencyProvider: Provider): Provider - - fun constraint(dependencyProvider: ProviderConvertible) = - constraint(dependencyProvider.asProvider()) - // dsl syntactic sugar val JvmTestSuite.image get() = forTestSuite(this).image fun JvmTestSuite.imageScope(scope: String) = forTestSuite(this).imageScope(scope) + + // no dsl syntactic sugar for Test because is should not be used inside a lazy task configuration } -interface OciDependencies { +interface OciDependencies : DependencyConstraintFactories { val image: ResolvableOciImageDependencies fun imageScope(scope: String): ResolvableOciImageDependencies - - // constraint factories - - fun constraint(dependencyConstraintNotation: CharSequence): DependencyConstraint - - fun constraint(project: Project): DependencyConstraint - - fun constraint(dependencyProvider: Provider): Provider - - fun constraint(dependencyProvider: ProviderConvertible) = - constraint(dependencyProvider.asProvider()) } 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 index 115d6507..64cde999 100644 --- a/src/main/kotlin/io/github/sgtsilvio/gradle/oci/dsl/OciImageDependencies.kt +++ b/src/main/kotlin/io/github/sgtsilvio/gradle/oci/dsl/OciImageDependencies.kt @@ -10,7 +10,7 @@ import org.gradle.api.provider.ProviderConvertible /** * @author Silvio Giebl */ -interface OciImageDependencies { +interface OciImageDependencies : DependencyConstraintFactories { val configuration: Configuration val set: DomainObjectSet @@ -60,17 +60,6 @@ interface OciImageDependencies { action: Action, ) - // create constraint from a different notation - - fun constraint(dependencyConstraintNotation: CharSequence): DependencyConstraint - - fun constraint(project: Project): DependencyConstraint - - fun constraint(dependencyProvider: Provider): Provider - - fun constraint(dependencyProvider: ProviderConvertible) = - constraint(dependencyProvider.asProvider()) - // dsl syntactic sugar for adding dependency operator fun invoke(dependency: ModuleDependency) = add(dependency) diff --git a/src/main/kotlin/io/github/sgtsilvio/gradle/oci/internal/dsl/DependencyConstraintFactoriesImpl.kt b/src/main/kotlin/io/github/sgtsilvio/gradle/oci/internal/dsl/DependencyConstraintFactoriesImpl.kt new file mode 100644 index 00000000..58590c04 --- /dev/null +++ b/src/main/kotlin/io/github/sgtsilvio/gradle/oci/internal/dsl/DependencyConstraintFactoriesImpl.kt @@ -0,0 +1,28 @@ +package io.github.sgtsilvio.gradle.oci.internal.dsl + +import io.github.sgtsilvio.gradle.oci.dsl.DependencyConstraintFactories +import org.gradle.api.Project +import org.gradle.api.artifacts.DependencyConstraint +import org.gradle.api.artifacts.MinimalExternalModuleDependency +import org.gradle.api.artifacts.dsl.DependencyConstraintHandler +import org.gradle.api.provider.Provider + +/** + * @author Silvio Giebl + */ +abstract class DependencyConstraintFactoriesImpl( + private val dependencyConstraintHandler: DependencyConstraintHandler, +) : DependencyConstraintFactories { + + final override fun constraint(dependencyConstraintNotation: CharSequence): DependencyConstraint = + dependencyConstraintHandler.create(dependencyConstraintNotation) + + final override fun constraint(project: Project): DependencyConstraint = dependencyConstraintHandler.create(project) + + private fun constraint(dependency: MinimalExternalModuleDependency): DependencyConstraint = + dependencyConstraintHandler.create(dependency) + + final override fun constraint( + dependencyProvider: Provider, + ): Provider = dependencyProvider.map { constraint(it) } +} diff --git a/src/main/kotlin/io/github/sgtsilvio/gradle/oci/internal/dsl/OciDependenciesExtensionImpl.kt b/src/main/kotlin/io/github/sgtsilvio/gradle/oci/internal/dsl/OciDependenciesExtensionImpl.kt index effc7a28..4f010214 100644 --- a/src/main/kotlin/io/github/sgtsilvio/gradle/oci/internal/dsl/OciDependenciesExtensionImpl.kt +++ b/src/main/kotlin/io/github/sgtsilvio/gradle/oci/internal/dsl/OciDependenciesExtensionImpl.kt @@ -7,14 +7,10 @@ import io.github.sgtsilvio.gradle.oci.dsl.OciDependenciesExtension import io.github.sgtsilvio.gradle.oci.dsl.OciExtension import io.github.sgtsilvio.gradle.oci.dsl.ResolvableOciImageDependencies import io.github.sgtsilvio.gradle.oci.internal.concatCamelCase -import org.gradle.api.Project -import org.gradle.api.artifacts.DependencyConstraint -import org.gradle.api.artifacts.MinimalExternalModuleDependency -import org.gradle.api.artifacts.dsl.DependencyHandler +import org.gradle.api.artifacts.dsl.DependencyConstraintHandler 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 @@ -31,8 +27,8 @@ internal abstract class OciDependenciesExtensionImpl @Inject constructor( private val objectFactory: ObjectFactory, private val taskContainer: TaskContainer, private val projectLayout: ProjectLayout, - private val dependencyHandler: DependencyHandler, -) : OciDependenciesExtension { + dependencyConstraintHandler: DependencyConstraintHandler, +) : DependencyConstraintFactoriesImpl(dependencyConstraintHandler), OciDependenciesExtension { private val testSuiteDependencies = HashMap() private val testDependencies = HashMap() @@ -64,27 +60,14 @@ internal abstract class OciDependenciesExtensionImpl @Inject constructor( } objectFactory.newInstance(testTaskName, registryDataTask, oci) } - - final override fun constraint(dependencyConstraintNotation: CharSequence): DependencyConstraint = - dependencyHandler.constraints.create(dependencyConstraintNotation) - - final override fun constraint(project: Project): DependencyConstraint = - dependencyHandler.constraints.create(project) - - private fun constraint(dependency: MinimalExternalModuleDependency): DependencyConstraint = - dependencyHandler.constraints.create(dependency) - - final override fun constraint( - dependencyProvider: Provider, - ): Provider = dependencyProvider.map { constraint(it) } } internal abstract class OciDependenciesImpl @Inject constructor( private val name: String, private val registryDataTask: TaskProvider, private val oci: OciExtension, - private val dependencyHandler: DependencyHandler, -) : OciDependencies { + dependencyConstraintHandler: DependencyConstraintHandler, +) : DependencyConstraintFactoriesImpl(dependencyConstraintHandler), OciDependencies { private val scopes = HashMap() @@ -97,17 +80,4 @@ internal abstract class OciDependenciesImpl @Inject constructor( } imageDependencies } - - final override fun constraint(dependencyConstraintNotation: CharSequence): DependencyConstraint = - dependencyHandler.constraints.create(dependencyConstraintNotation) - - final override fun constraint(project: Project): DependencyConstraint = - dependencyHandler.constraints.create(project) - - private fun constraint(dependency: MinimalExternalModuleDependency): DependencyConstraint = - dependencyHandler.constraints.create(dependency) - - final override fun constraint( - dependencyProvider: Provider, - ): Provider = dependencyProvider.map { constraint(it) } } 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 index feef0c2e..e15d3689 100644 --- 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 @@ -14,7 +14,7 @@ import org.gradle.kotlin.dsl.withType internal abstract class OciImageDependenciesImpl( final override val configuration: Configuration, private val dependencyHandler: DependencyHandler, -) : OciImageDependencies { +) : DependencyConstraintFactoriesImpl(dependencyHandler.constraints), OciImageDependencies { final override val set get() = configuration.allDependencies.withType(ModuleDependency::class) @@ -94,19 +94,4 @@ internal abstract class OciImageDependenciesImpl( dependencyConstraintProvider: Provider, action: Action, ) = configuration.dependencyConstraints.addLater(dependencyConstraintProvider.map { action.execute(it); it }) - - // create constraint from a different notation - - final override fun constraint(dependencyConstraintNotation: CharSequence): DependencyConstraint = - dependencyHandler.constraints.create(dependencyConstraintNotation) - - final override fun constraint(project: Project): DependencyConstraint = - dependencyHandler.constraints.create(project) - - private fun constraint(dependency: MinimalExternalModuleDependency): DependencyConstraint = - dependencyHandler.constraints.create(dependency) - - final override fun constraint( - dependencyProvider: Provider, - ): Provider = dependencyProvider.map { constraint(it) } }