ai.digital.integration.server.common.util.JavaUtil.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of integration-server-gradle-plugin Show documentation
Show all versions of integration-server-gradle-plugin Show documentation
The easy way to get custom setup for Deploy up and running
package ai.digital.integration.server.common.util
import ai.digital.integration.server.deploy.internals.DeployServerUtil
import org.gradle.api.Project
import org.jetbrains.kotlin.konan.file.File
class JavaUtil {
companion object {
@Suppress("UNCHECKED_CAST")
fun execJava(config: Map): Process {
val jvmPath =
config.getOrDefault("jvmPath", "${File.javaHome}${File.separator}bin${File.separator}java") as String
val jvmArgs = config.getOrDefault("jvmArgs", listOf()) as List
val programArgs = config.getOrDefault("programArgs", listOf()) as List
val mainClass = config["mainClass"] as String
val classpath = config["classpath"] as String
val configEnvironment = config.getOrDefault("environment", mapOf()) as Map
val environment = mutableMapOf()
environment.putAll(configEnvironment)
environment["CLASSPATH"] = classpath
val params = mutableListOf()
params.addAll(jvmArgs)
params.add(mainClass)
params.addAll(programArgs)
val command = mutableMapOf()
command.putAll(config)
command["command"] = jvmPath
command["runLocalShell"] = false
command["params"] = params
command["environment"] = environment
return ProcessUtil.exec(command)
}
fun debugJvmArg(project: Project, debugPort: Int, debugSuspend: Boolean): List {
project.logger.lifecycle("Enabled debug mode on port $debugPort")
return listOf(
"-Xdebug",
DeployServerUtil.createDebugString(debugSuspend, debugPort)
)
}
fun jvmPath(project: Project, integrationServerJVMPath: String): Map {
val jvmPath = "$integrationServerJVMPath${File.separator}bin${File.separator}java"
project.logger.lifecycle("Using JVM from location: $jvmPath")
return mapOf("jvmPath" to jvmPath)
}
}
}