Skip to content

Commit a64c2b4

Browse files
committed
[rd & logs]
1. fixes #1359 2. changes log formatting in IDEA process
1 parent d391c51 commit a64c2b4

File tree

11 files changed

+50
-76
lines changed

11 files changed

+50
-76
lines changed

utbot-framework/src/main/kotlin/org/utbot/framework/process/RdInstrumenter.kt

+5-5
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,17 @@ private val logger = KotlinLogging.logger { }
1414

1515
class RdInstrumenter(private val rdInstrumenterAdapter: RdInstrumenterAdapter) : InstrumenterAdapter() {
1616
override fun computeSourceFileByClass(
17-
className: String,
18-
packageName: String?,
17+
clazz: Class<*>,
1918
directoryToSearchRecursively: Path
2019
): File? {
21-
logger.debug { "starting computeSourceFileByClass with classname - $className" }
20+
val canonicalClassName = clazz.canonicalName
21+
logger.debug { "starting computeSourceFileByClass for class - $canonicalClassName" }
2222
val result = logger.logException {
23-
val arguments = ComputeSourceFileByClassArguments(className, packageName)
23+
val arguments = ComputeSourceFileByClassArguments(canonicalClassName)
2424

2525
rdInstrumenterAdapter.computeSourceFileByClass.startBlocking(arguments)
2626
}
27-
logger.debug { "computeSourceFileByClass result for $className from idea: $result" }
27+
logger.debug { "computeSourceFileByClass result for $canonicalClassName from idea: $result" }
2828
return result?.let { File(it) }
2929
}
3030
}

utbot-framework/src/main/kotlin/org/utbot/framework/process/generated/EngineProcessModel.Generated.kt

+16-16
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import kotlin.jvm.JvmStatic
1515

1616

