Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
## [Unreleased]

### Features

- Support [configuration cache](https://docs.gradle.org/current/userguide/configuration_cache.html)

### Housekeeping

- **Breaking change!** Remove task `:parsePluginYaml`.
`plugin.yml` from resources is parsed during configuration now.

## [1.1.0] - 2026-11-11

### Features
Expand Down
9 changes: 8 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import org.gradle.plugin.compatibility.compatibility

plugins {
`kotlin-dsl`
`maven-publish`
groovy
kotlin("plugin.serialization") version embeddedKotlinVersion
id("com.gradle.plugin-publish") version "1.3.1"
id("com.gradle.plugin-publish") version "2.2.1"
id("com.github.ben-manes.versions") version "0.52.0"
}

Expand Down Expand Up @@ -62,6 +64,11 @@ gradlePlugin {
description = "Gradle plugin providing integration for easier Bukkit plugins development."
implementationClass = "ru.endlesscode.bukkitgradle.BukkitGradlePlugin"
tags = listOf("minecraft", "bukkit", "spigot", "paper")
compatibility {
features {
configurationCache = true
}
}
}
}
}
14 changes: 4 additions & 10 deletions src/main/kotlin/plugin/PluginYamlFeature.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import ru.endlesscode.bukkitgradle.extensions.finalizeAndGet
import ru.endlesscode.bukkitgradle.extensions.mapNotNull
import ru.endlesscode.bukkitgradle.extensions.resourceFactory
import ru.endlesscode.bukkitgradle.extensions.sourceSets
import ru.endlesscode.bukkitgradle.plugin.task.ParsePluginYaml
import ru.endlesscode.bukkitgradle.plugin.util.MinecraftVersion
import ru.endlesscode.bukkitgradle.plugin.util.StringUtils
import xyz.jpenilla.resourcefactory.ExecuteResourceFactories
Expand Down Expand Up @@ -47,20 +46,15 @@ internal fun Project.configurePluginYamlFeature(bukkit: BukkitExtension) {
}
}

val parsePluginYamlProvider = tasks.register<ParsePluginYaml>("parsePluginYaml") {
pluginYaml.set(bukkitPluginYaml)
pluginYamlFile.set(sourcePluginYaml)

onlyIf { bukkit.generatePluginYaml.finalizeAndGet() }
}

