Skip to content

Commit

Permalink
Move OciImageDependencies(WithScopes) to separate file
Browse files Browse the repository at this point in the history
  • Loading branch information
SgtSilvio committed Sep 1, 2024
1 parent ae1afa6 commit a409d9e
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 119 deletions.
Original file line number Diff line number Diff line change
@@ -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<PlatformSelector>): Provider<List<OciImagesTask.ImageInput>>
}

interface OciImageDependenciesWithScopes : OciImageDependencies, DependencyConstraintFactories {

fun scope(name: String): OciImageDependencies

fun scope(name: String, action: Action<in OciImageDependencies>)
}
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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<PlatformSelector>): Provider<List<OciImagesTask.ImageInput>>
}

interface OciImageDependenciesWithScopes : OciImageDependencies, DependencyConstraintFactories {

fun scope(name: String): OciImageDependencies

fun scope(name: String, action: Action<in OciImageDependencies>)
}

// 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
*/
Original file line number Diff line number Diff line change
@@ -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

/**
Expand Down Expand Up @@ -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<ReferencableOciImageDependencyCollectorImpl>()

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<PlatformSelector>) =
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<String, OciImageDependencies>()

final override val runtime = scope("").runtime

final override fun resolve(platformSelector: Provider<PlatformSelector>): Provider<List<OciImagesTask.ImageInput>> {
val resolved = objectFactory.listProperty<OciImagesTask.ImageInput>()
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<in OciImageDependencies>) = action.execute(scope(name))
}
Original file line number Diff line number Diff line change
@@ -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<ReferencableOciImageDependencyCollectorImpl>()

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<PlatformSelector>) =
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<String, OciImageDependencies>()

final override val runtime = scope("").runtime

final override fun resolve(platformSelector: Provider<PlatformSelector>): Provider<List<OciImagesTask.ImageInput>> {
val resolved = objectFactory.listProperty<OciImagesTask.ImageInput>()
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<in OciImageDependencies>) = action.execute(scope(name))
}

0 comments on commit a409d9e

Please sign in to comment.