1
+ /*
2
+ * Copyright 2016-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3
+ */
4
+
5
+ @file:JvmName(" SystemPropsKt" )
6
+ @file:JvmMultifileClass
7
+
8
+ package kotlinx.coroutines.internal
9
+
10
+ import kotlin.jvm.*
11
+
12
+ /* *
13
+ * Gets the system property indicated by the specified [property name][propertyName],
14
+ * or returns [defaultValue] if there is no property with that key.
15
+ *
16
+ * **Note: this function should be used in JVM tests only, other platforms use the default value.**
17
+ */
18
+ internal fun systemProp (
19
+ propertyName : String ,
20
+ defaultValue : Boolean
21
+ ): Boolean = systemProp(propertyName)?.toBoolean() ? : defaultValue
22
+
23
+ /* *
24
+ * Gets the system property indicated by the specified [property name][propertyName],
25
+ * or returns [defaultValue] if there is no property with that key. It also checks that the result
26
+ * is between [minValue] and [maxValue] (inclusively), throws [IllegalStateException] if it is not.
27
+ *
28
+ * **Note: this function should be used in JVM tests only, other platforms use the default value.**
29
+ */
30
+ internal fun systemProp (
31
+ propertyName : String ,
32
+ defaultValue : Int ,
33
+ minValue : Int = 1,
34
+ maxValue : Int = Int .MAX_VALUE
35
+ ): Int = systemProp(propertyName, defaultValue.toLong(), minValue.toLong(), maxValue.toLong()).toInt()
36
+
37
+ /* *
38
+ * Gets the system property indicated by the specified [property name][propertyName],
39
+ * or returns [defaultValue] if there is no property with that key. It also checks that the result
40
+ * is between [minValue] and [maxValue] (inclusively), throws [IllegalStateException] if it is not.
41
+ *
42
+ * **Note: this function should be used in JVM tests only, other platforms use the default value.**
43
+ */
44
+ internal fun systemProp (
45
+ propertyName : String ,
46
+ defaultValue : Long ,
47
+ minValue : Long = 1,
48
+ maxValue : Long = Long .MAX_VALUE
49
+ ): Long {
50
+ val value = systemProp(propertyName) ? : return defaultValue
51
+ val parsed = value.toLongOrNull()
52
+ ? : error(" System property '$propertyName ' has unrecognized value '$value '" )
53
+ if (parsed !in minValue.. maxValue) {
54
+ error(" System property '$propertyName ' should be in range $minValue ..$maxValue , but is '$parsed '" )
55
+ }
56
+ return parsed
57
+ }
58
+
59
+ /* *
60
+ * Gets the system property indicated by the specified [property name][propertyName],
61
+ * or returns `null` if there is no property with that key.
62
+ *
63
+ * **Note: this function should be used in JVM tests only, other platforms use the default value.**
64
+ */
65
+ internal expect fun systemProp (propertyName : String ): String?
0 commit comments