Skip to content

Commit

Permalink
Merge pull request #676 from hexagonkt/develop
Browse files Browse the repository at this point in the history
Update dependencies and fix system properties loading
  • Loading branch information
jaguililla committed Dec 7, 2023
2 parents d3f9970 + dfbf058 commit a9bc96d
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 28 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ jobs:
java-version: 21
distribution: graalvm-community
cache: gradle
- run: ./gradlew --stacktrace nativeTest
- run: echo "COMMIT_COUNT=$(git log --oneline --since '24 hours ago' | wc -l)" >> $GITHUB_ENV
- if: ${{ env.COMMIT_COUNT > 0 }}
run: ./gradlew --stacktrace nativeTest

jmh:
uses: hexagonkt/.github/.github/workflows/graalvm_gradle.yml@master
Expand Down
8 changes: 7 additions & 1 deletion core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ application), you can import it with the following code:
```

# Package com.hexagonkt.core
JVM information and other useful utilities.
JVM information and other useful utilities. Includes basic program settings support at the [Jvm]
object (like loading and retrieving system settings).

[Jvm]: /api/core/com.hexagonkt.core/-jvm

# Package com.hexagonkt.core.logging
Provides a logging management capabilities abstracting the application from logging libraries.
Expand All @@ -55,3 +58,6 @@ Media types definitions and constants for default media types.

# Package com.hexagonkt.core.security
Cryptography and key stores utilities.

# Package com.hexagonkt.core.text
Text utilities to allow the use of ANSI escape codes and case converting tools among other features.
14 changes: 7 additions & 7 deletions core/src/main/kotlin/com/hexagonkt/core/Jvm.kt
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,14 @@ object Jvm {
}

/**
* Retrieve a setting by name by looking in the JVM system properties first and in OS
* environment variables if not found.
* Retrieve a setting by name by looking in OS environment variables first and in the JVM system
* properties if not found.
*
* @param type Type of the requested parameter. Supported types are: boolean, int, long, float,
* double and string, throw an error if other type is supplied.
* @param name Name of the searched parameter, can not be blank.
* @return Value of the searched parameter in the requested type, `null` if the parameter is not
* found on the JVM system properties and in OS environment variables.
* found on the OS environment variables or in JVM system properties.
*/
fun <T: Any> systemSettingOrNull(type: KClass<T>, name: String): T? =
systemSettingRaw(name).let { it.parseOrNull(type) }
Expand All @@ -122,8 +122,8 @@ object Jvm {
?: error("Required '${type.simpleName}' system setting '$name' not found")

/**
* Retrieve a flag (boolean parameter) by name by looking in the JVM system properties first and
* in OS environment variables if not found.
* Retrieve a flag (boolean parameter) by name by looking in OS environment variables first and
* in the JVM system properties if not found.
*
* @param name Name of the searched parameter, can not be blank.
* @return True if the parameter is found and its value is exactly 'true', false otherwise.
Expand All @@ -138,7 +138,7 @@ object Jvm {
* double and string, throw an error if other type is supplied.
* @param name Name of the searched parameter, can not be blank.
* @return Value of the searched parameter in the requested type, `null` if the parameter is not
* found on the JVM system properties and in OS environment variables.
* found on the OS environment variables or in JVM system properties.
*/
inline fun <reified T: Any> systemSettingOrNull(name: String): T? =
systemSettingOrNull(T::class, name)
Expand All @@ -149,7 +149,7 @@ object Jvm {
private fun systemSettingRaw(name: String): String? {
val correctName = name.matches(systemSettingPattern)
require(correctName) { "Setting name must match $systemSettingPattern" }
return System.getProperty(name, System.getenv(name))
return System.getenv(name) ?: System.getProperty(name)
}

/** Operating system name ('os.name' property). If `null` throws an exception. */
Expand Down
12 changes: 0 additions & 12 deletions core/src/test/kotlin/com/hexagonkt/core/HelpersTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,6 @@ internal class HelpersTest {
assertEquals("test", "echo test".shell().trim())
}

@Test fun `System setting works ok`() {
System.setProperty("system_property", "value")

assert(Jvm.systemSetting<String>("system_property") == "value")

assert(Jvm.systemSetting<String>("PATH").isNotEmpty())
assertNull(Jvm.systemSettingOrNull<String>("_not_defined_"))

System.setProperty("PATH", "path override")
assert(Jvm.systemSetting<String>("PATH") == "path override")
}

@Test fun `Multiple retry errors throw an exception`() {
val retries = 3
try {
Expand Down
2 changes: 1 addition & 1 deletion core/src/test/kotlin/com/hexagonkt/core/JvmTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ internal class JvmTest {
assertNull(Jvm.systemSettingOrNull<String>("_not_defined_"))

System.setProperty("PATH", "path override")
assert(Jvm.systemSetting<String>("PATH") == "path override")
assert(Jvm.systemSetting<String>("PATH") != "path override")
}

private fun checkOsKind(osName: String, osKind: OsKind) {
Expand Down
10 changes: 4 additions & 6 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ org.gradle.warning.mode=all
org.gradle.console=plain

# Gradle
version=3.4.4
version=3.4.5
group=com.hexagonkt
description=The atoms of your platform

Expand Down Expand Up @@ -50,19 +50,17 @@ helidonVersion=4.0.1

# http_server_servlet
servletVersion=6.0.0
jettyVersion=12.0.3
jettyVersion=12.0.4

# rest_tools
swaggerRequestValidatorVersion=2.39.0

# logging
slf4jVersion=2.0.9
logbackVersion=1.4.12
logbackVersion=1.4.14

# serialization
# TODO
#jacksonVersion=2.16.0
jacksonVersion=2.15.3
jacksonVersion=2.16.0
dslJsonVersion=2.0.2

# templates_freemarker
Expand Down

0 comments on commit a9bc96d

Please sign in to comment.