:wave: Hello! Is there a way to add a value to a `...
# plugin-development
k
šŸ‘‹ Hello! Is there a way to add a value to a
SetProperty<>
from a provider that may be
Missing
and not have the entire set conclude it is
Missing
?
I worked around this by an ugly hack:
Copy code
internal val subprojectRootsMap: MapProperty<String, Boolean> = objects.mapProperty<String, Boolean>().empty()
  val subprojectRoots = subprojectRootsMap.asTrueSetProvider()

  private fun MapProperty<String, Boolean>.asTrueSetProvider(): Provider<Set<String>> {
    return objects.setProperty<String>()
        .value(this.map { it.filterValues { v -> v }.keys })
        .apply {
          finalizeValueOnRead()
        }
  }
f
Have you considered doing
addAll
with a provider that can never be empty? I.e. your provider that might be empty should map to a singleton set but you can then do
orElse(Set.of())
? Then your set property is never empty due to other providers. I’m going on your initial question, not your workaround.
k
The
addAll(…)
was adding single elements. Of which any could be empty. but it turns out if any are empty the entire collection is empty 😬
f
Yes but if you add non empty provider containing an empty set, it should be fine no?
So each of your elements become singleton sets potentially empty sets, but the provider is never empty
k
Oh, something like:
setProperty.addAll(boolProperty.map { setOfNotNull("foo".takeIf { it } })