Skip to content

Commit

Permalink
Convert to new http4k version. Upgrade everything
Browse files Browse the repository at this point in the history
  • Loading branch information
daviddenton committed Sep 30, 2024
1 parent 562bf8b commit 9a6b69b
Show file tree
Hide file tree
Showing 19 changed files with 137 additions and 98 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,9 @@
.idea/
*.iml
build/
out/
.DS_Store
local.properties
lambda.properties
/app/src/main/generated/
*.env
1 change: 1 addition & 0 deletions .java-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
21
12 changes: 0 additions & 12 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion Procfile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
web: build/install/http4k-demo-irc/bin/http4k-demo-irc $PORT
web: build/install/http4k-irc/bin/http4k-irc $PORT
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ It is deployed into Heroku [**here**](http://http4k-demo-irc.herokuapp.com/).

## In action:

<img src="https://github.com/daviddenton/http4k-demo-irc/raw/master/screenshot.png"/>
<img src="https://github.com/http4k/http4k-irc/raw/master/screenshot.png"/>

## Running it locally

Expand Down
45 changes: 0 additions & 45 deletions build.gradle

This file was deleted.

83 changes: 83 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import org.gradle.api.JavaVersion.VERSION_21
import org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_21
import org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile

plugins {
kotlin("jvm") version "2.0.20"
java
application
id("com.gradleup.shadow") version "8.3.1"
id("nu.studer.rocker") version "3.0.4"
}

buildscript {
repositories {
mavenCentral()
gradlePluginPortal()
}

dependencies {
}
}

kotlin {
jvmToolchain {
languageVersion.set(JavaLanguageVersion.of(21))
}
}


allprojects {
apply(plugin = "java")
apply(plugin = "kotlin")
apply(plugin = "application")
apply(plugin = "com.gradleup.shadow")
apply(plugin = "nu.studer.rocker")

repositories {
mavenCentral()
}

dependencies {
api(platform("org.http4k:http4k-bom:${project.properties["http4k_version"]}"))
testApi(platform("org.junit:junit-bom:${project.properties["junit_version"]}"))

api("org.http4k:http4k-core")
api("org.http4k:http4k-config")
api("org.http4k:http4k-server-jetty")

testApi("org.http4k:http4k-testing-hamkrest")
testApi("org.http4k:http4k-client-websocket")

testApi("org.junit.jupiter:junit-jupiter-api")
testApi("org.junit.jupiter:junit-jupiter-engine")
}


tasks {
withType<KotlinJvmCompile>().configureEach {
compilerOptions {
allWarningsAsErrors = false
jvmTarget.set(JVM_21)
}
}

withType<Test> {
useJUnitPlatform()
}

java {
sourceCompatibility = VERSION_21
targetCompatibility = VERSION_21
}
}
}

tasks.register("stage") {
dependsOn("installDist")
}

application {
mainClass.set("org.http4k.demo.IrcLauncherKt")
}

8 changes: 5 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
org.gradle.parallel=true
http4k_version=3.263.0
junit_version=5.7.0
kotlin_version=1.4.10
http4k_connect_version=5.24.1.0
http4k_version=5.32.1.0
junit_version=5.11.0
kotlin_version=2.0.20
forkhandles_version=2.20.0.0
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,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.6-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
26 changes: 17 additions & 9 deletions gradlew
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env bash
#!/usr/bin/env sh

##############################################################################
##
Expand Down Expand Up @@ -33,11 +33,11 @@ DEFAULT_JVM_OPTS=""
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"

warn ( ) {
warn () {
echo "$*"
}

die ( ) {
die () {
echo
echo "$*"
echo
Expand Down Expand Up @@ -154,11 +154,19 @@ if $cygwin ; then
esac
fi

# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
function splitJvmOpts() {
JVM_OPTS=("$@")
# Escape application args
save () {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}
eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
APP_ARGS=$(save "$@")

exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
# Collect all arguments for the java command, following the shell quoting and substitution rules
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"

# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
cd "$(dirname "$0")"
fi

exec "$JAVACMD" "$@"
6 changes: 0 additions & 6 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ goto fail
@rem Get command-line arguments, handling Windows variants

if not "%OS%" == "Windows_NT" goto win9xME_args
if "%@eval[2+2]" == "4" goto 4NT_args

:win9xME_args
@rem Slurp the command line arguments.
Expand All @@ -60,11 +59,6 @@ set _SKIP=2
if "x%~1" == "x" goto execute

set CMD_LINE_ARGS=%*
goto execute

:4NT_args
@rem Get arguments from the 4NT Shell from JP Software
set CMD_LINE_ARGS=%$

:execute
@rem Setup the command line
Expand Down
2 changes: 0 additions & 2 deletions settings.gradle

This file was deleted.

1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rootProject.name = "http4k-irc"
32 changes: 18 additions & 14 deletions src/main/kotlin/org/http4k/demo/IrcApp.kt
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package org.http4k.demo

import org.http4k.cloudnative.env.Environment
import org.http4k.config.Environment
import org.http4k.core.Request
import org.http4k.core.then
import org.http4k.filter.ServerFilters.BasicAuth
import org.http4k.routing.ResourceLoader.Companion.Classpath
import org.http4k.routing.bind
import org.http4k.routing.static
import org.http4k.routing.websockets
import org.http4k.websocket.PolyHandler
import org.http4k.routing.ws.bind
import org.http4k.server.PolyHandler
import org.http4k.websocket.Websocket
import org.http4k.websocket.WsMessage
import org.http4k.websocket.WsResponse
import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.atomic.AtomicInteger

Expand All @@ -23,20 +25,22 @@ fun IrcApp(env: Environment): PolyHandler {
participants.values.forEach { it.send(WsMessage(new)) }
}

fun newConnection(ws: Websocket) {
val id = "user${userCounter.incrementAndGet()}"
participants += id to ws
messages.map(::WsMessage).forEach { ws.send(it) }
addMessage("$id joined")
ws.onMessage { addMessage("$id: ${it.bodyString()}") }
ws.onClose {
participants -= id
addMessage("$id left")
fun newConnection(req: Request) =
WsResponse { ws ->
val id = "user${userCounter.incrementAndGet()}"
participants += id to ws
messages.map(::WsMessage).forEach { ws.send(it) }
addMessage("$id joined")
ws.onMessage { addMessage("$id: ${it.bodyString()}") }
ws.onClose {
participants -= id
addMessage("$id left")
}
}
}

val http = BasicAuth("http4k", env[CREDENTIALS]).then(static(Classpath()))
val ws = websockets("/ws" bind ::newConnection)

return PolyHandler(http, ws)
}
}

2 changes: 1 addition & 1 deletion src/main/kotlin/org/http4k/demo/IrcLauncher.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.http4k.demo

import org.http4k.cloudnative.env.Environment
import org.http4k.config.Environment
import org.http4k.server.Jetty
import org.http4k.server.asServer

Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/org/http4k/demo/Settings.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.http4k.demo

import org.http4k.cloudnative.env.EnvironmentKey
import org.http4k.config.EnvironmentKey
import org.http4k.core.Credentials

val CREDENTIALS = EnvironmentKey.map(String::toCredentials, Credentials::fromCredentials)
Expand Down
2 changes: 1 addition & 1 deletion src/test/kotlin/org/http4k/demo/IrcAppServerTest.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.http4k.demo

import org.http4k.client.WebsocketClient
import org.http4k.cloudnative.env.Environment
import org.http4k.config.Environment
import org.http4k.core.Credentials
import org.http4k.core.Uri
import org.http4k.server.Jetty
Expand Down
2 changes: 1 addition & 1 deletion src/test/kotlin/org/http4k/demo/IrcAppUnitTest.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.http4k.demo

import org.http4k.cloudnative.env.Environment
import org.http4k.config.Environment
import org.http4k.core.Credentials
import org.http4k.core.Method.GET
import org.http4k.core.Request
Expand Down

0 comments on commit 9a6b69b

Please sign in to comment.