Skip to content

Commit

Permalink
chore: More cleaning. Upgrade workflows.
Browse files Browse the repository at this point in the history
  • Loading branch information
nhubbard committed Feb 10, 2024
1 parent b2f3c98 commit 98893bc
Show file tree
Hide file tree
Showing 43 changed files with 289 additions and 207 deletions.
22 changes: 12 additions & 10 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
name: Konf CI

on: [push]
on: [ push ]

jobs:
build:
name: Build on JDK ${{ matrix.java_version }} and ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
java_version: [8, 11, 16]
os: [ubuntu-latest, windows-latest, macOS-latest]
java_version: [ 8, 11, 17, 21 ]
os: [ ubuntu-latest, windows-latest, macOS-latest ]

steps:
- uses: actions/checkout@v2
- name: Set up JDK ${{ matrix.java_version }}
uses: actions/setup-java@v1
with:
java-version: ${{ matrix.java_version }}
- name: Build with Gradle
run: ./gradlew build
- uses: actions/checkout@v2
- name: Set up JDK ${{ matrix.java_version }}
uses: actions/setup-java@v1
with:
java-version: ${{ matrix.java_version }}
- name: Build with Gradle
run: ./gradlew build
- name: Test with Gradle
run: ./gradlew test
8 changes: 5 additions & 3 deletions src/main/kotlin/com/moandjiezana/toml/Toml4jWriter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,16 @@ import java.util.regex.Pattern
* are output to TOML tables, and {@link List}s and Array to TOML arrays.</p>
*
* <p>Example usage:</p>
* <pre><code>
* <pre>
* <code>
* class AClass {
* int anInt = 1;
* int[] anArray = { 2, 3 };
* }
*
* String tomlString = new TomlWriter().write(new AClass());
* </code></pre>
* </code>
* </pre>
*/
class Toml4jWriter {
/**
Expand Down Expand Up @@ -211,7 +213,7 @@ internal object NewMapValueWriter : ValueWriter {
}
}

// Render primitive types and arrays of primitive first so they are
// Render primitive types and arrays of primitive first, so they are
// grouped under the same table (if there is one)
for ((key, value1) in from) {
if (value1 == null) continue
Expand Down
8 changes: 4 additions & 4 deletions src/main/kotlin/com/nhubbard/konfig/BaseConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -406,13 +406,13 @@ open class BaseConfig(
if (value == null) {
if (item.nullable) {
item.notifySet(null)
item.notifyBeforeSet(this, value)
notifyBeforeSet(item, value)
item.notifyBeforeSet(this, null)
notifyBeforeSet(item, null)
lock.write {
setState(item, ValueState.Null)
}
notifyAfterSet(item, value)
item.notifyAfterSet(this, value)
notifyAfterSet(item, null)
item.notifyAfterSet(this, null)
} else {
throw ClassCastException(
"fail to cast null to ${item.type.rawClass}" +
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/com/nhubbard/konfig/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ internal fun getUnits(s: String): String {
/**
* Returns default value if string is empty, original string otherwise.
*/
fun String.notEmptyOr(default: String): String = if (isEmpty()) default else this
fun String.notEmptyOr(default: String): String = ifEmpty { default }

fun String.toLittleCase(): String {
return if (this.all { it.isUpperCase() }) {
Expand Down
56 changes: 28 additions & 28 deletions src/main/kotlin/com/nhubbard/konfig/source/DefaultLoaders.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import kotlin.coroutines.CoroutineContext
/**
* Default loaders for config.
*
* If [transform] is provided, source will be applied the given [transform] function when loaded.
* If [transform] is provided, the source will be applied to the given [transform] function when loaded.
*
* @param config parent config for loader
* @param transform the given transformation function
Expand All @@ -57,7 +57,7 @@ class DefaultLoaders(
private fun Source.orMapped(): Source = transform?.invoke(this) ?: this

/**
* Returns default loaders applied the given [transform] function.
* Return the default loaders applied to the given [transform] function.
*
* @param transform the given transformation function
* @return the default loaders applied the given [transform] function
Expand All @@ -75,10 +75,10 @@ class DefaultLoaders(
fun prefixed(prefix: String): DefaultLoaders = mapped { it.withPrefix(prefix) }

/**
* Returns default loaders where sources are scoped in specified path.
* Returns default loaders where sources are scoped in the specified path.
*
* @param path path that is the scope of sources
* @return the default loaders where sources are scoped in specified path
* @return the default loaders where sources are scoped in the specified path
*/
fun scoped(path: String): DefaultLoaders = mapped { it[path] }

Expand All @@ -93,13 +93,13 @@ class DefaultLoaders(
val json = Loader(config, JsonProvider.orMapped())

/**
* Loader for properties source.
* Loader for the properties source.
*/
@JvmField
val properties = Loader(config, PropertiesProvider.orMapped())

/**
* Loader for map source.
* Loader for the map source.
*/
@JvmField
val map = MapLoader(config, transform)
Expand Down Expand Up @@ -132,11 +132,11 @@ class DefaultLoaders(
fun systemProperties(): Config = config.withSource(PropertiesProvider.system().orMapped())

/**
* Returns corresponding loader based on extension.
* Returns the corresponding loader based on the provided extension.
*
* @param extension the file extension
* @param source the source description for error message
* @return the corresponding loader based on extension
* @return the corresponding loader based on the provided extension
*/
fun dispatchExtension(extension: String, source: String = ""): Loader =
Loader(
Expand All @@ -148,7 +148,7 @@ class DefaultLoaders(
/**
* Returns a child config containing values from specified file.
*
* Format of the file is auto-detected from the file extension.
* The format of the file is auto-detected from the file extension.
* Supported file formats and the corresponding extensions:
* - HOCON: conf
* - JSON: json
Expand All @@ -167,9 +167,9 @@ class DefaultLoaders(
fun file(file: File, optional: Boolean = this.optional): Config = dispatchExtension(file.extension, file.name).file(file, optional)

/**
* Returns a child config containing values from specified file path.
* Returns a child config containing values from the specified file path.
*
* Format of the file is auto-detected from the file extension.
* The format of the file is auto-detected from the file extension.
* Supported file formats and the corresponding extensions:
* - HOCON: conf
* - JSON: json
Expand All @@ -182,7 +182,7 @@ class DefaultLoaders(
*
* @param file specified file path
* @param optional whether the source is optional
* @return a child config containing values from specified file path
* @return a child config containing values from the specified file path
* @throws UnsupportedExtensionException
*/
fun file(file: String, optional: Boolean = this.optional): Config = file(File(file), optional)
Expand All @@ -191,7 +191,7 @@ class DefaultLoaders(
* Returns a child config containing values from specified file,
* and reloads values when file content has been changed.
*
* Format of the file is auto-detected from the file extension.
* The format of the file is auto-detected from the file extension.
* Supported file formats and the corresponding extensions:
* - HOCON: conf
* - JSON: json
Expand Down Expand Up @@ -222,10 +222,10 @@ class DefaultLoaders(
.watchFile(file, delayTime, unit, context, optional, onLoad)

/**
* Returns a child config containing values from specified file path,
* Returns a child config containing values from the specified file path,
* and reloads values when file content has been changed.
*
* Format of the file is auto-detected from the file extension.
* The format of the file is auto-detected from the file extension.
* Supported file formats and the corresponding extensions:
* - HOCON: conf
* - JSON: json
Expand Down Expand Up @@ -257,7 +257,7 @@ class DefaultLoaders(
/**
* Returns a child config containing values from specified url.
*
* Format of the url is auto-detected from the url extension.
* The format of the url is auto-detected from the url extension.
* Supported url formats and the corresponding extensions:
* - HOCON: conf
* - JSON: json
Expand All @@ -278,7 +278,7 @@ class DefaultLoaders(
/**
* Returns a child config containing values from specified url string.
*
* Format of the url is auto-detected from the url extension.
* The format of the url is auto-detected from the url extension.
* Supported url formats and the corresponding extensions:
* - HOCON: conf
* - JSON: json
Expand All @@ -300,7 +300,7 @@ class DefaultLoaders(
* Returns a child config containing values from specified url,
* and reloads values periodically.
*
* Format of the url is auto-detected from the url extension.
* The format of the url is auto-detected from the url extension.
* Supported url formats and the corresponding extensions:
* - HOCON: conf
* - JSON: json
Expand Down Expand Up @@ -334,7 +334,7 @@ class DefaultLoaders(
* Returns a child config containing values from specified url string,
* and reloads values periodically.
*
* Format of the url is auto-detected from the url extension.
* The format of the url is auto-detected from the url extension.
* Supported url formats and the corresponding extensions:
* - HOCON: conf
* - JSON: json
Expand Down Expand Up @@ -365,15 +365,15 @@ class DefaultLoaders(
}

/**
* Loader to load source from map of variant formats.
* Loader to load source from the map of variant formats.
*
* If [transform] is provided, source will be applied the given [transform] function when loaded.
* If [transform] is provided, the source will be applied to the given [transform] function when loaded.
*
* @param config parent config
*/
class MapLoader(
/**
* Parent config for all child configs loading source in this loader.
* Parent config for all child configs loading the source in this loader.
*/
val config: Config,
/**
Expand All @@ -384,26 +384,26 @@ class MapLoader(
private fun Source.orMapped(): Source = transform?.invoke(this) ?: this

/**
* Returns a child config containing values from specified hierarchical map.
* Returns a child config containing values from the specified hierarchical map.
*
* @param map a hierarchical map
* @return a child config containing values from specified hierarchical map
* @return a child config containing values from the specified hierarchical map
*/
fun hierarchical(map: Map<String, Any>): Config = config.withSource(MapSource(map).orMapped())

/**
* Returns a child config containing values from specified map in key-value format.
* Returns a child config containing values from the specified map in key-value format.
*
* @param map a map in key-value format
* @return a child config containing values from specified map in key-value format
* @return a child config containing values from the specified map in key-value format
*/
fun kv(map: Map<String, Any>): Config = config.withSource(KVSource(map).orMapped())

/**
* Returns a child config containing values from specified map in flat format.
* Returns a child config containing values from the specified map in flat format.
*
* @param map a map in flat format
* @return a child config containing values from specified map in flat format
* @return a child config containing values from the specified map in flat format
*/
fun flat(map: Map<String, String>): Config = config.withSource(FlatSource(map).orMapped())
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ fun DefaultLoaders.git(
* Returns a child config containing values from a specified git repository,
* and reloads values periodically.
*
* Format of the url is auto-detected from the url extension.
* The format of the url is auto-detected from the url extension.
* Supported url formats and the corresponding extensions:
* - HOCON: conf
* - JSON: json
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import java.io.File
/**
* Returns a source from a specified git repository.
*
* Format of the url is auto-detected from the url extension.
* The format of the url is auto-detected from the url extension.
* Supported url formats and the corresponding extensions:
* - HOCON: conf
* - JSON: json
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ fun Loader.git(
* @param dir local directory of the git repository
* @param branch the initial branch
* @param period reload period. The default value is 1.
* @param unit time unit of reload period. The default value is [TimeUnit.MINUTES].
* @param unit time unit of the reload period. The default value is [TimeUnit.MINUTES].
* @param context context of the coroutine. The default value is [Dispatchers.Default].
* @param optional whether the source is optional
* @param onLoad function invoked after the updated git file is loaded
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package com.nhubbard.konfig.source.js

import com.nhubbard.konfig.source.DefaultLoaders
import com.nhubbard.konfig.source.Loader
import com.nhubbard.konfig.source.js.JsProvider

/**
* Loader for JavaScript source.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
package com.nhubbard.konfig.source.js

import com.nhubbard.konfig.source.DefaultProviders
import com.nhubbard.konfig.source.js.JsProvider

/**
* Provider for JavaScript source.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ package com.nhubbard.konfig.source.toml
import com.nhubbard.konfig.source.DefaultProviders

/**
* Provider for TOML source.
* Provider for the TOML source.
*/
val DefaultProviders.toml get() = TomlProvider
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ package com.nhubbard.konfig.source.xml
import com.nhubbard.konfig.source.DefaultProviders

/**
* Provider for XML source.
* Provider for the XML source.
*/
val DefaultProviders.xml get() = XmlProvider
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import org.yaml.snakeyaml.constructor.SafeConstructor
import org.yaml.snakeyaml.nodes.Node
import org.yaml.snakeyaml.nodes.ScalarNode
import org.yaml.snakeyaml.nodes.Tag
import java.io.Closeable
import java.io.InputStream
import java.io.Reader

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@

import com.nhubbard.konfig.Config;

@SuppressWarnings("unused")
public class ServerInJava {
private String host;
private Integer tcpPort;
private final String host;
private final Integer tcpPort;

public ServerInJava(String host, Integer tcpPort) {
this.host = host;
Expand Down
2 changes: 1 addition & 1 deletion src/snippet/kotlin/com/nhubbard/konfig/snippet/Fork.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ fun main() {
config[Server.tcpPort] = 1000
// fork from parent config
val childConfig = config.withLayer("child")
// child config inherit values from parent config
// The child config inherits values from parent config
check(childConfig[Server.tcpPort] == 1000)
// modifications in parent config affect values in child config
config[Server.tcpPort] = 2000
Expand Down
2 changes: 1 addition & 1 deletion src/snippet/kotlin/com/nhubbard/konfig/snippet/Load.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import com.nhubbard.konfig.Config

fun main() {
val config = Config { addSpec(Server) }
// values in source is loaded into new layer in child config
// The values in the source are loaded into new layer in child config
val childConfig = config.from.env()
check(childConfig.parent === config)
}
2 changes: 2 additions & 0 deletions src/snippet/kotlin/com/nhubbard/konfig/snippet/Server.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
* limitations under the License.
*/

@file:Suppress("unused")

package com.nhubbard.konfig.snippet

import com.nhubbard.konfig.Config
Expand Down
Loading

0 comments on commit 98893bc

Please sign in to comment.