Fix server logs coloring
This commit is contained in:
@@ -10,10 +10,12 @@ import okhttp3.internal.EMPTY_REQUEST
|
|||||||
class ApiTool {
|
class ApiTool {
|
||||||
companion object {
|
companion object {
|
||||||
const val JSON = "application/json"
|
const val JSON = "application/json"
|
||||||
val apiRoot = System.getProperty("pairgoth.api.url").let { base ->
|
val apiRoot =
|
||||||
if (base.endsWith('/')) "${base}api/"
|
(System.getProperty("pairgoth.api.url") ?: System.getProperty("pairgoth.webapp.url"))
|
||||||
else "${base}/api/"
|
.let { base ->
|
||||||
}
|
if (base.endsWith('/')) "${base}api/"
|
||||||
|
else "${base}/api/"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
private val client = OkHttpClient()
|
private val client = OkHttpClient()
|
||||||
private fun prepare(url: String) = Request.Builder().url("$apiRoot$url").header("Accept", JSON)
|
private fun prepare(url: String) = Request.Builder().url("$apiRoot$url").header("Accept", JSON)
|
||||||
|
@@ -35,7 +35,11 @@ import java.util.regex.Pattern
|
|||||||
|
|
||||||
fun main(vararg args: String) {
|
fun main(vararg args: String) {
|
||||||
try {
|
try {
|
||||||
|
// read default properties and provided ones, if any
|
||||||
|
readProperties()
|
||||||
|
// extract war files from main archive
|
||||||
extractWarFiles()
|
extractWarFiles()
|
||||||
|
// launch web server
|
||||||
launchServer()
|
launchServer()
|
||||||
} catch (t: Throwable) {
|
} catch (t: Throwable) {
|
||||||
t.printStackTrace(System.err)
|
t.printStackTrace(System.err)
|
||||||
@@ -45,6 +49,30 @@ fun main(vararg args: String) {
|
|||||||
private val tmp = System.getProperty("java.io.tmpdir")
|
private val tmp = System.getProperty("java.io.tmpdir")
|
||||||
private val version = "1.0-SNAPSHOT" // TODO CB
|
private val version = "1.0-SNAPSHOT" // TODO CB
|
||||||
|
|
||||||
|
private fun readProperties() {
|
||||||
|
val defaultProps = getResource("/server.default.properties") ?: throw Error("missing default server properties")
|
||||||
|
defaultProps.openStream().use {
|
||||||
|
serverProps.load(InputStreamReader(it, StandardCharsets.UTF_8))
|
||||||
|
}
|
||||||
|
val properties = File("./pairgoth.properties")
|
||||||
|
if (properties.exists()) {
|
||||||
|
serverProps.load(FileReader(properties))
|
||||||
|
serverProps.entries.forEach { entry ->
|
||||||
|
val property = entry.key as String
|
||||||
|
val value = entry.value as String
|
||||||
|
if (!property.startsWith("webapp.ssl.")) {
|
||||||
|
// do not propagate ssl properties further
|
||||||
|
System.setProperty("pairgoth.$property", value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// we want colorized output on linux
|
||||||
|
if (System.getProperty("os.name") == "Linux")
|
||||||
|
{
|
||||||
|
System.setProperty("org.eclipse.jetty.logging.appender.MESSAGE_ESCAPE", "false");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun extractWarFiles() {
|
private fun extractWarFiles() {
|
||||||
// val jarLocation = object{}::class.java.protectionDomain.codeSource.location
|
// val jarLocation = object{}::class.java.protectionDomain.codeSource.location
|
||||||
// prepare output directory
|
// prepare output directory
|
||||||
@@ -66,11 +94,11 @@ private fun extractWarFiles() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private val mainClass = object{}::class.java.enclosingClass
|
private val mainClass = object{}::class.java.enclosingClass
|
||||||
private val jarPath = mainClass.protectionDomain.codeSource.location.path.let { URLDecoder.decode(it, "UTF-8") }
|
private val jarPath = mainClass.protectionDomain.codeSource.location.path.let { URLDecoder.decode(it, "UTF-8") }
|
||||||
private val serverProps = Properties()
|
private val serverProps = Properties()
|
||||||
private fun getResource(resource: String) = mainClass.getResource(resource)
|
private fun getResource(resource: String) = mainClass.getResource(resource)
|
||||||
|
|
||||||
private fun getResourceProperty(key: String) = serverProps.getProperty(key)?.let { property ->
|
private fun getResourceProperty(key: String) = serverProps.getProperty(key)?.let { property ->
|
||||||
val url = property.replace("\$jar", jarPath)
|
val url = property.replace("\$jar", jarPath)
|
||||||
if (!Resource.newResource(url).exists()) throw Error("resource not found: $url")
|
if (!Resource.newResource(url).exists()) throw Error("resource not found: $url")
|
||||||
@@ -78,10 +106,6 @@ private fun getResourceProperty(key: String) = serverProps.getProperty(key)?.let
|
|||||||
} ?: throw Error("missing property: $key")
|
} ?: throw Error("missing property: $key")
|
||||||
|
|
||||||
private fun launchServer() {
|
private fun launchServer() {
|
||||||
|
|
||||||
// read default properties and provided ones, if any
|
|
||||||
readProperties()
|
|
||||||
|
|
||||||
// create webapps contexts
|
// create webapps contexts
|
||||||
val webAppContexts = mutableListOf<WebAppContext>()
|
val webAppContexts = mutableListOf<WebAppContext>()
|
||||||
val mode = serverProps["mode"] ?: throw Error("missing property: mode")
|
val mode = serverProps["mode"] ?: throw Error("missing property: mode")
|
||||||
@@ -125,26 +149,6 @@ private fun createContext(webapp: String, contextPath: String) = WebAppContext()
|
|||||||
context.contextPath = contextPath
|
context.contextPath = contextPath
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun readProperties() {
|
|
||||||
val defaultProps = getResource("/server.default.properties") ?: throw Error("missing default server properties")
|
|
||||||
defaultProps.openStream().use {
|
|
||||||
serverProps.load(InputStreamReader(it, StandardCharsets.UTF_8))
|
|
||||||
}
|
|
||||||
val properties = File("./pairgoth.properties")
|
|
||||||
if (properties.exists()) {
|
|
||||||
serverProps.load(FileReader(properties))
|
|
||||||
serverProps.entries.forEach { entry ->
|
|
||||||
val property = entry.key as String
|
|
||||||
val value = entry.value as String
|
|
||||||
if (!property.startsWith("webapp.ssl.")) {
|
|
||||||
// do not propagate ssl properties further
|
|
||||||
} else {
|
|
||||||
System.setProperty("pairgoth.$property", value)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun buildSecureConnector(server: Server, port: Int): ServerConnector {
|
private fun buildSecureConnector(server: Server, port: Int): ServerConnector {
|
||||||
// set up http/2
|
// set up http/2
|
||||||
val httpConfig = HttpConfiguration().apply {
|
val httpConfig = HttpConfiguration().apply {
|
||||||
|
Reference in New Issue
Block a user