Skip to content

Commit

Permalink
Merge pull request #645 from hexagonkt/develop
Browse files Browse the repository at this point in the history
Update dependencies and fix warnings
  • Loading branch information
jaguililla authored Aug 2, 2023
2 parents 3e8b769 + a84a548 commit 702da22
Show file tree
Hide file tree
Showing 115 changed files with 374 additions and 289 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ jobs:
distribution: graalvm-community
cache: gradle
- name: Build Project
run: ./gradlew --info --stacktrace nativeTest
run: ./gradlew --stacktrace nativeTest

build_site:
name: Build Site
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ jobs:
export REMOTE="https://$GITHUB_ACTOR:[email protected]/$GITHUB_REPOSITORY.git"
git remote set-url origin "$REMOTE"
git clone "$REMOTE" --branch gh-pages build/gh-pages
./gradlew --info build
./gradlew --info -x build buildSite
./gradlew build
./gradlew -x build buildSite
ls -AlF site/build/site
- name: Publish Packages
Expand All @@ -50,7 +50,7 @@ jobs:
OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }}
SIGNING_KEY: ${{ secrets.SIGNING_KEY }}
SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }}
run: ./gradlew --info --no-daemon -x test release
run: ./gradlew --no-daemon -x test release

- name: Publish Site
run: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release_branch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ jobs:
SIGNING_KEY: ${{ secrets.SIGNING_KEY }}
SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }}
run: |
./gradlew --info build
./gradlew --info --no-daemon -x test release
./gradlew build
./gradlew --no-daemon -x test release
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ from scratch following these steps:

```kotlin
// hello_world
import com.hexagonkt.core.media.TEXT_PLAIN
import com.hexagonkt.http.model.ContentType
import com.hexagonkt.http.server.HttpServer
import com.hexagonkt.http.server.jetty.serve

lateinit var server: HttpServer
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ plugins {
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.23") apply(false)
id("io.gitlab.arturbosch.detekt") version("1.23.0") apply(false)
id("io.gitlab.arturbosch.detekt") version("1.23.1") apply(false)
id("me.champeau.jmh") version("0.7.1") apply(false)
}

Expand Down
2 changes: 1 addition & 1 deletion core/src/main/kotlin/com/hexagonkt/core/Network.kt
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ fun URL.firstVariant(vararg suffixes: String): URL {
val fileName = file.removeSuffix(".$extension")

suffixes.forEach {
val u = URL("$protocol:$fileName$it.$extension")
val u = urlOf("$protocol:$fileName$it.$extension")
if (u.exists())
return u
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/kotlin/com/hexagonkt/core/Strings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ fun <T : Any> String.parse(type: KClass<T>): T =
Double::class -> this.toDoubleOrNull()
String::class -> this
InetAddress::class -> this.let(InetAddress::getByName)
URL::class -> this.let(::URL)
URL::class -> this.let(::urlOf)
URI::class -> this.let(::URI)
File::class -> this.let(::File)
LocalDate::class -> LocalDate.parse(this)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import kotlin.test.Test
import org.junit.jupiter.api.TestInstance
import org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS
import java.net.MalformedURLException
import java.net.URL
import kotlin.test.assertFailsWith

@TestInstance(PER_CLASS)
Expand All @@ -23,26 +22,26 @@ internal class ClasspathHandlerProviderTest {
}

@Test fun `Require classpath resource`() {
val resource = URL("classpath:application_test.yml")
val resource = urlOf("classpath:application_test.yml")
assert(resource.file == resource.file)
val e = assertFailsWith<ResourceNotFoundException> {
URL("classpath:foo.txt").openConnection()
urlOf("classpath:foo.txt").openConnection()
}
assert(e.message == "classpath:foo.txt cannot be open")
}

@Test fun `Classpath resource folder`() {
assert(URL("classpath:data").readText().lines().isNotEmpty())
assert(urlOf("classpath:data").readText().lines().isNotEmpty())
}

@Test fun `Read classpath resource returns resource's text` () {
val resourceText = URL("classpath:sample.properties").readText()
val resourceText = urlOf("classpath:sample.properties").readText()
assert(resourceText.contains("handlers=com.hexagonkt.core.logging.jul.SystemStreamHandler"))
}

