Skip to content

Commit 7152209

Browse files
committed
feat(Meta): Add api-version implementation
1 parent 71aea3b commit 7152209

7 files changed

Lines changed: 29 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,18 @@ bukkit {
3737
```
3838
If `bukkit.server.version` is not specified, will be used `bukkit.apiVersion` for server.
3939

40+
Now, BukkitGradle adds `api-version` field to `plugin.yml`.
41+
It will be parsed from `bukkit.apiVersion` but you can override it with `bukkit.meta.apiVersion` if need:
42+
```kotlin
43+
bukkit {
44+
apiVersion = "1.16.4" // Inferred api-version is 1.16
45+
46+
meta {
47+
apiVersion.set("1.13") // But here you can override it
48+
}
49+
}
50+
```
51+
4052
### Re-written in Kotlin
4153
The plugin has been converted to Kotlin to make support easier.
4254
The plugin still can be configured with Groovy DSL but
@@ -51,6 +63,7 @@ now it is friendly to Kotlin DSL.
5163
- Add `nogui` argument by default to `bukkitArgs`
5264
- Type of properties `server.jvmArgs` and `server.bukkitArgs` changed from `String` to `List<String>`.
5365
It makes it easier to add arguments without overriding defaults
66+
- Default main class pattern changed from `<groupId>.<lowercased name>.<name>` to `<groupId>.<name>`
5467

5568
### Housekeeping
5669
- Default bukkit version now is 1.16.4

src/main/kotlin/BukkitGradlePlugin.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public class BukkitGradlePlugin : Plugin<Project> {
4848
description.convention(provider { project.description })
4949
main.convention(name.map { "${project.group}.${StringUtils.toPascalCase(it)}" })
5050
version.convention(provider { project.version.toString() })
51+
apiVersion.convention(provider { StringUtils.parseApiVersion(bukkit.apiVersion) })
5152
url.convention(provider { findProperty("url")?.toString() })
5253
}
5354
}

src/main/kotlin/meta/extension/PluginMeta.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ public interface PluginMeta {
1919
@get:Input
2020
public val version: Provider<String>
2121

22+
@get:Optional
23+
@get:Input
24+
public val apiVersion: Provider<String>
25+
2226
@get:Optional
2327
@get:Input
2428
public val url: Provider<String>

src/main/kotlin/meta/extension/PluginMetaImpl.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public class PluginMetaImpl(objects: ObjectFactory) : PluginMeta {
1515
override val description: Property<String> = objects.property()
1616
override val main: Property<String> = objects.property()
1717
override val version: Property<String> = objects.property()
18+
override val apiVersion: Property<String> = objects.property()
1819
override val url: Property<String> = objects.property()
1920
override val authors: ListProperty<String> = objects.listProperty()
2021

src/main/kotlin/meta/task/MergePluginMeta.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public open class MergePluginMeta @Inject internal constructor(
5252
name = meta.name.get(),
5353
description = meta.description.orNull,
5454
version = meta.version.get(),
55+
apiVersion = meta.apiVersion.orNull,
5556
website = meta.url.orNull,
5657
authors = meta.authors.get().takeIf { it.isNotEmpty() }
5758
)

src/main/kotlin/meta/task/ParsePluginMetaFile.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ internal open class ParsePluginMetaFile @Inject constructor(
5656
name?.let(meta.name::convention)
5757
description?.let(meta.description::convention)
5858
version?.let(meta.version::convention)
59+
apiVersion?.let(meta.apiVersion::convention)
5960
website?.let(meta.url::convention)
6061
authors?.let(meta.authors::convention)
6162
}

src/main/kotlin/meta/util/StringUtils.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,12 @@ internal object StringUtils {
88
val camelCaseText = text.replace(Regex("[ _-]([A-Za-z0-9])")) { match -> match.groupValues[1].toUpperCase() }
99
return camelCaseText.capitalize()
1010
}
11+
12+
@JvmStatic
13+
fun parseApiVersion(version: String): String? {
14+
val versionParts = version.split('.').mapNotNull { it.toIntOrNull() }
15+
require(versionParts.size in 2..3) { "Unable to parse API version '$version'." }
16+
val (major, minor) = versionParts
17+
return if (major >= 1 && minor >= 13) "$major.$minor" else null
18+
}
1119
}

0 commit comments

Comments
 (0)