-
Notifications
You must be signed in to change notification settings - Fork 0
feat: enhance plugin file generation with JSON output and task improvements #211
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,5 @@ | ||
| package dev.slne.surf.surfapi.gradle.generators | ||
|
|
||
| import dev.slne.surf.surfapi.gradle.generators.pluginfiles.CommonPluginFile | ||
| import kotlinx.serialization.ExperimentalSerializationApi | ||
| import kotlinx.serialization.InternalSerializationApi | ||
| import kotlinx.serialization.KSerializer | ||
|
|
@@ -11,35 +10,40 @@ import kotlinx.serialization.encoding.Encoder | |
| import kotlinx.serialization.json.Json | ||
| import org.gradle.api.DefaultTask | ||
| import org.gradle.api.NamedDomainObjectContainer | ||
| import org.gradle.api.file.DirectoryProperty | ||
| import org.gradle.api.file.RegularFileProperty | ||
| import org.gradle.api.provider.Property | ||
| import org.gradle.api.tasks.CacheableTask | ||
| import org.gradle.api.tasks.Input | ||
| import org.gradle.api.tasks.Nested | ||
| import org.gradle.api.tasks.OutputDirectory | ||
| import org.gradle.api.tasks.TaskAction | ||
|
|
||
| @CacheableTask | ||
| abstract class GeneratePluginFile : DefaultTask() { | ||
| @get:Input | ||
| abstract val fileName: Property<String> | ||
|
|
||
| @get:Nested | ||
| abstract val pluginFile: Property<CommonPluginFile> | ||
| @get:Input | ||
| abstract val pluginFileJson: Property<String> | ||
|
|
||
| @get:OutputDirectory | ||
| abstract val outputDirectory: DirectoryProperty | ||
| abstract val outputFile: RegularFileProperty | ||
|
Comment on lines
28
to
+29
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The task now exposes Useful? React with 👍 / 👎. |
||
|
|
||
|
Comment on lines
27
to
30
|
||
| @TaskAction | ||
| fun generate() { | ||
| val pluginFile = pluginFile.get() | ||
| if (pluginFile.isApplied()) { | ||
| val encoded = json.encodeToString(pluginFile) | ||
| outputDirectory.file(fileName).get().asFile.writeText(encoded) | ||
| val out = outputFile.get().asFile | ||
| val json = pluginFileJson.get() | ||
|
|
||
| if (json.isNotBlank()) { | ||
| out.parentFile.mkdirs() | ||
| out.writeText(json) | ||
| } else { | ||
| if (out.exists()) out.delete() | ||
| } | ||
| } | ||
|
|
||
| @OptIn(ExperimentalSerializationApi::class) | ||
| companion object { | ||
| private val json = Json { | ||
| val json = Json { | ||
| isLenient = true | ||
| prettyPrint = true | ||
| prettyPrintIndent = " " | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,27 +30,28 @@ abstract class CommonSurfPluginWithPluginFile<E : CommonSurfExtension, F : Commo | |
| val createdPluginFile = createPluginFile(this) | ||
| extensions.add("${platformName}PluginFile", createdPluginFile) | ||
|
|
||
| val generateTask = tasks.register<GeneratePluginFile>("generate${platformName.uppercaseFirstChar()}PluginFile") { | ||
| group = "surf-api" | ||
|
|
||
| fileName.set(pluginFileName) | ||
| outputDirectory.set(generatedResourcesDirectory) | ||
| pluginFile.set(provider { | ||
| createdPluginFile.setDefaults(target) | ||
| createdPluginFile | ||
| }) | ||
|
|
||
| doFirst { | ||
| if (createdPluginFile.isApplied()) { | ||
| createdPluginFile.validate() | ||
| } else { | ||
| logger.warn( | ||
| "Plugin file generation is skipped because the plugin file is not applied. " + | ||
| "Please check if the plugin file is applied in the build.gradle.kts file." | ||
| ) | ||
| } | ||
| val generateTask = | ||
| tasks.register<GeneratePluginFile>("generate${platformName.uppercaseFirstChar()}PluginFile") { | ||
| group = "surf-api" | ||
|
|
||
| fileName.set(pluginFileName) | ||
|
|
||
| outputFile.set(generatedResourcesDirectory.map { it.file(pluginFileName) }) | ||
|
Comment on lines
+35
to
+39
|
||
| pluginFileJson.set(provider { | ||
| createdPluginFile.setDefaults(target) | ||
|
|
||
| if (createdPluginFile.isApplied()) { | ||
| createdPluginFile.validate() | ||
| GeneratePluginFile.json.encodeToString<CommonPluginFile>(createdPluginFile) | ||
| } else { | ||
| logger.warn( | ||
| "Plugin file generation is skipped because the plugin file is not applied. " + | ||
| "Please check if the plugin file is applied in the build.gradle.kts file." | ||
| ) | ||
| "" | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| plugins.withType<JavaPlugin> { | ||
| extensions.getByType<SourceSetContainer>().named(SourceSet.MAIN_SOURCE_SET_NAME) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fileNameis still declared as an@Input, but the task no longer uses it (the output path is fully determined byoutputFile). This adds unnecessary configuration and affects the task cache key; consider removingfileNameentirely or using it to deriveoutputFileinside the task configuration.