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

ai.digital.integration.server.common.pluginManager.StartPluginManagerTask.kt Maven / Gradle / Ivy

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

import ai.digital.integration.server.common.constant.PluginConstant.PLUGIN_GROUP
import ai.digital.integration.server.common.domain.Server
import ai.digital.integration.server.common.util.ProcessUtil
import ai.digital.integration.server.deploy.tasks.server.StartDeployServerInstanceTask
import ai.digital.integration.server.deploy.tasks.tls.TlsApplicationConfigurationOverrideTask
import ai.digital.integration.server.deploy.internals.DeployServerUtil
import ai.digital.integration.server.deploy.internals.EnvironmentUtil
import org.gradle.api.DefaultTask
import org.gradle.api.tasks.TaskAction
import java.io.File
import java.nio.file.Paths

open class StartPluginManagerTask : DefaultTask() {

    init {
        val dependencies = mutableListOf(StartDeployServerInstanceTask.NAME)

        if (DeployServerUtil.isTls(project)) {
            dependencies.add(TlsApplicationConfigurationOverrideTask.NAME)
        }

        this.dependsOn(dependencies)
        this.group = PLUGIN_GROUP
        this.onlyIf { !DeployServerUtil.isDockerBased(project) }
    }

    private fun getBinDir(): File {
        return Paths.get(DeployServerUtil.getServerWorkingDir(project), "bin").toFile()
    }

    private fun startPluginManager(server: Server) {
        val process = ProcessUtil.exec(
            mapOf(
                "command" to "run",
                "discardIO" to true,
                "environment" to EnvironmentUtil.getServerEnv(project, server),
                "params" to arrayOf("plugin-manager-cli"),
                "workDir" to getBinDir()
            )
        )
        project.logger.lifecycle(
            "Launched Plugin Manager on Deploy server $server.name on PID [${process.pid()}] with command [${
                process.info().commandLine().orElse("")
            }]."
        )
    }

    @TaskAction
    fun launch() {
        val server = DeployServerUtil.getServer(project)
        project.logger.lifecycle("Launching Plugin Manager on Deploy server $server.name")
        startPluginManager(server)
    }

    companion object {
        const val NAME = "startPluginManager"
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy