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

ai.digital.integration.server.deploy.internals.EnvironmentUtil.kt Maven / Gradle / Ivy

There is a newer version: 23.3.0-1025.941
Show newest version
package ai.digital.integration.server.deploy.internals

import ai.digital.integration.server.deploy.domain.Cli
import ai.digital.integration.server.common.domain.Server
import ai.digital.integration.server.common.util.OsUtil
import ai.digital.integration.server.common.util.TlsUtil
import org.gradle.api.Project
import java.io.File

class EnvironmentUtil {
    companion object {
        fun getServerEnv(project: Project,server: Server): MutableMap {
            return getEnv(project, "JDK_JAVA_OPTIONS", server.debugSuspend, server.debugPort, null)
        }

        fun getCliEnv(project: Project, cli: Cli, extraParams: Map, extraClassPath: List, auxiliaryServer: Boolean = false): Map {
            val env = getEnv(project, "JDK_JAVA_OPTIONS", cli.debugSuspend, cli.debugPort, null, extraParams, auxiliaryServer)
            env["EXTRA_DEPLOYIT_CLI_CLASSPATH"] = extraClassPath.joinToString(separator = OsUtil.getPathSeparator())
            return env
        }

        fun getEnv(
            project: Project,
            variableName: String,
            debugSuspend: Boolean,
            debugPort: Int?,
            logFileName: String?
        ): MutableMap {
            return getEnv(project, variableName, debugSuspend, debugPort, logFileName, mutableMapOf())
        }

        fun getEnv(
            project: Project,
            variableName: String,
            debugSuspend: Boolean,
            debugPort: Int?,
            logFileName: String?,
            extraProps: Map,
            auxiliaryServer: Boolean = false
        ): MutableMap {
            var opts = if (!logFileName.isNullOrEmpty()) "-Xmx1024m -DLOGFILE=\"$logFileName\"" else "-Xmx1024m"

            debugPort?.let {
                opts = "$opts ${DeployServerUtil.createDebugString(debugSuspend, it)} "
            }

            if (!auxiliaryServer && DeployServerUtil.isTls(project)) {
                val tls = TlsUtil.getTls(project, DeployServerUtil.getServerWorkingDir(project))
                opts = "$opts -Djavax.net.ssl.trustStore=\"${tls?.trustStoreFile()}\" -Djavax.net.ssl.trustStorePassword=\"${tls?.truststorePassword}\" "
            }

            opts += extraProps
                .filterValues { it != null }
                .map { "-D${it.key}=\"${it.value}\"" }
                .joinToString(separator = " ")

            return mutableMapOf(
                variableName to opts
            )
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy