From 29ca2f8a73011b44b3db2183bfd9b5ccfea7012a Mon Sep 17 00:00:00 2001 From: Shane Hird Date: Mon, 28 Aug 2023 12:50:00 +1000 Subject: [PATCH] Use appropriate class loader for servermanger commands --- .../groovy/org/akhikhl/gretty/Runner.groovy | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/libs/gretty-runner/src/main/groovy/org/akhikhl/gretty/Runner.groovy b/libs/gretty-runner/src/main/groovy/org/akhikhl/gretty/Runner.groovy index 0b386e08..e574a224 100644 --- a/libs/gretty-runner/src/main/groovy/org/akhikhl/gretty/Runner.groovy +++ b/libs/gretty-runner/src/main/groovy/org/akhikhl/gretty/Runner.groovy @@ -44,6 +44,7 @@ final class Runner { def serverManager = null final def reader = ServiceProtocol.createReader() final def writer = ServiceProtocol.createWriter(params.statusPort) + def cl = null try { writer.write("init ${reader.port}") while(true) { @@ -52,7 +53,7 @@ final class Runner { params << new JsonSlurper().parseText(data) paramsLoaded = true - def cl = createClassLoader() + cl = createClassLoader() ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader() Thread.currentThread().setContextClassLoader(cl) try { @@ -78,12 +79,26 @@ final class Runner { } else if(data == 'restart') { serverManager.stopServer() - serverManager.startServer() + ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader() + Thread.currentThread().setContextClassLoader(cl) + try { + serverManager.startServer() + } + finally { + Thread.currentThread().setContextClassLoader(oldClassLoader) + } } else if(data == 'restartWithEvent') { serverManager.stopServer() - def event = serverManager.startServer() - onServerStarted(writer, event.getServerStartInfo()) + ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader() + Thread.currentThread().setContextClassLoader(cl) + try { + def event = serverManager.startServer() + onServerStarted(writer, event.getServerStartInfo()) + } + finally { + Thread.currentThread().setContextClassLoader(oldClassLoader) + } } else if (data.startsWith('redeploy ')) { List webappList = data.replace('redeploy ', '').split(' ').toList()