From a792f7a5bd4dfbc796b27aceb195a5acab99e6cb Mon Sep 17 00:00:00 2001 From: "Artemii.Kononov" Date: Mon, 10 Apr 2023 10:48:00 +0300 Subject: [PATCH] [utbot-spring] Making process specific arguments as lambda --- .../process/AbstractRDProcessCompanion.kt | 7 +++---- .../instrumentation/rd/InstrumentedProcess.kt | 21 ++++++++++--------- .../intellij/plugin/process/EngineProcess.kt | 6 ++---- .../spring/process/SpringAnalyzerProcess.kt | 15 ++++++------- 4 files changed, 24 insertions(+), 25 deletions(-) diff --git a/utbot-framework-api/src/main/kotlin/org/utbot/framework/process/AbstractRDProcessCompanion.kt b/utbot-framework-api/src/main/kotlin/org/utbot/framework/process/AbstractRDProcessCompanion.kt index cfd0492b25..41b0499cae 100644 --- a/utbot-framework-api/src/main/kotlin/org/utbot/framework/process/AbstractRDProcessCompanion.kt +++ b/utbot-framework-api/src/main/kotlin/org/utbot/framework/process/AbstractRDProcessCompanion.kt @@ -9,16 +9,15 @@ import kotlin.io.path.pathString abstract class AbstractRDProcessCompanion( private val debugPort: Int, private val runWithDebug: Boolean, - private val suspendExecutionInDebugMode: Boolean + private val suspendExecutionInDebugMode: Boolean, + private val processSpecificCommandLineArgs: () -> List ) { private val javaExecutablePathString get() = JdkInfoService.provide().path.resolve("bin${File.separatorChar}${osSpecificJavaExecutable()}") - protected abstract fun obtainProcessSpecificCommandLineArgs(): List - protected fun obtainProcessCommandLine(port: Int): List = buildList { addAll(obtainCommonProcessCommandLineArgs()) - addAll(obtainProcessSpecificCommandLineArgs()) + addAll(processSpecificCommandLineArgs()) add(rdPortArgument(port)) } 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 a662146c01..03d1ccb4ec 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 @@ -95,16 +95,17 @@ class InstrumentedProcess private constructor( companion object : AbstractRDProcessCompanion( debugPort = UtSettings.instrumentedProcessDebugPort, runWithDebug = UtSettings.runInstrumentedProcessWithDebug, - suspendExecutionInDebugMode = UtSettings.suspendInstrumentedProcessExecutionInDebugMode - ) { - override fun obtainProcessSpecificCommandLineArgs(): List = buildList { - add("-javaagent:${instrumentationJarFile.path}") - add("-ea") - add("-jar") - add(instrumentationJarFile.path) - if (!UtSettings.useSandbox) - add(DISABLE_SANDBOX_OPTION) - } + suspendExecutionInDebugMode = UtSettings.suspendInstrumentedProcessExecutionInDebugMode, + processSpecificCommandLineArgs = { + buildList { + add("-javaagent:${instrumentationJarFile.path}") + add("-ea") + add("-jar") + add(instrumentationJarFile.path) + if (!UtSettings.useSandbox) + add(DISABLE_SANDBOX_OPTION) + } + }) { suspend operator fun > invoke( parent: Lifetime, 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 6e74a92d9d..ca27e4bd85 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 @@ -100,11 +100,9 @@ class EngineProcess private constructor(val project: Project, private val classN companion object : AbstractRDProcessCompanion( debugPort = UtSettings.engineProcessDebugPort, runWithDebug = UtSettings.runEngineProcessWithDebug, - suspendExecutionInDebugMode = UtSettings.suspendEngineProcessExecutionInDebugMode + suspendExecutionInDebugMode = UtSettings.suspendEngineProcessExecutionInDebugMode, + processSpecificCommandLineArgs = { listOf("-ea", log4j2ConfigSwitch, "-cp", pluginClasspath, startFileName) } ) { - override fun obtainProcessSpecificCommandLineArgs(): List = - listOf("-ea", log4j2ConfigSwitch, "-cp", pluginClasspath, startFileName) - fun createBlocking(project: Project, classNameToPath: Map): EngineProcess = runBlocking { EngineProcess(project, classNameToPath) } suspend operator fun invoke(project: Project, classNameToPath: Map): EngineProcess = diff --git a/utbot-spring-analyzer/src/main/kotlin/org/utbot/spring/process/SpringAnalyzerProcess.kt b/utbot-spring-analyzer/src/main/kotlin/org/utbot/spring/process/SpringAnalyzerProcess.kt index 03945fa5cc..e7381e939f 100644 --- a/utbot-spring-analyzer/src/main/kotlin/org/utbot/spring/process/SpringAnalyzerProcess.kt +++ b/utbot-spring-analyzer/src/main/kotlin/org/utbot/spring/process/SpringAnalyzerProcess.kt @@ -61,13 +61,14 @@ class SpringAnalyzerProcess private constructor( companion object : AbstractRDProcessCompanion( debugPort = UtSettings.springAnalyzerProcessDebugPort, runWithDebug = UtSettings.runSpringAnalyzerProcessWithDebug, - suspendExecutionInDebugMode = UtSettings.suspendSpringAnalyzerProcessExecutionInDebugMode - ) { - override fun obtainProcessSpecificCommandLineArgs(): List = listOf( - "-Dorg.apache.commons.logging.LogFactory=org.utbot.spring.loggers.RDApacheCommonsLogFactory", - "-jar", - springAnalyzerJarFile.path - ) + suspendExecutionInDebugMode = UtSettings.suspendSpringAnalyzerProcessExecutionInDebugMode, + processSpecificCommandLineArgs = { + listOf( + "-Dorg.apache.commons.logging.LogFactory=org.utbot.spring.loggers.RDApacheCommonsLogFactory", + "-jar", + springAnalyzerJarFile.path + ) + }) { fun createBlocking() = runBlocking { SpringAnalyzerProcess() }