Skip to content

Commit ed7d870

Browse files
authored
Extract utbot-spring-framework module from utbot-framework (#2570)
* Make `relevantFieldManagers` a dynamic property, since it's Spring-specific Remove `CgContext.relevantFieldManagers` field * Move `springNoConfigApplicationContext` constant from `utbot-testing` to `utbot-spring-test` * Extract `utbot-spring-framework` module from `utbot-framework-module` Remove duplicated `include("utbot-spring-framework")` in `settings.gradle.kts` * Rename `DependencyInjectionFramework` to `SpringModule` and stop implementing `CodeGenerationSettingItem` as it's not a setting * Move `SpringModule` from `utbot-framework` to `utbot-spring-framework` * Remove unused imports, update comments * Introduce `EngineProcessTask` * Use `EngineProcessTask` to call spring analyzer * Make `SpringModule` a `enum`
1 parent 9c122a9 commit ed7d870

File tree

54 files changed

+371
-541
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+371
-541
lines changed

settings.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ if (includeRiderInBuild.toBoolean()) {
5656

5757
include("utbot-ui-commons")
5858

59+
include("utbot-spring-framework")
5960
include("utbot-spring-commons-api")
6061
include("utbot-spring-commons")
6162
include("utbot-spring-analyzer")

utbot-core/src/main/kotlin/org/utbot/common/DynamicProperties.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ interface MutableDynamicProperties<TOwner> : DynamicProperties<TOwner> {
3636
operator fun <T> set(property: DynamicProperty<TOwner, T>, value: T)
3737
}
3838

39+
fun <TOwner, T> MutableDynamicProperties<TOwner>.getOrPut(property: DynamicProperty<TOwner, T>, default: () -> T): T {
40+
if (property !in this) set(property, default())
41+
return getValue(property)
42+
}
43+
3944
fun <TOwner> Iterable<InitialisedDynamicProperty<TOwner, *>>.toMutableDynamicProperties(): MutableDynamicProperties<TOwner> =
4045
DynamicPropertiesImpl<TOwner>().also { properties ->
4146
forEach { properties.add(it) }

utbot-framework/build.gradle

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ plugins {
33
}
44

55
configurations {
6-
fetchSpringAnalyzerJar
7-
fetchSpringCommonsJar
86
fetchInstrumentationJar
97
}
108

@@ -48,23 +46,10 @@ dependencies {
4846
implementation group: 'com.github.UnitTestBot.ksmt', name: 'ksmt-z3', version: ksmtVersion
4947

5048
fetchInstrumentationJar project(path: ':utbot-instrumentation', configuration: 'instrumentationArchive')
51-
52-
implementation project(':utbot-spring-commons-api')
53-
implementation project(':utbot-spring-analyzer')
54-
fetchSpringAnalyzerJar project(path: ':utbot-spring-analyzer', configuration: 'springAnalyzerJar')
55-
fetchSpringCommonsJar project(path: ':utbot-spring-commons', configuration: 'springCommonsJar')
5649
}
5750

5851
processResources {
5952
from(configurations.fetchInstrumentationJar) {
6053
into "lib"
6154
}
62-
63-
from(configurations.fetchSpringAnalyzerJar) {
64-
into "lib"
65-
}
66-
67-
from(configurations.fetchSpringCommonsJar) {
68-
into "lib"
69-
}
7055
}

utbot-framework/src/main/kotlin/org/utbot/framework/assemble/AssembleModelGenerator.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,12 +205,12 @@ class AssembleModelGenerator(private val basePackageName: String) {
205205
is UtClassRefModel,
206206
is UtVoidModel,
207207
is UtEnumConstantModel,
208-
is UtCustomModel -> utModel
208+
is UtCustomModel -> utModel // for example, UtSpringContextModel
209209
is UtLambdaModel -> assembleLambdaModel(utModel)
210210
is UtArrayModel -> assembleArrayModel(utModel)
211211
is UtCompositeModel -> assembleCompositeModel(utModel)
212212
is UtAssembleModel -> assembleAssembleModel(utModel)
213-
// Python, JavaScript, UtSpringContextModel are supposed to be here as well
213+
// Python, JavaScript are supposed to be here as well
214214
else -> utModel
215215
}
216216
} catch (e: AssembleException) {

utbot-framework/src/main/kotlin/org/utbot/framework/codegen/domain/Domain.kt

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -711,47 +711,6 @@ enum class ProjectType {
711711
JavaScript,
712712
}
713713

714-
abstract class DependencyInjectionFramework(
715-
override val id: String,
716-
override val displayName: String,
717-
override val description: String = "Use $displayName as dependency injection framework",
718-
val testFrameworkDisplayName: String,
719-
/**
720-
* Generation Spring specific tests requires special spring test framework being installed,
721-
* so we can use `TestContextManager` from `spring-test` to configure test context in
722-
* spring-analyzer and to run integration tests.
723-
*/
724-
var testFrameworkInstalled: Boolean = false
725-
) : CodeGenerationSettingItem {
726-
var isInstalled = false
727-
728-
companion object : CodeGenerationSettingBox {
729-
override val defaultItem: DependencyInjectionFramework get() = SpringBoot
730-
override val allItems: List<DependencyInjectionFramework> get() = listOf(SpringBoot, SpringBeans)
731-
732-
val installedItems get() = allItems.filter { it.isInstalled }
733-
734-
/**
735-
* Generation Spring specific tests requires special spring test framework being installed,
736-
* so we can use `TestContextManager` from `spring-test` to configure test context in
737-
* spring-analyzer and to run integration tests.
738-
*/
739-
var testFrameworkInstalled: Boolean = false
740-
}
741-
}
742-
743-
object SpringBeans : DependencyInjectionFramework(
744-
id = "spring-beans",
745-
displayName = "Spring Beans",
746-
testFrameworkDisplayName = "spring-test",
747-
)
748-
749-
object SpringBoot : DependencyInjectionFramework(
750-
id = "spring-boot",
751-
displayName = "Spring Boot",
752-
testFrameworkDisplayName = "spring-boot-test",
753-
)
754-
755714
/**
756715
* Extended [UtModel] model with testSet id and execution id.
757716
*

utbot-framework/src/main/kotlin/org/utbot/framework/codegen/domain/builtin/MockitoBuiltins.kt

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,6 @@ internal val mockitoClassId = BuiltinClassId(
2020
simpleName = "Mockito",
2121
)
2222

23-
internal val mockClassId = BuiltinClassId(
24-
canonicalName = "org.mockito.Mock",
25-
simpleName = "Mock",
26-
)
27-
28-
internal val spyClassId = BuiltinClassId(
29-
canonicalName = "org.mockito.Spy",
30-
simpleName = "Spy"
31-
)
32-
33-
internal val injectMocksClassId = BuiltinClassId(
34-
canonicalName = "org.mockito.InjectMocks",
35-
simpleName = "InjectMocks",
36-
)
37-
3823
internal val ongoingStubbingClassId = BuiltinClassId(
3924
canonicalName = "org.mockito.stubbing.OngoingStubbing",
4025
simpleName = "OngoingStubbing",

utbot-framework/src/main/kotlin/org/utbot/framework/codegen/domain/builtin/UtilMethodBuiltins.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ internal class UtilClassFileMethodProvider(language: CodegenLanguage)
278278
val UTIL_CLASS_VERSION = "2.1"
279279
}
280280

281-
internal class TestClassUtilMethodProvider(testClassId: ClassId) : UtilMethodProvider(testClassId)
281+
class TestClassUtilMethodProvider(testClassId: ClassId) : UtilMethodProvider(testClassId)
282282

283283
internal fun selectUtilClassId(codegenLanguage: CodegenLanguage): ClassId =
284284
when (codegenLanguage) {

utbot-framework/src/main/kotlin/org/utbot/framework/codegen/domain/context/CgContext.kt

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ import kotlinx.collections.immutable.PersistentSet
1313
import kotlinx.collections.immutable.persistentListOf
1414
import kotlinx.collections.immutable.persistentMapOf
1515
import kotlinx.collections.immutable.persistentSetOf
16+
import org.utbot.common.DynamicProperty
17+
import org.utbot.common.MutableDynamicProperties
18+
import org.utbot.common.mutableDynamicPropertiesOf
1619
import org.utbot.framework.codegen.domain.UtModelWrapper
1720
import org.utbot.framework.codegen.domain.ProjectType
1821
import org.utbot.framework.codegen.domain.builtin.TestClassUtilMethodProvider
@@ -25,7 +28,6 @@ import org.utbot.framework.codegen.tree.importIfNeeded
2528
import org.utbot.framework.plugin.api.BuiltinClassId
2629
import org.utbot.framework.plugin.api.ClassId
2730
import org.utbot.framework.codegen.services.language.CgLanguageAssistant
28-
import org.utbot.framework.codegen.tree.fieldmanager.CgAbstractClassFieldManager
2931
import org.utbot.framework.plugin.api.CodegenLanguage
3032
import org.utbot.framework.plugin.api.ExecutableId
3133
import org.utbot.framework.plugin.api.FieldId
@@ -38,6 +40,9 @@ import org.utbot.framework.plugin.api.util.isCheckedException
3840
import org.utbot.framework.plugin.api.util.isSubtypeOf
3941
import org.utbot.framework.plugin.api.util.jClass
4042

43+
typealias CgContextProperties = MutableDynamicProperties<CgContext>
44+
typealias CgContextProperty<T> = DynamicProperty<CgContext, T>
45+
4146
/**
4247
* Interface for all code generation context aware entities
4348
*
@@ -243,10 +248,16 @@ interface CgContextOwner {
243248
var successfulExecutionsModels: List<UtModel>
244249

245250
/**
246-
* Managers to process annotated fields of the class under test
247-
* relevant for the current generation type.
251+
* Many of [CgContext] properties are only needed in some specific scenarios
252+
* (e.g. Spring-related properties and parametrized test specific properties).
253+
*
254+
* To avoid overly inflating [CgContext] interface such properties should
255+
* be added as dynamic properties.
256+
*
257+
* @see DynamicProperty
248258
*/
249-
val relevantFieldManagers: MutableList<CgAbstractClassFieldManager>
259+
// TODO make parameterized test specific properties dynamic
260+
val properties: CgContextProperties
250261

251262
fun block(init: () -> Unit): Block {
252263
val prevBlock = currentBlock
@@ -509,8 +520,8 @@ class CgContext(
509520
RuntimeExceptionTestsBehaviour.defaultItem,
510521
override val hangingTestsTimeout: HangingTestsTimeout = HangingTestsTimeout(),
511522
override val enableTestsTimeout: Boolean = true,
512-
override val relevantFieldManagers: MutableList<CgAbstractClassFieldManager> = mutableListOf(),
513523
override var containsReflectiveCall: Boolean = false,
524+
override val properties: CgContextProperties = mutableDynamicPropertiesOf(),
514525
) : CgContextOwner {
515526
override lateinit var statesCache: EnvironmentFieldStateCache
516527
override lateinit var actual: CgVariable
@@ -667,5 +678,6 @@ class CgContext(
667678
hangingTestsTimeout = this.hangingTestsTimeout,
668679
enableTestsTimeout = this.enableTestsTimeout,
669680
containsReflectiveCall = this.containsReflectiveCall,
681+
properties = this.properties,
670682
)
671683
}

utbot-framework/src/main/kotlin/org/utbot/framework/codegen/services/access/CgCallableAccessManager.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ interface CgCallableAccessManager {
8787
operator fun ClassId.get(fieldId: FieldId): CgStaticFieldAccess
8888
}
8989

90-
internal class CgCallableAccessManagerImpl(val context: CgContext) : CgCallableAccessManager,
90+
class CgCallableAccessManagerImpl(val context: CgContext) : CgCallableAccessManager,
9191
CgContextOwner by context {
9292

9393
private val statementConstructor by lazy { getStatementConstructorBy(context) }

utbot-framework/src/main/kotlin/org/utbot/framework/codegen/services/framework/TestFrameworkManager.kt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@ import org.utbot.framework.plugin.api.BuiltinMethodId
2525
import org.utbot.framework.plugin.api.ClassId
2626
import org.utbot.framework.plugin.api.CodegenLanguage
2727
import org.utbot.framework.plugin.api.ConstructorId
28-
import org.utbot.framework.plugin.api.util.SpringModelUtils.extendWithClassId
29-
import org.utbot.framework.plugin.api.util.SpringModelUtils.runWithClassId
30-
import org.utbot.framework.plugin.api.util.SpringModelUtils.springExtensionClassId
3128
import org.utbot.framework.plugin.api.util.booleanArrayClassId
3229
import org.utbot.framework.plugin.api.util.byteArrayClassId
3330
import org.utbot.framework.plugin.api.util.charArrayClassId

0 commit comments

Comments
 (0)