aboutsummaryrefslogtreecommitdiff
path: root/dokka-runners/dokkatoo/modules/dokkatoo-plugin/src/testFixtures/kotlin/systemVariableProviders.kt
diff options
context:
space:
mode:
Diffstat (limited to 'dokka-runners/dokkatoo/modules/dokkatoo-plugin/src/testFixtures/kotlin/systemVariableProviders.kt')
-rw-r--r--dokka-runners/dokkatoo/modules/dokkatoo-plugin/src/testFixtures/kotlin/systemVariableProviders.kt40
1 files changed, 40 insertions, 0 deletions
diff --git a/dokka-runners/dokkatoo/modules/dokkatoo-plugin/src/testFixtures/kotlin/systemVariableProviders.kt b/dokka-runners/dokkatoo/modules/dokkatoo-plugin/src/testFixtures/kotlin/systemVariableProviders.kt
new file mode 100644
index 00000000..b15b3edb
--- /dev/null
+++ b/dokka-runners/dokkatoo/modules/dokkatoo-plugin/src/testFixtures/kotlin/systemVariableProviders.kt
@@ -0,0 +1,40 @@
+package org.jetbrains.dokka.dokkatoo.utils
+
+import kotlin.properties.ReadOnlyProperty
+
+// Utilities for fetching System Properties and Environment Variables via delegated properties
+
+
+internal fun optionalSystemProperty() = optionalSystemProperty { it }
+
+internal fun <T : Any> optionalSystemProperty(
+ convert: (String) -> T?
+): ReadOnlyProperty<Any, T?> =
+ ReadOnlyProperty { _, property ->
+ val value = System.getProperty(property.name)
+ if (value != null) convert(value) else null
+ }
+
+
+internal fun systemProperty() = systemProperty { it }
+
+internal fun <T> systemProperty(
+ convert: (String) -> T
+): ReadOnlyProperty<Any, T> =
+ ReadOnlyProperty { _, property ->
+ val value = requireNotNull(System.getProperty(property.name)) {
+ "system property ${property.name} is unavailable"
+ }
+ convert(value)
+ }
+
+
+internal fun optionalEnvironmentVariable() = optionalEnvironmentVariable { it }
+
+internal fun <T : Any> optionalEnvironmentVariable(
+ convert: (String) -> T?
+): ReadOnlyProperty<Any, T?> =
+ ReadOnlyProperty { _, property ->
+ val value = System.getenv(property.name)
+ if (value != null) convert(value) else null
+ }