@@ -2,19 +2,14 @@ package org.utbot.instrumentation.rd
22
33import com.jetbrains.rd.util.lifetime.Lifetime
44import mu.KotlinLogging
5- import org.utbot.common.currentProcessPid
5+ import org.utbot.common.JarUtils
66import org.utbot.common.debug
7- import org.utbot.common.firstOrNullResourceIS
87import org.utbot.common.getPid
98import org.utbot.common.measureTime
10- import org.utbot.common.nameOfPackage
11- import org.utbot.common.scanForResourcesContaining
12- import org.utbot.common.utBotTempDirectory
139import org.utbot.framework.UtSettings
1410import org.utbot.framework.plugin.api.UtModel
1511import org.utbot.framework.plugin.services.WorkingDirService
1612import org.utbot.framework.process.AbstractRDProcessCompanion
17- import org.utbot.instrumentation.agent.DynamicClassTransformer
1813import org.utbot.instrumentation.instrumentation.Instrumentation
1914import org.utbot.instrumentation.process.DISABLE_SANDBOX_OPTION
2015import org.utbot.instrumentation.process.generated.AddPathsParams
@@ -27,7 +22,6 @@ import org.utbot.rd.ProcessWithRdServer
2722import org.utbot.rd.exceptions.InstantProcessDeathException
2823import org.utbot.rd.generated.LoggerModel
2924import org.utbot.rd.generated.loggerModel
30- import org.utbot.rd.loggers.UtRdKLogger
3125import org.utbot.rd.loggers.setup
3226import org.utbot.rd.onSchedulerBlocking
3327import org.utbot.rd.startBlocking
@@ -37,43 +31,25 @@ import java.io.File
3731
3832private val logger = KotlinLogging .logger { }
3933
40- private const val UTBOT_INSTRUMENTATION = " utbot-instrumentation-shadow"
41- private const val INSTRUMENTATION_LIB = " lib"
42-
43- private fun tryFindInstrumentationJarInResources (): File ? {
44- logger.debug(" Trying to find jar in the resources." )
45- val tempDir = utBotTempDirectory.toFile()
46- val unzippedJarName = " $UTBOT_INSTRUMENTATION -${currentProcessPid} .jar"
47- val instrumentationJarFile = File (tempDir, unzippedJarName)
48-
49- InstrumentedProcess ::class .java.classLoader
50- .firstOrNullResourceIS(INSTRUMENTATION_LIB ) { resourcePath ->
51- resourcePath.contains(UTBOT_INSTRUMENTATION ) && resourcePath.endsWith(" .jar" )
52- }
53- ?.use { input ->
54- instrumentationJarFile.writeBytes(input.readBytes())
55- } ? : return null
56- return instrumentationJarFile
57- }
58-
59- private fun tryFindInstrumentationJarOnClasspath (): File ? {
60- logger.debug(" Trying to find it in the classpath." )
61- return InstrumentedProcess ::class .java.classLoader
62- .scanForResourcesContaining(DynamicClassTransformer ::class .java.nameOfPackage)
63- .firstOrNull {
64- it.absolutePath.contains(UTBOT_INSTRUMENTATION ) && it.extension == " jar"
65- }
66- }
34+ private const val UTBOT_INSTRUMENTATION_JAR_FILENAME = " utbot-instrumentation-shadow.jar"
6735
6836private val instrumentationJarFile: File =
69- logger.debug().measureTime({ " Finding $UTBOT_INSTRUMENTATION jar" } ) {
70- tryFindInstrumentationJarInResources() ? : run {
71- logger.debug(" Failed to find jar in the resources." )
72- tryFindInstrumentationJarOnClasspath()
73- } ? : error("""
74- Can't find file: $UTBOT_INSTRUMENTATION .jar.
75- Make sure you added $UTBOT_INSTRUMENTATION .jar to the resources folder from gradle.
76- """ .trimIndent())
37+ logger.debug().measureTime({ " Finding $UTBOT_INSTRUMENTATION_JAR_FILENAME jar" } ) {
38+ try {
39+ JarUtils .extractJarFileFromResources(
40+ jarFileName = UTBOT_INSTRUMENTATION_JAR_FILENAME ,
41+ jarResourcePath = " lib/$UTBOT_INSTRUMENTATION_JAR_FILENAME " ,
42+ targetDirectoryName = " utbot-instrumentation"
43+ )
44+ } catch (e: Exception ) {
45+ throw IllegalStateException (
46+ """
47+ Can't find file: $UTBOT_INSTRUMENTATION_JAR_FILENAME .
48+ Make sure you added $UTBOT_INSTRUMENTATION_JAR_FILENAME to the resources folder from gradle.
49+ """ .trimIndent(),
50+ e
51+ )
52+ }
7753 }
7854
7955class InstrumentedProcessInstantDeathException :
0 commit comments