Fix/plugin file generation#212
Conversation
…roduce DTOs for serialization
There was a problem hiding this comment.
Pull request overview
This PR refactors Gradle plugin-file generation to improve type safety and serialization clarity by introducing DTO-based serialization and migrating plugin-file models to Gradle Property APIs, while also simplifying extension registration.
Changes:
- Introduce serializable DTOs (
HytalePluginFileDto,VelocityPluginFileDto) and serialize DTOs instead of plugin-file model objects. - Migrate
HytalePluginFile/VelocityPluginFileto GradleProperty/ListProperty/MapProperty-based models and adjust plugin wiring accordingly. - Simplify plugin extension creation by switching from factory methods to
extensionClass, and bump gradle-plugin version suffix to-1.12.0.
Reviewed changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| surf-api-gradle-plugin/src/main/kotlin/dev/slne/surf/surfapi/gradle/platform/velocity/VelocitySurfPlugin.kt | Wires Velocity plugin-file creation + DTO serializer into the common generation pipeline. |
| surf-api-gradle-plugin/src/main/kotlin/dev/slne/surf/surfapi/gradle/platform/hytale/HytaleSurfPlugin.kt | Wires Hytale plugin-file creation + DTO serializer into the common generation pipeline. |
| surf-api-gradle-plugin/src/main/kotlin/dev/slne/surf/surfapi/gradle/platform/standalone/StandaloneSurfPlugin.kt | Updates standalone plugin to new extensionClass-based extension creation. |
| surf-api-gradle-plugin/src/main/kotlin/dev/slne/surf/surfapi/gradle/platform/paper/raw/RawPaperSurfPlugin.kt | Updates raw paper plugin to new extensionClass-based extension creation. |
| surf-api-gradle-plugin/src/main/kotlin/dev/slne/surf/surfapi/gradle/platform/paper/plugin/PaperPluginSurfPlugin.kt | Updates paper plugin to new extensionClass-based extension creation. |
| surf-api-gradle-plugin/src/main/kotlin/dev/slne/surf/surfapi/gradle/platform/core/CoreSurfPlugin.kt | Updates core plugin to new extensionClass-based extension creation. |
| surf-api-gradle-plugin/src/main/kotlin/dev/slne/surf/surfapi/gradle/platform/common/CommonSurfPlugin.kt | Replaces createExtension(...) factory with extensionClass and extensions.create(...). |
| surf-api-gradle-plugin/src/main/kotlin/dev/slne/surf/surfapi/gradle/platform/common/CommonSurfPluginWithPluginFile.kt | Switches plugin-file generation to encode DTOs using a provided SerializationStrategy. |
| surf-api-gradle-plugin/src/main/kotlin/dev/slne/surf/surfapi/gradle/generators/pluginfiles/dto/VelocityPluginFileDto.kt | Adds Velocity DTO and mapping from VelocityPluginFile. |
| surf-api-gradle-plugin/src/main/kotlin/dev/slne/surf/surfapi/gradle/generators/pluginfiles/dto/HytalePluginFileDto.kt | Adds Hytale DTO and mapping from HytalePluginFile. |
| surf-api-gradle-plugin/src/main/kotlin/dev/slne/surf/surfapi/gradle/generators/pluginfiles/VelocityPluginFile.kt | Converts Velocity plugin-file model to Gradle managed properties + container-based deps. |
| surf-api-gradle-plugin/src/main/kotlin/dev/slne/surf/surfapi/gradle/generators/pluginfiles/HytalePluginFile.kt | Converts Hytale plugin-file model to Gradle managed properties. |
| surf-api-gradle-plugin/src/main/kotlin/dev/slne/surf/surfapi/gradle/generators/pluginfiles/CommonPluginFile.kt | Removes direct serialization support and old setDefaults hook from common base. |
| surf-api-gradle-plugin/src/main/kotlin/dev/slne/surf/surfapi/gradle/generators/GeneratePluginFile.kt | Removes the no-longer-needed container serializer helper. |
| surf-api-gradle-plugin/build.gradle.kts | Bumps plugin version suffix from -1.11.8 to -1.12.0. |
| override fun createPluginFile(project: Project) = VelocityPluginFile(project) | ||
| override fun createPluginFile( | ||
| project: Project | ||
| ) = project.extensions.create<VelocityPluginFile>("velocityPluginFile").apply { |
There was a problem hiding this comment.
createPluginFile uses extensions.create<VelocityPluginFile>("velocityPluginFile"). CommonSurfPluginWithPluginFile.apply() also registers the returned plugin file under the name velocityPluginFile ("${platformName}PluginFile"), which will cause a duplicate-extension error when applying the plugin. Instantiate the plugin file without registering it (e.g. project.objects.newInstance(...)), or remove the second registration in CommonSurfPluginWithPluginFile.
| ) = project.extensions.create<VelocityPluginFile>("velocityPluginFile").apply { | |
| ) = project.objects.newInstance(VelocityPluginFile::class.java).apply { |
| override fun createPluginFile(project: Project) = HytalePluginFile(project) | ||
| override fun createPluginFile( | ||
| project: Project | ||
| ) = project.extensions.create<HytalePluginFile>("hytalePluginFile").apply { |
There was a problem hiding this comment.
createPluginFile registers a HytalePluginFile extension named hytalePluginFile via extensions.create(...), but CommonSurfPluginWithPluginFile.apply() also adds the returned plugin file to extensions under the same name ("${platformName}PluginFile" -> hytalePluginFile). This will fail at runtime due to duplicate extension names. Consider creating the plugin file instance without registering it (e.g. project.objects.newInstance(...)) or removing the second registration in CommonSurfPluginWithPluginFile.
| ) = project.extensions.create<HytalePluginFile>("hytalePluginFile").apply { | |
| ) = project.objects.newInstance(HytalePluginFile::class.java).apply { |
| fun fromFile(file: HytalePluginFile) = HytalePluginFileDto( | ||
| group = file.group.get(), | ||
| name = file.name.get(), | ||
| version = file.version.get(), | ||
| description = file.description.get(), |
There was a problem hiding this comment.
HytalePluginFileDto.fromFile(...) never populates the id field (serializes as "Id"), even though HytalePluginFile has an id property and HytaleSurfPlugin sets a convention for it. This will generate manifests with a missing/null Id. Map file.id into the DTO (and decide whether it should be required vs optional).
This pull request refactors the plugin file system in the Gradle plugin to improve type safety, serialization, and maintainability. The main changes include replacing direct serialization of plugin file classes with dedicated DTOs, updating property management to use Gradle's
PropertyandListPropertyAPIs, and simplifying the plugin extension and validation logic.Plugin file and serialization refactor:
HytalePluginFileDtoandVelocityPluginFileDto) to handle serialization, replacing custom serializers and direct annotation-based serialization in plugin file classes. (surf-api-gradle-plugin/src/main/kotlin/dev/slne/surf/surfapi/gradle/generators/pluginfiles/dto/HytalePluginFileDto.kt[1]surf-api-gradle-plugin/src/main/kotlin/dev/slne/surf/surfapi/gradle/generators/pluginfiles/dto/VelocityPluginFileDto.kt[2]HytalePluginFileandVelocityPluginFile, and migrated their properties to use Gradle'sProperty,ListProperty, andMapPropertyAPIs for better integration with Gradle's configuration and task system. (surf-api-gradle-plugin/src/main/kotlin/dev/slne/surf/surfapi/gradle/generators/pluginfiles/HytalePluginFile.kt[1]surf-api-gradle-plugin/src/main/kotlin/dev/slne/surf/surfapi/gradle/generators/pluginfiles/VelocityPluginFile.kt[2]surf-api-gradle-plugin/src/main/kotlin/dev/slne/surf/surfapi/gradle/platform/common/CommonSurfPluginWithPluginFile.kt[1] [2]Codebase simplification and cleanup:
GeneratePluginFile.kt,CommonPluginFile.kt, and others, reducing complexity and technical debt. (surf-api-gradle-plugin/src/main/kotlin/dev/slne/surf/surfapi/gradle/generators/GeneratePluginFile.kt[1] [2]surf-api-gradle-plugin/src/main/kotlin/dev/slne/surf/surfapi/gradle/generators/pluginfiles/CommonPluginFile.kt[3]surf-api-gradle-plugin/src/main/kotlin/dev/slne/surf/surfapi/gradle/platform/common/CommonSurfPlugin.kt[1] [2]Version update:
1.11.8to1.12.0in the build file. (surf-api-gradle-plugin/build.gradle.ktssurf-api-gradle-plugin/build.gradle.ktsL24-R24)