Skip to content

Commit

Permalink
Merge pull request #693 from hexagonkt/develop
Browse files Browse the repository at this point in the history
Improve OpenAPI filter and logging modules removal
  • Loading branch information
jaguililla committed Feb 28, 2024
2 parents 897071b + a990185 commit 830a9ec
Show file tree
Hide file tree
Showing 95 changed files with 520 additions and 2,504 deletions.
2 changes: 1 addition & 1 deletion .sdkmanrc
@@ -1,3 +1,3 @@
# Enable auto-env through the sdkman_auto_env config
# Add key=value pairs of SDKs to use below
java=21.0.1-graalce
java=21.0.2-graalce
10 changes: 6 additions & 4 deletions build.gradle.kts
Expand Up @@ -25,9 +25,9 @@ plugins {
id("project-report")
id("org.jetbrains.dokka") version("1.9.10")
id("com.github.jk1.dependency-license-report") version("2.5")
id("org.jetbrains.kotlinx.binary-compatibility-validator") version("0.13.2")
id("org.graalvm.buildtools.native") version("0.9.28") apply(false)
id("io.gitlab.arturbosch.detekt") version("1.23.4") apply(false)
id("org.jetbrains.kotlinx.binary-compatibility-validator") version("0.14.0")
id("org.graalvm.buildtools.native") version("0.10.1") apply(false)
id("io.gitlab.arturbosch.detekt") version("1.23.5") apply(false)
id("me.champeau.jmh") version("0.7.2") apply(false)
}

Expand Down Expand Up @@ -140,7 +140,7 @@ gradle.taskGraph.whenReady(closureOf<TaskExecutionGraph> {
})

tasks.wrapper {
gradleVersion = "8.5"
gradleVersion = "8.6"
distributionType = ALL
}

Expand All @@ -159,6 +159,8 @@ apiValidation {
// Experimental modules
"rest",
"rest_tools",
// "serverless_http",
// "serverless_http_google",
"web",
"templates_jte",
)
Expand Down
10 changes: 2 additions & 8 deletions core/README.md
Expand Up @@ -42,16 +42,10 @@ The following code block shows the most common use cases for the [Logger] class:

@code core/src/test/kotlin/com/hexagonkt/core/logging/LoggerTest.kt?logger

By default, Hexagon uses the [Java Util Logging] logging library, you can use any of its
implementations by just adding another logging adapter as a dependency. Below you can see some
alternatives:

* [Logback](/logging_logback)
* [SLF4J JUL](/logging_slf4j_jul)
By default, Hexagon uses the [System.Logger] class.

[Logger]: /api/core/com.hexagonkt.core.logging/-logger
[Java Util Logging]:
https://docs.oracle.com/javase/8/docs/api/java/util/logging/package-summary.html
[System.Logger]: https://docs.oracle.com/javase/9/docs/api/java/lang/System.Logger.html

