-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement shared properties mechanism
- Loading branch information
Showing
8 changed files
with
73 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
airin-core/src/jvmMain/kotlin/io/morfly/airin/SharedPropertiesHolder.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package io.morfly.airin | ||
|
||
interface SharedPropertiesHolder { | ||
|
||
val sharedProperties: MutableMap<String, Any?> | ||
|
||
val sharedPropertiesAvailable: Boolean | ||
} | ||
|
||
//@Suppress("UNCHECKED_CAST") | ||
//val MutableMap<String, Any?>.allMavenArtifacts: MutableSet<MavenCoordinates> | ||
// get() { | ||
// val artifacts = getOrPut("allMavenArtifacts") { mutableSetOf<MavenCoordinates>() } | ||
// return artifacts as MutableSet<MavenCoordinates> | ||
// } |
32 changes: 32 additions & 0 deletions
32
airin-core/src/jvmMain/kotlin/io/morfly/airin/SharedPropertyDelegate.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package io.morfly.airin | ||
|
||
import java.io.Serializable | ||
import kotlin.reflect.KProperty | ||
|
||
class SharedPropertyDelegate<V : Any>(val defaultValue: V) : Serializable { | ||
|
||
operator fun provideDelegate( | ||
holder: SharedPropertiesHolder, property: KProperty<*> | ||
): SharedPropertyDelegate<V> = this | ||
|
||
operator fun getValue(holder: SharedPropertiesHolder, property: KProperty<*>): V { | ||
validate(holder, property.name) | ||
@Suppress("UNCHECKED_CAST") | ||
return holder.sharedProperties.getOrPut(property.name) { defaultValue } as V | ||
} | ||
|
||
operator fun setValue(holder: SharedPropertiesHolder, property: KProperty<*>, value: V) { | ||
validate(holder, property.name) | ||
holder.sharedProperties[property.name] = value | ||
} | ||
|
||
private fun validate(holder: SharedPropertiesHolder, property: String) { | ||
require(holder.sharedPropertiesAvailable) { | ||
"Shared property $property is not available during build configuration phase!" | ||
} | ||
} | ||
} | ||
|
||
fun <V : Any> SharedPropertiesHolder.sharedProperty(default: V): SharedPropertyDelegate<V> { | ||
return SharedPropertyDelegate(default) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters