Skip to content

Commit

Permalink
Rename ArtifactViewComponentFilter -> ArtifactViewVariantFilter and m…
Browse files Browse the repository at this point in the history
…ake it independent of oci code
  • Loading branch information
SgtSilvio committed Jul 10, 2024
1 parent 1acf40e commit dd1fede
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import io.github.sgtsilvio.gradle.oci.dsl.ResolvableOciImageDependencies.Nameabl
import io.github.sgtsilvio.gradle.oci.dsl.ResolvableOciImageDependencies.Taggable
import io.github.sgtsilvio.gradle.oci.internal.gradle.attribute
import io.github.sgtsilvio.gradle.oci.internal.gradle.zipAbsentAsNull
import io.github.sgtsilvio.gradle.oci.internal.resolution.ArtifactViewComponentFilter
import io.github.sgtsilvio.gradle.oci.internal.resolution.ArtifactViewVariantFilter
import io.github.sgtsilvio.gradle.oci.internal.resolution.resolveOciImageSpecs
import org.gradle.api.artifacts.ConfigurationContainer
import org.gradle.api.artifacts.ModuleDependency
Expand All @@ -26,6 +26,7 @@ import org.gradle.api.provider.Provider
import org.gradle.kotlin.dsl.named
import org.gradle.kotlin.dsl.property
import org.gradle.kotlin.dsl.setProperty
import java.util.HashSet
import javax.inject.Inject

/**
Expand Down Expand Up @@ -55,7 +56,12 @@ internal abstract class ResolvableOciImageDependenciesImpl @Inject constructor(
val rootComponentProvider = configuration.incoming.resolutionResult.rootComponent
val imageSpecsProvider = rootComponentProvider.map(::resolveOciImageSpecs)
val artifactsResultsProvider = configuration.incoming.artifactView {
componentFilter(ArtifactViewComponentFilter(rootComponentProvider, imageSpecsProvider))
componentFilter(
ArtifactViewVariantFilter(
rootComponentProvider,
imageSpecsProvider.map { imageSpecs -> imageSpecs.flatMapTo(HashSet()) { it.variants } },
)
)
}.artifacts.resolvedArtifacts
// zip or map is not used here because their mapper function is executed after the file contents are available
// this mapper function does not read the file contents, so can already be called once the value is available
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,25 @@ import java.util.*
/**
* @author Silvio Giebl
*/
internal class ArtifactViewComponentFilter(
private val rootComponentResultProvider: Provider<ResolvedComponentResult>,
private val imageSpecsProvider: Provider<List<OciImageSpec>>,
internal class ArtifactViewVariantFilter(
private val rootComponentResult: Provider<ResolvedComponentResult>,
private val selectedVariantResults: Provider<Set<ResolvedVariantResult>>,
) : Spec<ComponentIdentifier> {

private class State(
val componentIdToVariantResults: Map<ComponentIdentifier, CyclicIterator<ResolvedVariantResult>>,
val selectedVariantResults: Set<ResolvedVariantResult?>,
val selectedVariantResults: Set<ResolvedVariantResult>,
)

private var state: State? = null

private fun getState(): State {
return state ?: run {
val rootComponentResult = rootComponentResultProvider.get()
val imageSpecs = imageSpecsProvider.get()
val rootComponentResult = rootComponentResult.get()
val selectedVariantResults = selectedVariantResults.get()
val componentIdToVariantResults =
rootComponentResult.allComponents.associateByTo(HashMap(), { it.id }) { CyclicIterator(it.variants) }
componentIdToVariantResults[rootComponentResult.id] = CyclicIterator(rootComponentResult.variants.drop(1))
val selectedVariantResults = imageSpecs.flatMapTo(HashSet<ResolvedVariantResult?>()) { it.variants }
val newState = State(componentIdToVariantResults, selectedVariantResults)
state = newState
newState
Expand Down

0 comments on commit dd1fede

Please sign in to comment.