Skip to content

Commit a85ca71

Browse files
committed
Avoid exposing AbstractDsl#initialize in public API
Closes #218
1 parent ff97821 commit a85ca71

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

kofu/src/main/kotlin/org/springframework/fu/kofu/AbstractDsl.kt

+4-3
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ internal annotation class KofuMarker
2626
/**
2727
* Kofu DSL base class.
2828
*
29-
* Make sure to invoke `super.initialize(context)` from [initialize] in inherited classes to get the context initialized.
29+
* Make sure to invoke `super.initialize(context)` in inherited classes to get the context initialized.
3030
*
3131
* @author Sebastien Deleuze
3232
*/
3333
@KofuMarker
34-
abstract class AbstractDsl : ApplicationContextInitializer<GenericApplicationContext> {
34+
abstract class AbstractDsl {
3535

3636
@PublishedApi
3737
internal lateinit var context: GenericApplicationContext
@@ -58,8 +58,9 @@ abstract class AbstractDsl : ApplicationContextInitializer<GenericApplicationCon
5858
}
5959
}
6060

61-
override fun initialize(context: GenericApplicationContext) {
61+
internal open fun initialize(context: GenericApplicationContext) {
6262
this.context = context
6363
}
6464

65+
internal fun toInitializer() = ApplicationContextInitializer<GenericApplicationContext> { initialize(it) }
6566
}

kofu/src/main/kotlin/org/springframework/fu/kofu/ConfigurationDsl.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ open class ConfigurationDsl(private val dsl: ConfigurationDsl.() -> Unit): Abstr
3636
* @see configuration
3737
* @sample org.springframework.fu.kofu.samples.applicationDslWithConfiguration
3838
*/
39-
fun enable(configuration: ApplicationContextInitializer<GenericApplicationContext>) {
39+
fun enable(configuration: AbstractDsl) {
4040
configuration.initialize(context)
4141
}
4242

kofu/src/main/kotlin/org/springframework/fu/kofu/KofuApplication.kt

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import org.springframework.context.support.GenericApplicationContext
1111
* @see application
1212
* @author Sebastien Deleuze
1313
*/
14-
abstract class KofuApplication(private val initializer: ApplicationContextInitializer<GenericApplicationContext>) {
14+
abstract class KofuApplication(private val initializer: AbstractDsl) {
1515

1616
private var customizer: (ApplicationDsl.() -> Unit)? = null
1717

@@ -31,8 +31,8 @@ abstract class KofuApplication(private val initializer: ApplicationContextInitia
3131
if (!profiles.isEmpty()) {
3232
app.setAdditionalProfiles(*profiles.split(",").map { it.trim() }.toTypedArray())
3333
}
34-
app.addInitializers(initializer)
35-
if (customizer != null) app.addInitializers(ApplicationDsl(customizer!!))
34+
app.addInitializers(initializer.toInitializer())
35+
if (customizer != null) app.addInitializers(ApplicationDsl(customizer!!).toInitializer())
3636
System.setProperty("spring.backgroundpreinitializer.ignore", "true")
3737
System.setProperty("spring.main.lazy-initialization", "true")
3838
return app.run(*args)

0 commit comments

Comments
 (0)