# Package com.hexagonkt.core.media
Media types definitions and constants for default media types.
Expand Down
68 changes: 7 additions & 61 deletions core/api/core.api
Expand Up @@ -157,10 +157,10 @@ public final class com/hexagonkt/core/Jvm {
public final fun getVersion ()Ljava/lang/String;
public final fun getZoneId ()Ljava/time/ZoneId;
public final fun isConsole ()Z
public final fun loadSystemSettings (Ljava/util/Map;Z)V
public static synthetic fun loadSystemSettings$default (Lcom/hexagonkt/core/Jvm;Ljava/util/Map;ZILjava/lang/Object;)V
public final fun loadSystemSettings (Ljava/util/Map;)V
public final fun systemFlag (Ljava/lang/String;)Z
public final fun systemSetting (Lkotlin/reflect/KClass;Ljava/lang/String;)Ljava/lang/Object;
public final fun systemSetting (Lkotlin/reflect/KClass;Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object;
public final fun systemSettingOrNull (Lkotlin/reflect/KClass;Ljava/lang/String;)Ljava/lang/Object;
public final fun totalMemory ()Ljava/lang/String;
public final fun usedMemory ()Ljava/lang/String;
Expand Down Expand Up @@ -220,34 +220,24 @@ public final class com/hexagonkt/core/UuidsKt {
}

public final class com/hexagonkt/core/logging/Logger {
public fun <init> (Ljava/lang/String;)V
public fun <init> (Ljava/lang/String;Ljava/lang/System$Logger;)V
public synthetic fun <init> (Ljava/lang/String;Ljava/lang/System$Logger;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun <init> (Lkotlin/reflect/KClass;)V
public final fun debug (Lkotlin/jvm/functions/Function0;)V
public final fun error (Ljava/lang/Throwable;Lkotlin/jvm/functions/Function1;)V
public final fun error (Lkotlin/jvm/functions/Function0;)V
public static synthetic fun error$default (Lcom/hexagonkt/core/logging/Logger;Ljava/lang/Throwable;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)V
public final fun getName ()Ljava/lang/String;
public final fun info (Lkotlin/jvm/functions/Function0;)V
public final fun isDebugEnabled ()Z
public final fun isErrorEnabled ()Z
public final fun isInfoEnabled ()Z
public final fun isLoggerLevelEnabled (Lcom/hexagonkt/core/logging/LoggingLevel;)Z
public final fun isTraceEnabled ()Z
public final fun isWarnEnabled ()Z
public final fun log (Lcom/hexagonkt/core/logging/LoggingLevel;Ljava/lang/Throwable;Lkotlin/jvm/functions/Function1;)V
public final fun log (Lcom/hexagonkt/core/logging/LoggingLevel;Lkotlin/jvm/functions/Function0;)V
public final fun setLoggerLevel (Lcom/hexagonkt/core/logging/LoggingLevel;)V
public final fun isLoggable (Ljava/lang/System$Logger$Level;)Z
public final fun log (Ljava/lang/System$Logger$Level;Ljava/lang/Throwable;Lkotlin/jvm/functions/Function1;)V
public final fun log (Ljava/lang/System$Logger$Level;Lkotlin/jvm/functions/Function0;)V
public final fun trace (Lkotlin/jvm/functions/Function0;)V
public final fun warn (Ljava/lang/Throwable;Lkotlin/jvm/functions/Function1;)V
public final fun warn (Lkotlin/jvm/functions/Function0;)V
public static synthetic fun warn$default (Lcom/hexagonkt/core/logging/Logger;Ljava/lang/Throwable;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)V
}

public abstract interface class com/hexagonkt/core/logging/LoggerPort {
public abstract fun log (Lcom/hexagonkt/core/logging/LoggingLevel;Ljava/lang/Throwable;Lkotlin/jvm/functions/Function1;)V
public abstract fun log (Lcom/hexagonkt/core/logging/LoggingLevel;Lkotlin/jvm/functions/Function0;)V
}

public final class com/hexagonkt/core/logging/LoggingKt {
public static final fun debug (Ljava/lang/Object;Ljava/lang/String;)Ljava/lang/Object;
public static synthetic fun debug$default (Ljava/lang/Object;Ljava/lang/String;ILjava/lang/Object;)Ljava/lang/Object;
Expand All @@ -258,50 +248,6 @@ public final class com/hexagonkt/core/logging/LoggingKt {
public static synthetic fun trace$default (Ljava/lang/Object;Ljava/lang/String;ILjava/lang/Object;)Ljava/lang/Object;
}

public final class com/hexagonkt/core/logging/LoggingLevel : java/lang/Enum {
public static final field DEBUG Lcom/hexagonkt/core/logging/LoggingLevel;
public static final field ERROR Lcom/hexagonkt/core/logging/LoggingLevel;
public static final field INFO Lcom/hexagonkt/core/logging/LoggingLevel;
public static final field OFF Lcom/hexagonkt/core/logging/LoggingLevel;
public static final field TRACE Lcom/hexagonkt/core/logging/LoggingLevel;
public static final field WARN Lcom/hexagonkt/core/logging/LoggingLevel;
public static fun getEntries ()Lkotlin/enums/EnumEntries;
public static fun valueOf (Ljava/lang/String;)Lcom/hexagonkt/core/logging/LoggingLevel;
public static fun values ()[Lcom/hexagonkt/core/logging/LoggingLevel;
}

public final class com/hexagonkt/core/logging/LoggingManager {
public static final field INSTANCE Lcom/hexagonkt/core/logging/LoggingManager;
public final fun getAdapter ()Lcom/hexagonkt/core/logging/LoggingPort;
public final fun getDefaultLoggerName ()Ljava/lang/String;
public final fun getUseColor ()Z
public final fun isLoggerLevelEnabled (Lcom/hexagonkt/core/logging/LoggingLevel;)Z
public final fun isLoggerLevelEnabled (Ljava/lang/Object;Lcom/hexagonkt/core/logging/LoggingLevel;)Z
public final fun isLoggerLevelEnabled (Ljava/lang/String;Lcom/hexagonkt/core/logging/LoggingLevel;)Z
public final fun isLoggerLevelEnabled (Lkotlin/reflect/KClass;Lcom/hexagonkt/core/logging/LoggingLevel;)Z
public final fun setAdapter (Lcom/hexagonkt/core/logging/LoggingPort;)V
public final fun setDefaultLoggerName (Ljava/lang/String;)V
public final fun setLoggerLevel (Lcom/hexagonkt/core/logging/LoggingLevel;)V
public final fun setLoggerLevel (Ljava/lang/String;Lcom/hexagonkt/core/logging/LoggingLevel;)V
public final fun setLoggerLevel (Lkotlin/reflect/KClass;Lcom/hexagonkt/core/logging/LoggingLevel;)V
public final fun setUseColor (Z)V
}

public abstract interface class com/hexagonkt/core/logging/LoggingPort {
public abstract fun createLogger (Ljava/lang/String;)Lcom/hexagonkt/core/logging/LoggerPort;
public abstract fun isLoggerLevelEnabled (Ljava/lang/String;Lcom/hexagonkt/core/logging/LoggingLevel;)Z
public abstract fun setLoggerLevel (Ljava/lang/String;Lcom/hexagonkt/core/logging/LoggingLevel;)V
}

public final class com/hexagonkt/core/logging/SystemLoggingAdapter : com/hexagonkt/core/logging/LoggingPort {
public fun <init> ()V
public fun <init> (Lcom/hexagonkt/core/logging/LoggingLevel;)V
public synthetic fun <init> (Lcom/hexagonkt/core/logging/LoggingLevel;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun createLogger (Ljava/lang/String;)Lcom/hexagonkt/core/logging/LoggerPort;
public fun isLoggerLevelEnabled (Ljava/lang/String;Lcom/hexagonkt/core/logging/LoggingLevel;)Z
public fun setLoggerLevel (Ljava/lang/String;Lcom/hexagonkt/core/logging/LoggingLevel;)V
}

public final class com/hexagonkt/core/media/MediaType {
public static final field Companion Lcom/hexagonkt/core/media/MediaType$Companion;
public fun <init> (Lcom/hexagonkt/core/media/MediaTypeGroup;Ljava/lang/String;)V
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/kotlin/com/hexagonkt/core/ClasspathHandler.kt
@@ -1,5 +1,6 @@
package com.hexagonkt.core

import com.hexagonkt.core.logging.logger
import java.net.URL
import java.net.URLConnection
import java.net.URLStreamHandler
Expand All @@ -21,7 +22,7 @@ object ClasspathHandler : URLStreamHandler() {
}
}
catch (e: Error) {
e.printStackTrace()
logger.error(e)
}
}

Expand Down
26 changes: 12 additions & 14 deletions core/src/main/kotlin/com/hexagonkt/core/Jvm.kt
Expand Up @@ -85,24 +85,16 @@ object Jvm {
(runtime.totalMemory() - runtime.freeMemory()).let { "%,d".format(it / 1024) }

/**
* Add a map to system properties, optionally overriding them.
* Add a map to system properties, overriding entries if already set.
*
* @param settings Data to be added to system properties.
* @param overwrite If true, overwrite existing entries with supplied data.
*/
fun loadSystemSettings(settings: Map<String, String>, overwrite: Boolean = false) {
settings.keys.forEach {
check(it.matches(systemSettingPattern)) {
"Property name must match $systemSettingPattern ($it)"
}
fun loadSystemSettings(settings: Map<String, String>) {
settings.entries.forEach { (k, v) ->
val matchPattern = k.matches(systemSettingPattern)
check(matchPattern) { "Property name must match $systemSettingPattern ($k)" }
System.setProperty(k, v)
}

val systemProperties = System.getProperties()
val properties =
if (overwrite) settings.entries
else settings.entries.filter { !systemProperties.containsKey(it.key) }

properties.forEach { (k, v) -> System.setProperty(k, v) }
}

/**
Expand All @@ -122,6 +114,9 @@ object Jvm {
systemSettingOrNull(type, name)
?: error("Required '${type.simpleName}' system setting '$name' not found")

fun <T: Any> systemSetting(type: KClass<T>, name: String, defaultValue: T): T =
systemSettingOrNull(type, name) ?: defaultValue

/**
* Retrieve a flag (boolean parameter) by name by looking in OS environment variables first and
* in the JVM system properties if not found.
Expand All @@ -147,6 +142,9 @@ object Jvm {
inline fun <reified T: Any> systemSetting(name: String): T =
systemSetting(T::class, name)

inline fun <reified T: Any> systemSetting(name: String, defaultValue: T): T =
systemSetting(T::class, name, defaultValue)

private fun systemSettingRaw(name: String): String? {
val correctName = name.matches(systemSettingPattern)
require(correctName) { "Setting name must match $systemSettingPattern" }
Expand Down
@@ -1,7 +1,7 @@
package com.hexagonkt.core

/**
* Exception with a list of causes. Cause is `null` as it can't be tell which one of the list is the
* Exception with a list of causes. Cause is `null` as it can't be told which one of the list is the
* cause.
*
* A coded multiple exception should be created this way:
Expand Down

0 comments on commit 830a9ec

Please sign in to comment.