Skip to content

Commit

Permalink
Pass the version selector callback as a property
Browse files Browse the repository at this point in the history
Fixes #149
  • Loading branch information
hvisser committed Oct 16, 2024
1 parent 32f7d9b commit 30c29ee
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,21 @@ import nl.littlerobots.vcu.model.VersionCatalog
import nl.littlerobots.vcu.model.VersionDefinition
import nl.littlerobots.vcu.plugin.resolver.DependencyResolver
import nl.littlerobots.vcu.plugin.resolver.DependencyResolverResult
import nl.littlerobots.vcu.plugin.resolver.ModuleVersionCandidate
import nl.littlerobots.vcu.plugin.resolver.ModuleVersionSelector
import org.gradle.api.model.ObjectFactory
import org.gradle.api.provider.Property
import org.gradle.api.tasks.Internal
import org.gradle.api.tasks.TaskAction
import javax.inject.Inject

abstract class ExperimentalVersionCatalogUpdateTask @Inject constructor(private val objectFactory: ObjectFactory) :
BaseVersionCatalogUpdateTask() {
private lateinit var result: DependencyResolverResult
private var versionSelector: ModuleVersionSelector = object : ModuleVersionSelector {
override fun select(candidate: ModuleVersionCandidate): Boolean {
return true
}
}
@get:Internal
internal abstract val versionSelector: Property<ModuleVersionSelector>

fun versionSelector(filter: ModuleVersionSelector) {
this.versionSelector = filter
versionSelector.set(filter)
}

override fun onVersionCatalogUpdated(updatedCatalog: VersionCatalog, currentCatalog: VersionCatalog) {
Expand Down Expand Up @@ -188,7 +186,7 @@ abstract class ExperimentalVersionCatalogUpdateTask @Inject constructor(private
project.buildscript.configurations.detachedConfiguration(),
project.dependencies,
currentCatalog,
versionSelector
versionSelector.get()
)
this.result = result
return result.versionCatalog
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import org.gradle.api.Project
import org.gradle.api.artifacts.MinimalExternalModuleDependency
import org.gradle.api.artifacts.ModuleIdentifier
import org.gradle.api.file.RegularFileProperty
import org.gradle.api.model.ObjectFactory
import org.gradle.api.provider.Property
import org.gradle.api.provider.Provider
import org.gradle.api.provider.SetProperty
Expand All @@ -34,7 +35,7 @@ import org.gradle.plugin.use.PluginDependency
import java.io.Serializable
import javax.inject.Inject

abstract class VersionCatalogUpdateExtension {
abstract class VersionCatalogUpdateExtension @Inject constructor(private val objectFactory: ObjectFactory) {
@get:Optional
abstract val sortByKey: Property<Boolean>

Expand All @@ -51,10 +52,10 @@ abstract class VersionCatalogUpdateExtension {
abstract val versionCatalogs: NamedDomainObjectContainer<VersionCatalogConfig>

@get:Optional
internal abstract var versionSelector: ModuleVersionSelector?
internal abstract val versionSelector: Property<ModuleVersionSelector>

fun versionSelector(selector: ModuleVersionSelector) {
this.versionSelector = selector
versionSelector.set(selector)
}

fun pin(action: Action<PinConfiguration>) {
Expand Down Expand Up @@ -89,10 +90,10 @@ abstract class VersionCatalogConfig @Inject constructor(val name: String) {
abstract val keep: KeepConfiguration

@get:Optional
internal abstract var versionSelector: ModuleVersionSelector?
internal abstract val versionSelector: Property<ModuleVersionSelector>

fun versionSelector(selector: ModuleVersionSelector) {
this.versionSelector = selector
versionSelector.set(selector)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ class VersionCatalogUpdatePlugin : Plugin<Project> {
task.catalogFile.set(versionCatalogConfig.catalogFile.asFile)
task.notCompatibleWithConfigurationCache("Uses project")
task.outputs.upToDateWhen { false }
val versionSelector = versionCatalogConfig.versionSelector ?: extension.versionSelector ?: VersionSelectors.PREFER_STABLE
task.versionSelector(versionSelector)
val versionSelector = versionCatalogConfig.versionSelector.orElse(extension.versionSelector).orElse(VersionSelectors.PREFER_STABLE)
task.versionSelector.set(versionSelector)
}
}

Expand Down

0 comments on commit 30c29ee

Please sign in to comment.