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.
46 lines
1.3 KiB
46 lines
1.3 KiB
package de.joshavg
|
|
|
|
import org.eclipse.microprofile.config.inject.ConfigProperty
|
|
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? = null) {
|
|
fun asPublic() = copy(key = null)
|
|
}
|
|
|
|
@ApplicationScoped
|
|
class Builds(@ConfigProperty(name = "alfred.home")
|
|
val home: String) {
|
|
|
|
fun buildConfig(build: String): BuildConfig {
|
|
val path = Paths.get(home, "builds", "$build.properties")
|
|
val props = Properties()
|
|
props.load(path.toFile().inputStream())
|
|
|
|
return BuildConfig(
|
|
exec = props.getProperty("exec"),
|
|
user = props.getProperty("user"),
|
|
dir = props.getProperty("dir"),
|
|
key = props.getProperty("key"))
|
|
}
|
|
|
|
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()
|
|
}
|
|
|
|
}
|