Skip to content

Commit d22e212

Browse files
RBusarowkodiakhq[bot]
authored andcommitted
make Gradle property version argument parsing friendly to lists
1 parent f58b7c7 commit d22e212

4 files changed

Lines changed: 8 additions & 84 deletions

File tree

build-logic/core/src/main/kotlin/modulecheck/builds/BaseYamlMatrixTask.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2021-2023 Rick Busarow
2+
* Copyright (C) 2021-2024 Rick Busarow
33
* Licensed under the Apache License, Version 2.0 (the "License");
44
* you may not use this file except in compliance with the License.
55
* You may obtain a copy of the License at
@@ -40,11 +40,11 @@ abstract class BaseYamlMatrixTask @Inject constructor(
4040

4141
@get:Input abstract val startTagProperty: Property<String>
4242
private val startTag: String
43-
get() = startTagProperty.getFinal()
43+
get() = startTagProperty.get()
4444

4545
@get:Input abstract val endTagProperty: Property<String>
4646
private val endTag: String
47-
get() = endTagProperty.getFinal()
47+
get() = endTagProperty.get()
4848

4949
@get:Internal
5050
protected val matrixSectionRegex by lazy(NONE) {
Lines changed: 1 addition & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2021-2023 Rick Busarow
2+
* Copyright (C) 2021-2024 Rick Busarow
33
* Licensed under the Apache License, Version 2.0 (the "License");
44
* you may not use this file except in compliance with the License.
55
* You may obtain a copy of the License at
@@ -15,87 +15,10 @@
1515

1616
package modulecheck.builds
1717

18-
import org.gradle.api.Project
19-
import org.gradle.api.model.ObjectFactory
2018
import org.gradle.api.provider.Property
21-
import org.gradle.api.provider.Provider
22-
import kotlin.properties.ReadWriteProperty
23-
import kotlin.reflect.KProperty
24-
25-
inline fun <reified T : Any> ObjectFactory.property(
26-
initialValue: T,
27-
crossinline onSet: (T) -> Unit
28-
): ReadWriteProperty<Any, T> = object : ReadWriteProperty<Any, T> {
29-
30-
val delegate = property(T::class.java).convention(initialValue)
31-
32-
override fun getValue(thisRef: Any, property: KProperty<*>): T {
33-
// return delegate.get()
34-
return delegate.getFinal()
35-
}
36-
37-
override fun setValue(thisRef: Any, property: KProperty<*>, value: T) {
38-
// delegate.set(value)
39-
delegate.setFinal(value)
40-
onSet(value)
41-
}
42-
}
43-
44-
inline fun <reified T> ObjectFactory.optionalProperty(
45-
crossinline onSet: (T) -> Unit
46-
): ReadWriteProperty<Any, T?> = object : ReadWriteProperty<Any, T?> {
47-
48-
val delegate = property(T::class.java)
49-
50-
override fun getValue(thisRef: Any, property: KProperty<*>): T? {
51-
return delegate.orNull
52-
// return delegate.getFinal()
53-
}
54-
55-
override fun setValue(thisRef: Any, property: KProperty<*>, value: T?) {
56-
// delegate.set(value)
57-
delegate.setFinal(value)
58-
if (value != null) {
59-
onSet(value)
60-
}
61-
}
62-
}
63-
64-
fun <T> Property<T>.getOrNullFinal(): T? {
65-
finalizeValueOnRead()
66-
disallowChanges()
67-
return orNull
68-
}
6919

7020
fun <T> Property<T>.getFinal(): T {
7121
finalizeValueOnRead()
7222
disallowChanges()
7323
return get()
7424
}
75-
76-
@PublishedApi
77-
internal fun <T> Property<T>.setFinal(value: T) {
78-
set(value)
79-
disallowUnsafeRead()
80-
disallowChanges()
81-
}
82-
83-
fun <T> Project.propertyNamed(name: String): T {
84-
return requireNotNull(findPropertyNamed(name))
85-
}
86-
87-
fun <T> Project.findPropertyNamed(name: String): T? {
88-
@Suppress("UNCHECKED_CAST")
89-
return findProperty(name) as? T
90-
}
91-
92-
fun <T> Project.gradlePropertyAsProvider(name: String): Provider<T?> {
93-
return provider { findPropertyNamed(name) }
94-
}
95-
96-
inline fun <T, R> Project.gradlePropertyAsProvider(
97-
name: String,
98-
crossinline transform: (T?) -> R
99-
): Provider<R?> {
100-
return provider { transform(findPropertyNamed(name)) }
101-
}

build-logic/versions-matrix/src/main/kotlin/modulecheck/builds/matrix/VersionsMatrixExtension.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import com.rickbusarow.kgx.listProperty
2121
import com.rickbusarow.kgx.pluginId
2222
import com.rickbusarow.kgx.propertyOrNull
2323
import com.rickbusarow.kgx.version
24-
import modulecheck.builds.gradlePropertyAsProvider
2524
import org.gradle.api.Project
2625
import org.gradle.api.provider.ListProperty
2726
import org.gradle.kotlin.dsl.buildConfigField
@@ -51,7 +50,9 @@ open class Versions @Inject constructor(
5150
propertyName: String,
5251
default: List<String>
5352
): ListProperty<String> = convention(
54-
target.gradlePropertyAsProvider<List<String>>(propertyName).orElse(default)
53+
target.providers.gradleProperty(propertyName)
54+
.map { it.split("""\s*,\s*""".toRegex()) }
55+
.orElse(default)
5556
)
5657
}
5758

modulecheck-internal-testing/src/main/kotlin/modulecheck/testing/BaseTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import java.io.File
3232
interface BaseTest :
3333
HasTestEnvironmentFactory<DefaultTestEnvironment.Factory>,
3434
TrimmedAsserts {
35-
override val testEnvironmentFactory
35+
override val testEnvironmentFactory: DefaultTestEnvironment.Factory
3636
get() = DefaultTestEnvironment.Factory()
3737

3838
/** shorthand for executing a test in a hermetic TestEnvironment but without any kase parameters */

0 commit comments

Comments
 (0)