forked from LOOHP/InteractionVisualizer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.gradle.kts
More file actions
374 lines (341 loc) · 15.7 KB
/
Copy pathbuild.gradle.kts
File metadata and controls
374 lines (341 loc) · 15.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import org.gradle.jvm.tasks.Jar
import java.util.zip.ZipFile
plugins {
java
id("com.gradleup.shadow") version "9.5.1"
}
group = "com.loohp"
version = "2026.1.2.0"
val pluginVersion = version.toString()
val paper26_1Version = "26.1.2.build.74-stable"
val paper26_2Version = "26.2.build.56-alpha"
val craftEngineVersion = "26.7.2"
val sparrowHeartVersion = "0.72"
val caffeineVersion = "3.2.3"
val paper26_2CompileClasspath = configurations.create("paper26_2CompileClasspath") {
isCanBeConsumed = false
isCanBeResolved = true
extendsFrom(configurations.implementation.get())
}
repositories {
mavenCentral()
maven("https://repo.papermc.io/repository/maven-public/")
maven("https://repo.extendedclip.com/content/repositories/placeholderapi/")
maven("https://repo.momirealms.net/releases")
}
dependencies {
compileOnly("io.papermc.paper:paper-api:$paper26_1Version")
compileOnly("me.clip:placeholderapi:2.11.7")
compileOnly("net.momirealms:craft-engine-core:$craftEngineVersion")
compileOnly("net.momirealms:craft-engine-bukkit:$craftEngineVersion")
implementation("net.momirealms:sparrow-yaml:1.0.7")
implementation("net.momirealms:sparrow-heart:$sparrowHeartVersion")
implementation("com.github.ben-manes.caffeine:caffeine:$caffeineVersion")
testImplementation(platform("org.junit:junit-bom:5.13.4"))
testImplementation("org.junit.jupiter:junit-jupiter")
testImplementation("io.papermc.paper:paper-api:$paper26_1Version")
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
paper26_2CompileClasspath("io.papermc.paper:paper-api:$paper26_2Version")
paper26_2CompileClasspath("me.clip:placeholderapi:2.11.7")
paper26_2CompileClasspath("net.momirealms:craft-engine-core:$craftEngineVersion")
paper26_2CompileClasspath("net.momirealms:craft-engine-bukkit:$craftEngineVersion")
}
java {
toolchain.languageVersion = JavaLanguageVersion.of(25)
withSourcesJar()
}
sourceSets {
main {
java.setSrcDirs(
listOf(
"abstraction/src/main/java",
"common/src/main/java",
),
)
resources.setSrcDirs(listOf("common/src/main/resources"))
}
test {
java.setSrcDirs(listOf("common/src/test/java"))
}
}
val benchmarkSourceSet = sourceSets.create("benchmark") {
java.setSrcDirs(listOf("benchmark/src/main/java"))
resources.setSrcDirs(listOf("benchmark/src/main/resources"))
compileClasspath += sourceSets.main.get().output + configurations.compileClasspath.get()
runtimeClasspath += output + compileClasspath
}
val runtimeComparisonSourceSet = sourceSets.create("runtimeComparison") {
java.setSrcDirs(listOf("benchmark-runtime/src/main/java"))
resources.setSrcDirs(listOf("benchmark-runtime/src/main/resources"))
compileClasspath += configurations.compileClasspath.get()
runtimeClasspath += output + compileClasspath
}
sourceSets.test {
compileClasspath += runtimeComparisonSourceSet.output
runtimeClasspath += runtimeComparisonSourceSet.output
}
val benchmarkJar = tasks.register<Jar>("benchmarkJar") {
description = "Builds the standalone Paper A/B benchmark plugin (never shipped in production)."
group = LifecycleBasePlugin.VERIFICATION_GROUP
dependsOn(benchmarkSourceSet.classesTaskName)
archiveClassifier = "benchmark"
from(benchmarkSourceSet.output)
from(sourceSets.main.get().output) {
include("com/loohp/interactionvisualizer/entities/DroppedItemSpatialIndex*.class")
}
}
val runtimeComparisonJar = tasks.register<Jar>("runtimeComparisonJar") {
description = "Builds the target-independent Paper runtime comparison driver."
group = LifecycleBasePlugin.VERIFICATION_GROUP
dependsOn(runtimeComparisonSourceSet.classesTaskName)
archiveClassifier = "runtime-compare"
from(runtimeComparisonSourceSet.output)
}
tasks.withType<JavaCompile>().configureEach {
options.release = 25
options.encoding = "UTF-8"
options.compilerArgs.addAll(listOf("-parameters", "-Xlint:deprecation", "-Xlint:unchecked"))
}
tasks.processResources {
inputs.property("version", pluginVersion)
filesMatching("plugin.yml") {
expand("project" to mapOf("version" to pluginVersion))
}
}
val testRuntimeClasspathFiles = sourceSets.test.get().runtimeClasspath
val testClasspathJar = tasks.register<Jar>("testClasspathJar") {
description = "Builds an ASCII-path classpath JAR for reliable tests from Unicode Windows workspaces."
val projectPathHash = rootDir.absolutePath.hashCode().toUInt().toString(16)
archiveFileName = "interactionvisualizer-$projectPathHash-test-classpath.jar"
destinationDirectory = file(System.getProperty("java.io.tmpdir"))
.resolve("interactionvisualizer-gradle")
inputs.files(testRuntimeClasspathFiles)
doFirst {
manifest.attributes["Class-Path"] = testRuntimeClasspathFiles.files
.joinToString(" ") { it.toURI().toASCIIString() }
}
}
tasks.withType<Test>().configureEach {
useJUnitPlatform()
dependsOn(testClasspathJar)
classpath = files(testClasspathJar.flatMap { it.archiveFile })
}
val legacyTextCacheDisableProperty = "interactionvisualizer.disableLegacyTextComponentCache"
tasks.named<Test>("test") {
systemProperty(legacyTextCacheDisableProperty, "false")
exclude("**/LegacyTextComponentCacheDisabledTest.class")
}
val testLegacyTextComponentCacheDisabled = tasks.register<Test>("testLegacyTextComponentCacheDisabled") {
description = "Verifies the isolated JVM rollback path for legacy text component caching."
group = LifecycleBasePlugin.VERIFICATION_GROUP
testClassesDirs = sourceSets.test.get().output.classesDirs
include("**/LegacyTextComponentCacheDisabledTest.class")
systemProperty(legacyTextCacheDisableProperty, "true")
dependsOn(tasks.testClasses)
}
val compilePaper26_2 = tasks.register<JavaCompile>("compilePaper26_2") {
description = "Compiles the same Paper-API-only sources against Paper 26.2."
group = LifecycleBasePlugin.VERIFICATION_GROUP
source = sourceSets.main.get().allJava
classpath = paper26_2CompileClasspath
destinationDirectory = layout.buildDirectory.dir("classes/java/paper26_2")
options.release = 25
options.encoding = "UTF-8"
options.compilerArgs.addAll(listOf("-parameters", "-Xlint:deprecation", "-Xlint:unchecked"))
}
val verifyPaperOnlyArchitecture = tasks.register("verifyPaperOnlyArchitecture") {
description = "Confines NMS reflection to the isolated client packet bridges and rejects legacy layers."
group = LifecycleBasePlugin.VERIFICATION_GROUP
val sources = sourceSets.main.get().allJava
inputs.files(sources)
doLast {
val forbidden = listOf(
"net.minecraft",
"org.bukkit.craftbukkit",
"ArmorStand",
"MCVersion",
"com.loohp.platformscheduler",
"com.loohp.yamlconfiguration",
"net.md_5",
"org.bukkit.ChatColor",
"org.awaitility",
"HOTBAR_MOVE_AND_READD",
"runTaskTimerAsynchronously",
"new Thread(",
"new Timer(",
"getDescription()",
"getPluginLoader()",
".spigot()",
)
val pickupBridge = file(
"common/src/main/java/com/loohp/interactionvisualizer/integration/packet/ClientPickupAnimationBridge.java",
).canonicalFile
val textDisplayBridge = file(
"common/src/main/java/com/loohp/interactionvisualizer/integration/packet/ClientTextDisplayBridge.java",
).canonicalFile
val packetBridges = setOf(pickupBridge, textDisplayBridge)
val bridgeTokens = setOf("net.minecraft", "org.bukkit.craftbukkit")
val violations = sources.files.flatMap { source ->
val text = source.readText()
forbidden.filter(text::contains).mapNotNull { token ->
val allowed = source.canonicalFile in packetBridges && token in bridgeTokens
if (allowed) null else "${source.relativeTo(rootDir)}: $token"
}
}
check(violations.isEmpty()) {
"Paper-only architecture violations:\n${violations.joinToString("\n")}"
}
}
}
val verifyCustomContentIsolation = tasks.register("verifyCustomContentIsolation") {
description = "Keeps optional provider APIs behind their reflection-loaded bridge implementations."
group = LifecycleBasePlugin.VERIFICATION_GROUP
val sources = sourceSets.main.get().allJava
inputs.files(sources)
doLast {
val allowedCraftEngineSource = file(
"common/src/main/java/com/loohp/interactionvisualizer/integration/craftengine/CraftEngineCustomContentBridge.java",
).canonicalFile
val allowedCraftEngineLightSource = file(
"common/src/main/java/com/loohp/interactionvisualizer/integration/craftengine/CraftEngineLightManager.java",
).canonicalFile
val allowedCraftEngineCullingSource = file(
"common/src/main/java/com/loohp/interactionvisualizer/integration/craftengine/CraftEngineViewerCullingManager.java",
).canonicalFile
val managerSource = file(
"common/src/main/java/com/loohp/interactionvisualizer/integration/CustomContentManager.java",
).canonicalFile
val lightLoaderSource = file(
"common/src/main/java/com/loohp/interactionvisualizer/managers/LightManager.java",
).canonicalFile
val cullingLoaderSource = file(
"common/src/main/java/com/loohp/interactionvisualizer/integration/ViewerCullingManagerLoader.java",
).canonicalFile
val stableApiClass = "net.momirealms.craftengine.bukkit.api.CraftEngineItems"
val lightSentinelClass = "net.momirealms.craftengine.bukkit.api.BukkitAdaptor"
val cullingSentinelClass = "net.momirealms.craftengine.core.entity.culling.Cullable"
val craftEngineToken = Regex("net\\.momirealms\\.craftengine(?:\\.[A-Za-z_$][A-Za-z0-9_$]*)+")
val violations = sources.files.flatMap { source ->
craftEngineToken.findAll(source.readText()).mapNotNull { match ->
val allowed = when (source.canonicalFile) {
allowedCraftEngineSource, managerSource -> match.value == stableApiClass
lightLoaderSource -> match.value == lightSentinelClass
cullingLoaderSource -> match.value == cullingSentinelClass
allowedCraftEngineLightSource, allowedCraftEngineCullingSource -> true
else -> false
}
if (allowed) null else "${source.relativeTo(rootDir)}: ${match.value}"
}.toList()
}.toMutableList()
val allowedArtifacts = setOf("craft-engine-core", "craft-engine-bukkit")
configurations.flatMap { it.dependencies }
.filter { it.group == "net.momirealms" && it.name.startsWith("craft-engine-") }
.filter { it.name !in allowedArtifacts }
.forEach { dependency ->
violations.add("Unexpected CraftEngine artifact: ${dependency.group}:${dependency.name}")
}
check(violations.isEmpty()) {
"CraftEngine API escaped its optional bridge implementation:\n${violations.joinToString("\n")}"
}
}
}
tasks.check {
dependsOn(compilePaper26_2)
dependsOn(verifyPaperOnlyArchitecture)
dependsOn(verifyCustomContentIsolation)
dependsOn(testLegacyTextComponentCacheDisabled)
dependsOn(runtimeComparisonJar)
}
tasks.named<ShadowJar>("shadowJar") {
archiveClassifier = ""
mergeServiceFiles()
relocate("net.momirealms.sparrow.yaml", "com.loohp.interactionvisualizer.libs.sparrow.yaml")
relocate("net.momirealms.sparrow.heart", "com.loohp.interactionvisualizer.libs.sparrow.heart")
relocate("com.github.benmanes.caffeine", "com.loohp.interactionvisualizer.libs.caffeine")
relocate("org.jspecify", "com.loohp.interactionvisualizer.libs.jspecify")
relocate("com.google.errorprone.annotations", "com.loohp.interactionvisualizer.libs.errorprone.annotations")
isPreserveFileTimestamps = false
isReproducibleFileOrder = true
doLast {
ZipFile(archiveFile.get().asFile).use { jar ->
val bundledCraftEngine = jar.entries().asSequence()
.map { it.name }
.filter { it.startsWith("net/momirealms/craftengine/") }
.toList()
check(bundledCraftEngine.isEmpty()) {
"CraftEngine must remain compileOnly, but provider classes were bundled:\n" +
bundledCraftEngine.joinToString("\n")
}
check(jar.getEntry("com/loohp/interactionvisualizer/libs/sparrow/heart/SparrowHeart.class") != null) {
"The shaded Sparrow Heart runtime is missing"
}
listOf("r26_1", "r26_2").forEach { adapter ->
check(jar.getEntry(
"com/loohp/interactionvisualizer/libs/sparrow/heart/impl/$adapter/Heart.class",
) != null) {
"The shaded Sparrow Heart $adapter adapter is missing"
}
}
val unrelocatedHeart = jar.entries().asSequence()
.map { it.name }
.filter { it.startsWith("net/momirealms/sparrow/heart/") }
.toList()
check(unrelocatedHeart.isEmpty()) {
"Unrelocated Sparrow Heart classes were bundled:\n" + unrelocatedHeart.joinToString("\n")
}
check(jar.getEntry("META-INF/licenses/sparrow-heart.txt") != null) {
"The Sparrow Heart MIT license notice is missing"
}
check(jar.getEntry("META-INF/licenses/caffeine.txt") != null) {
"The Caffeine Apache-2.0 license notice is missing"
}
check(jar.getEntry("META-INF/licenses/jspecify.txt") != null) {
"The JSpecify Apache-2.0 license notice is missing"
}
check(jar.getEntry("META-INF/licenses/error-prone-annotations.txt") != null) {
"The Error Prone Annotations Apache-2.0 license notice is missing"
}
check(jar.getEntry(
"com/loohp/interactionvisualizer/libs/caffeine/cache/Caffeine.class",
) != null) {
"The shaded Caffeine runtime is missing"
}
val unrelocatedCaffeine = jar.entries().asSequence()
.map { it.name }
.filter { it.startsWith("com/github/benmanes/caffeine/") }
.toList()
check(unrelocatedCaffeine.isEmpty()) {
"Unrelocated Caffeine classes were bundled:\n" +
unrelocatedCaffeine.joinToString("\n")
}
val unrelocatedAnnotationDependencies = jar.entries().asSequence()
.map { it.name }
.filter {
it.startsWith("org/jspecify/") ||
it.startsWith("com/google/errorprone/annotations/")
}
.toList()
check(unrelocatedAnnotationDependencies.isEmpty()) {
"Unrelocated Caffeine annotation dependencies were bundled:\n" +
unrelocatedAnnotationDependencies.joinToString("\n")
}
check(jar.getEntry(
"com/loohp/interactionvisualizer/libs/jspecify/annotations/NullMarked.class",
) != null) {
"The relocated JSpecify annotations are missing"
}
check(jar.getEntry(
"com/loohp/interactionvisualizer/libs/errorprone/annotations/CanIgnoreReturnValue.class",
) != null) {
"The relocated Error Prone annotations are missing"
}
}
}
}
tasks.jar {
enabled = false
}
tasks.assemble {
dependsOn(tasks.shadowJar)
}