Skip to content

Commit 23337fa

Browse files
committed
build: add --jmx-port to allow JMX connections to gradle game
1 parent 374bf10 commit 23337fa

File tree

1 file changed

+29
-0
lines changed
  • build-logic/src/main/kotlin/org/terasology/gradology

1 file changed

+29
-0
lines changed

build-logic/src/main/kotlin/org/terasology/gradology/exec.kt

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,13 @@ import org.apache.tools.ant.taskdefs.condition.Os
77
import org.gradle.api.logging.Logger
88
import org.gradle.api.logging.Logging
99
import org.gradle.api.plugins.JavaApplication
10+
import org.gradle.api.provider.Property
11+
import org.gradle.api.tasks.Input
1012
import org.gradle.api.tasks.JavaExec
1113
import org.gradle.api.tasks.SourceSetContainer
1214
import org.gradle.api.tasks.options.Option
1315
import org.gradle.kotlin.dsl.get
16+
import org.gradle.kotlin.dsl.property
1417
import org.gradle.kotlin.dsl.the
1518

1619
const val DEFAULT_MAX_HEAP_SIZE = "3G"
@@ -45,6 +48,14 @@ fun isMacOS() : Boolean {
4548

4649
open class RunTerasology : JavaExec() {
4750

51+
@get:Input
52+
val jmxPort: Property<Int> = objectFactory.property()
53+
54+
@Option(option="jmx-port", description="Enable JMX connections on this port (jmxremote.port)")
55+
fun parseJmxPort(value: String?) {
56+
jmxPort.set(value.takeUnless { it.isNullOrEmpty() }?.toIntOrNull())
57+
}
58+
4859
@Option(option="max-heap", description="Set maximum heap size (-Xmx)")
4960
override fun setMaxHeapSize(heapSize: String?) {
5061
super.setMaxHeapSize(heapSize)
@@ -56,6 +67,8 @@ open class RunTerasology : JavaExec() {
5667
mainClass.set(project.the<JavaApplication>().mainClass)
5768
workingDir = project.rootDir
5869

70+
// All calls to non-final Task methods must be within a non-final method
71+
// themselves. This includes #dependsOn, #args, etc.
5972
initConfig()
6073
}
6174

@@ -71,5 +84,21 @@ open class RunTerasology : JavaExec() {
7184
args("--no-splash")
7285
jvmArgs("-XstartOnFirstThread", "-Djava.awt.headless=true")
7386
}
87+
88+
// Any configuration that depends on the value of a task Property like jmxPort
89+
// should be done later, as that Property value will change between object
90+
// construction time and task execution time.
91+
}
92+
93+
override fun exec() {
94+
jmxPort.orNull?.let {
95+
systemProperty("com.sun.management.jmxremote.port", it)
96+
systemProperty("com.sun.management.jmxremote.rmi.port",it + 1)
97+
systemProperty("com.sun.management.jmxremote.password.file",
98+
project.rootProject.file("config/jmxremote.password"))
99+
systemProperty("com.sun.management.jmxremote.ssl", "false")
100+
}
101+
102+
super.exec()
74103
}
75104
}

0 commit comments

Comments
 (0)