tasks.named<ExecuteResourceFactories>("${SOURCE_SET_NAME}ResourceFactory") {
val generatePluginYaml = bukkit.generatePluginYaml.finalizeAndGet()
onlyIf("Flag generatePluginYaml is enabled") { generatePluginYaml }
if (!generatePluginYaml) return@named

val parsePluginYaml = parsePluginYamlProvider.get()
if (parsePluginYaml.pluginYamlFile.isPresent) dependsOn(parsePluginYaml)
val sourcePluginYamlFile = sourcePluginYaml.orNull ?: return@named
// Don't use asText as it uses the default charset, but plugin.yml is always in UTF-8
val content = providers.fileContents(sourcePluginYamlFile).asBytes.get()
bukkitPluginYaml.applyConventionsFromSource(content.decodeToString())
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,61 +1,35 @@
package ru.endlesscode.bukkitgradle.plugin.task
package ru.endlesscode.bukkitgradle.plugin

import com.charleskorn.kaml.*
import org.gradle.api.DefaultTask
import kotlinx.serialization.decodeFromString
import org.gradle.api.GradleException
import org.gradle.api.file.RegularFileProperty
import org.gradle.api.provider.Property
import org.gradle.api.tasks.*
import org.gradle.work.DisableCachingByDefault
import ru.endlesscode.bukkitgradle.TASKS_GROUP_BUKKIT
import ru.endlesscode.bukkitgradle.plugin.BukkitPluginYamlDefaults
import xyz.jpenilla.resourcefactory.bukkit.BukkitPluginYaml
import xyz.jpenilla.resourcefactory.bukkit.Permission

@DisableCachingByDefault(because = "Parsing a small file is faster than caching")
internal abstract class ParsePluginYaml : DefaultTask() {

private val yaml by lazy {
Yaml(
configuration = YamlConfiguration(
strictMode = false,
decodeEnumCaseInsensitive = true,
yamlNamingStrategy = YamlNamingStrategy.KebabCase,
)
private val yaml by lazy {
Yaml(
configuration = YamlConfiguration(
strictMode = false,
decodeEnumCaseInsensitive = true,
yamlNamingStrategy = YamlNamingStrategy.KebabCase,
)
}

@get:Internal
abstract val pluginYaml: Property<BukkitPluginYaml>

@get:SkipWhenEmpty
@get:InputFile
@get:PathSensitive(PathSensitivity.NONE)
abstract val pluginYamlFile: RegularFileProperty

init {
group = TASKS_GROUP_BUKKIT
description = "Parse plugin.yml file if it exists and add its content as defaults to generation"
}
)
}

@TaskAction
fun parseAndSetDefaults() {
val defaults = readFromFile()
if (defaults != null) pluginYaml.get().applyConventions(defaults)
}
/** Parses the source plugin.yml [content] and uses its values as conventions. */
internal fun BukkitPluginYaml.applyConventionsFromSource(content: String) {
val defaults = parseDefaults(content)
if (defaults != null) applyConventions(defaults)
}

private fun readFromFile(): BukkitPluginYamlDefaults? {
return try {
pluginYamlFile.get().asFile
.inputStream()
.use { yaml.decodeFromStream<BukkitPluginYamlDefaults>(it) }
} catch (cause: EmptyYamlDocumentException) {
logger.debug("plugin.yml is empty – skipping defaults setting", cause)
null
} catch (cause: Exception) {
throw GradleException("Failed to parse plugin.yml: ${cause.message}.\n" +
"Ensure the file is valid YAML that matches plugin.yml schema.", cause)
}
private fun parseDefaults(content: String): BukkitPluginYamlDefaults? {
return try {
yaml.decodeFromString<BukkitPluginYamlDefaults>(content)
} catch (_: EmptyYamlDocumentException) {
null
} catch (cause: Exception) {
throw GradleException("Failed to parse plugin.yml: ${cause.message}.\n" +
"Ensure the file is valid YAML that matches plugin.yml schema.", cause)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class PluginSpecification extends Specification {
}

protected def run(String... args) {
result = getRunner().withArguments(args.toList() + "--stacktrace").build()
result = getRunner().withArguments(args.toList() + "--stacktrace" + "--configuration-cache").build()
}

protected TaskOutcome taskOutcome(String task) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import ru.endlesscode.bukkitgradle.util.CharsetUtils
class GeneratePluginYamlSpec extends PluginSpecification {

private final static RESOURCE_FACTORY = ':mainResourceFactory'
private final static PARSE_PLUGIN_YAML = ':parsePluginYaml'

private File pluginYamlFile
private File generatedPluginYamlFile
Expand All @@ -29,9 +28,6 @@ class GeneratePluginYamlSpec extends PluginSpecification {

then:
taskOutcome(RESOURCE_FACTORY) == TaskOutcome.SUCCESS

and:
taskOutcome(PARSE_PLUGIN_YAML) == TaskOutcome.SUCCESS
}

def 'when run processResources - and plugin.yml generation disabled - should not run resource factory'() {
Expand All @@ -43,9 +39,6 @@ class GeneratePluginYamlSpec extends PluginSpecification {

then:
taskOutcome(RESOURCE_FACTORY) == TaskOutcome.SKIPPED

and:
taskOutcome(PARSE_PLUGIN_YAML) == null
}

def 'when run processResources - and plugin.yml generation disabled - should use source plugin.yml'() {
Expand All @@ -64,7 +57,7 @@ class GeneratePluginYamlSpec extends PluginSpecification {
projectPath("build/resources/main/$PluginYamlFeatureKt.PLUGIN_YML").text == sourceContent
}

def 'when run processResources - and plugin.yml doesnt exist - should skip parsing'() {
def 'when run processResources - and plugin.yml doesnt exist - should run resource factory'() {
given:
pluginYamlFile.delete()

Expand All @@ -73,20 +66,6 @@ class GeneratePluginYamlSpec extends PluginSpecification {

then:
taskOutcome(RESOURCE_FACTORY) == TaskOutcome.SUCCESS

and:
taskOutcome(PARSE_PLUGIN_YAML) == null
}

def 'when run parsing - and plugin.yml doesnt exist - should show NO_SOURCE'() {
given:
pluginYamlFile.delete()

when:
run(PARSE_PLUGIN_YAML)

then:
taskOutcome(PARSE_PLUGIN_YAML) == TaskOutcome.NO_SOURCE
}

def 'when generate plugin.yml - should generate default plugin.yml successfully'() {
Expand Down Expand Up @@ -143,6 +122,20 @@ class GeneratePluginYamlSpec extends PluginSpecification {
secondRunOutcome == TaskOutcome.UP_TO_DATE
}

def 'when generate plugin.yml - and generate it again - should reuse configuration cache'() {
given:
pluginYamlFile.text = "depend: [Vault]\n"

when:
run(RESOURCE_FACTORY)

and: "run generation again"
run(RESOURCE_FACTORY)

then:
result.output.contains("Reusing configuration cache.")
}

def 'when generate plugin.yml - and changed plugin configuration - should update plugin.yml'() {
when:
run(RESOURCE_FACTORY)
Expand Down Expand Up @@ -186,6 +179,36 @@ class GeneratePluginYamlSpec extends PluginSpecification {
hasSourceFile << [true, false]
}

void 'when generate plugin.yml - and changed source plugin.yml - should update plugin.yml'(boolean hasSourceFile) {
given:
if (!hasSourceFile) pluginYamlFile.delete()

when:
run(RESOURCE_FACTORY)

and: "changed source plugin.yml"
pluginYamlFile.text = "depend: [Vault]\n"

and:
run(RESOURCE_FACTORY)

then:
taskOutcome(RESOURCE_FACTORY) == TaskOutcome.SUCCESS

and:
generatedPluginYamlFile.text == """\
api-version: '1.16'
name: test-plugin
version: '1.0'
main: com.example.testplugin.TestPlugin
depend:
- Vault
""".stripIndent()

where:
hasSourceFile << [true, false]
}

void 'when generate plugin.yml - should keep source resources unchanged'() {
given:
def sourceContent = "depend: [Vault]\n"
Expand Down
Loading