blob: b15b3edbb6fd17178e837b6436b6acd6cfefbf34 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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
}
|