Skip to content

Commit 5852e38

Browse files
committed
WIP — use application plugin.
1 parent 730287a commit 5852e38

File tree

6 files changed

+206
-84
lines changed

6 files changed

+206
-84
lines changed

TODO.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
DO NOT MERGE:
2+
3+
- Verify:
4+
- Simulator (including continuous build/reload)
5+
- Dev mode run (including continuous bild/reload)
6+
- Artifact run
7+
- baaahs.github.io/sparklemotion run
8+
- Currently broken:
9+
- Routes in JVM
10+
- Refer to vici for config

build.gradle.kts

Lines changed: 72 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask
2-
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
32
import org.gradle.internal.os.OperatingSystem
43
import org.jetbrains.dokka.gradle.DokkaTask
54
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilationToRunnableFiles
@@ -30,9 +29,10 @@ val lwjglNatives = when {
3029

3130
plugins {
3231
kotlin("multiplatform") version Versions.kotlin
32+
application //to run JVM part
3333
kotlin("plugin.serialization") version Versions.kotlin
3434
id("org.jetbrains.dokka") version Versions.dokka
35-
id("com.github.johnrengelman.shadow") version "5.2.0"
35+
// id("com.github.johnrengelman.shadow") version "5.2.0"
3636
id("com.github.ben-manes.versions") version "0.29.0"
3737
id("maven-publish")
3838
id("name.remal.check-dependency-updates") version "1.0.211"
@@ -51,9 +51,14 @@ group = "org.baaahs"
5151
version = "0.0.1"
5252

5353
kotlin {
54-
jvm()
54+
jvm {
55+
withJava()
56+
}
57+
5558
js {
5659
browser {
60+
binaries.executable()
61+
5762
useCommonJs()
5863

5964
webpackTask {
@@ -87,9 +92,11 @@ kotlin {
8792
@Suppress("UNUSED_VARIABLE")
8893
val jvmMain by getting {
8994
dependencies {
95+
implementation("org.jetbrains.kotlinx:kotlinx-html-jvm:${Versions.kotlinxHtml}")
9096
implementation("io.ktor:ktor-server-core:${Versions.ktor}")
9197
implementation("io.ktor:ktor-server-netty:${Versions.ktor}")
9298
implementation("io.ktor:ktor-server-host-common:${Versions.ktor}")
99+
implementation("io.ktor:ktor-html-builder:${Versions.ktor}")
93100
implementation("io.ktor:ktor-websockets:${Versions.ktor}")
94101
implementation("ch.qos.logback:logback-classic:1.2.3")
95102
implementation("com.xenomachina:kotlin-argparser:2.0.7")
@@ -196,16 +203,32 @@ kotlin {
196203
}
197204
}
198205

199-
// workaround for https://youtrack.jetbrains.com/issue/KT-24463:
200-
tasks.named<KotlinCompile>("compileKotlinJvm") {
201-
dependsOn(":copySheepModel")
202-
}
206+
application {
207+
mainClass.set("baaahs.PinkyMainKt")
208+
209+
applicationDefaultJvmArgs = listOf(
210+
"-Djava.library.path=${file("src/jvmMain/jni")}",
211+
"-Dio.ktor.development=true"
212+
)
203213

204-
tasks.create<Copy>("copySheepModel") {
205-
from("src/commonMain/resources")
206-
into("build/classes/kotlin/jvm/main")
214+
if (isMac()) {
215+
applicationDefaultJvmArgs += listOf(
216+
"-XstartOnFirstThread", // required for OpenGL: https://github.com/LWJGL/lwjgl3/issues/311
217+
"-Djava.awt.headless=true" // required for Beat Link; otherwise we get this: https://jogamp.org/bugzilla/show_bug.cgi?id=485
218+
)
219+
}
207220
}
208221

222+
//// workaround for https://youtrack.jetbrains.com/issue/KT-24463:
223+
//tasks.named<KotlinCompile>("compileKotlinJvm") {
224+
// dependsOn(":copySheepModel")
225+
//}
226+
227+
//tasks.create<Copy>("copySheepModel") {
228+
// from("src/commonMain/resources")
229+
// into("build/classes/kotlin/jvm/main")
230+
//}
231+
209232
tasks.withType(Kotlin2JsCompile::class) {
210233
kotlinOptions.sourceMap = true
211234
kotlinOptions.sourceMapEmbedSources = "always"
@@ -221,7 +244,7 @@ tasks.withType(KotlinCompile::class) {
221244
}
222245

223246
tasks.named<ProcessResources>("jsProcessResources") {
224-
dependsOn("kotlinNpmInstall") // for node_modules stuff
247+
// dependsOn("kotlinNpmInstall") // for node_modules stuff
225248

226249
from("build/js/node_modules/requirejs") { include("require.js") }
227250
from("build/js/node_modules/three/build") { include("three.js") }
@@ -245,9 +268,9 @@ tasks.named<ProcessResources>("jsProcessResources") {
245268
}
246269

247270
tasks.named<ProcessResources>("jvmProcessResources") {
248-
dependsOn("jsBrowserDevelopmentWebpack")
249-
250-
from("build/distributions") { include("sparklemotion.js") }
271+
// dependsOn("jsBrowserDevelopmentWebpack")
272+
//
273+
// from("build/distributions") { include("sparklemotion.js") }
251274

252275
doLast {
253276
createResourceFilesList(File(buildDir, "processedResources/jvm/main"))
@@ -302,27 +325,43 @@ tasks.create<JavaExec>("runGlslJvmTests") {
302325
}
303326
}
304327

305-
tasks.create<Copy>("packageClientResources") {
306-
dependsOn("jsProcessResources", "jsBrowserWebpack")
307-
duplicatesStrategy = DuplicatesStrategy.WARN
308-
from(project.file("build/processedResources/js/main"))
309-
from(project.file("build/distributions"))
310-
into("build/classes/kotlin/jvm/main/htdocs")
328+
//tasks.create<Copy>("packageClientResources") {
329+
// dependsOn("jsProcessResources", "jsBrowserWebpack")
330+
// duplicatesStrategy = DuplicatesStrategy.WARN
331+
// from(project.file("build/processedResources/js/main"))
332+
// from(project.file("build/distributions"))
333+
// into("build/classes/kotlin/jvm/main/htdocs")
334+
//}
335+
336+
//tasks.named<Jar>("jvmJar") {
337+
// dependsOn("packageClientResources")
338+
// duplicatesStrategy = DuplicatesStrategy.WARN
339+
//}
340+
341+
//// include JS artifacts in any JAR we generate
342+
//tasks.getByName<Jar>("jvmJar") {
343+
// val taskName = if (project.hasProperty("isProduction")) {
344+
// "jsBrowserProductionWebpack"
345+
// } else {
346+
// "jsBrowserDevelopmentWebpack"
347+
// }
348+
// val webpackTask = tasks.getByName<KotlinWebpack>(taskName)
349+
// dependsOn(webpackTask) // make sure JS gets compiled first
350+
// from(File(webpackTask.destinationDirectory, webpackTask.outputFileName)) // bring output file along into the JAR
351+
//}
352+
353+
tasks.getByName<JavaExec>("run") {
354+
classpath(tasks.getByName<Jar>("jvmJar")) // so that the JS artifacts generated by `jvmJar` can be found and served
311355
}
312356

313-
tasks.named<Jar>("jvmJar") {
314-
dependsOn("packageClientResources")
315-
duplicatesStrategy = DuplicatesStrategy.WARN
316-
}
317-
318-
tasks.create<ShadowJar>("shadowJar") {
319-
dependsOn("jvmJar")
320-
from(tasks.named<Jar>("jvmJar").get().archiveFile)
321-
configurations = listOf(project.configurations["jvmRuntimeClasspath"])
322-
manifest {
323-
attributes["Main-Class"] = "baaahs.PinkyMainKt"
324-
}
325-
}
357+
//tasks.create<ShadowJar>("shadowJar") {
358+
// dependsOn("jvmJar")
359+
// from(tasks.named<Jar>("jvmJar").get().archiveFile)
360+
// configurations = listOf(project.configurations["jvmRuntimeClasspath"])
361+
// manifest {
362+
// attributes["Main-Class"] = "baaahs.PinkyMainKt"
363+
// }
364+
//}
326365

327366
tasks.withType(Test::class) {
328367
useJUnitPlatform {

data/Honcho.sparkle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1759,6 +1759,9 @@
17591759
"beatLink": {
17601760
"type": "baaahs.BeatLink:BeatLink"
17611761
},
1762+
"beatInfo": {
1763+
"type": "baaahs.BeatLink:BeatInfo"
1764+
},
17621765
"conflagrationSlider": {
17631766
"type": "baaahs.Core:Slider",
17641767
"title": "Conflagration",

src/jsMain/kotlin/baaahs/app/ui/AppDrawer.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ val AppDrawer = xComponent<AppDrawerProps>("AppDrawer", isPure = true) { props -
7171
attrs.button = true
7272
attrs.onClickFunction = props.onNewShow.withEvent()
7373
listItemIcon { icon(materialui.icons.Add) }
74-
listItemText { attrs.primary { +"New Show…" } }
74+
listItemText { attrs.primary { +"zNew Show…" } }
7575
}
7676

7777
listItem {

src/jvmMain/kotlin/baaahs/PinkyMain.kt

Lines changed: 54 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,27 @@ import baaahs.gl.GlBase
88
import baaahs.io.Fs
99
import baaahs.io.RealFs
1010
import baaahs.net.JvmNetwork
11+
import baaahs.server.index
1112
import baaahs.util.KoinLogger
1213
import baaahs.util.Logger
1314
import com.xenomachina.argparser.ArgParser
1415
import com.xenomachina.argparser.default
1516
import com.xenomachina.argparser.mainBody
1617
import io.ktor.application.*
1718
import io.ktor.features.*
19+
import io.ktor.html.*
20+
import io.ktor.http.*
1821
import io.ktor.http.content.*
19-
import io.ktor.response.*
2022
import io.ktor.routing.*
2123
import kotlinx.coroutines.CoroutineDispatcher
2224
import kotlinx.coroutines.ObsoleteCoroutinesApi
2325
import kotlinx.coroutines.runBlocking
26+
import kotlinx.html.HTML
2427
import org.koin.core.qualifier.named
2528
import org.koin.dsl.koinApplication
2629
import java.io.FileNotFoundException
27-
import java.nio.file.FileSystems
2830
import java.nio.file.Files
2931
import java.nio.file.Path
30-
import java.nio.file.Paths
3132

3233
@ObsoleteCoroutinesApi
3334
fun main(args: Array<String>) {
@@ -62,59 +63,62 @@ class PinkyMain(private val args: Args) {
6263

6364
val ktor = (pinky.httpServer as JvmNetwork.RealLink.KtorHttpServer)
6465
val resource = Pinky::class.java.classLoader.getResource("baaahs")!!
65-
if (resource.protocol == "jar") {
66-
val uri = resource.toURI()!!
67-
FileSystems.newFileSystem(uri, mapOf("create" to "true"))
68-
val jsResDir = Paths.get(uri).parent.resolve("htdocs")
69-
testForIndexDotHtml(jsResDir)
70-
logger.info { "Serving from jar at $jsResDir." }
66+
// if (resource.protocol == "jar") {
67+
// val uri = resource.toURI()!!
68+
// FileSystems.newFileSystem(uri, mapOf("create" to "true"))
69+
// val jsResDir = Paths.get(uri).parent.resolve("htdocs")
70+
// testForIndexDotHtml(jsResDir)
71+
// logger.info { "Serving from jar at $jsResDir." }
7172

7273
ktor.application.routing {
73-
static {
74-
resources("htdocs")
75-
get("mapper") { call.respondRedirect("mapper/") }
76-
route("mapper/") { defaultResource("htdocs/mapper/index.html") }
77-
get("monitor") { call.respondRedirect("monitor/") }
78-
route("monitor/") { defaultResource("htdocs/monitor/index.html") }
79-
get("ui") { call.respondRedirect("ui/") }
80-
route("ui/") { defaultResource("htdocs/ui/index.html") }
81-
defaultResource("htdocs/ui-index.html")
74+
// get("mapper") { call.respondRedirect("mapper/") }
75+
// route("mapper/") { defaultResource("htdocs/mapper/index.html") }
76+
// get("monitor") { call.respondRedirect("monitor/") }
77+
// route("monitor/") { defaultResource("htdocs/monitor/index.html") }
78+
// get("ui") { call.respondRedirect("ui/") }
79+
// route("ui/") { defaultResource("htdocs/ui/index.html") }
80+
81+
get("/") {
82+
call.respondHtml(HttpStatusCode.OK, HTML::index)
8283
}
83-
}
84-
} else {
85-
val classPathBaseDir = Paths.get(resource.file).parent
86-
val repoDir = classPathBaseDir.parent.parent.parent.parent.parent
87-
val jsResDir = repoDir.resolve("build/processedResources/js/main")
88-
val jsPackageDir = "build/distributions"
89-
testForIndexDotHtml(jsResDir)
90-
logger.info { "Serving resources from files at $jsResDir." }
91-
logger.info { "Serving sparklemotion from files at $jsPackageDir." }
92-
93-
ktor.application.routing {
9484
static {
95-
staticRootFolder = jsResDir.toFile()
96-
97-
file("sparklemotion.js",
98-
repoDir.resolve("$jsPackageDir/sparklemotion.js").toFile())
99-
file("sparklemotion.js.map",
100-
repoDir.resolve("$jsPackageDir/sparklemotion.js.map").toFile())
101-
102-
file("vendors.js",
103-
repoDir.resolve("$jsPackageDir/vendors.js").toFile())
104-
file("vendors.js.map",
105-
repoDir.resolve("$jsPackageDir/vendors.js.map").toFile())
106-
107-
files(jsResDir.toFile())
108-
get("mapper") { call.respondRedirect("mapper/") }
109-
route("mapper/") { default("mapper/index.html") }
110-
get("monitor") { call.respondRedirect("monitor/") }
111-
route("monitor/") { default("monitor/index.html") }
112-
get("ui") { call.respondRedirect("ui/") }
113-
route("ui/") { default("ui/index.html") }
114-
default("ui-index.html")
85+
resources()
11586
}
11687
}
117-
}
88+
// } else {
89+
// val classPathBaseDir = Paths.get(resource.file).parent
90+
// val repoDir = classPathBaseDir.parent.parent.parent.parent.parent
91+
// val jsResDir = repoDir.resolve("build/processedResources/js/main")
92+
// val jsPackageDir = "build/distributions"
93+
// testForIndexDotHtml(jsResDir)
94+
// logger.info { "Serving resources from files at $jsResDir." }
95+
// logger.info { "Serving sparklemotion from files at $jsPackageDir." }
96+
//
97+
// ktor.application.routing {
98+
// static {
99+
// staticRootFolder = jsResDir.toFile()
100+
//
101+
// file("sparklemotion.js",
102+
// repoDir.resolve("$jsPackageDir/sparklemotion.js").toFile())
103+
// file("sparklemotion.js.map",
104+
// repoDir.resolve("$jsPackageDir/sparklemotion.js.map").toFile())
105+
//
106+
// file("vendors.js",
107+
// repoDir.resolve("$jsPackageDir/vendors.js").toFile())
108+
// file("vendors.js.map",
109+
// repoDir.resolve("$jsPackageDir/vendors.js.map").toFile())
110+
//
111+
// files(jsResDir.toFile())
112+
// get("mapper") { call.respondRedirect("mapper/") }
113+
// route("mapper/") { default("mapper/index.html") }
114+
// get("monitor") { call.respondRedirect("monitor/") }
115+
// route("monitor/") { default("monitor/index.html") }
116+
// get("ui") { call.respondRedirect("ui/") }
117+
// route("ui/") { default("ui/index.html") }
118+
// default("ui-index.html")
119+
// }
120+
// }
121+
// }
118122

119123
ktor.application.install(CallLogging)
120124
ktor.application.routing {

0 commit comments

Comments
 (0)