Skip to content

Commit

Permalink
Refactor OciImageDefinition.Variant.parentImages -> dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
SgtSilvio committed Sep 1, 2024
1 parent a409d9e commit d027b40
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 35 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ oci {
}
imageDefinitions.register("main") {
allPlatforms {
parentImages {
add("library:eclipse-temurin:21.0.2_13-jre-jammy")
dependencies {
runtime("library:eclipse-temurin:21.0.2_13-jre-jammy")
}
config {
entryPoint = listOf("java", "-jar")
Expand Down
4 changes: 2 additions & 2 deletions examples/java-app-groovy-dsl/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ oci {
}
imageDefinitions.register("main") {
allPlatforms {
parentImages {
add("library:eclipse-temurin:21.0.2_13-jre-jammy")
dependencies {
runtime.add("library:eclipse-temurin:21.0.2_13-jre-jammy")
}
config {
entryPoint = ["java", "-jar"]
Expand Down
4 changes: 2 additions & 2 deletions examples/java-app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ oci {
}
imageDefinitions.register("main") {
allPlatforms {
parentImages {
add("library:eclipse-temurin:21.0.2_13-jre-jammy")
dependencies {
runtime("library:eclipse-temurin:21.0.2_13-jre-jammy")
}
config {
entryPoint = listOf("java", "-jar")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ internal class PublishMetadataTest {
}
imageDefinitions.register("main") {
allPlatforms {
parentImages {
add("library:eclipse-temurin:17.0.7_7-jre-jammy")
dependencies {
runtime("library:eclipse-temurin:17.0.7_7-jre-jammy")
}
config {
entryPoint.set(listOf("java", "-jar", "app.jar"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ internal class TestProject(projectDir: File) {
}
imageDefinitions.register("main") {
allPlatforms {
parentImages {
add("library:eclipse-temurin:17.0.7_7-jre-jammy")
dependencies {
runtime("library:eclipse-temurin:17.0.7_7-jre-jammy")
}
config {
entryPoint.set(listOf("java", "-jar", "app.jar"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,17 @@ interface OciImageDefinition : Named {
}

interface Variant {
val parentImages: ParentImages
val dependencies: Dependencies
val config: Config
val layers: Layers

fun parentImages(configuration: Action<in ParentImages>)
fun dependencies(configuration: Action<in Dependencies>)
fun config(configuration: Action<in Config>)
fun layers(configuration: Action<in Layers>)

interface ParentImages : OciImageDependencyCollector<Unit>
interface Dependencies : DependencyConstraintFactories {
val runtime: OciImageDependencyCollector<Unit>
}

interface Config {
val creationTime: Property<Instant>
Expand Down Expand Up @@ -99,7 +101,7 @@ interface OciImageDefinition : Named {
interface VariantScope {
val layers: Layers

fun parentImages(configuration: Action<in Variant.ParentImages>)
fun dependencies(configuration: Action<in Variant.Dependencies>)
fun config(configuration: Action<in Variant.Config>)
fun layers(configuration: Action<in Layers>)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import org.gradle.api.provider.ProviderConvertible
/**
* @author Silvio Giebl
*/
interface OciImageDependencyCollector<T> : DependencyConstraintFactories {
interface OciImageDependencyCollector<T> {

val dependencies: Provider<Set<ModuleDependency>>
val dependencyConstraints: Provider<Set<DependencyConstraint>>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import org.gradle.api.Action
import org.gradle.api.DomainObjectSet
import org.gradle.api.Project
import org.gradle.api.artifacts.*
import org.gradle.api.artifacts.dsl.DependencyHandler
import org.gradle.api.artifacts.dsl.DependencyConstraintHandler
import org.gradle.api.attributes.Bundling
import org.gradle.api.attributes.Category
import org.gradle.api.capabilities.Capability
Expand Down Expand Up @@ -223,7 +223,7 @@ internal abstract class OciImageDefinitionImpl @Inject constructor(
projectName: String,
) : OciImageDefinition.Variant {

final override val parentImages = objectFactory.newInstance<ParentImages>()
final override val dependencies = objectFactory.newInstance<Dependencies>()
final override val config = objectFactory.newInstance<OciImageDefinition.Variant.Config>().apply {
entryPoint.convention(null)
arguments.convention(null)
Expand All @@ -232,8 +232,8 @@ internal abstract class OciImageDefinitionImpl @Inject constructor(
objectFactory.newInstance<Layers>(imageDefinition.name, Optional.ofNullable(platform))

init {
configuration.dependencies.addAllLater(parentImages.dependencies)
configuration.dependencyConstraints.addAllLater(parentImages.dependencyConstraints)
configuration.dependencies.addAllLater(dependencies.runtime.dependencies)
configuration.dependencyConstraints.addAllLater(dependencies.runtime.dependencyConstraints)
val metadata = createMetadata(providerFactory)
val metadataTask = taskContainer.createMetadataTask(imageDefinition.name, platform, metadata, projectLayout)
configuration.outgoing.addArtifacts(providerFactory.provider {
Expand Down Expand Up @@ -292,25 +292,21 @@ internal abstract class OciImageDefinitionImpl @Inject constructor(
listProvider
}

final override fun parentImages(configuration: Action<in OciImageDefinition.Variant.ParentImages>) =
configuration.execute(parentImages)
final override fun dependencies(configuration: Action<in OciImageDefinition.Variant.Dependencies>) =
configuration.execute(dependencies)

final override fun config(configuration: Action<in OciImageDefinition.Variant.Config>) =
configuration.execute(config)

final override fun layers(configuration: Action<in OciImageDefinition.Variant.Layers>) =
configuration.execute(layers)

abstract class ParentImages @Inject constructor(
dependencyHandler: DependencyHandler,
abstract class Dependencies @Inject constructor(
objectFactory: ObjectFactory,
) : OciImageDependencyCollectorImpl<Unit>(dependencyHandler, objectFactory),
OciImageDefinition.Variant.ParentImages {
dependencyConstraintHandler: DependencyConstraintHandler,
) : DependencyConstraintFactoriesImpl(dependencyConstraintHandler), OciImageDefinition.Variant.Dependencies {

final override fun addInternal(dependency: ModuleDependency) = dependencies.add(dependency)

final override fun addInternal(dependencyProvider: Provider<out ModuleDependency>) =
dependencies.add(dependencyProvider)
final override val runtime = objectFactory.newInstance<OciImageDependencyCollectorImpl.Default>()
}

abstract class Layers @Inject constructor(
Expand Down Expand Up @@ -519,8 +515,8 @@ internal abstract class OciImageDefinitionImpl @Inject constructor(
}
final override val layers = objectFactory.newInstance<Layers>(platformFilter, imageDefName, filteredVariants)

final override fun parentImages(configuration: Action<in OciImageDefinition.Variant.ParentImages>) =
filteredVariants.configureEach { parentImages(configuration) }
final override fun dependencies(configuration: Action<in OciImageDefinition.Variant.Dependencies>) =
filteredVariants.configureEach { dependencies(configuration) }

final override fun config(configuration: Action<in OciImageDefinition.Variant.Config>) =
filteredVariants.configureEach { config(configuration) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ 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
Expand Down Expand Up @@ -33,8 +32,7 @@ internal abstract class OciImageDependenciesImpl @Inject constructor(

final override fun getName() = name

final override val runtime: ReferencableOciImageDependencyCollector =
objectFactory.newInstance<ReferencableOciImageDependencyCollectorImpl>()
final override val runtime = objectFactory.newInstance<ReferencableOciImageDependencyCollectorImpl>()

private val configuration: Configuration = configurationContainer.create(name + "OciImages").apply {
description = "OCI image dependencies '$name'"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ import org.gradle.api.artifacts.dsl.DependencyHandler
import org.gradle.api.model.ObjectFactory
import org.gradle.api.provider.Provider
import org.gradle.kotlin.dsl.setProperty
import javax.inject.Inject

/**
* @author Silvio Giebl
*/
internal abstract class OciImageDependencyCollectorImpl<T>(
private val dependencyHandler: DependencyHandler,
objectFactory: ObjectFactory,
) : DependencyConstraintFactoriesImpl(dependencyHandler.constraints), OciImageDependencyCollector<T> {
) : OciImageDependencyCollector<T> {

final override val dependencies = objectFactory.setProperty<ModuleDependency>()
final override val dependencyConstraints = objectFactory.setProperty<DependencyConstraint>()
Expand Down Expand Up @@ -88,4 +89,16 @@ internal abstract class OciImageDependencyCollectorImpl<T>(
dependencyConstraintProvider: Provider<out DependencyConstraint>,
action: Action<in DependencyConstraint>,
) = dependencyConstraints.add(dependencyConstraintProvider.map { action.execute(it); it })


internal abstract class Default @Inject constructor(
dependencyHandler: DependencyHandler,
objectFactory: ObjectFactory,
) : OciImageDependencyCollectorImpl<Unit>(dependencyHandler, objectFactory) {

final override fun addInternal(dependency: ModuleDependency) = dependencies.add(dependency)

final override fun addInternal(dependencyProvider: Provider<out ModuleDependency>) =
dependencies.add(dependencyProvider)
}
}

0 comments on commit d027b40

Please sign in to comment.