Skip to content

Commit 926cab5

Browse files
authored
Kotlin: replace ini4j with apache-commons-configuration (#1387)
1 parent 5407e63 commit 926cab5

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

kotlin/build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ dependencies {
2929
implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion"
3030

3131
implementation "io.github.cdimascio:dotenv-kotlin:6.2.2"
32-
implementation "org.ini4j:ini4j:0.5.4"
32+
33+
implementation "commons-configuration:commons-configuration:1.10"
3334

3435
implementation "com.google.http-client:google-http-client:$googleHttpVersion"
3536
implementation "com.google.http-client:google-http-client-apache-v2:$googleHttpVersion"

kotlin/src/main/com/looker/sdk/ApiSettings.kt

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ import com.looker.rtl.DEFAULT_HTTP_TRANSPORT
2929
import com.looker.rtl.DEFAULT_TIMEOUT
3030
import com.looker.rtl.asBoolean
3131
import com.looker.rtl.unQuote
32-
import org.ini4j.Ini
33-
import java.io.ByteArrayInputStream
32+
import org.apache.commons.configuration.HierarchicalINIConfiguration
3433
import java.io.File
34+
import java.io.StringReader
3535

3636
/** Structure read from an .INI file */
3737
typealias ApiSections = Map<String, Map<String, String>>
@@ -40,14 +40,20 @@ typealias ApiSections = Map<String, Map<String, String>>
4040
* Parse and cleanup something that looks like an .INI file, stripping outermost quotes for values
4141
*/
4242
fun apiConfig(contents: String): ApiSections {
43-
val iniParser = Ini(ByteArrayInputStream(contents.toByteArray()))
44-
45-
val ret = mutableMapOf<String, Map<String, String>>()
46-
iniParser.forEach { (section, values) ->
47-
ret[section] = values.map { it.key to unQuote(it.value) }.toMap()
43+
val iniParser = HierarchicalINIConfiguration()
44+
iniParser.load(StringReader(contents))
45+
46+
return mutableMapOf<String, Map<String, String>>().also { mapToReturn ->
47+
iniParser.sections.forEach { section ->
48+
mapToReturn[section] = mutableMapOf<String, String>().also { sectionMap ->
49+
iniParser.getKeys(section).forEach { key ->
50+
// `key` is fully scoped (e.g. `Looker.<key>`) but we just want the key so
51+
// remove the section prefix before adding to the map.
52+
sectionMap[key.removePrefix("$section.")] = unQuote(iniParser.getString(key))
53+
}
54+
}
55+
}
4856
}
49-
50-
return ret
5157
}
5258

5359
// TODO why no @JvmOverloads here?

0 commit comments

Comments
 (0)