@@ -20,10 +20,7 @@ import com.fasterxml.jackson.databind.ObjectMapper
20
20
import com.fasterxml.jackson.databind.util.ClassUtil
21
21
import com.fasterxml.jackson.module.kotlin.KotlinModule
22
22
import com.github.jonpeterson.jackson.module.versioning.VersioningModule
23
- import com.netflix.spinnaker.keel.Intent
24
- import com.netflix.spinnaker.keel.IntentActivityRepository
25
- import com.netflix.spinnaker.keel.IntentRepository
26
- import com.netflix.spinnaker.keel.IntentSpec
23
+ import com.netflix.spinnaker.keel.*
27
24
import com.netflix.spinnaker.keel.memory.MemoryIntentActivityRepository
28
25
import com.netflix.spinnaker.keel.memory.MemoryIntentRepository
29
26
import com.netflix.spinnaker.keel.memory.MemoryTraceRepository
@@ -38,6 +35,7 @@ import org.springframework.context.annotation.Configuration
38
35
import org.springframework.core.type.filter.AssignableTypeFilter
39
36
import org.springframework.util.ClassUtils
40
37
import java.time.Clock
38
+ import kotlin.reflect.KClass
41
39
42
40
@Configuration
43
41
@ComponentScan(basePackages = arrayOf(
@@ -50,35 +48,24 @@ open class KeelConfiguration {
50
48
@Autowired
51
49
open fun objectMapper (objectMapper : ObjectMapper ) {
52
50
objectMapper.apply {
53
- registerSubtypes(* findAllIntentSubtypes().toTypedArray())
54
- registerSubtypes(* findAllIntentSpecSubtypes().toTypedArray())
51
+ registerSubtypes(* findAllSubtypes(Intent ::class .java, " com.netflix.spinnaker.keel.intents" ).toTypedArray())
52
+ registerSubtypes(* findAllSubtypes(IntentSpec ::class .java, " com.netflix.spinnaker.keel.intents" ).toTypedArray())
53
+ registerSubtypes(* findAllSubtypes(Policy ::class .java, " com.netflix.spinnaker.keel.policy" ).toTypedArray())
55
54
}
56
55
.registerModule(KotlinModule ())
57
56
.registerModule(VersioningModule ())
58
57
.disable(DeserializationFeature .FAIL_ON_UNKNOWN_PROPERTIES )
59
58
}
60
59
61
- private fun findAllIntentSubtypes (): List <Class <* >> {
62
- return ClassPathScanningCandidateComponentProvider (false )
63
- .apply { addIncludeFilter(AssignableTypeFilter (Intent ::class .java)) }
64
- .findCandidateComponents(" com.netflix.spinnaker.keel.intents" )
65
- .map {
66
- val cls = ClassUtils .resolveClassName(it.beanClassName, ClassUtils .getDefaultClassLoader())
67
- log.info(" Registering Intent: ${cls.simpleName} " )
68
- return @map cls
69
- }
70
- }
71
-
72
- private fun findAllIntentSpecSubtypes (): List <Class <* >> {
73
- return ClassPathScanningCandidateComponentProvider (false )
74
- .apply { addIncludeFilter(AssignableTypeFilter (IntentSpec ::class .java)) }
75
- .findCandidateComponents(" com.netflix.spinnaker.keel.intents" )
76
- .map {
77
- val cls = ClassUtils .resolveClassName(it.beanClassName, ClassUtils .getDefaultClassLoader())
78
- log.info(" Registering IntentSpec: ${cls.simpleName} " )
79
- return @map cls
80
- }
81
- }
60
+ private fun findAllSubtypes (clazz : Class <* >, pkg : String ): List <Class <* >>
61
+ = ClassPathScanningCandidateComponentProvider (false )
62
+ .apply { addIncludeFilter(AssignableTypeFilter (clazz)) }
63
+ .findCandidateComponents(pkg)
64
+ .map {
65
+ val cls = ClassUtils .resolveClassName(it.beanClassName, ClassUtils .getDefaultClassLoader())
66
+ log.info(" Registering ${cls.simpleName} " )
67
+ return @map cls
68
+ }
82
69
83
70
@Bean
84
71
@ConditionalOnMissingBean(IntentRepository ::class )
0 commit comments