Skip to content

Commit

Permalink
feat: ktor support
Browse files Browse the repository at this point in the history
  • Loading branch information
radstevee committed Dec 12, 2024
1 parent 483353e commit a0f9510
Show file tree
Hide file tree
Showing 16 changed files with 140 additions and 47 deletions.
5 changes: 0 additions & 5 deletions api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@ plugins {
`maven-publish`
}

fun prop(name: String) = project.rootProject.property(name) as String

group = prop("group")
version = prop("version")

base {
archivesName.set("${rootProject.name}-${project.name}")
}
Expand Down
12 changes: 10 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
plugins {
id("xyz.jpenilla.run-paper") version "2.3.1" apply false
id("io.papermc.paperweight.userdev") version "1.7.4" apply false
kotlin("jvm") version "2.1.0" apply false
}

version = project.property("version") as String
group = project.property("group") as String
fun prop(name: String) = property("version") as String

version = prop("version")
group = prop("group")

subprojects {
version = prop("version")
group = prop("version")
}
8 changes: 0 additions & 8 deletions examples/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,9 @@ plugins {
java
}

fun prop(name: String) = project.rootProject.property(name) as String

group = prop("group")
version = prop("version")

subprojects {
apply(plugin = "java")

group = prop("group")
version = prop("version")

repositories {
mavenCentral()
}
Expand Down
3 changes: 0 additions & 3 deletions examples/http-example/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ plugins {

fun prop(name: String) = project.rootProject.property(name) as String

version = prop("version")
group = prop("group")

dependencies {
minecraft("com.mojang:minecraft:${prop("minecraft_version")}")
mappings("net.fabricmc:yarn:${prop("yarn_mappings")}:v2")
Expand Down
37 changes: 37 additions & 0 deletions examples/ktor-example/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
plugins {
kotlin("jvm") version "2.1.0"
id("xyz.jpenilla.run-paper")
id("com.gradleup.shadow") version "9.0.0-beta4"
}

repositories {
mavenCentral()
maven("https://repo.papermc.io/repository/maven-public/")
}

dependencies {
implementation(project(":spigot"))
implementation(project(":http"))
implementation(project(":api"))
implementation(project(":jetty"))
implementation(project(":ktor")) {
isTransitive = false
}

val ktorVersion = "3.0.2"
implementation("io.ktor:ktor-server-core:$ktorVersion")
implementation("io.ktor:ktor-server-jetty-jakarta:$ktorVersion")

compileOnly("io.netty:netty-all:4.1.97.Final")
compileOnly("org.slf4j:slf4j-api:1.7.30")

compileOnly("io.papermc.paper:paper-api:1.21.4-R0.1-SNAPSHOT")
}

tasks.runServer {
minecraftVersion("1.21.4")
}

tasks.assemble {
dependsOn(tasks.shadowJar)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package net.mcbrawls.inject.examples.ktor

import io.ktor.server.engine.EmbeddedServer
import io.ktor.server.jetty.jakarta.JettyApplicationEngine
import io.ktor.server.jetty.jakarta.JettyApplicationEngineBase
import io.ktor.server.response.respondText
import io.ktor.server.routing.get
import io.ktor.server.routing.routing
import net.mcbrawls.inject.ktor.jettyKtorServer
import net.mcbrawls.inject.ktor.startOnNewThread
import net.mcbrawls.inject.spigot.InjectSpigot
import org.bukkit.plugin.java.JavaPlugin

class InjectKtorExample : JavaPlugin() {
private var ktor: EmbeddedServer<JettyApplicationEngine, JettyApplicationEngineBase.Configuration>? = null

private fun initKtor() {
ktor = jettyKtorServer(InjectSpigot.INSTANCE) {
routing {
get("/") {
call.respondText("Hello, from Ktor!")
}
}
}

ktor!!.startOnNewThread()
}

override fun onEnable() {
initKtor()
}

override fun onDisable() {
ktor?.stop()
}
}
4 changes: 4 additions & 0 deletions examples/ktor-example/src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
name: "inject-ktor-example"
version: "0.0"
main: net.mcbrawls.inject.examples.ktor.InjectKtorExample
api-version: "1.21"
3 changes: 0 additions & 3 deletions fabric/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ plugins {

fun prop(name: String) = project.rootProject.property(name) as String

version = prop("version")
group = prop("group")

base {
archivesName.set("${rootProject.name}-${project.name}")
}
Expand Down
5 changes: 0 additions & 5 deletions http/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@ plugins {
`maven-publish`
}

fun prop(name: String) = project.rootProject.property(name) as String

group = prop("group")
version = prop("version")

base {
archivesName.set("${rootProject.name}-${project.name}")
}
Expand Down
5 changes: 0 additions & 5 deletions javalin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@ plugins {
`maven-publish`
}

fun prop(name: String) = project.rootProject.property(name) as String

group = prop("group")
version = prop("version")

base {
archivesName.set("${rootProject.name}-${project.name}")
}
Expand Down
5 changes: 0 additions & 5 deletions jetty/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@ plugins {
`maven-publish`
}

fun prop(name: String) = project.rootProject.property(name) as String

group = prop("group")
version = prop("version")

base {
archivesName.set("${rootProject.name}-${project.name}")
}
Expand Down
17 changes: 17 additions & 0 deletions ktor/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
plugins {
kotlin("jvm") version "2.1.0"
}

repositories {
mavenCentral()
}

dependencies {
val ktorVersion = "3.0.2"

implementation(project(":api"))
implementation(project(":jetty"))

compileOnly("io.ktor:ktor-server-core:$ktorVersion")
compileOnly("io.ktor:ktor-server-jetty-jakarta:$ktorVersion")
}
30 changes: 30 additions & 0 deletions ktor/src/main/kotlin/net/mcbrawls/inject/ktor/InjectKtor.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package net.mcbrawls.inject.ktor

import io.ktor.server.application.Application
import io.ktor.server.engine.EmbeddedServer
import io.ktor.server.engine.embeddedServer
import io.ktor.server.jetty.jakarta.Jetty
import io.ktor.server.jetty.jakarta.JettyApplicationEngine
import io.ktor.server.jetty.jakarta.JettyApplicationEngineBase
import net.mcbrawls.inject.api.InjectPlatform
import net.mcbrawls.inject.jetty.JettyInjector
import org.eclipse.jetty.server.LocalConnector

fun jettyKtorServer(platform: InjectPlatform, module: Application.() -> Unit = {}) = embeddedServer(
Jetty,
configure = {
configureServer = {
val connector = LocalConnector(this)
server.connectors = arrayOf(connector)

platform.registerInjector(JettyInjector(connector))
}
},
module = module,
)

fun EmbeddedServer<JettyApplicationEngine, JettyApplicationEngineBase.Configuration>.startOnNewThread() {
Thread({
start(wait = true)
}, "Ktor").start()
}
9 changes: 6 additions & 3 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@ include(":fabric")
include(":spigot")
include(":http")
include(":examples")
include(":examples:http-example")
include(":examples:javalin-example")
include(":examples:spring-example")
include(":jetty")
include(":javalin")
include(":spring")
include(":ktor")

include(":examples:http-example")
include(":examples:javalin-example")
include(":examples:spring-example")
include(":examples:ktor-example")
3 changes: 0 additions & 3 deletions spigot/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ plugins {

fun prop(name: String) = project.rootProject.property(name) as String

group = prop("group")
version = prop("version")

repositories {
mavenCentral()
maven("https://repo.papermc.io/repository/maven-public/")
Expand Down
5 changes: 0 additions & 5 deletions spring/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@ plugins {
`maven-publish`
}

fun prop(name: String) = project.rootProject.property(name) as String

group = prop("group")
version = prop("version")

base {
archivesName.set("${rootProject.name}-${project.name}")
}
Expand Down

0 comments on commit a0f9510

Please sign in to comment.