1717
/**
18-
* #### Generated from [EngineProcessModel.kt:31]
18+
* #### Generated from [EngineProcessModel.kt:30]
1919
*/
2020
class EngineProcessModel private constructor(
2121
private val _setupUtContext: RdCall<SetupContextParams, Unit>,
@@ -177,7 +177,7 @@ val IProtocol.engineProcessModel get() = getOrCreateExtension(EngineProcessModel
177177

178178

179179
/**
180-
* #### Generated from [EngineProcessModel.kt:100]
180+
* #### Generated from [EngineProcessModel.kt:99]
181181
*/
182182
data class FindMethodParamNamesArguments (
183183
val classId: ByteArray,
@@ -240,7 +240,7 @@ data class FindMethodParamNamesArguments (
240240

241241

242242
/**
243-
* #### Generated from [EngineProcessModel.kt:104]
243+
* #### Generated from [EngineProcessModel.kt:103]
244244
*/
245245
data class FindMethodParamNamesResult (
246246
val paramNames: ByteArray
@@ -297,7 +297,7 @@ data class FindMethodParamNamesResult (
297297

298298

299299
/**
300-
* #### Generated from [EngineProcessModel.kt:93]
300+
* #### Generated from [EngineProcessModel.kt:92]
301301
*/
302302
data class FindMethodsInClassMatchingSelectedArguments (
303303
val classId: ByteArray,
@@ -360,7 +360,7 @@ data class FindMethodsInClassMatchingSelectedArguments (
360360

361361

362362
/**
363-
* #### Generated from [EngineProcessModel.kt:97]
363+
* #### Generated from [EngineProcessModel.kt:96]
364364
*/
365365
data class FindMethodsInClassMatchingSelectedResult (
366366
val executableIds: ByteArray
@@ -417,7 +417,7 @@ data class FindMethodsInClassMatchingSelectedResult (
417417

418418

419419
/**
420-
* #### Generated from [EngineProcessModel.kt:43]
420+
* #### Generated from [EngineProcessModel.kt:42]
421421
*/
422422
data class GenerateParams (
423423
val mockInstalled: Boolean,
@@ -540,7 +540,7 @@ data class GenerateParams (
540540

541541

542542
/**
543-
* #### Generated from [EngineProcessModel.kt:61]
543+
* #### Generated from [EngineProcessModel.kt:60]
544544
*/
545545
data class GenerateResult (
546546
val notEmptyCases: Int,
@@ -603,7 +603,7 @@ data class GenerateResult (
603603

604604

605605
/**
606-
* #### Generated from [EngineProcessModel.kt:112]
606+
* #### Generated from [EngineProcessModel.kt:111]
607607
*/
608608
data class GenerateTestReportArgs (
609609
val eventLogMessage: String?,
@@ -696,7 +696,7 @@ data class GenerateTestReportArgs (
696696

697697

698698
/**
699-
* #### Generated from [EngineProcessModel.kt:121]
699+
* #### Generated from [EngineProcessModel.kt:120]
700700
*/
701701
data class GenerateTestReportResult (
702702
val notifyMessage: String,
@@ -765,7 +765,7 @@ data class GenerateTestReportResult (
765765

766766

767767
/**
768-
* #### Generated from [EngineProcessModel.kt:32]
768+
* #### Generated from [EngineProcessModel.kt:31]
769769
*/
770770
data class JdkInfo (
771771
val path: String,
@@ -828,7 +828,7 @@ data class JdkInfo (
828828

829829

830830
/**
831-
* #### Generated from [EngineProcessModel.kt:65]
831+
* #### Generated from [EngineProcessModel.kt:64]
832832
*/
833833
data class RenderParams (
834834
val testSetsId: Long,
@@ -969,7 +969,7 @@ data class RenderParams (
969969

970970

971971
/**
972-
* #### Generated from [EngineProcessModel.kt:82]
972+
* #### Generated from [EngineProcessModel.kt:81]
973973
*/
974974
data class RenderResult (
975975
val generatedCode: String,
@@ -1032,7 +1032,7 @@ data class RenderResult (
10321032

10331033

10341034
/**
1035-
* #### Generated from [EngineProcessModel.kt:86]
1035+
* #### Generated from [EngineProcessModel.kt:85]
10361036
*/
10371037
data class SetupContextParams (
10381038
val classpathForUrlsClassloader: List<String>
@@ -1089,7 +1089,7 @@ data class SetupContextParams (
10891089

10901090

10911091
/**
1092-
* #### Generated from [EngineProcessModel.kt:89]
1092+
* #### Generated from [EngineProcessModel.kt:88]
10931093
*/
10941094
data class Signature (
10951095
val name: String,
@@ -1152,7 +1152,7 @@ data class Signature (
11521152

11531153

11541154
/**
1155-
* #### Generated from [EngineProcessModel.kt:37]
1155+
* #### Generated from [EngineProcessModel.kt:36]
11561156
*/
11571157
data class TestGeneratorParams (
11581158
val buildDir: Array<String>,
@@ -1227,7 +1227,7 @@ data class TestGeneratorParams (
12271227

12281228

12291229
/**
1230-
* #### Generated from [EngineProcessModel.kt:107]
1230+
* #### Generated from [EngineProcessModel.kt:106]
12311231
*/
12321232
data class WriteSarifReportArguments (
12331233
val testSetsId: Long,

utbot-framework/src/main/kotlin/org/utbot/framework/process/generated/RdInstrumenterAdapter.Generated.kt

+8-14
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class RdInstrumenterAdapter private constructor(
4747

4848
private val __StringNullableSerializer = FrameworkMarshallers.String.nullable()
4949

50-
const val serializationHash = -671974871925861655L
50+
const val serializationHash = 1502978559314472937L
5151

5252
}
5353
override val serializersOwner: ISerializersOwner get() = RdInstrumenterAdapter
@@ -97,8 +97,7 @@ val IProtocol.rdInstrumenterAdapter get() = getOrCreateExtension(RdInstrumenterA
9797
* #### Generated from [EngineProcessModel.kt:8]
9898
*/
9999
data class ComputeSourceFileByClassArguments (
100-
val className: String,
101-
val packageName: String?
100+
val canonicalClassName: String
102101
) : IPrintable {
103102
//companion
104103

@@ -107,14 +106,12 @@ data class ComputeSourceFileByClassArguments (
107106

108107
@Suppress("UNCHECKED_CAST")
109108
override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): ComputeSourceFileByClassArguments {
110-
val className = buffer.readString()
111-
val packageName = buffer.readNullable { buffer.readString() }
112-
return ComputeSourceFileByClassArguments(className, packageName)
109+
val canonicalClassName = buffer.readString()
110+
return ComputeSourceFileByClassArguments(canonicalClassName)
113111
}
114112

115113
override fun write(ctx: SerializationCtx, buffer: AbstractBuffer, value: ComputeSourceFileByClassArguments) {
116-
buffer.writeString(value.className)
117-
buffer.writeNullable(value.packageName) { buffer.writeString(it) }
114+
buffer.writeString(value.canonicalClassName)
118115
}
119116

120117

@@ -130,24 +127,21 @@ data class ComputeSourceFileByClassArguments (
130127

131128
other as ComputeSourceFileByClassArguments
132129

133-
if (className != other.className) return false
134-
if (packageName != other.packageName) return false
130+
if (canonicalClassName != other.canonicalClassName) return false
135131

136132
return true
137133
}
138134
//hash code trait
139135
override fun hashCode(): Int {
140136
var __r = 0
141-
__r = __r*31 + className.hashCode()
142-
__r = __r*31 + if (packageName != null) packageName.hashCode() else 0
137+
__r = __r*31 + canonicalClassName.hashCode()
143138
return __r
144139
}
145140
//pretty print
146141
override fun print(printer: PrettyPrinter) {
147142
printer.println("ComputeSourceFileByClassArguments (")
148143
printer.indent {
149-
print("className = "); className.print(printer); println()
150-
print("packageName = "); packageName.print(printer); println()
144+
print("canonicalClassName = "); canonicalClassName.print(printer); println()
151145
}
152146
printer.print(")")
153147
}

utbot-framework/src/main/kotlin/org/utbot/framework/process/generated/RdSourceFindingStrategy.Generated.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import kotlin.jvm.JvmStatic
1515

1616

1717
/**
18-
* #### Generated from [EngineProcessModel.kt:17]
18+
* #### Generated from [EngineProcessModel.kt:16]
1919
*/
2020
class RdSourceFindingStrategy private constructor(
2121
private val _testsRelativePath: RdCall<Long, String>,
@@ -108,7 +108,7 @@ val IProtocol.rdSourceFindingStrategy get() = getOrCreateExtension(RdSourceFindi
108108

109109

110110
/**
111-
* #### Generated from [EngineProcessModel.kt:18]
111+
* #### Generated from [EngineProcessModel.kt:17]
112112
*/
113113
data class SourceStrategyMethodArgs (
114114
val testSetId: Long,

utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/instrumenter/InstrumenterAdapter.kt

+6-6
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,7 @@ open class InstrumenterAdapter {
5252
computeSourceFileByClass(it, directoryToSearchRecursively)
5353
}
5454

55-
fun computeSourceFileByClass(clazz: Class<*>, directoryToSearchRecursively: Path = Paths.get("")): File? {
56-
val packageName = clazz.`package`?.name?.replace('.', File.separatorChar)
57-
return computeSourceFileByClass(clazz.name, packageName, directoryToSearchRecursively)
58-
}
59-
60-
open fun computeSourceFileByClass(
55+
fun computeSourceFileByNameAndPackage(
6156
className: String, packageName: String?, directoryToSearchRecursively: Path
6257
): File? {
6358
val sourceFileName = computeSourceFileName(className) ?: return null
@@ -73,4 +68,9 @@ open class InstrumenterAdapter {
7368
}
7469
return fileWithoutPackage
7570
}
71+
72+
open fun computeSourceFileByClass(clazz: Class<*>, directoryToSearchRecursively: Path = Paths.get("")): File? {
73+
val packageName = clazz.`package`?.name?.replace('.', File.separatorChar)
74+
return computeSourceFileByNameAndPackage(clazz.name, packageName, directoryToSearchRecursively)
75+
}
7676
}

utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/generator/UtTestsDialogProcessor.kt

+7
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,13 @@ object UtTestsDialogProcessor {
294294
}
295295

296296
private val PsiClass.canonicalName: String
297+
/*
298+
This method calculates exactly name that is used by compiler convention,
299+
i.e. result is the exact name of .class file for provided PsiClass.
300+
This value is used to provide classes to engine process - follow usages for clarification.
301+
Equivalent for Class.getCanonicalName.
302+
P.S. We cannot load project class in IDEA jvm
303+
*/
297304
get() {
298305
return if (packageName.isEmpty()) {
299306
qualifiedName?.replace(".", "$") ?: ""

utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/process/EngineProcess.kt

+2-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,8 @@ class EngineProcess private constructor(val project: Project, rdProcess: Process
169169
private fun computeSourceFileByClass(params: ComputeSourceFileByClassArguments): String =
170170
DumbService.getInstance(project).runReadActionInSmartMode<String?> {
171171
val scope = GlobalSearchScope.allScope(project)
172-
val psiClass = JavaFileManager.getInstance(project).findClass(params.className, scope)
172+
// JavaFileManager requires canonical name as it is said in import
173+
val psiClass = JavaFileManager.getInstance(project).findClass(params.canonicalClassName, scope)
173174
val sourceFile = psiClass?.navigationElement?.containingFile?.virtualFile?.canonicalPath
174175

175176
logger.debug { "computeSourceFileByClass result: $sourceFile" }

utbot-intellij/src/main/resources/log4j2.xml

+1-28
Original file line numberDiff line numberDiff line change
@@ -1,28 +1 @@
1-
<?xml version="1.0" encoding="UTF-8"?>
2-
<Configuration>
3-
<Appenders>
4-
<!-- Idea catches plugin stdout log and wraps it in its own format, so in IDE only message is logged-->
5-
<Console name="IdeaAppender" target="SYSTEM_OUT">
6-
<PatternLayout pattern="%msg%n"/>
7-
</Console>
8-
<!-- When working as separate process - temporary log4j2.xml would be created, in which -->
9-
<!-- substring `ref="IdeaAppender"` will be replaced with `ref="EngineProcessAppender"`-->
10-
<Console name="EngineProcessAppender" target="SYSTEM_OUT">
11-
<PatternLayout pattern="%d{HH:mm:ss.SSS} | %-5level | %-25c{1} | %msg%n"/>
12-
</Console>
13-
</Appenders>
14-
<Loggers>
15-
<Logger name="org.utbot.intellij" level="info" additivity="false">
16-
<AppenderRef ref="IdeaAppender"/>
17-
</Logger>
18-
<Logger name="org.utbot.IntelliJApiHelper" level="info" additivity="false">
19-
<AppenderRef ref="IdeaAppender"/>
20-
</Logger>
21-
<Logger name="org.utbot" level="debug" additivity="false">
22-
<AppenderRef ref="IdeaAppender"/>
23-
</Logger>
24-
<Root level="error">
25-
<AppenderRef ref="IdeaAppender"/>
26-
</Root>
27-
</Loggers>
28-
</Configuration>
1+
<?xml version="1.0" encoding="UTF-8"?><Configuration> <Appenders><!-- Idea catches plugin stdout log and wraps it in its own format, so in IDE only message is logged--> <Console name="IdeaAppender" target="SYSTEM_OUT"> <PatternLayout pattern="| UtBot - %-25c{1} | %msg%n"/> </Console><!-- When working as separate process - temporary log4j2.xml would be created, in which --><!-- substring `ref="IdeaAppender"` will be replaced with `ref="EngineProcessAppender"`--> <Console name="EngineProcessAppender" target="SYSTEM_OUT"> <PatternLayout pattern="%d{HH:mm:ss.SSS} | %-5level | %-25c{1} | %msg%n"/> </Console> </Appenders> <Loggers> <Logger name="org.utbot.intellij" level="debug" additivity="false"> <AppenderRef ref="IdeaAppender"/> </Logger> <Logger name="org.utbot" level="debug" additivity="false"> <AppenderRef ref="IdeaAppender"/> </Logger> <Root level="error"> <AppenderRef ref="IdeaAppender"/> </Root> </Loggers></Configuration>

utbot-rd/src/main/rdgen/org/utbot/rd/models/EngineProcessModel.kt

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ object EngineProcessRoot : Root()
66

77
object RdInstrumenterAdapter: Ext(EngineProcessRoot) {
88
val computeSourceFileByClassArguments = structdef {
9-
field("className", PredefinedType.string)
10-
field("packageName", PredefinedType.string.nullable)
9+
field("canonicalClassName", PredefinedType.string)
1110
}
1211
init {
1312
call("computeSourceFileByClass", computeSourceFileByClassArguments, PredefinedType.string.nullable).async

utbot-summary/src/main/kotlin/org/utbot/summary/Summarization.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ private fun invokeDescriptions(testSet: UtMethodTestSet, searchDirectory: Path):
362362
//TODO(SAT-1170)
363363
.filterNot { "\$lambda" in it.declaringClass.name }
364364
.mapNotNull { sootMethod ->
365-
val methodFile = Instrumenter.adapter.computeSourceFileByClass(
365+
val methodFile = Instrumenter.adapter.computeSourceFileByNameAndPackage(
366366
sootMethod.declaringClass.name,
367367
sootMethod.declaringClass.javaPackageName.replace(".", File.separator),
368368
searchDirectory

utbot-ui-commons/src/main/kotlin/org/utbot/intellij/plugin/util/IntelliJApiHelper.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import org.jetbrains.kotlin.idea.util.application.invokeLater
1818
* This object is required to encapsulate Android API usage and grant safe access to it.
1919
*/
2020
object IntelliJApiHelper {
21-
private val logger = KotlinLogging.logger {"org.utbot.IntelliJApiHelper"}
21+
private val logger = KotlinLogging.logger {}
2222
enum class Target { THREAD_POOL, READ_ACTION, WRITE_ACTION, EDT_LATER }
2323

2424
fun run(target: Target, indicator: ProgressIndicator? = null, logMessage : String, runnable: Runnable) {

0 commit comments

Comments
 (0)