mirror of https://github.com/micromata/borgbackup-butler.git

Kai Reinhard
17.59.2021 c6e77f6fa462e292db5f693a33e7c483b5a6e19e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package de.micromata.borgbutler.server
 
import de.micromata.borgbutler.config.Configuration
import de.micromata.borgbutler.config.ConfigurationHandler.Companion.getConfiguration
import mu.KotlinLogging
import org.apache.commons.lang3.StringUtils
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.annotation.Value
import org.springframework.stereotype.Component
 
private val log = KotlinLogging.logger {}
 
class ServerConfiguration : Configuration() {
    var port = WEBSERVER_PORT_DEFAULT
 
    /**
     * If true, CrossOriginFilter will be set.
     */
    var isWebDevelopmentMode = WEB_DEVELOPMENT_MODE_PREF_DEFAULT
 
    fun copyFrom(other: ServerConfiguration) {
        super.copyFrom(other)
        port = other.port
        isWebDevelopmentMode = other.isWebDevelopmentMode
    }
 
    companion object {
        val supportedLanguages = arrayOf("en", "de")
        const val WEBSERVER_PORT_DEFAULT = 9042
        private const val WEB_DEVELOPMENT_MODE_PREF_DEFAULT = false
        @JvmStatic
        var applicationHome: String? = null
            get() {
                if (field == null) {
                    field = System.getProperty("applicationHome")
                    if (StringUtils.isBlank(field)) {
                        field = System.getProperty("user.dir")
                        log.info("applicationHome is not given as JVM   parameter. Using current working dir (OK for start in IDE): $field")
                    }
                }
                return field
            }
            private set
 
        @JvmStatic
        fun get(): ServerConfiguration {
            return getConfiguration() as ServerConfiguration
        }
    }
}