@Test fun `Unknown protocol throws exception`() {
val e = assertFailsWith<MalformedURLException> {
assert(URL("unknown:data").readText().lines().isNotEmpty())
assert(urlOf("unknown:data").readText().lines().isNotEmpty())
}

val errorJvm = "unknown protocol: unknown"
Expand All @@ -52,7 +51,7 @@ internal class ClasspathHandlerProviderTest {
}

@Test fun `Resource loading using URL returns data`() {
assert(URL("classpath:data/companies.json").readText().isNotBlank())
assert(URL("file:README.md").readText().isNotBlank())
assert(urlOf("classpath:data/companies.json").readText().isNotBlank())
assert(urlOf("file:README.md").readText().isNotBlank())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@ import com.hexagonkt.core.logging.logger
import com.hexagonkt.core.logging.Logger
import com.hexagonkt.core.logging.LoggingLevel.*
import com.hexagonkt.core.logging.LoggingManager
import java.net.URL
import kotlin.test.Test
import kotlin.test.assertContains

internal class HexagonCoreSamplesTest {

@Test fun buildPropertiesBundled() {
val hexagonProperties = URL("classpath:hexagon.properties").readText()
val hexagonProperties = urlOf("classpath:hexagon.properties").readText()

assertContains(hexagonProperties, "project=")
assertContains(hexagonProperties, "module=")
Expand Down
5 changes: 2 additions & 3 deletions core/src/test/kotlin/com/hexagonkt/core/JvmTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import kotlin.test.Test
import kotlin.IllegalArgumentException
import java.net.Inet4Address
import java.net.URI
import java.net.URL
import kotlin.test.*

internal class JvmTest {
Expand Down Expand Up @@ -58,7 +57,7 @@ internal class JvmTest {
System.setProperty("validFloat", 0.5F.toString())
System.setProperty("validDouble", 1.5.toString())
System.setProperty("validInetAddress", LOOPBACK_INTERFACE.hostName)
System.setProperty("validURL", URL("http://localhost:1234/path").toString())
System.setProperty("validURL", urlOf("http://localhost:1234/path").toString())
System.setProperty("validURI", URI("ws://localhost:1234/path").toString())
System.setProperty("invalidBoolean", "_")
System.setProperty("invalidInt", "_")
Expand All @@ -77,7 +76,7 @@ internal class JvmTest {
assertEquals(0.5F, Jvm.systemSetting("validFloat"))
assertEquals(1.5, Jvm.systemSetting("validDouble"))
assertEquals(LOOPBACK_INTERFACE, Jvm.systemSetting("validInetAddress"))
assertEquals(URL("http://localhost:1234/path"), Jvm.systemSetting("validURL"))
assertEquals(urlOf("http://localhost:1234/path"), Jvm.systemSetting("validURL"))
assertEquals(URI("ws://localhost:1234/path"), Jvm.systemSetting("validURI"))

assertNull(Jvm.systemSettingOrNull<Int>("invalidInt"))
Expand Down
20 changes: 10 additions & 10 deletions core/src/test/kotlin/com/hexagonkt/core/media/MediaTypesTest.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.hexagonkt.core.media

import com.hexagonkt.core.media.MediaTypeGroup.*
import com.hexagonkt.core.urlOf
import kotlin.test.Test
import java.io.File
import java.net.URI
import kotlin.IllegalArgumentException
import kotlin.IllegalStateException
import java.net.URL
import java.nio.file.Path
import kotlin.test.assertEquals
import kotlin.test.assertFailsWith
Expand Down Expand Up @@ -44,14 +44,14 @@ internal class MediaTypesTest {

@Test fun `Media types of files and URLs can be retrieved`() {
assertEquals(APPLICATION_TOML, mediaTypeOfOrNull(URI("http://localhost/file.toml")))
assertEquals(TEXT_PLAIN, mediaTypeOfOrNull(URL("http://localhost/file.txt")))
assertEquals(APPLICATION_JSON, mediaTypeOfOrNull(URL("http://localhost/file.json")))
assertEquals(TEXT_PLAIN, mediaTypeOfOrNull(urlOf("http://localhost/file.txt")))
assertEquals(APPLICATION_JSON, mediaTypeOfOrNull(urlOf("http://localhost/file.json")))
assertEquals(APPLICATION_TOML, mediaTypeOf(URI("http://localhost/file.toml")))
assertEquals(TEXT_PLAIN, mediaTypeOf(URL("http://localhost/file.txt")))
assertEquals(APPLICATION_JSON, mediaTypeOf(URL("http://localhost/file.json")))
assertEquals(TEXT_PLAIN, mediaTypeOf(urlOf("http://localhost/file.txt")))
assertEquals(APPLICATION_JSON, mediaTypeOf(urlOf("http://localhost/file.json")))
assertEquals(APPLICATION_AVRO, mediaTypeOf("avro"))
assertNull(mediaTypeOfOrNull(URL("http://localhost/file")))
assertNull(mediaTypeOfOrNull(URL("http://localhost/file.foo")))
assertNull(mediaTypeOfOrNull(urlOf("http://localhost/file")))
assertNull(mediaTypeOfOrNull(urlOf("http://localhost/file.foo")))

assertEquals(TEXT_HTML, mediaTypeOfOrNull(File("file.html")))
assertEquals(TEXT_HTML, mediaTypeOfOrNull(File("file.htm")))
Expand All @@ -64,7 +64,7 @@ internal class MediaTypesTest {
assertNull(mediaTypeOfOrNull(File("file")))
assertNull(mediaTypeOfOrNull(File("file.baz")))
assertNull(mediaTypeOfOrNull(URI("http://localhost/file.baz")))
assertNull(mediaTypeOfOrNull(URL("http://localhost/file.baz")))
assertNull(mediaTypeOfOrNull(urlOf("http://localhost/file.baz")))
assertEquals(TEXT_HTML, mediaTypeOfOrNull(Path.of("file.html")))
assertEquals(TEXT_HTML, mediaTypeOfOrNull(Path.of("file.htm")))
assertEquals(APPLICATION_YAML, mediaTypeOfOrNull(Path.of("file.yaml")))
Expand All @@ -80,12 +80,12 @@ internal class MediaTypesTest {
@Test fun `Exception is thrown if the media type is not found`() {
assertEquals(
"Media type not found for: 'http://host/f' URL",
assertFailsWith<IllegalStateException> { mediaTypeOf(URL("http://host/f")) }.message
assertFailsWith<IllegalStateException> { mediaTypeOf(urlOf("http://host/f")) }.message
)

assertEquals(
"Media type not found for: 'http://host/f.foo' URL",
assertFailsWith<IllegalStateException> { mediaTypeOf(URL("http://host/f.foo")) }.message
assertFailsWith<IllegalStateException> { mediaTypeOf(urlOf("http://host/f.foo")) }.message
)

assertEquals(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.hexagonkt.core.security

import com.hexagonkt.core.urlOf
import kotlin.test.Test
import org.junit.jupiter.api.condition.DisabledOnOs
import org.junit.jupiter.api.condition.OS.WINDOWS
import java.io.File
import java.net.URL
import java.security.cert.X509Certificate
import kotlin.test.assertEquals

Expand All @@ -18,7 +18,7 @@ internal class KeyStoresTest {
val pwd = f.reversed()
val p = if (File("http_test").exists()) "http/http_test" else "../http/http_test"

val ks = loadKeyStore(URL("file:$p/src/main/resources/ssl/$f"), pwd)
val ks = loadKeyStore(urlOf("file:$p/src/main/resources/ssl/$f"), pwd)
val public = ks.getPublicKey(n)
val private = ks.getPrivateKey(n, pwd)
val cert = ks.getCertificate(n) as X509Certificate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ 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: 4 additions & 2 deletions detekt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ style:
active: true
ForbiddenComment:
active: true
values: [ TODO, FIXME ]
comments: [ TODO, FIXME ]
ForbiddenVoid:
active: true
ignoreOverridden: false
Expand Down Expand Up @@ -197,8 +197,10 @@ style:
active: true
OptionalUnit:
active: true
OptionalWhenBraces:
BracesOnWhenStatements:
active: true
singleLine: necessary
multiLine: necessary
PreferToOverPairSyntax:
active: true
RedundantExplicitType:
Expand Down
10 changes: 5 additions & 5 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.0-B8
version=3.0.0-B9
group=com.hexagonkt
description=The atoms of your platform

Expand Down Expand Up @@ -34,19 +34,19 @@ iconsDirectory=content
kotlinVersion=1.9.0
dokkaVersion=1.8.20
mockkVersion=1.13.5
junitVersion=5.9.3
junitVersion=5.10.0
gatlingVersion=3.9.5
jmhVersion=1.36
mkdocsMaterialVersion=9.1.18
mkdocsMaterialVersion=9.1.21
mermaidDokkaVersion=0.4.4
nativeToolsVersion=0.9.23

# http_server_netty
nettyVersion=4.1.94.Final
nettyVersion=4.1.96.Final
nettyTcNativeVersion=2.0.61.Final

# http_server_nima
nimaVersion=4.0.0-ALPHA6
nimaVersion=4.0.0-M1

# http_server_servlet
servletVersion=5.0.0
Expand Down
4 changes: 4 additions & 0 deletions gradle/detekt.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

apply(plugin: "io.gitlab.arturbosch.detekt")

check {
dependsOn(dependsOn.findAll { it != "detekt" })
}

detekt {
final String detektConfigPath = findProperty("detektConfigPath")

Expand Down
2 changes: 1 addition & 1 deletion gradle/kotlin.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ repositories {
}

dependencies {
final String scriptJunitVersion = findProperty("junitVersion") ?: "5.9.3"
final String scriptJunitVersion = findProperty("junitVersion") ?: "5.10.0"

implementation("org.jetbrains.kotlin:kotlin-stdlib")

Expand Down
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-all.zip
distributionUrl=https://services.gradle.org/distributions/gradle-8.2.1-all.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
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
@@ -1,3 +1,5 @@
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
@@ -1,5 +1,6 @@
package com.hexagonkt.http.model

import com.hexagonkt.core.urlOf
import com.hexagonkt.http.formatQueryString
import java.net.URL
import java.security.cert.X509Certificate
Expand Down Expand Up @@ -78,7 +79,7 @@ interface HttpRequestPort : HttpMessage {
queryParameters.isEmpty() -> "${protocol.schema}://$host:$port/$path"
else -> "${protocol.schema}://$host:$port/$path?${formatQueryString(queryParameters)}"
}
.let(::URL)
.let(::urlOf)

fun userAgent(): String? =
headers["user-agent"]?.value as? String
Expand Down
Loading

0 comments on commit 702da22

Please sign in to comment.