Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move to Kotlin 1.9.10, and related packages. #29

Merged
merged 2 commits into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,13 @@ charset = utf-8
insert_final_newline = true
indent_style = space

[*.{kt,kts}]
max_line_length = 120
ktlint_code_style = intellij_idea

# I find trailing commas annoying
ktlint_standard_trailing-comma-on-call-site = disabled
ktlint_standard_trailing-comma-on-declaration-site = disabled

[pom.xml]
indent_size = 4
15 changes: 11 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,10 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<kotlin.version>1.6.21</kotlin.version>
<kotest.version>4.6.1</kotest.version>
<dokka.version>1.6.21</dokka.version>
<kotlin.version>1.9.10</kotlin.version>
<kotest.version>5.7.2</kotest.version>
<dokka.version>1.9.0</dokka.version>
<mockk.version>1.13.8</mockk.version>
</properties>

<dependencies>
Expand All @@ -82,6 +83,12 @@
<version>${kotest.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.mockk</groupId>
<artifactId>mockk-jvm</artifactId>
<version>${mockk.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down Expand Up @@ -162,7 +169,7 @@
<plugin>
<groupId>com.github.gantsign.maven</groupId>
<artifactId>ktlint-maven-plugin</artifactId>
<version>1.13.1</version>
<version>3.0.0</version>
<configuration>
<sourceRoots>
<sourceRoot>${project.basedir}/src/main/kotlin</sourceRoot>
Expand Down
5 changes: 4 additions & 1 deletion src/main/kotlin/org/jitsi/metaconfig/MapConfigSource.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ class MapConfigSource(
override val name: String,
private val configValues: MutableMap<String, Any> = mutableMapOf()
) : ConfigSource, MutableMap<String, Any> by configValues {
constructor(name: String, mapBuilder: MutableMap<String, Any>.() -> Unit) : this(name, LinkedHashMap<String, Any>().apply(mapBuilder))
constructor(
name: String,
mapBuilder: MutableMap<String, Any>.() -> Unit
) : this(name, LinkedHashMap<String, Any>().apply(mapBuilder))

override fun getterFor(type: KType): (String) -> Any {
return when (type) {
Expand Down
13 changes: 10 additions & 3 deletions src/main/kotlin/org/jitsi/metaconfig/MetaconfigSettings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package org.jitsi.metaconfig
class MetaconfigSettings {
companion object {
val DefaultLogger = NoOpLogger

/**
* A logger for metaconfig to use, if desired. Defaults
* to a no-op implementation
Expand Down Expand Up @@ -55,7 +56,13 @@ val NoOpLogger = object : MetaconfigLogger {
}

val StdOutLogger = object : MetaconfigLogger {
override fun error(block: () -> String) { println("ERROR: ${block()}") }
override fun warn(block: () -> String) { println("WARN: ${block()}") }
override fun debug(block: () -> String) { println("DEBUG: ${block()}") }
override fun error(block: () -> String) {
println("ERROR: ${block()}")
}
override fun warn(block: () -> String) {
println("WARN: ${block()}")
}
override fun debug(block: () -> String) {
println("DEBUG: ${block()}")
}
}
4 changes: 3 additions & 1 deletion src/main/kotlin/org/jitsi/metaconfig/SupplierBuilder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ class SupplierBuilder<T : Any>(val finalType: KType) {
* we need to recreate the underlying supplier to retrieve a different type than was originally inferred (we can
* add support for other suppliers where this makes sense as the need arises).
*/
inline fun <reified RetrieveType : Any> ConfigSourceSupplier<T>.convertFrom(noinline converter: (RetrieveType) -> T): TypeConvertingSupplier<RetrieveType, T> {
inline fun <reified RetrieveType : Any> ConfigSourceSupplier<T>.convertFrom(
noinline converter: (RetrieveType) -> T
): TypeConvertingSupplier<RetrieveType, T> {
suppliers -= this
return TypeConvertingSupplier(
// Re-create the underyling ConfigSourceSupplier, but have it retrieve a different type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,6 @@ class ConditionalSupplier<ValueType : Any>(
override fun withDeprecation(deprecation: Deprecation): LambdaSupplier<ValueType> =
throw Exception("ConditionalSupplier can't be marked as deprecated!")

override fun toString(): String = "${this::class.simpleName}: Enabled only when ${condition.context}: $innerSupplier"
override fun toString(): String =
"${this::class.simpleName}: Enabled only when ${condition.context}: $innerSupplier"
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ class ConfigSourceSupplier<ValueType : Any>(
try {
return (source.getterFor(type)(key) as ValueType).also {
MetaconfigSettings.logger.debug {
"${this::class.simpleName}: Found value $it for key '$key' from source '${source.name}' as type $type"
"${this::class.simpleName}: Found value $it for key '$key' from source '${source.name}' " +
"as type $type"
}
if (deprecation is Deprecation.Deprecated.Soft && !deprecationWarningLogged) {
MetaconfigSettings.logger.warn {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ class ConfigSourceSupplierTest : ShouldSpec({
noDeprecation()
)
context("when the property isn't present") {
every { configSource.getterFor(typeOf<Int>()) } throws ConfigException.UnableToRetrieve.NotFound("not found")
every { configSource.getterFor(typeOf<Int>()) } throws
ConfigException.UnableToRetrieve.NotFound("not found")
shouldThrow<ConfigException.UnableToRetrieve.NotFound> {
css.get()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ class ConfigValueSupplierTest : ShouldSpec({
context("marked as soft deprecated") {
context("that finds a value") {
val s = ConfigSourceSupplier<Int>(
"new.num", config, typeOf<Int>(), softDeprecation("deprecated")
"new.num",
config,
typeOf<Int>(),
softDeprecation("deprecated")
)
should("log a warning") {
s.get() shouldBe 42
Expand All @@ -90,7 +93,10 @@ class ConfigValueSupplierTest : ShouldSpec({
}
context("that doesn't find a value") {
val s = ConfigSourceSupplier<Int>(
"missing.num", config, typeOf<Int>(), softDeprecation("deprecated")
"missing.num",
config,
typeOf<Int>(),
softDeprecation("deprecated")
)
should("not log a warning") {
shouldThrow<ConfigException.UnableToRetrieve.NotFound> {
Expand All @@ -105,7 +111,10 @@ class ConfigValueSupplierTest : ShouldSpec({
context("marked as hard deprecated") {
context("that finds a value") {
val s = ConfigSourceSupplier<Int>(
"new.num", config, typeOf<Int>(), hardDeprecation("deprecated")
"new.num",
config,
typeOf<Int>(),
hardDeprecation("deprecated")
)
should("throw an exception") {
val ex = shouldThrow<ConfigException.UnableToRetrieve.Deprecated> {
Expand All @@ -116,7 +125,10 @@ class ConfigValueSupplierTest : ShouldSpec({
}
context("that doesn't find a value") {
val s = ConfigSourceSupplier<Int>(
"missing.num", config, typeOf<Int>(), hardDeprecation("deprecated")
"missing.num",
config,
typeOf<Int>(),
hardDeprecation("deprecated")
)
should("throw the UnableToRetrieve exception") {
shouldThrow<ConfigException.UnableToRetrieve.NotFound> {
Expand Down
Loading