Skip to content

Commit

Permalink
Cleanup OciImageDependenciesImpl
Browse files Browse the repository at this point in the history
  • Loading branch information
SgtSilvio committed Jul 16, 2024
1 parent 20e9fff commit eebbb40
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -304,12 +304,12 @@ internal abstract class OciImageDefinitionImpl @Inject constructor(
dependencyHandler: DependencyHandler,
) : OciImageDependenciesImpl<Unit>(configuration, dependencyHandler), OciImageDefinition.Bundle.ParentImages {

final override fun addInternal(dependency: ModuleDependency) {
configuration.dependencies.add(dependency)
final override fun DependencySet.addInternal(dependency: ModuleDependency) {
add(dependency)
}

final override fun addInternal(dependencyProvider: Provider<out ModuleDependency>) {
configuration.dependencies.addLater(dependencyProvider)
final override fun DependencySet.addInternal(dependencyProvider: Provider<out ModuleDependency>) {
addLater(dependencyProvider)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ internal abstract class OciImageDependenciesImpl<T>(
addInternal(dependencyProvider, action)

private fun <D : ModuleDependency> addInternal(dependency: D, action: Action<in D>?) =
addInternal(finalizeDependency(dependency, action))
configuration.dependencies.addInternal(finalizeDependency(dependency, action))

private fun <D : ModuleDependency> addInternal(dependencyProvider: Provider<out D>, action: Action<in D>?) =
addInternal(dependencyProvider.map { finalizeDependency(it, action) })
configuration.dependencies.addInternal(dependencyProvider.map { finalizeDependency(it, action) })

protected abstract fun addInternal(dependency: ModuleDependency): T
protected abstract fun DependencySet.addInternal(dependency: ModuleDependency): T

protected abstract fun addInternal(dependencyProvider: Provider<out ModuleDependency>): T
protected abstract fun DependencySet.addInternal(dependencyProvider: Provider<out ModuleDependency>): T

private fun <D : ModuleDependency> finalizeDependency(dependency: D, action: Action<in D>?): D {
@Suppress("UNCHECKED_CAST") val finalizedDependency = dependencyHandler.create(dependency) as D
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import io.github.sgtsilvio.gradle.oci.internal.gradle.attribute
import io.github.sgtsilvio.gradle.oci.internal.gradle.zipAbsentAsNull
import io.github.sgtsilvio.gradle.oci.metadata.OciImageReferenceSpec
import org.gradle.api.artifacts.ConfigurationContainer
import org.gradle.api.artifacts.DependencySet
import org.gradle.api.artifacts.ModuleDependency
import org.gradle.api.artifacts.dsl.DependencyHandler
import org.gradle.api.attributes.Bundling
Expand Down Expand Up @@ -44,17 +45,17 @@ internal abstract class ResolvableOciImageDependenciesImpl @Inject constructor(

final override fun getName() = name

final override fun addInternal(dependency: ModuleDependency): ReferenceSpecBuilder {
final override fun DependencySet.addInternal(dependency: ModuleDependency): ReferenceSpecBuilder {
val referenceSpecBuilder = ReferenceSpecBuilder(objectFactory)
configuration.dependencies.addLater(referenceSpecBuilder.attribute.map { attribute ->
addLater(referenceSpecBuilder.attribute.map { attribute ->
dependency.attribute(OCI_IMAGE_REFERENCE_ATTRIBUTE, attribute)
})
return referenceSpecBuilder
}

final override fun addInternal(dependencyProvider: Provider<out ModuleDependency>): ReferenceSpecBuilder {
final override fun DependencySet.addInternal(dependencyProvider: Provider<out ModuleDependency>): ReferenceSpecBuilder {
val referenceSpecBuilder = ReferenceSpecBuilder(objectFactory)
configuration.dependencies.addLater(dependencyProvider.zip(referenceSpecBuilder.attribute) { dependency, attribute ->
addLater(dependencyProvider.zip(referenceSpecBuilder.attribute) { dependency, attribute ->
dependency.attribute(OCI_IMAGE_REFERENCE_ATTRIBUTE, attribute)
})
return referenceSpecBuilder
Expand Down

0 comments on commit eebbb40

Please sign in to comment.