Skip to content

Commit 330847c

Browse files
authored
feat: Provide default info component for plugin (#24)
* feat - Provide default info component * test - Fix plugin test
1 parent 2ca6915 commit 330847c

File tree

3 files changed

+26
-17
lines changed

3 files changed

+26
-17
lines changed

kotlin-asyncapi-maven-plugin/src/main/kotlin/org/openfolder/kotlinasyncapi/mavenplugin/AsyncApiPlugin.kt

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import org.apache.maven.plugins.annotations.LifecyclePhase
66
import org.apache.maven.plugins.annotations.Mojo
77
import org.apache.maven.plugins.annotations.Parameter
88
import org.apache.maven.project.MavenProject
9+
import org.openfolder.kotlinasyncapi.model.AsyncApi
910
import java.io.File
1011
import javax.inject.Inject
1112

@@ -33,12 +34,23 @@ internal class AsyncApiPlugin @Inject constructor(
3334
lateinit var project: MavenProject
3435

3536
override fun execute() {
36-
val asyncApi = scriptRunner.run(File(sourcePath))
37+
val asyncApi = AsyncApi.asyncApi {
38+
info {
39+
title(project.name)
40+
version(project.version)
41+
description(project.description)
42+
}
43+
channels { }
44+
}
45+
scriptRunner.run(
46+
script = File(sourcePath),
47+
receiver = asyncApi
48+
)
49+
3750
val fullTargetPath = "./target/$targetPath".let {
3851
if (it.last() != '/') it.plus('/')
3952
else it
4053
}
41-
4254
log.info("Writing $targetFileName to $fullTargetPath")
4355
fileWriter.write(
4456
asyncApi = asyncApi,

kotlin-asyncapi-maven-plugin/src/main/kotlin/org/openfolder/kotlinasyncapi/mavenplugin/AsyncApiScriptRunner.kt

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import kotlin.script.experimental.host.toScriptSource
1010
import kotlin.script.experimental.jvmhost.BasicJvmScriptingHost
1111

1212
internal interface AsyncApiScriptRunner {
13-
fun run(script: File): AsyncApi
13+
fun run(script: File, receiver: AsyncApi = AsyncApi()): AsyncApi
1414
}
1515

1616
@Singleton
@@ -19,16 +19,13 @@ internal class AsyncApiScriptHost : AsyncApiScriptRunner {
1919

2020
private val jvmScriptingHost = BasicJvmScriptingHost()
2121

22-
override fun run(script: File): AsyncApi {
23-
val scriptReceiver = AsyncApi()
24-
25-
jvmScriptingHost.evalWithTemplate<AsyncApiScript>(
26-
script = script.toScriptSource(),
27-
evaluation = {
28-
implicitReceivers(scriptReceiver)
29-
}
30-
)
31-
32-
return scriptReceiver
33-
}
22+
override fun run(script: File, receiver: AsyncApi) =
23+
receiver.also {
24+
jvmScriptingHost.evalWithTemplate<AsyncApiScript>(
25+
script = script.toScriptSource(),
26+
evaluation = {
27+
implicitReceivers(it)
28+
}
29+
)
30+
}
3431
}

kotlin-asyncapi-maven-plugin/src/test/kotlin/org/openfolder/kotlinasyncapi/mavenplugin/AsyncApiPluginTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ internal class AsyncApiPluginTest {
4242
}
4343

4444
every {
45-
scriptRunner.run(any())
45+
scriptRunner.run(any(), any())
4646
} returns asyncApi
4747
every {
4848
fileWriter.write(capture(asyncApiSlot), json)
@@ -55,7 +55,7 @@ internal class AsyncApiPluginTest {
5555
}.execute()
5656

5757
verify {
58-
scriptRunner.run(script)
58+
scriptRunner.run(script, ofType(AsyncApi::class))
5959
fileWriter.write(asyncApiSlot.captured, json)
6060
mavenProject.addResource(any())
6161
}

0 commit comments

Comments
 (0)