Skip to content

Commit

Permalink
Merge pull request #651 from hexagonkt/develop
Browse files Browse the repository at this point in the history
Minor improvements
  • Loading branch information
jaguililla authored Aug 24, 2023
2 parents 50a1eb6 + b74fe02 commit 75e6a3d
Show file tree
Hide file tree
Showing 59 changed files with 142 additions and 140 deletions.
55 changes: 21 additions & 34 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import com.github.jk1.license.render.ReportRenderer
*/

plugins {
kotlin("jvm") version("1.9.0") apply(false)
kotlin("jvm") version("1.9.10") apply(false)

id("idea")
id("eclipse")
Expand Down Expand Up @@ -82,49 +82,36 @@ task("nativeTestModules") {
val gitHub = "https://github.com/hexagonkt/hexagon/tree/master"
val entries = subprojects
.filter { sp -> sp.tasks.any { t -> t.name == "nativeTest" } }
.sortedBy { sp -> "${sp.group}:${sp.name}" }
.joinToString(",\n") { sp ->
val n = sp.name
val g = sp.group
val d = gitHub + sp.projectDir.absolutePath.removePrefix(rootDir.absolutePath)
val r = sp.projectDir.resolve("src/main/resources/META-INF/native-image/$g/$n")
val t = "$d/src/test"
if (r.exists())
"""
{
"artifact": "$g:$n",
"description": "${sp.description}",
"details": [
{
"minimum_version": "${sp.version}",
"test_level": "fully-tested",
"metadata_locations": [
"$gitHub${r.absolutePath.removePrefix(rootDir.absolutePath)}"
],
"tests_locations": [
"$t",
"https://github.com/hexagonkt/hexagon/actions/workflows/nightly.yml"
]
}
]
val m =
if (r.exists()) {
val metadata = r.absolutePath.removePrefix(rootDir.absolutePath)
"\n \"$gitHub$metadata\"\n "
}
""".trimIndent()
else
"""
else ""
"""
{
"artifact": "$g:$n",
"description": "${sp.description}",
"details": [
{
"artifact": "$g:$n",
"description": "${sp.description}",
"details": [
{
"minimum_version": "${sp.version}",
"test_level": "fully-tested",
"tests_locations": [
"$t",
"https://github.com/hexagonkt/hexagon/actions/workflows/nightly.yml"
]
}
"minimum_version": "${sp.version}",
"test_level": "fully-tested",
"metadata_locations": [$m],
"tests_locations": [
"$t",
"https://github.com/hexagonkt/hexagon/actions/workflows/nightly.yml"
]
}
""".trimIndent()
]
}
""".trimIndent()
}
.lines()
.joinToString("") { " $it\n" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package com.hexagonkt.core.logging
import com.hexagonkt.core.logging.LoggingLevel.INFO
import com.hexagonkt.core.require

// TODO Wrap these loggers using System.Logger:
// https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/System.Logger.html
class PrintLoggingAdapter(defaultLevel: LoggingLevel = INFO) : LoggingPort {

private val loggerLevels: MutableMap<String, LoggingLevel> = mutableMapOf("" to defaultLevel)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ Args= \
-ea \
-H:IncludeResources=.* \
--enable-url-protocols=ftp \
--initialize-at-build-time=org.junit.platform.launcher.core.LauncherConfig \
--initialize-at-build-time=org.junit.jupiter.engine.config.InstantiatingConfigurationParameterConverter \
--initialize-at-build-time=org.junit.jupiter.api.condition.OS \
--initialize-at-build-time=kotlin.annotation.AnnotationRetention \
--initialize-at-build-time=kotlin.annotation.AnnotationTarget
6 changes: 3 additions & 3 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.0.1
version=3.0.2
group=com.hexagonkt
description=The atoms of your platform

Expand All @@ -31,13 +31,13 @@ logoSmall=assets/img/logo.svg
iconsDirectory=content

# VERSIONS
kotlinVersion=1.9.0
kotlinVersion=1.9.10
dokkaVersion=1.8.20
mockkVersion=1.13.7
junitVersion=5.10.0
gatlingVersion=3.9.5
jmhVersion=1.37
mkdocsMaterialVersion=9.1.21
mkdocsMaterialVersion=9.2.3
mermaidDokkaVersion=0.4.4
nativeToolsVersion=0.9.24

Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https://services.gradle.org/distributions/gradle-8.2.1-all.zip
distributionUrl=https://services.gradle.org/distributions/gradle-8.3-all.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
3 changes: 2 additions & 1 deletion gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ done
# This is normally unused
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down
1 change: 1 addition & 0 deletions handlers/src/main/kotlin/com/hexagonkt/handlers/Handler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package com.hexagonkt.handlers
*
* @param T Event type.
*/
// TODO Add 'parent' in order to ease their use as a tree
interface Handler<T : Any> {
val predicate: (Context<T>) -> Boolean
val callback: (Context<T>) -> Context<T>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
Args= \
--initialize-at-build-time=org.junit.platform.launcher.core.LauncherConfig \
--initialize-at-build-time=org.junit.jupiter.engine.config.InstantiatingConfigurationParameterConverter \
--initialize-at-build-time=kotlin.annotation.AnnotationRetention \
--initialize-at-build-time=kotlin.annotation.AnnotationTarget
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import java.time.Instant

data class Cookie(
val name: String,
val value: String,
val value: String = "",
val maxAge: Long = -1,
val secure: Boolean = false,
val path: String = "/",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,7 @@ internal class CookieTest {
assertEquals(0, cookie.maxAge)
assertTrue(cookie.secure)
assertTrue(cookie.deleted)

assertEquals(cookie, Cookie("name", secure = true).delete())
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
Args= \
-ea \
-H:IncludeResources=.* \
--initialize-at-build-time=org.junit.platform.launcher.core.LauncherConfig \
--initialize-at-build-time=org.junit.jupiter.engine.config.InstantiatingConfigurationParameterConverter \
--initialize-at-build-time=kotlin.annotation.AnnotationRetention \
--initialize-at-build-time=kotlin.annotation.AnnotationTarget
10 changes: 6 additions & 4 deletions http/http_client/api/http_client.api
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,23 @@ public final class com/hexagonkt/http/client/HttpClientPort$DefaultImpls {

public final class com/hexagonkt/http/client/HttpClientSettings {
public fun <init> ()V
public fun <init> (Ljava/net/URL;Lcom/hexagonkt/http/model/ContentType;ZLcom/hexagonkt/http/model/Headers;ZLcom/hexagonkt/http/SslSettings;Lcom/hexagonkt/http/model/Authorization;)V
public synthetic fun <init> (Ljava/net/URL;Lcom/hexagonkt/http/model/ContentType;ZLcom/hexagonkt/http/model/Headers;ZLcom/hexagonkt/http/SslSettings;Lcom/hexagonkt/http/model/Authorization;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun <init> (Ljava/net/URL;Lcom/hexagonkt/http/model/ContentType;ZLcom/hexagonkt/http/model/Headers;ZLcom/hexagonkt/http/SslSettings;Lcom/hexagonkt/http/model/Authorization;Z)V
public synthetic fun <init> (Ljava/net/URL;Lcom/hexagonkt/http/model/ContentType;ZLcom/hexagonkt/http/model/Headers;ZLcom/hexagonkt/http/SslSettings;Lcom/hexagonkt/http/model/Authorization;ZILkotlin/jvm/internal/DefaultConstructorMarker;)V
public final fun component1 ()Ljava/net/URL;
public final fun component2 ()Lcom/hexagonkt/http/model/ContentType;
public final fun component3 ()Z
public final fun component4 ()Lcom/hexagonkt/http/model/Headers;
public final fun component5 ()Z
public final fun component6 ()Lcom/hexagonkt/http/SslSettings;
public final fun component7 ()Lcom/hexagonkt/http/model/Authorization;
public final fun copy (Ljava/net/URL;Lcom/hexagonkt/http/model/ContentType;ZLcom/hexagonkt/http/model/Headers;ZLcom/hexagonkt/http/SslSettings;Lcom/hexagonkt/http/model/Authorization;)Lcom/hexagonkt/http/client/HttpClientSettings;
public static synthetic fun copy$default (Lcom/hexagonkt/http/client/HttpClientSettings;Ljava/net/URL;Lcom/hexagonkt/http/model/ContentType;ZLcom/hexagonkt/http/model/Headers;ZLcom/hexagonkt/http/SslSettings;Lcom/hexagonkt/http/model/Authorization;ILjava/lang/Object;)Lcom/hexagonkt/http/client/HttpClientSettings;
public final fun component8 ()Z
public final fun copy (Ljava/net/URL;Lcom/hexagonkt/http/model/ContentType;ZLcom/hexagonkt/http/model/Headers;ZLcom/hexagonkt/http/SslSettings;Lcom/hexagonkt/http/model/Authorization;Z)Lcom/hexagonkt/http/client/HttpClientSettings;
public static synthetic fun copy$default (Lcom/hexagonkt/http/client/HttpClientSettings;Ljava/net/URL;Lcom/hexagonkt/http/model/ContentType;ZLcom/hexagonkt/http/model/Headers;ZLcom/hexagonkt/http/SslSettings;Lcom/hexagonkt/http/model/Authorization;ZILjava/lang/Object;)Lcom/hexagonkt/http/client/HttpClientSettings;
public fun equals (Ljava/lang/Object;)Z
public final fun getAuthorization ()Lcom/hexagonkt/http/model/Authorization;
public final fun getBaseUrl ()Ljava/net/URL;
public final fun getContentType ()Lcom/hexagonkt/http/model/ContentType;
public final fun getFollowRedirects ()Z
public final fun getHeaders ()Lcom/hexagonkt/http/model/Headers;
public final fun getInsecure ()Z
public final fun getSslSettings ()Lcom/hexagonkt/http/SslSettings;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ data class HttpClientSettings(
val insecure: Boolean = false,
val sslSettings: SslSettings? = null,
val authorization: Authorization? = null,
val followRedirects: Boolean = false,
)
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ internal class HttpClientSettingsTest {
assertEquals(Headers(), it.headers)
assertFalse(it.insecure)
assertNull(it.sslSettings)
assertFalse(it.followRedirects)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
Args= \
--initialize-at-build-time=org.junit.platform.launcher.core.LauncherConfig \
--initialize-at-build-time=org.junit.jupiter.engine.config.InstantiatingConfigurationParameterConverter \
--initialize-at-build-time=kotlin.annotation.AnnotationRetention \
--initialize-at-build-time=kotlin.annotation.AnnotationTarget
3 changes: 1 addition & 2 deletions http/http_client_jetty/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,5 @@ dependencies {
val jettyVersion = properties["jettyVersion"]

"api"(project(":http:http_client"))
"api"(platform("org.eclipse.jetty:jetty-bom:$jettyVersion"))
"api"("org.eclipse.jetty.http2:jetty-http2-client-transport") { exclude(group = "org.slf4j") }
"api"("org.eclipse.jetty.http2:jetty-http2-client-transport:$jettyVersion")
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ open class JettyClientAdapter : HttpClientPort {
httpClient = client

jettyClient.userAgentField = null // Disable default user agent header
jettyClient.isFollowRedirects = client.settings.followRedirects
jettyClient.start()
started = true
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
Args= \
--initialize-at-build-time=org.junit.platform.launcher.core.LauncherConfig \
--initialize-at-build-time=org.junit.jupiter.engine.config.InstantiatingConfigurationParameterConverter \
--initialize-at-build-time=kotlin.annotation.AnnotationRetention \
--initialize-at-build-time=kotlin.annotation.AnnotationTarget
4 changes: 3 additions & 1 deletion http/http_client_jetty_ws/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ apply(from = "$rootDir/gradle/detekt.gradle")
description = "HTTP client adapter for Jetty (with WebSockets support)."

dependencies {
val jettyVersion = properties["jettyVersion"]

"api"(project(":http:http_client_jetty"))
"api"("org.eclipse.jetty.websocket:jetty-websocket-jetty-client")
"api"("org.eclipse.jetty.websocket:jetty-websocket-jetty-client:$jettyVersion")
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
Args= \
--initialize-at-build-time=org.junit.platform.launcher.core.LauncherConfig \
--initialize-at-build-time=org.junit.jupiter.engine.config.InstantiatingConfigurationParameterConverter \
--initialize-at-build-time=kotlin.annotation.AnnotationRetention \
--initialize-at-build-time=kotlin.annotation.AnnotationTarget
2 changes: 2 additions & 0 deletions http/http_handlers/api/http_handlers.api
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,8 @@ public final class com/hexagonkt/http/handlers/HttpContext : com/hexagonkt/handl
public static synthetic fun notFound$default (Lcom/hexagonkt/http/handlers/HttpContext;Ljava/lang/Object;Lcom/hexagonkt/http/model/Headers;Lcom/hexagonkt/http/model/ContentType;Ljava/util/List;Ljava/util/Map;ILjava/lang/Object;)Lcom/hexagonkt/http/handlers/HttpContext;
public final fun ok (Ljava/lang/Object;Lcom/hexagonkt/http/model/Headers;Lcom/hexagonkt/http/model/ContentType;Ljava/util/List;Ljava/util/Map;)Lcom/hexagonkt/http/handlers/HttpContext;
public static synthetic fun ok$default (Lcom/hexagonkt/http/handlers/HttpContext;Ljava/lang/Object;Lcom/hexagonkt/http/model/Headers;Lcom/hexagonkt/http/model/ContentType;Ljava/util/List;Ljava/util/Map;ILjava/lang/Object;)Lcom/hexagonkt/http/handlers/HttpContext;
public final fun redirect (Lcom/hexagonkt/http/model/HttpStatus;Ljava/net/URI;Lcom/hexagonkt/http/model/Headers;Ljava/util/List;Ljava/util/Map;)Lcom/hexagonkt/http/handlers/HttpContext;
public static synthetic fun redirect$default (Lcom/hexagonkt/http/handlers/HttpContext;Lcom/hexagonkt/http/model/HttpStatus;Ljava/net/URI;Lcom/hexagonkt/http/model/Headers;Ljava/util/List;Ljava/util/Map;ILjava/lang/Object;)Lcom/hexagonkt/http/handlers/HttpContext;
public final fun request (Ljava/lang/Object;Lcom/hexagonkt/http/model/Headers;Lcom/hexagonkt/http/model/ContentType;Ljava/util/List;Ljava/util/Map;)Lcom/hexagonkt/http/handlers/HttpContext;
public static synthetic fun request$default (Lcom/hexagonkt/http/handlers/HttpContext;Ljava/lang/Object;Lcom/hexagonkt/http/model/Headers;Lcom/hexagonkt/http/model/ContentType;Ljava/util/List;Ljava/util/Map;ILjava/lang/Object;)Lcom/hexagonkt/http/handlers/HttpContext;
public final fun send (Lcom/hexagonkt/http/model/HttpRequestPort;Ljava/util/Map;)Lcom/hexagonkt/http/handlers/HttpContext;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import com.hexagonkt.http.model.*
import com.hexagonkt.http.model.INTERNAL_SERVER_ERROR_500
import com.hexagonkt.http.model.ServerEvent
import com.hexagonkt.http.model.ws.WsSession
import java.net.URI
import java.net.URL
import java.security.cert.X509Certificate
import java.util.concurrent.Flow.Publisher
Expand Down Expand Up @@ -201,6 +202,20 @@ data class HttpContext(
): HttpContext =
send(CREATED_201, body, headers, contentType, cookies, attributes)

fun redirect(
status: HttpStatus,
location: URI,
headers: Headers = response.headers,
cookies: List<Cookie> = response.cookies,
attributes: Map<*, *> = this.attributes,
): HttpContext =
send(
status,
headers = headers + Header("location", location),
cookies = cookies,
attributes = attributes
)

fun accepted(
onConnect: WsSession.() -> Unit = {},
onBinary: WsSession.(data: ByteArray) -> Unit = {},
Expand Down Expand Up @@ -252,6 +267,7 @@ data class HttpContext(
attributes = attributes
)

// TODO Change by receive?
fun request(
body: Any = response.body,
headers: Headers = response.headers,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.hexagonkt.http.handlers

import com.hexagonkt.core.logging.Logger
import com.hexagonkt.core.media.TEXT_PLAIN
import com.hexagonkt.core.toText
import com.hexagonkt.handlers.ChainHandler
Expand All @@ -19,6 +20,8 @@ data class PathHandler(
)
{

private val logger: Logger = Logger(PathHandler::class)

private companion object {
fun nestedMethods(handlers: List<HttpHandler>): Set<HttpMethod> =
handlers
Expand Down Expand Up @@ -51,17 +54,26 @@ data class PathHandler(
val response = event.response
val exception = it.exception

if (exception != null && response.status.type != SERVER_ERROR)
it.with(
event = event.copy(
response = response.with(
body = exception.toText(),
contentType = ContentType(TEXT_PLAIN),
status = INTERNAL_SERVER_ERROR_500,
if (exception != null) {
logger.error(exception) {
"Exception received at call processing end. Clear/handle exception in a handler"
}
if (response.status.type != SERVER_ERROR)
it.with(
event = event.copy(
response = response.with(
body = exception.toText(),
contentType = ContentType(TEXT_PLAIN),
status = INTERNAL_SERVER_ERROR_500,
)
)
)
)
else it
else
it
}
else {
it
}
} as HttpContext

override fun addPrefix(prefix: String): HttpHandler =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
Args= \
--initialize-at-build-time=org.junit.platform.launcher.core.LauncherConfig \
--initialize-at-build-time=org.junit.jupiter.engine.config.InstantiatingConfigurationParameterConverter \
--initialize-at-build-time=kotlin.annotation.AnnotationRetention \
--initialize-at-build-time=kotlin.annotation.AnnotationTarget
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class LoggingCallback(
}

val body = m.formatBody()
return "Request:\n${m.method} ${m.path}$headers$body".trim()
return "${m.method} ${m.path}$headers$body".trim()
}

internal fun details(n: HttpRequestPort, m: HttpResponsePort, ns: Long): String {
Expand All @@ -52,7 +52,7 @@ class LoggingCallback(
val result = "${m.status.type}(${m.status.code})"
val time = "(${ns / 10e5} ms)"
val body = m.formatBody()
return "Response (partial headers):\n$path -> $result $time$headers$body".trim()
return "$path -> $result $time$headers$body".trim()
}

private fun HttpMessage.formatBody(): String =
Expand Down
Loading

0 comments on commit 75e6a3d

Please sign in to comment.