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
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ org.jetbrains.dokka.experimental.gradle.pluginMode=V2Enabled
javaVersion=25
mcVersion=26.3
group=dev.slne.surf.api
version=3.47.0
version=3.47.1
relocationPrefix=dev.slne.surf.api.libs
snapshot=false
14 changes: 11 additions & 3 deletions surf-api-gradle-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ plugins {

group = groupId
version = buildString {
append("2.2.1")
append("2.3.0")
if (snapshot) append("-SNAPSHOT")
}

Expand All @@ -46,6 +46,14 @@ dependencies {

implementation("com.palantir.javapoet:javapoet:0.20.0")
implementation(libs.bundles.kotlin.serialization)

testImplementation(kotlin("test"))
testImplementation(libs.junit.jupiter)
testRuntimeOnly(libs.junit.platform.launcher)
}

tasks.test {
useJUnitPlatform()
}

gradlePlugin {
Expand Down Expand Up @@ -123,7 +131,7 @@ val generateConstants = tasks.register("generateConstants") {
inputs.property("libs.auto.service.annotations", libs.auto.service.annotations.get().toString())
inputs.property("libs.versions.commandapiplugin", libs.versions.commandapiplugin.get())
inputs.property("libs.versions.placeholder.api", libs.versions.placeholder.api.get())
inputs.property("libs.versions.luckperms", libs.versions.luckperms.get())
inputs.property("libs.versions.luckpermsplugin.bukkit", libs.versions.luckpermsplugin.bukkit.get())
inputs.property(
"libs.versions.packetevents",
libs.versions.packetevents.plugin.get()
Expand Down Expand Up @@ -165,7 +173,7 @@ val generateConstants = tasks.register("generateConstants") {
|
| const val COMMAND_API_VERSION = "${libs.versions.commandapiplugin.get()}"
| const val PLACEHOLDER_API_VERSION = "${libs.versions.placeholder.api.get()}"
| const val LUCKPERMS_VERSION = "${libs.versions.luckperms.get()}"
| const val LUCKPERMS_VERSION = "${libs.versions.luckpermsplugin.bukkit.get()}"
| const val PACKETEVENTS_VERSION = "${libs.versions.packetevents.plugin.get()}"
|
| const val TEST_JUNIT_VERSION = "${libs.versions.junit.asProvider().get()}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import dev.slne.surf.api.gradle.SurfCoreModules
import dev.slne.surf.api.gradle.platform.common.testing.SurfTestingExtension
import org.gradle.api.Action
import org.gradle.api.model.ObjectFactory
import org.gradle.api.provider.Provider
import org.gradle.kotlin.dsl.newInstance
import org.gradle.kotlin.dsl.property
import org.jetbrains.annotations.MustBeInvokedByOverriders
Expand All @@ -19,6 +20,7 @@ abstract class CommonSurfExtension(protected val objects: ObjectFactory) {
internal val withSurfRedis = objects.property<Boolean>().convention(false)
internal val surfRedisVersion = objects.property<String>()
internal val surfRedisRelocation = objects.property<String>()
internal val withSurfNats = objects.property<Boolean>().convention(false)
internal val withSurfDatabaseR2dbc = objects.property<Boolean>().convention(false)
internal val surfDatabaseR2dbcVersion = objects.property<String>()
internal val surfDatabaseR2dbcRelocation = objects.property<String>()
Expand Down Expand Up @@ -54,6 +56,15 @@ abstract class CommonSurfExtension(protected val objects: ObjectFactory) {
surfRedisRelocation.finalizeValue()
}


fun withSurfNats() {
withSurfNats.set(true)
withSurfNats.finalizeValue()
}

val surfNatsEnabled: Provider<Boolean>
get() = withSurfNats

fun withSurfDatabaseR2dbc(version: String, relocation: String) {
withSurfDatabaseR2dbc.set(true)
withSurfDatabaseR2dbc.finalizeValue()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,13 @@ abstract class CommonSurfPlugin<E : CommonSurfExtension>(
private fun Project.configureKotlin() = configure<KotlinJvmProjectExtension> {
jvmToolchain(Constants.JAVA_VERSION)
compilerOptions {
freeCompilerArgs.addAll(listOf("-Xjsr305=strict", "-Xcontext-parameters"))
freeCompilerArgs.addAll(
listOf(
"-Xjsr305=strict",
"-Xcontext-parameters",
"-Xreturn-value-checker=check",
)
)
javaParameters = true
}
}
Expand Down Expand Up @@ -269,6 +275,16 @@ abstract class CommonSurfPlugin<E : CommonSurfExtension>(
}
}

if (extension.withSurfNats.get()) {
dependencies {
val notation = "dev.slne.surf.nats:surf-nats-api:+"
add(COMPILE_ONLY, notation)
if (testingEnabled) {
add(SurfTestingConfigurer.TEST_IMPLEMENTATION, notation)
}
}
}

if (extension.withSurfDatabaseR2dbc.get()) {
dependencies {
add(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package dev.slne.surf.api.gradle.platform.core

import dev.slne.surf.api.gradle.platform.SurfApiPlatform
import dev.slne.surf.api.gradle.platform.common.CommonSurfPlugin
import dev.slne.surf.api.gradle.platform.common.testing.SurfTestingConfigurer
import org.gradle.api.Project

internal abstract class AbstractCoreSurfPlugin<E : CoreSurfExtension>(
Expand All @@ -28,4 +29,11 @@ internal abstract class AbstractCoreSurfPlugin<E : CoreSurfExtension>(
internal class CoreSurfPlugin :
AbstractCoreSurfPlugin<CoreSurfExtension>("core", SurfApiPlatform.CORE) {
override val extensionClass = CoreSurfExtension::class.java

override fun Project.platformTestDependencies(extension: CoreSurfExtension) {
dependencies.add(
SurfTestingConfigurer.TEST_RUNTIME_ONLY,
SurfApiPlatform.STANDALONE.dependency
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ internal class PaperPluginSurfPlugin :
registerRequired("surf-redis-paper")
}

if (extension.withSurfNats.get()) {
registerRequired("surf-nats-paper")
}

extension.bootstrapDependencies.orNull?.execute(this)
}

Expand All @@ -73,6 +77,10 @@ internal class PaperPluginSurfPlugin :
registerRequired("surf-redis-paper")
}

if (extension.withSurfNats.get()) {
registerRequired("surf-nats-paper")
}

if (extension.installSurfNpc.get()) {
registerRequired("surf-npc-paper")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ internal class VelocitySurfPlugin :
optional.convention(false)
enabled.convention(redisEnabled)
}

register("surf-nats-velocity") {
optional.convention(false)
enabled.convention(ext.withSurfNats)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
package dev.slne.surf.api.gradle.platform

import dev.slne.surf.api.gradle.generated.Constants
import dev.slne.surf.api.gradle.generators.pluginfiles.VelocityPluginFile
import dev.slne.surf.api.gradle.platform.core.CoreSurfExtension
import dev.slne.surf.api.gradle.platform.core.CoreSurfPlugin
import dev.slne.surf.api.gradle.platform.paper.plugin.PaperPluginSurfExtension
import dev.slne.surf.api.gradle.platform.paper.plugin.PaperPluginSurfPlugin
import dev.slne.surf.api.gradle.platform.velocity.VelocitySurfExtension
import dev.slne.surf.api.gradle.platform.velocity.VelocitySurfPlugin
import net.minecrell.pluginyml.paper.PaperPluginDescription
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.internal.project.ProjectInternal
import org.gradle.kotlin.dsl.getByType
import org.gradle.testfixtures.ProjectBuilder
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension
import kotlin.test.*

class SurfNatsPluginTest {

private val natsApi = "dev.slne.surf.nats:surf-nats-api:+"
private val standaloneApi = SurfApiPlatform.STANDALONE.dependency

private inline fun <reified E : Any> evaluatedProject(
plugin: Class<out Plugin<Project>>,
configure: E.() -> Unit = {},
): Project {
val project = ProjectBuilder.builder().build()
project.plugins.apply(plugin)
project.extensions.getByType<E>().configure()
(project as ProjectInternal).evaluate()
return project
}

private fun Project.dependencyNotations(configuration: String) =
configurations.getByName(configuration).dependencies
.map { "${it.group}:${it.name}:${it.version}" }

@Test
fun `withSurfNats adds surf-nats-api as compileOnly and testImplementation`() {
val project = evaluatedProject<CoreSurfExtension>(CoreSurfPlugin::class.java) {
withSurfNats()
}

assertTrue(natsApi in project.dependencyNotations("compileOnly"))
assertTrue(natsApi in project.dependencyNotations("testImplementation"))
assertFalse(natsApi in project.dependencyNotations("implementation"))
assertFalse(natsApi in project.dependencyNotations("api"))
}

@Test
fun `withSurfNats skips testImplementation when testing is disabled`() {
val project = evaluatedProject<CoreSurfExtension>(CoreSurfPlugin::class.java) {
withSurfNats()
testing.enabled.set(false)
}

assertTrue(natsApi in project.dependencyNotations("compileOnly"))
assertFalse(natsApi in project.dependencyNotations("testImplementation"))
}

@Test
fun `surf-nats is absent without withSurfNats`() {
val project = evaluatedProject<CoreSurfExtension>(CoreSurfPlugin::class.java)

assertFalse(natsApi in project.dependencyNotations("compileOnly"))
assertFalse(project.extensions.getByType<CoreSurfExtension>().surfNatsEnabled.get())
}

@Test
fun `surfNatsEnabled reflects withSurfNats`() {
val project = evaluatedProject<CoreSurfExtension>(CoreSurfPlugin::class.java) {
withSurfNats()
}

assertTrue(project.extensions.getByType<CoreSurfExtension>().surfNatsEnabled.get())
}

@Test
fun `core tests get the standalone runtime`() {
val project = evaluatedProject<CoreSurfExtension>(CoreSurfPlugin::class.java)

assertTrue(standaloneApi in project.dependencyNotations("testRuntimeOnly"))
}

@Test
fun `core without testing gets no standalone runtime`() {
val project = evaluatedProject<CoreSurfExtension>(CoreSurfPlugin::class.java) {
testing.enabled.set(false)
}

assertFalse(standaloneApi in project.dependencyNotations("testRuntimeOnly"))
}

@Test
fun `return value checker is enabled`() {
val project = evaluatedProject<CoreSurfExtension>(CoreSurfPlugin::class.java)

val args = project.extensions.getByType<KotlinJvmProjectExtension>()
.compilerOptions.freeCompilerArgs.get()
assertTrue("-Xreturn-value-checker=check" in args)
}

@Test
fun `paper plugin requires surf-nats-paper`() {
val project =
evaluatedProject<PaperPluginSurfExtension>(PaperPluginSurfPlugin::class.java) {
mainClass("dev.slne.test.TestPlugin")
withSurfNats()
}

val description = project.extensions.getByType<PaperPluginDescription>()
for (dependencies in listOf(description.bootstrapDependencies, description.serverDependencies)) {
val nats = assertNotNull(dependencies.findByName("surf-nats-paper"))
assertEquals(true, nats.required)
}
}

@Test
fun `paper plugin without withSurfNats does not require surf-nats-paper`() {
val project =
evaluatedProject<PaperPluginSurfExtension>(PaperPluginSurfPlugin::class.java) {
mainClass("dev.slne.test.TestPlugin")
}

val description = project.extensions.getByType<PaperPluginDescription>()
assertEquals(null, description.serverDependencies.findByName("surf-nats-paper"))
assertEquals(null, description.bootstrapDependencies.findByName("surf-nats-paper"))
}

@Test
fun `velocity plugin depends on surf-nats-velocity`() {
val project = evaluatedProject<VelocitySurfExtension>(VelocitySurfPlugin::class.java) {
withSurfNats()
}

val nats = project.extensions.getByType<VelocityPluginFile>()
.pluginDependencies.getByName("surf-nats-velocity")
assertTrue(nats.enabled.get())
assertFalse(nats.optional.get())
}

@Test
fun `velocity plugin without withSurfNats leaves surf-nats-velocity disabled`() {
val project = evaluatedProject<VelocitySurfExtension>(VelocitySurfPlugin::class.java)

val nats = project.extensions.getByType<VelocityPluginFile>()
.pluginDependencies.getByName("surf-nats-velocity")
assertFalse(nats.enabled.get())
}

@Test
fun `luckperms version is the modrinth plugin version`() {
assertTrue(Constants.LUCKPERMS_VERSION.endsWith("-bukkit"), Constants.LUCKPERMS_VERSION)
}
}
Loading