From 0a85c5477e589b1bc7fd194f5c02d4e9e6e3a16b Mon Sep 17 00:00:00 2001 From: IlyaMuravjov Date: Wed, 5 Apr 2023 12:31:40 +0300 Subject: [PATCH] Resolve issues with SpringAnalyzerProcess --- .../org/utbot/common/StandardStreamUtil.kt | 21 ------- .../framework/process/CommonProcessArgs.kt | 34 +++++------ .../process/SpringAnalyzerProcess.kt | 57 +++++++++++-------- .../process/InstrumentedProcessMain.kt | 6 +- .../process/InstrumentedProcessRunner.kt | 4 +- .../instrumentation/rd/InstrumentedProcess.kt | 6 +- .../intellij/plugin/process/EngineProcess.kt | 29 +++++----- utbot-rd/build.gradle | 1 - .../kotlin/org/utbot/rd/StandardStreamUtil.kt | 24 ++++++++ .../rd/generated/LoggerModel.Generated.kt | 9 ++- .../SynchronizationModel.Generated.kt | 9 +-- .../org/utbot/rd/loggers/UtRdLogUtil.kt | 11 ++-- .../rdgen/org/utbot/rd/models/LoggerModel.kt | 1 + .../utbot/rd/models/SynchronizationModel.kt | 1 - utbot-spring-analyzer/build.gradle.kts | 4 +- .../loggers/RDApacheCommonsLogFactory.kt | 4 +- .../process/SpringAnalyzerProcessMain.kt | 6 +- 17 files changed, 118 insertions(+), 109 deletions(-) delete mode 100644 utbot-core/src/main/kotlin/org/utbot/common/StandardStreamUtil.kt create mode 100644 utbot-rd/src/main/kotlin/org/utbot/rd/StandardStreamUtil.kt rename {utbot-rd/src/main/kotlin/org/utbot/rd => utbot-spring-analyzer/src/main/kotlin/org/utbot/spring}/loggers/RDApacheCommonsLogFactory.kt (95%) diff --git a/utbot-core/src/main/kotlin/org/utbot/common/StandardStreamUtil.kt b/utbot-core/src/main/kotlin/org/utbot/common/StandardStreamUtil.kt deleted file mode 100644 index c5ac9a8f16..0000000000 --- a/utbot-core/src/main/kotlin/org/utbot/common/StandardStreamUtil.kt +++ /dev/null @@ -1,21 +0,0 @@ -package org.utbot.common - -import java.io.OutputStream -import java.io.PrintStream - -fun silentlyCloseStandardStreams() { - // we should change out/err streams as not to spend time on user output - // and also because rd default logging system writes some initial values to stdout, polluting it as well - val tmpStream = PrintStream(object : OutputStream() { - override fun write(b: Int) {} - }) - val prevOut = System.out - val prevError = System.err - System.setOut(tmpStream) - System.setErr(tmpStream) - // stdin/stderr should be closed as not to leave hanging descriptors - // and we cannot log any exceptions here as rd remote logging is still not configured - // so we pass any exceptions - silent { prevOut.close() } - silent { prevError.close() } -} \ No newline at end of file diff --git a/utbot-framework-api/src/main/kotlin/org/utbot/framework/process/CommonProcessArgs.kt b/utbot-framework-api/src/main/kotlin/org/utbot/framework/process/CommonProcessArgs.kt index c95e30c633..27326400fa 100644 --- a/utbot-framework-api/src/main/kotlin/org/utbot/framework/process/CommonProcessArgs.kt +++ b/utbot-framework-api/src/main/kotlin/org/utbot/framework/process/CommonProcessArgs.kt @@ -6,22 +6,24 @@ import java.io.File import java.nio.file.Path import kotlin.io.path.pathString -private val javaExecutablePathString: Path - get() = JdkInfoService.jdkInfoProvider.info.path.resolve("bin${File.separatorChar}${osSpecificJavaExecutable()}") +object CommonProcessArgs { + private val javaExecutablePathString: Path + get() = JdkInfoService.provide().path.resolve("bin${File.separatorChar}${osSpecificJavaExecutable()}") -fun obtainCommonProcessCommandLineArgs( - debugPort: Int, - runWithDebug: Boolean, - suspendExecutionInDebugMode: Boolean, -): List = buildList { - val suspendValue = if (suspendExecutionInDebugMode) "y" else "n" - val debugArgument = "-agentlib:jdwp=transport=dt_socket,server=n,suspend=${suspendValue},quiet=y,address=$debugPort" - .takeIf { runWithDebug } + fun obtainCommonProcessCommandLineArgs( + debugPort: Int, + runWithDebug: Boolean, + suspendExecutionInDebugMode: Boolean, + ): List = buildList { + val suspendValue = if (suspendExecutionInDebugMode) "y" else "n" + val debugArgument = "-agentlib:jdwp=transport=dt_socket,server=n,suspend=${suspendValue},quiet=y,address=$debugPort" + .takeIf { runWithDebug } - add(javaExecutablePathString.pathString) - val javaVersionSpecificArgs = OpenModulesContainer.javaVersionSpecificArguments - if (javaVersionSpecificArgs.isNotEmpty()) { - addAll(javaVersionSpecificArgs) + add(javaExecutablePathString.pathString) + val javaVersionSpecificArgs = OpenModulesContainer.javaVersionSpecificArguments + if (javaVersionSpecificArgs.isNotEmpty()) { + addAll(javaVersionSpecificArgs) + } + debugArgument?.let { add(it) } } - debugArgument?.let { add(it) } -} \ No newline at end of file +} diff --git a/utbot-framework/src/main/kotlin/org/utbot/framework/process/SpringAnalyzerProcess.kt b/utbot-framework/src/main/kotlin/org/utbot/framework/process/SpringAnalyzerProcess.kt index b5ad5cec6d..88a2860a06 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/framework/process/SpringAnalyzerProcess.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/framework/process/SpringAnalyzerProcess.kt @@ -11,9 +11,8 @@ import org.utbot.rd.ProcessWithRdServer import org.utbot.rd.exceptions.InstantProcessDeathException import org.utbot.rd.generated.LoggerModel import org.utbot.rd.generated.loggerModel -import org.utbot.rd.generated.synchronizationModel import org.utbot.rd.loggers.UtRdKLogger -import org.utbot.rd.loggers.setupRdLogger +import org.utbot.rd.loggers.setup import org.utbot.rd.onSchedulerBlocking import org.utbot.rd.rdPortArgument import org.utbot.rd.startBlocking @@ -28,6 +27,8 @@ class SpringAnalyzerProcessInstantDeathException : InstantProcessDeathException(UtSettings.springAnalyzerProcessDebugPort, UtSettings.runSpringAnalyzerProcessWithDebug) private const val SPRING_ANALYZER_JAR_FILENAME = "utbot-spring-analyzer-shadow.jar" +private const val SPRING_ANALYZER_JAR_PATH = "lib/$SPRING_ANALYZER_JAR_FILENAME" +private const val UNKNOWN_MODIFICATION_TIME = 0L private val logger = KotlinLogging.logger {} private val rdLogger = UtRdKLogger(logger, "") @@ -36,16 +37,34 @@ class SpringAnalyzerProcess private constructor( ) : ProcessWithRdServer by rdProcess { companion object { - private fun obtainProcessSpecificCommandLineArgs(port: Int): List { - val jarFile = - Files.createDirectories(utBotTempDirectory.toFile().resolve("spring-analyzer").toPath()) - .toFile().resolve(SPRING_ANALYZER_JAR_FILENAME) - FileUtils.copyURLToFile( - this::class.java.classLoader.getResource("lib/$SPRING_ANALYZER_JAR_FILENAME"), - jarFile - ) - return listOf( - "-Dorg.apache.commons.logging.LogFactory=org.utbot.rd.loggers.RDApacheCommonsLogFactory", + private val jarFile by lazy { + Files.createDirectories(utBotTempDirectory.toFile().resolve("spring-analyzer").toPath()) + .toFile().resolve(SPRING_ANALYZER_JAR_FILENAME).also { jarFile -> + val resource = this::class.java.classLoader.getResource(SPRING_ANALYZER_JAR_PATH) + ?: error("Unable to find \"$SPRING_ANALYZER_JAR_PATH\" in resources, make sure it's on the classpath") + val resourceConnection = resource.openConnection() + val lastResourceModification = try { + resourceConnection.lastModified + } finally { + resourceConnection.getInputStream().close() + } + if ( + !jarFile.exists() || + jarFile.lastModified() == UNKNOWN_MODIFICATION_TIME || + lastResourceModification == UNKNOWN_MODIFICATION_TIME || + jarFile.lastModified() < lastResourceModification + ) + FileUtils.copyURLToFile(resource, jarFile) + } + } + + private fun obtainSpringAnalyzerProcessCommandLine(port: Int): List { + return CommonProcessArgs.obtainCommonProcessCommandLineArgs( + debugPort = UtSettings.springAnalyzerProcessDebugPort, + runWithDebug = UtSettings.runSpringAnalyzerProcessWithDebug, + suspendExecutionInDebugMode = UtSettings.suspendSpringAnalyzerProcessExecutionInDebugMode, + ) + listOf( + "-Dorg.apache.commons.logging.LogFactory=org.utbot.spring.loggers.RDApacheCommonsLogFactory", "-jar", jarFile.path, rdPortArgument(port) @@ -56,11 +75,7 @@ class SpringAnalyzerProcess private constructor( suspend operator fun invoke(): SpringAnalyzerProcess = LifetimeDefinition().terminateOnException { lifetime -> val rdProcess = startUtProcessWithRdServer(lifetime) { port -> - val cmd = obtainCommonProcessCommandLineArgs( - debugPort = UtSettings.springAnalyzerProcessDebugPort, - runWithDebug = UtSettings.runSpringAnalyzerProcessWithDebug, - suspendExecutionInDebugMode = UtSettings.suspendSpringAnalyzerProcessExecutionInDebugMode, - ) + obtainProcessSpecificCommandLineArgs(port) + val cmd = obtainSpringAnalyzerProcessCommandLine(port) val process = ProcessBuilder(cmd) .directory(Files.createTempDirectory(utBotTempDirectory, "spring-analyzer").toFile()) .start() @@ -73,7 +88,7 @@ class SpringAnalyzerProcess private constructor( } rdProcess.awaitProcessReady() val proc = SpringAnalyzerProcess(rdProcess) - setupRdLogger(rdProcess, proc.loggerModel, rdLogger) + proc.loggerModel.setup(rdLogger, proc.lifetime) return proc } } @@ -81,12 +96,6 @@ class SpringAnalyzerProcess private constructor( private val springAnalyzerModel: SpringAnalyzerProcessModel = onSchedulerBlocking { protocol.springAnalyzerProcessModel } private val loggerModel: LoggerModel = onSchedulerBlocking { protocol.loggerModel } - init { - lifetime.onTermination { - protocol.synchronizationModel.stopProcess.fire(Unit) - } - } - fun getBeanQualifiedNames( classpath: List, configuration: String, diff --git a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/process/InstrumentedProcessMain.kt b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/process/InstrumentedProcessMain.kt index 030b401138..2639b38aff 100644 --- a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/process/InstrumentedProcessMain.kt +++ b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/process/InstrumentedProcessMain.kt @@ -21,8 +21,8 @@ import org.utbot.rd.RdSettingsContainerFactory import org.utbot.rd.findRdPort import org.utbot.rd.generated.loggerModel import org.utbot.rd.generated.settingsModel -import org.utbot.rd.generated.synchronizationModel import org.utbot.rd.loggers.UtRdRemoteLoggerFactory +import org.utbot.rd.StandardStreamUtil import java.io.File import java.net.URLClassLoader import java.security.AllPermission @@ -83,7 +83,7 @@ object InstrumentedProcessMain */ fun main(args: Array) = runBlocking { // We don't want user code to litter the standard output, so we redirect it. - silentlyCloseStandardStreams() + StandardStreamUtil.silentlyCloseStandardStreams() if (!args.contains(DISABLE_SANDBOX_OPTION)) { permissions { @@ -97,7 +97,7 @@ fun main(args: Array) = runBlocking { try { ClientProtocolBuilder().withProtocolTimeout(messageFromMainTimeout).start(port) { - synchronizationModel.initRemoteLogging.adviseOnce(lifetime) { + loggerModel.initRemoteLogging.adviseOnce(lifetime) { Logger.set(Lifetime.Eternal, UtRdRemoteLoggerFactory(loggerModel)) this.protocol.scheduler.queue { warmupMockito() } } diff --git a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/process/InstrumentedProcessRunner.kt b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/process/InstrumentedProcessRunner.kt index ef1d3c98de..4a2f1e9599 100644 --- a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/process/InstrumentedProcessRunner.kt +++ b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/process/InstrumentedProcessRunner.kt @@ -6,7 +6,7 @@ import org.utbot.common.scanForResourcesContaining import org.utbot.common.utBotTempDirectory import org.utbot.framework.UtSettings import org.utbot.framework.plugin.services.WorkingDirService -import org.utbot.framework.process.obtainCommonProcessCommandLineArgs +import org.utbot.framework.process.CommonProcessArgs import org.utbot.instrumentation.agent.DynamicClassTransformer import org.utbot.rd.rdPortArgument import java.io.File @@ -15,7 +15,7 @@ private val logger = KotlinLogging.logger {} class InstrumentedProcessRunner { private val cmds: List by lazy { - obtainCommonProcessCommandLineArgs( + CommonProcessArgs.obtainCommonProcessCommandLineArgs( debugPort = UtSettings.instrumentedProcessDebugPort, runWithDebug = UtSettings.runInstrumentedProcessWithDebug, suspendExecutionInDebugMode = UtSettings.suspendInstrumentedProcessExecutionInDebugMode diff --git a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/rd/InstrumentedProcess.kt b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/rd/InstrumentedProcess.kt index eb79ee1464..9c1d3d5ed4 100644 --- a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/rd/InstrumentedProcess.kt +++ b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/rd/InstrumentedProcess.kt @@ -14,10 +14,8 @@ import org.utbot.rd.ProcessWithRdServer import org.utbot.rd.exceptions.InstantProcessDeathException import org.utbot.rd.generated.LoggerModel import org.utbot.rd.generated.loggerModel -import org.utbot.rd.generated.synchronizationModel import org.utbot.rd.loggers.UtRdKLogger -import org.utbot.rd.loggers.UtRdRemoteLogger -import org.utbot.rd.loggers.setupRdLogger +import org.utbot.rd.loggers.setup import org.utbot.rd.onSchedulerBlocking import org.utbot.rd.startUtProcessWithRdServer import org.utbot.rd.terminateOnException @@ -64,7 +62,7 @@ class InstrumentedProcess private constructor( logger.trace("rd process started") val proc = InstrumentedProcess(classLoader, rdProcess) - setupRdLogger(rdProcess, proc.loggerModel, rdLogger) + proc.loggerModel.setup(rdLogger, proc.lifetime) proc.lifetime.onTermination { logger.trace { "process is terminating" } diff --git a/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/process/EngineProcess.kt b/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/process/EngineProcess.kt index 88ba27824e..8aa5f138e7 100644 --- a/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/process/EngineProcess.kt +++ b/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/process/EngineProcess.kt @@ -20,9 +20,9 @@ import org.utbot.framework.codegen.tree.ututils.UtilClassKind import org.utbot.framework.plugin.api.* import org.utbot.framework.plugin.services.JdkInfo import org.utbot.framework.plugin.services.WorkingDirService +import org.utbot.framework.process.CommonProcessArgs import org.utbot.framework.process.generated.* import org.utbot.framework.process.generated.MethodDescription -import org.utbot.framework.process.obtainCommonProcessCommandLineArgs import org.utbot.framework.util.Conflict import org.utbot.framework.util.ConflictTriggers import org.utbot.instrumentation.util.KryoHelper @@ -102,25 +102,26 @@ class EngineProcess private constructor(val project: Project, private val classN private const val startFileName = "org.utbot.framework.process.EngineProcessMainKt" - private fun obtainProcessSpecificCommandLineArgs(port: Int) = listOf( - "-ea", - log4j2ConfigSwitch, - "-cp", - pluginClasspath, - startFileName, - rdPortArgument(port) - ) + private fun obtainEngineProcessCommandLine(port: Int): List = + CommonProcessArgs.obtainCommonProcessCommandLineArgs( + debugPort = UtSettings.engineProcessDebugPort, + runWithDebug = UtSettings.runEngineProcessWithDebug, + suspendExecutionInDebugMode = UtSettings.suspendEngineProcessExecutionInDebugMode, + ) + listOf( + "-ea", + log4j2ConfigSwitch, + "-cp", + pluginClasspath, + startFileName, + rdPortArgument(port) + ) fun createBlocking(project: Project, classNameToPath: Map): EngineProcess = runBlocking { EngineProcess(project, classNameToPath) } suspend operator fun invoke(project: Project, classNameToPath: Map): EngineProcess = LifetimeDefinition().terminateOnException { lifetime -> val rdProcess = startUtProcessWithRdServer(lifetime) { port -> - val cmd = obtainCommonProcessCommandLineArgs( - debugPort = UtSettings.engineProcessDebugPort, - runWithDebug = UtSettings.runEngineProcessWithDebug, - suspendExecutionInDebugMode = UtSettings.suspendEngineProcessExecutionInDebugMode, - ) + obtainProcessSpecificCommandLineArgs(port) + val cmd = obtainEngineProcessCommandLine(port) val directory = WorkingDirService.provide().toFile() val builder = ProcessBuilder(cmd).directory(directory) val process = builder.start() diff --git a/utbot-rd/build.gradle b/utbot-rd/build.gradle index 4e0b26a4bf..85bb42fcf5 100644 --- a/utbot-rd/build.gradle +++ b/utbot-rd/build.gradle @@ -69,7 +69,6 @@ dependencies { implementation group: 'com.jetbrains.rd', name: 'rd-core', version: rdVersion implementation group: 'io.github.microutils', name: 'kotlin-logging', version: kotlinLoggingVersion - implementation group: 'commons-logging', name: 'commons-logging', version: commonsLoggingVersion processWithRdServerMockImplementation project(':utbot-rd') diff --git a/utbot-rd/src/main/kotlin/org/utbot/rd/StandardStreamUtil.kt b/utbot-rd/src/main/kotlin/org/utbot/rd/StandardStreamUtil.kt new file mode 100644 index 0000000000..b96e7eab42 --- /dev/null +++ b/utbot-rd/src/main/kotlin/org/utbot/rd/StandardStreamUtil.kt @@ -0,0 +1,24 @@ +package org.utbot.rd + +import org.utbot.common.silent +import java.io.OutputStream +import java.io.PrintStream + +object StandardStreamUtil { + fun silentlyCloseStandardStreams() { + // we should change out/err streams as not to spend time on user output + // and also because rd default logging system writes some initial values to stdout, polluting it as well + val tmpStream = PrintStream(object : OutputStream() { + override fun write(b: Int) {} + }) + val prevOut = System.out + val prevError = System.err + System.setOut(tmpStream) + System.setErr(tmpStream) + // stdin/stderr should be closed as not to leave hanging descriptors + // and we cannot log any exceptions here as rd remote logging is still not configured + // so we pass any exceptions + silent { prevOut.close() } + silent { prevError.close() } + } +} diff --git a/utbot-rd/src/main/kotlin/org/utbot/rd/generated/LoggerModel.Generated.kt b/utbot-rd/src/main/kotlin/org/utbot/rd/generated/LoggerModel.Generated.kt index 11d81e7768..f5a45841b3 100644 --- a/utbot-rd/src/main/kotlin/org/utbot/rd/generated/LoggerModel.Generated.kt +++ b/utbot-rd/src/main/kotlin/org/utbot/rd/generated/LoggerModel.Generated.kt @@ -18,6 +18,7 @@ import kotlin.jvm.JvmStatic * #### Generated from [LoggerModel.kt:8] */ class LoggerModel private constructor( + private val _initRemoteLogging: RdSignal, private val _log: RdSignal, private val _getCategoryMinimalLogLevel: RdCall ) : RdExtBase() { @@ -47,13 +48,14 @@ class LoggerModel private constructor( } - const val serializationHash = -6259198217478203203L + const val serializationHash = 1686273842005935878L } override val serializersOwner: ISerializersOwner get() = LoggerModel override val serializationHash: Long get() = LoggerModel.serializationHash //fields + val initRemoteLogging: IAsyncSignal get() = _initRemoteLogging val log: IAsyncSignal get() = _log /** @@ -64,11 +66,13 @@ class LoggerModel private constructor( //methods //initializer init { + _initRemoteLogging.async = true _log.async = true _getCategoryMinimalLogLevel.async = true } init { + bindableChildren.add("initRemoteLogging" to _initRemoteLogging) bindableChildren.add("log" to _log) bindableChildren.add("getCategoryMinimalLogLevel" to _getCategoryMinimalLogLevel) } @@ -76,6 +80,7 @@ class LoggerModel private constructor( //secondary constructor private constructor( ) : this( + RdSignal(FrameworkMarshallers.Void), RdSignal(LogArguments), RdCall(FrameworkMarshallers.String, FrameworkMarshallers.Int) ) @@ -86,6 +91,7 @@ class LoggerModel private constructor( override fun print(printer: PrettyPrinter) { printer.println("LoggerModel (") printer.indent { + print("initRemoteLogging = "); _initRemoteLogging.print(printer); println() print("log = "); _log.print(printer); println() print("getCategoryMinimalLogLevel = "); _getCategoryMinimalLogLevel.print(printer); println() } @@ -94,6 +100,7 @@ class LoggerModel private constructor( //deepClone override fun deepClone(): LoggerModel { return LoggerModel( + _initRemoteLogging.deepClonePolymorphic(), _log.deepClonePolymorphic(), _getCategoryMinimalLogLevel.deepClonePolymorphic() ) diff --git a/utbot-rd/src/main/kotlin/org/utbot/rd/generated/SynchronizationModel.Generated.kt b/utbot-rd/src/main/kotlin/org/utbot/rd/generated/SynchronizationModel.Generated.kt index 503f6dd889..06c65bcc62 100644 --- a/utbot-rd/src/main/kotlin/org/utbot/rd/generated/SynchronizationModel.Generated.kt +++ b/utbot-rd/src/main/kotlin/org/utbot/rd/generated/SynchronizationModel.Generated.kt @@ -19,7 +19,6 @@ import kotlin.jvm.JvmStatic */ class SynchronizationModel private constructor( private val _suspendTimeoutTimer: RdCall, - private val _initRemoteLogging: RdSignal, private val _synchronizationSignal: RdSignal, private val _stopProcess: RdSignal ) : RdExtBase() { @@ -48,7 +47,7 @@ class SynchronizationModel private constructor( } - const val serializationHash = 5881306106692642003L + const val serializationHash = -8851121542976813112L } override val serializersOwner: ISerializersOwner get() = SynchronizationModel @@ -56,7 +55,6 @@ class SynchronizationModel private constructor( //fields val suspendTimeoutTimer: RdCall get() = _suspendTimeoutTimer - val initRemoteLogging: IAsyncSignal get() = _initRemoteLogging val synchronizationSignal: IAsyncSignal get() = _synchronizationSignal /** @@ -67,14 +65,12 @@ class SynchronizationModel private constructor( //initializer init { _suspendTimeoutTimer.async = true - _initRemoteLogging.async = true _synchronizationSignal.async = true _stopProcess.async = true } init { bindableChildren.add("suspendTimeoutTimer" to _suspendTimeoutTimer) - bindableChildren.add("initRemoteLogging" to _initRemoteLogging) bindableChildren.add("synchronizationSignal" to _synchronizationSignal) bindableChildren.add("stopProcess" to _stopProcess) } @@ -83,7 +79,6 @@ class SynchronizationModel private constructor( private constructor( ) : this( RdCall(FrameworkMarshallers.Bool, FrameworkMarshallers.Void), - RdSignal(FrameworkMarshallers.Void), RdSignal(FrameworkMarshallers.String), RdSignal(FrameworkMarshallers.Void) ) @@ -95,7 +90,6 @@ class SynchronizationModel private constructor( printer.println("SynchronizationModel (") printer.indent { print("suspendTimeoutTimer = "); _suspendTimeoutTimer.print(printer); println() - print("initRemoteLogging = "); _initRemoteLogging.print(printer); println() print("synchronizationSignal = "); _synchronizationSignal.print(printer); println() print("stopProcess = "); _stopProcess.print(printer); println() } @@ -105,7 +99,6 @@ class SynchronizationModel private constructor( override fun deepClone(): SynchronizationModel { return SynchronizationModel( _suspendTimeoutTimer.deepClonePolymorphic(), - _initRemoteLogging.deepClonePolymorphic(), _synchronizationSignal.deepClonePolymorphic(), _stopProcess.deepClonePolymorphic() ) diff --git a/utbot-rd/src/main/kotlin/org/utbot/rd/loggers/UtRdLogUtil.kt b/utbot-rd/src/main/kotlin/org/utbot/rd/loggers/UtRdLogUtil.kt index f24bf5b0b9..4ed40d3f2f 100644 --- a/utbot-rd/src/main/kotlin/org/utbot/rd/loggers/UtRdLogUtil.kt +++ b/utbot-rd/src/main/kotlin/org/utbot/rd/loggers/UtRdLogUtil.kt @@ -4,10 +4,7 @@ import com.jetbrains.rd.util.* import com.jetbrains.rd.util.lifetime.Lifetime import mu.KLogger import org.utbot.common.LoggerWithLogMethod -import org.utbot.rd.ProcessWithRdServer import org.utbot.rd.generated.LoggerModel -import org.utbot.rd.generated.synchronizationModel - fun Logger.withLevel(logLevel: LogLevel): LoggerWithLogMethod = LoggerWithLogMethod { this.log(logLevel, it) @@ -29,19 +26,19 @@ fun overrideDefaultRdLoggerFactoryWithKLogger(logger: KLogger) { } } -fun setupRdLogger(rdProcess: ProcessWithRdServer, loggerModel: LoggerModel, rdLogger: UtRdKLogger) { +fun LoggerModel.setup(rdLogger: UtRdKLogger, processLifetime: Lifetime) { // currently we do not specify log level for different categories // though it is possible with some additional map on categories -> consider performance - loggerModel.getCategoryMinimalLogLevel.set { _ -> + getCategoryMinimalLogLevel.set { _ -> // this logLevel is obtained from KotlinLogger rdLogger.logLevel.ordinal } - loggerModel.log.advise(rdProcess.lifetime) { + log.advise(processLifetime) { val logLevel = UtRdRemoteLogger.logLevelValues[it.logLevelOrdinal] // assume throwable already in message rdLogger.log(logLevel, it.message, null) } - rdProcess.protocol.synchronizationModel.initRemoteLogging.fire(Unit) + initRemoteLogging.fire(Unit) } diff --git a/utbot-rd/src/main/rdgen/org/utbot/rd/models/LoggerModel.kt b/utbot-rd/src/main/rdgen/org/utbot/rd/models/LoggerModel.kt index 7ca4d8e6b7..c3f2e93e4f 100644 --- a/utbot-rd/src/main/rdgen/org/utbot/rd/models/LoggerModel.kt +++ b/utbot-rd/src/main/rdgen/org/utbot/rd/models/LoggerModel.kt @@ -13,6 +13,7 @@ object LoggerModel : Ext(LoggerRoot) { } init { + signal("initRemoteLogging", PredefinedType.void).async signal("log", logArguments).async call( "getCategoryMinimalLogLevel", diff --git a/utbot-rd/src/main/rdgen/org/utbot/rd/models/SynchronizationModel.kt b/utbot-rd/src/main/rdgen/org/utbot/rd/models/SynchronizationModel.kt index 077173ba23..f0d86d23fa 100644 --- a/utbot-rd/src/main/rdgen/org/utbot/rd/models/SynchronizationModel.kt +++ b/utbot-rd/src/main/rdgen/org/utbot/rd/models/SynchronizationModel.kt @@ -8,7 +8,6 @@ object SynchronizationRoot: Root() object SynchronizationModel: Ext(SynchronizationRoot) { init { call("suspendTimeoutTimer", PredefinedType.bool, PredefinedType.void).async - signal("initRemoteLogging", PredefinedType.void).async signal("synchronizationSignal", PredefinedType.string).async signal("StopProcess", PredefinedType.void).apply { async diff --git a/utbot-spring-analyzer/build.gradle.kts b/utbot-spring-analyzer/build.gradle.kts index 09881cb8fc..2220aeb586 100644 --- a/utbot-spring-analyzer/build.gradle.kts +++ b/utbot-spring-analyzer/build.gradle.kts @@ -2,8 +2,7 @@ import com.github.jengelman.gradle.plugins.shadow.transformers.Log4j2PluginsCach import com.github.jengelman.gradle.plugins.shadow.transformers.PropertiesFileTransformer val rdVersion: String by rootProject -val log4j2Version: String by rootProject -val kotlinLoggingVersion: String? by rootProject +val commonsLoggingVersion: String by rootProject plugins { id("org.springframework.boot") version "2.7.8" @@ -27,6 +26,7 @@ dependencies { implementation(project(":utbot-core")) implementation("com.jetbrains.rd:rd-framework:$rdVersion") implementation("com.jetbrains.rd:rd-core:$rdVersion") + implementation("commons-logging:commons-logging:$commonsLoggingVersion") } application { diff --git a/utbot-rd/src/main/kotlin/org/utbot/rd/loggers/RDApacheCommonsLogFactory.kt b/utbot-spring-analyzer/src/main/kotlin/org/utbot/spring/loggers/RDApacheCommonsLogFactory.kt similarity index 95% rename from utbot-rd/src/main/kotlin/org/utbot/rd/loggers/RDApacheCommonsLogFactory.kt rename to utbot-spring-analyzer/src/main/kotlin/org/utbot/spring/loggers/RDApacheCommonsLogFactory.kt index 26e0ba146f..9fd5f67c9c 100644 --- a/utbot-rd/src/main/kotlin/org/utbot/rd/loggers/RDApacheCommonsLogFactory.kt +++ b/utbot-spring-analyzer/src/main/kotlin/org/utbot/spring/loggers/RDApacheCommonsLogFactory.kt @@ -1,11 +1,11 @@ -package org.utbot.rd.loggers +package org.utbot.spring.loggers import com.jetbrains.rd.util.LogLevel import com.jetbrains.rd.util.getLogger import org.apache.commons.logging.Log import org.apache.commons.logging.impl.LogFactoryImpl -@Suppress("unused") // used via -Dorg.apache.commons.logging.LogFactory=org.utbot.rd.loggers.RDApacheCommonsLogFactory +@Suppress("unused") // used via -Dorg.apache.commons.logging.LogFactory=org.utbot.spring.loggers.RDApacheCommonsLogFactory class RDApacheCommonsLogFactory : LogFactoryImpl() { override fun getInstance(name: String): Log { val logger = getLogger(category = name) diff --git a/utbot-spring-analyzer/src/main/kotlin/org/utbot/spring/process/SpringAnalyzerProcessMain.kt b/utbot-spring-analyzer/src/main/kotlin/org/utbot/spring/process/SpringAnalyzerProcessMain.kt index ac7abb88f1..9c4253b4a8 100644 --- a/utbot-spring-analyzer/src/main/kotlin/org/utbot/spring/process/SpringAnalyzerProcessMain.kt +++ b/utbot-spring-analyzer/src/main/kotlin/org/utbot/spring/process/SpringAnalyzerProcessMain.kt @@ -7,7 +7,7 @@ import com.jetbrains.rd.util.info import com.jetbrains.rd.util.lifetime.Lifetime import com.jetbrains.rd.util.reactive.adviseOnce import org.utbot.common.AbstractSettings -import org.utbot.common.silentlyCloseStandardStreams +import org.utbot.rd.StandardStreamUtil import org.utbot.rd.ClientProtocolBuilder import org.utbot.rd.IdleWatchdog import org.utbot.rd.RdSettingsContainerFactory @@ -32,13 +32,13 @@ object SpringAnalyzerProcessMain suspend fun main(args: Array) { // We don't want user code to litter the standard output, so we redirect it. - silentlyCloseStandardStreams() + StandardStreamUtil.silentlyCloseStandardStreams() val port = findRdPort(args) ClientProtocolBuilder().withProtocolTimeout(messageFromMainTimeoutMillis).start(port) { - synchronizationModel.initRemoteLogging.adviseOnce(lifetime) { + loggerModel.initRemoteLogging.adviseOnce(lifetime) { Logger.set(Lifetime.Eternal, UtRdRemoteLoggerFactory(loggerModel)) logger.info { "-----------------------------------------------------------------------" } logger.info { "------------------NEW SPRING ANALYZER PROCESS STARTED------------------" }