From 04a898748b36dd1c0294499f49898f24dee1daed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20=E2=80=9CCLOVIS=E2=80=9D=20Canet?= Date: Sat, 21 Mar 2026 22:47:12 +0100 Subject: [PATCH] build(dsl-templator): Create the templator plugin --- dsl-template/README.md | 2 +- dsl/build.gradle.kts | 1 + gradle/conventions/dsl-templator/README.md | 5 +++ .../dsl-templator/build.gradle.kts | 35 +++++++++++++++++++ .../main/kotlin/KtMongoDslTemplatorPlugin.kt | 26 ++++++++++++++ gradle/conventions/gradle.properties | 17 +++++++++ gradle/conventions/settings.gradle.kts | 20 +++++++++++ 7 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 gradle/conventions/dsl-templator/README.md create mode 100644 gradle/conventions/dsl-templator/build.gradle.kts create mode 100644 gradle/conventions/dsl-templator/src/main/kotlin/KtMongoDslTemplatorPlugin.kt create mode 100644 gradle/conventions/gradle.properties diff --git a/dsl-template/README.md b/dsl-template/README.md index da144767..34967ecc 100644 --- a/dsl-template/README.md +++ b/dsl-template/README.md @@ -59,4 +59,4 @@ Additionally, KotlinX.Serialization must know the compile-time type of any seria Instead of developing the DSL module directly, all production code is written in this template module. On each build, the `:dsl` module is regenerated by copying this template module, adding all the necessary overloads in the process. -Note that the templating engine is a dumb script. It does not invoke the Kotlin compiler nor do any actual parsing. +The templating engine is implemented in the [dsl-templator](../gradle/conventions/dsl-templator) Gradle plugin. diff --git a/dsl/build.gradle.kts b/dsl/build.gradle.kts index 4be94b86..f588f92b 100644 --- a/dsl/build.gradle.kts +++ b/dsl/build.gradle.kts @@ -18,6 +18,7 @@ plugins { alias(opensavvyConventions.plugins.base) alias(opensavvyConventions.plugins.kotlin.library) alias(libsCommon.plugins.testBalloon) + id("dev.opensavvy.ktmongo.build.templator") } kotlin { diff --git a/gradle/conventions/dsl-templator/README.md b/gradle/conventions/dsl-templator/README.md new file mode 100644 index 00000000..f63502c8 --- /dev/null +++ b/gradle/conventions/dsl-templator/README.md @@ -0,0 +1,5 @@ +# DSL Templator + +The DSL Templator is a Gradle plugin based on ANTLR that implements the templating required by the `:dsl` module. For general information, see [dsl-template/README.md](../../../dsl-template/README.md). + +## Templating diff --git a/gradle/conventions/dsl-templator/build.gradle.kts b/gradle/conventions/dsl-templator/build.gradle.kts new file mode 100644 index 00000000..5c29ee6e --- /dev/null +++ b/gradle/conventions/dsl-templator/build.gradle.kts @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2026, OpenSavvy and contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +plugins { + `kotlin-dsl` + alias(opensavvyConventions.plugins.base) + alias(opensavvyConventions.plugins.plugin) + antlr +} + +tasks.generateGrammarSource { + arguments = arguments + listOf("-package", "opensavvy.ktmongo.build.kotlin", "-visitor") +} + +gradlePlugin { + plugins { + create("antlr-kotlin") { + id = "dev.opensavvy.ktmongo.build.templator" + implementationClass = "opensavvy.ktmongo.build.KtMongoDslTemplatorPlugin" + } + } +} diff --git a/gradle/conventions/dsl-templator/src/main/kotlin/KtMongoDslTemplatorPlugin.kt b/gradle/conventions/dsl-templator/src/main/kotlin/KtMongoDslTemplatorPlugin.kt new file mode 100644 index 00000000..b085fda8 --- /dev/null +++ b/gradle/conventions/dsl-templator/src/main/kotlin/KtMongoDslTemplatorPlugin.kt @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2026, OpenSavvy and contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package opensavvy.ktmongo.build + +import org.gradle.api.Plugin +import org.gradle.api.Project + +class KtMongoDslTemplatorPlugin : Plugin { + override fun apply(target: Project) { + println("Applying the templator plugin to ${target.path}") + } +} diff --git a/gradle/conventions/gradle.properties b/gradle/conventions/gradle.properties new file mode 100644 index 00000000..3ce7bedb --- /dev/null +++ b/gradle/conventions/gradle.properties @@ -0,0 +1,17 @@ +# +# Copyright (c) 2026, OpenSavvy and contributors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +appGroup=dev.opensavvy.ktmongo diff --git a/gradle/conventions/settings.gradle.kts b/gradle/conventions/settings.gradle.kts index 88351f68..d775fb1f 100644 --- a/gradle/conventions/settings.gradle.kts +++ b/gradle/conventions/settings.gradle.kts @@ -1,3 +1,19 @@ +/* + * Copyright (c) 2026, OpenSavvy and contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + rootProject.name = "conventions" dependencyResolutionManagement { @@ -52,3 +68,7 @@ plugins { } enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS") + +include( + "dsl-templator", +) -- 2.51.2