Skip to content

Commit 2c6fe52

Browse files
committed
refactor: extract relocateCloudNetty logic and simplify plugin initialization
- Moved `relocateCloudNetty` logic to a shared function for reuse across plugins. - Cleaned up initialization in `CommonSurfPlugin`, `AbstractPaperSurfPlugin`, and `VelocitySurfPlugin`. - Removed duplicate relocation logic and improved modularity. - Bumped version to 1.4.4.
1 parent 0cf2f0c commit 2c6fe52

File tree

6 files changed

+25
-16
lines changed

6 files changed

+25
-16
lines changed

.idea/vcs.xml

Lines changed: 0 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

surf-api-gradle-plugin/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ plugins {
2020
group = groupId
2121
version = buildString {
2222
append(mcVersion)
23-
append("-1.4.3")
23+
append("-1.4.4")
2424
if (snapshot) append("-SNAPSHOT")
2525
}
2626

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package dev.slne.surf.surfapi.gradle.platform
2+
3+
import dev.slne.surf.surfapi.gradle.platform.common.CommonSurfPlugin
4+
5+
fun CommonSurfPlugin<*>.relocateCloudNetty() {
6+
addRelocationsForDependency(
7+
"surf-cloud-api-common",
8+
"io.netty" to "dev.slne.surf.cloud.netty"
9+
)
10+
}

surf-api-gradle-plugin/src/main/kotlin/dev/slne/surf/surfapi/gradle/platform/common/CommonSurfPlugin.kt

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,6 @@ abstract class CommonSurfPlugin<E : CommonSurfExtension>(
4040
private val relocations = mutableMapOf<String, String>()
4141
private val dependencyDependentRelocations = mutableMapOf<String, MutableMap<String, String>>()
4242

43-
init {
44-
addRelocationsForDependency(
45-
"surf-cloud-api-common",
46-
"io.netty" to "dev.slne.surf.cloud.netty"
47-
)
48-
}
49-
5043
protected abstract fun createExtension(objects: ObjectFactory, project: Project): E
5144

5245
override fun apply(target: Project) = with(target) {
@@ -76,7 +69,7 @@ abstract class CommonSurfPlugin<E : CommonSurfExtension>(
7669
relocations[this] = to
7770
}
7871

79-
protected fun addRelocationsForDependency(
72+
fun addRelocationsForDependency(
8073
dependency: String,
8174
vararg relocations: Pair<String, String>,
8275
) {

surf-api-gradle-plugin/src/main/kotlin/dev/slne/surf/surfapi/gradle/platform/paper/AbstractPaperSurfPlugin.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,18 @@ package dev.slne.surf.surfapi.gradle.platform.paper
33
import dev.slne.surf.surfapi.gradle.generated.Constants
44
import dev.slne.surf.surfapi.gradle.platform.SurfApiPlatform
55
import dev.slne.surf.surfapi.gradle.platform.core.AbstractCoreSurfPlugin
6+
import dev.slne.surf.surfapi.gradle.platform.relocateCloudNetty
67
import org.gradle.api.Project
78
import org.gradle.kotlin.dsl.dependencies
89
import org.jetbrains.kotlin.gradle.utils.COMPILE_ONLY
910

1011
internal abstract class AbstractPaperSurfPlugin<E : AbstractPaperSurfExtension>(platformName: String) :
1112
AbstractCoreSurfPlugin<E>(platformName, SurfApiPlatform.PAPER) {
1213

14+
init {
15+
relocateCloudNetty()
16+
}
17+
1318
override fun Project.configure0() {
1419
dependencies {
1520
add(COMPILE_ONLY, Constants.PAPER_API)

surf-api-gradle-plugin/src/main/kotlin/dev/slne/surf/surfapi/gradle/platform/velocity/VelocitySurfPlugin.kt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import dev.slne.surf.surfapi.gradle.generated.Constants
44
import dev.slne.surf.surfapi.gradle.generators.pluginfiles.VelocityPluginFile
55
import dev.slne.surf.surfapi.gradle.platform.SurfApiPlatform
66
import dev.slne.surf.surfapi.gradle.platform.common.CommonSurfPluginWithPluginFile
7+
import dev.slne.surf.surfapi.gradle.platform.relocateCloudNetty
78
import org.gradle.api.Project
89
import org.gradle.api.model.ObjectFactory
910
import org.gradle.kotlin.dsl.dependencies
@@ -15,7 +16,13 @@ internal class VelocitySurfPlugin :
1516
SurfApiPlatform.VELOCITY,
1617
"velocity-plugin.json"
1718
) {
18-
override fun createExtension(objects: ObjectFactory, project: Project) = VelocitySurfExtension(project, objects)
19+
20+
init {
21+
relocateCloudNetty()
22+
}
23+
24+
override fun createExtension(objects: ObjectFactory, project: Project) =
25+
VelocitySurfExtension(project, objects)
1926

2027
init {
2128
"it.unimi.dsi.fastutil" relocatesTo "fastutil"

0 commit comments

Comments
 (0)