All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ai.digital.integration.server.common.util.JavaUtil.kt Maven / Gradle / Ivy

There is a newer version: 23.3.0-1025.941
Show newest version
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)
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy