aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/language-web/build.gradle.kts
blob: e1d250ec96fce5e70efd1c12cf6f7f7bf6a4b703 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*
 * SPDX-FileCopyrightText: 2021-2023 The Refinery Authors <https://refinery.tools/>
 *
 * SPDX-License-Identifier: EPL-2.0
 */

plugins {
	id("tools.refinery.gradle.java-application")
	id("tools.refinery.gradle.xtext-generated")
}

val webapp: Configuration by configurations.creating {
	isCanBeConsumed = false
	isCanBeResolved = true
}

dependencies {
	implementation(project(":refinery-language"))
	implementation(project(":refinery-language-ide"))
	implementation(libs.jetty.server)
	implementation(libs.jetty.servlet)
	implementation(libs.jetty.websocket.server)
	implementation(libs.slf4j.api)
	implementation(libs.xtext.web)
	webapp(project(path = ":refinery-frontend", configuration = "productionAssets"))
	testImplementation(testFixtures(project(":refinery-language")))
	testImplementation(libs.jetty.websocket.client)
}

application {
	mainClass.set("tools.refinery.language.web.ServerLauncher")
	// Enable JDK 19 preview features for virtual thread support.
	applicationDefaultJvmArgs += "--enable-preview"
}

// Enable JDK 19 preview features for virtual thread support.
fun enablePreview(task: JavaForkOptions) {
	task.jvmArgs("--enable-preview")
}

tasks {
	val generateXtextLanguage by project(":refinery-language").tasks.existing

	for (taskName in listOf("compileJava", "processResources")) {
		named(taskName) {
			dependsOn(generateXtextLanguage)
		}
	}

	withType(JavaCompile::class) {
		options.release.set(19)
		// Enable JDK 19 preview features for virtual thread support.
		options.compilerArgs.plusAssign("--enable-preview")
	}

	withType(Test::class) {
		enablePreview(this)
	}

	jar {
		dependsOn(webapp)
		from(webapp) {
			into("webapp")
		}
	}

	shadowJar {
		dependsOn(webapp)
		from(project.sourceSets.main.map { it.output })
		exclude("META-INF/INDEX.LIST", "META-INF/*.SF", "META-INF/*.DSA", "META-INF/*.RSA", "schema/*",
				".options", ".api_description", "*.profile", "about.*", "about_*.html", "about_files/*",
				"plugin.xml", "systembundle.properties", "profile.list", "META-INF/resources/xtext/**")
		append("plugin.properties")
		from(webapp) {
			into("webapp")
		}
	}

	register<JavaExec>("serveBackend") {
		dependsOn(webapp)
		val mainRuntimeClasspath = sourceSets.main.map { it.runtimeClasspath }
		dependsOn(mainRuntimeClasspath)
		classpath(mainRuntimeClasspath)
		mainClass.set(application.mainClass)
		enablePreview(this)
		standardInput = System.`in`
		val baseResource = webapp.incoming.artifacts.artifactFiles.first()
		environment("BASE_RESOURCE", baseResource)
		group = "run"
		description = "Start a Jetty web server serving the Xtex API and assets."
	}
}