You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
62 lines
1.8 KiB
62 lines
1.8 KiB
package de.joshavg
|
|
|
|
import org.eclipse.microprofile.config.inject.ConfigProperty
|
|
import org.slf4j.Logger
|
|
import org.slf4j.LoggerFactory
|
|
import java.io.File
|
|
import java.nio.file.Files
|
|
import java.nio.file.Paths
|
|
import java.time.LocalDateTime
|
|
import java.time.format.DateTimeFormatter
|
|
import java.util.*
|
|
import javax.enterprise.context.ApplicationScoped
|
|
|
|
data class BuildConfig(val exec: String,
|
|
val user: String,
|
|
val dir: String,
|
|
val key: String,
|
|
val env: Map<String, String>) {
|
|
fun asPublic() = copy(key = "")
|
|
}
|
|
|
|
@ApplicationScoped
|
|
class Builds(@ConfigProperty(name = "ALFRED_HOME")
|
|
private val home: String) {
|
|
|
|
private val logger: Logger = LoggerFactory.getLogger(this::class.java)
|
|
|
|
init {
|
|
logger.info("ALFRED_HOME is $home")
|
|
}
|
|
|
|
fun buildConfig(build: String): BuildConfig {
|
|
val path = Paths.get(home, "builds", "$build.properties")
|
|
val props = Properties()
|
|
props.load(path.toFile().inputStream())
|
|
|
|
val env = props
|
|
.entries
|
|
.filter { it.key.toString() == it.key.toString().toUpperCase() }
|
|
.map { Pair(it.key.toString(), it.value.toString()) }
|
|
.toMap()
|
|
|
|
return BuildConfig(
|
|
exec = props.getProperty("exec"),
|
|
user = props.getProperty("user"),
|
|
dir = props.getProperty("dir"),
|
|
key = props.getProperty("key") ?: "",
|
|
env = env)
|
|
}
|
|
|
|
fun createLogFile(build: String): File {
|
|
val nowStr = LocalDateTime.now().format(DateTimeFormatter.ISO_DATE_TIME)
|
|
val fileName = "$build.$nowStr.log"
|
|
|
|
val path = Paths.get(home, "logs", fileName)
|
|
path.toFile().parentFile.mkdirs()
|
|
|
|
return Files.createFile(path).toFile()
|
|
}
|
|
|
|
}
|