Debugging main class

This commit is contained in:
Claude Brisson
2023-06-09 06:32:04 +02:00
parent 83ce0cfe10
commit 2766b7a0f3

View File

@@ -2,12 +2,16 @@ package org.jeudego.pairgoth.application
import org.apache.commons.io.FileUtils import org.apache.commons.io.FileUtils
import org.eclipse.jetty.server.Server import org.eclipse.jetty.server.Server
import org.eclipse.jetty.server.handler.ContextHandlerCollection
import org.eclipse.jetty.webapp.WebAppContext
import java.io.File
import java.io.FileReader
import java.net.JarURLConnection import java.net.JarURLConnection
import java.nio.file.Files import java.nio.file.Files
import java.nio.file.Path import java.nio.file.Path
import java.util.*
import java.util.jar.JarFile import java.util.jar.JarFile
fun main(vararg args: String) { fun main(vararg args: String) {
try { try {
extractWarFiles() extractWarFiles()
@@ -17,10 +21,12 @@ fun main(vararg args: String) {
} }
} }
fun extractWarFiles() { private val tmp = System.getProperty("java.io.tmpdir")
private val version = "1.0-SNAPSHOT" // TODO CB
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
val tmp = System.getProperty("java.io.tmpdir")
val targetPath = Path.of("${tmp}/pairgoth/webapps") val targetPath = Path.of("${tmp}/pairgoth/webapps")
FileUtils.deleteDirectory(targetPath.toFile()) FileUtils.deleteDirectory(targetPath.toFile())
Files.createDirectories(targetPath) Files.createDirectories(targetPath)
@@ -40,11 +46,45 @@ fun extractWarFiles() {
} }
} }
fun launchServer() { private fun launchServer() {
// create server // create server
val server = Server(8080) val server = Server(8080)
server.start()
server.join()
// create webapps contexts
val apiContext = createContext("api", "/api");
val viewContext = createContext("view", "/");
// handle properties
val properties = File("./pairgoth.properties");
if (properties.exists()) {
val props = Properties()
props.load(FileReader(properties));
props.entries.forEach { entry ->
val property = entry.key as String
val value = entry.value as String
if (property.startsWith("logger.")) {
// special handling for logger properties
val webappLoggerPropKey = "webapp-slf4j-logger.${property.substring(7)}"
apiContext.setInitParameter(webappLoggerPropKey, value);
viewContext.setInitParameter(webappLoggerPropKey, value);
} else {
System.setProperty("pairgoth.$property", value);
}
}
}
// register webapps // register webapps
// server. server.handler = ContextHandlerCollection(apiContext, viewContext);
// launch server
server.start()
server.join()
}
private fun createContext(webapp: String, contextPath: String) = WebAppContext().also { context ->
context.war = "$tmp/pairgoth/webapps/$webapp-webapp-$version.war"
context.contextPath = contextPath;
} }