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

ai.digital.integration.server.deploy.internals.CentralConfigurationServerUtil.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.common.util.PropertiesUtil
import ai.digital.integration.server.common.util.PropertyUtil
import ai.digital.integration.server.deploy.domain.CentralConfigurationServer
import org.gradle.api.Project
import java.io.File
import java.nio.file.Path
import java.nio.file.Paths
import kotlin.system.exitProcess

class CentralConfigurationServerUtil {
    companion object {

        fun hasCentralConfigurationServer(project: Project): Boolean {
            return DeployExtensionUtil.getExtension(project).centralConfigurationServer.get().enable
        }

        fun getCentralConfigurationServer(project: Project): CentralConfigurationServer {
            val cc = DeployExtensionUtil.getExtension(project).centralConfigurationServer.get()
            cc.version = getVersion(project, cc)
            cc.debugPort = getDebugPort(project, cc)
            return cc
        }

        private fun getDebugPort(project: Project, cc: CentralConfigurationServer): Int? {
            return if (PropertyUtil.resolveBooleanValue(project, "debug", true)) {
                PropertyUtil.resolveIntValue(project, "ccDebugPort", cc.debugPort)
            } else {
                null
            }
        }

        private fun getVersion(project: Project, cc: CentralConfigurationServer): String? {
            return if (project.hasProperty("centralConfigurationVersion")) {
                    project.property("centralConfigurationVersion").toString()
                } else if (!cc.version.isNullOrEmpty()) {
                    cc.version
                } else if (!DeployServerUtil.getServer(project).version.isNullOrEmpty()) {
                    DeployServerUtil.getServer(project).version
                } else {
                    project.logger.error("Central Configuration Server Version is not specified")
                    exitProcess(1)
                }
        }

        fun getServerPath(project: Project, cc: CentralConfigurationServer): Path {
            val targetDir = DeployServerUtil.getServerDistFolderPath(project).toString()
            return Paths.get(targetDir, "central-configuration-${cc.version}-server").toAbsolutePath()
        }

        fun getBinDir(project: Project, cc: CentralConfigurationServer): File {
            return Paths.get(getServerPath(project, cc).toString(), "bin").toFile()
        }

        fun getLogDir(project: Project, cc: CentralConfigurationServer): File {
            return Paths.get(getServerPath(project, cc).toString(), "log").toFile()
        }

        fun readDeployitConfProperty(project: Project, key: String): String {
            val deployitConf = Paths.get("${getServerPath(project, getCentralConfigurationServer(project))}/conf/deployit.conf").toFile()
            return PropertiesUtil.readProperty(deployitConf, key)
        }

        fun logFileName(): String {
            return "central-config"
        }

        fun getBaseUrl(project: Project): String {
            return "http://localhost:${readDeployitConfProperty(project, "http.port")}"
        }

    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy