mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-22 18:45:54 +01:00
79e2cb620e
Upstream has released updates that appear to apply and compile correctly. This update has not been tested by PaperMC and as with ANY update, please do your own testing Bukkit Changes: 376e37db SPIGOT-7677: Update which entities are marked as spawnable 06c4add3 SPIGOT-7737: Add separate TreeType.MEGA_PINE 19b7caaa SPIGOT-7731: Spawn eggs cannot have damage e585297e PR-1022: Add force option to Player#spawnParticle d26e0094 PR-1018: Add methods to get players seeing specific chunks 8df1ed18 PR-978: Add Material#isCompostable and Material#getCompostChance 4b9b59c7 SPIGOT-7676: Enforce locale parameter in toLowerCase and toUpperCase method calls and always use root locale 8d1e700a PR-1020: Cast instead of using #typed when getting BlockType and ItemType to better work with testing / mocks fa28607a PR-1016: Fix incorrect assumption of Fireball having constant speed 4c6c8586 PR-1015: Add a tool component to ItemMeta 6f6b2123 PR-1014: Add PotionEffectTypeCategory to distinguish between beneficial and harmful effects f511cfe1 PR-1013, SPIGOT-4288, SPIGOT-6202: Add material rerouting in preparation for the switch to ItemType and BlockType def44cbf SPIGOT-7669: Fix typo in ProjectileHitEvent#getHitBlockFace documentation 53fa4f72 PR-1011: Throw an exception if a RecipeChoice is ever supplied air CraftBukkit Changes: ee95e171a SPIGOT-7737: Add separate TreeType.MEGA_PINE 0dae4c62c Fix spawn egg equality check and copy constructor ab59e847c Fix spawn eggs with no entity creating invalid stacks and disconnect creative clients 3b6093b28 SPIGOT-7736: Creative spawn egg use loses components c6b4d5a87 SPIGOT-7731: Spawn eggs cannot have damage 340ccd57f SPIGOT-7735: Fix serialization of player heads with note block sound fd2f41834 SPIGOT-7734: Can't register a custom advancement using unsafe() 02456e2a5 PR-1413: Add force option to Player#spawnParticle 6a61f38b2 SPIGOT-7680: Per-world weather command 58c41cebb PR-1409: Add methods to get players seeing specific chunks 16c976797 PR-1412: Fix shipwreck loot tables not being set for BlockTransformers 7189ba636 PR-1360: Add Material#isCompostable and Material#getCompostChance 900384556 SPIGOT-7676: Enforce locale parameter in toLowerCase and toUpperCase method calls and always use root locale bdb40c5f1 Increase outdated build delay d6607c7dd SPIGOT-7675: Fix FoodComponent config deserialization b148ed332 PR-1406: Fix incorrect assumption of Fireball having constant speed 3ec31ca75 PR-1405: Add a tool component to ItemMeta 5d7d675b9 PR-1404: Add PotionEffectTypeCategory to distinguish between beneficial and harmful effects 960827981 PR-1403, SPIGOT-4288, SPIGOT-6202: Add material rerouting in preparation for the switch to ItemType and BlockType 94e44ec93 PR-1401: Add a config option to accept old keys in registry get calls a43701920 PR-1402: Fix ChunkSnapshot#isSectionEmpty() is always false 87d0a3368 SPIGOT-7668: Move NONE Registry updater to FieldRename to avoid some class loader issues 2ea1e7ac2 PR-1399: Fix regression preventing positive .setDamage value from causing knockback for 0 damage events ba2d49d21 Increase outdated build delay Spigot Changes: fcd94e21 Rebuild patches 342f4939 SPIGOT-7661: Add experimental unload-frozen-chunks option
251 lines
11 KiB
Diff
251 lines
11 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Shane Freeder <theboyetronic@gmail.com>
|
|
Date: Sun, 17 Mar 2019 23:04:30 +0000
|
|
Subject: [PATCH] Test changes
|
|
|
|
- Allow use of TYPE_USE annotations
|
|
- Ignore package-private methods for nullability annotations
|
|
- Add excludes for classes which don't pass
|
|
- Disable stupid BukkitMirrorTest
|
|
|
|
Co-authored-by: Riley Park <rileysebastianpark@gmail.com>
|
|
Co-authored-by: Jake Potrebic <jake.m.potrebic@gmail.com>
|
|
|
|
diff --git a/build.gradle.kts b/build.gradle.kts
|
|
index a918fd14c95e714e935758d60bccd72755e00b11..768024b2b4584fd7dd86f068c0e79c89ffc5faa1 100644
|
|
--- a/build.gradle.kts
|
|
+++ b/build.gradle.kts
|
|
@@ -105,6 +105,12 @@ tasks.test {
|
|
useJUnitPlatform()
|
|
}
|
|
|
|
+// Paper start - compile tests with -parameters for better junit parameterized test names
|
|
+tasks.compileTestJava {
|
|
+ options.compilerArgs.add("-parameters")
|
|
+}
|
|
+// Paper end
|
|
+
|
|
// Paper start
|
|
val scanJar = tasks.register("scanJarForBadCalls", io.papermc.paperweight.tasks.ScanJarForBadCalls::class) {
|
|
badAnnotations.add("Lio/papermc/paper/annotation/DoNotUse;")
|
|
diff --git a/src/test/java/io/papermc/paper/testing/EmptyTag.java b/src/test/java/io/papermc/paper/testing/EmptyTag.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..77154095cfb8b259bdb318e8ff40cb6f559ebc18
|
|
--- /dev/null
|
|
+++ b/src/test/java/io/papermc/paper/testing/EmptyTag.java
|
|
@@ -0,0 +1,31 @@
|
|
+package io.papermc.paper.testing;
|
|
+
|
|
+import java.util.Collections;
|
|
+import java.util.Set;
|
|
+import org.bukkit.Keyed;
|
|
+import org.bukkit.NamespacedKey;
|
|
+import org.bukkit.Tag;
|
|
+import org.jetbrains.annotations.NotNull;
|
|
+
|
|
+public record EmptyTag(NamespacedKey key) implements Tag<Keyed> {
|
|
+
|
|
+ @SuppressWarnings("deprecation")
|
|
+ public EmptyTag() {
|
|
+ this(NamespacedKey.randomKey());
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public @NotNull NamespacedKey getKey() {
|
|
+ return this.key;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public boolean isTagged(@NotNull final Keyed item) {
|
|
+ return false;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public @NotNull Set<Keyed> getValues() {
|
|
+ return Collections.emptySet();
|
|
+ }
|
|
+}
|
|
diff --git a/src/test/java/org/bukkit/AnnotationTest.java b/src/test/java/org/bukkit/AnnotationTest.java
|
|
index 64e7aef6220097edefdff3b98a771b988365930d..a899f63eb2ce58b3cf708e91819cbbdeffda5d9f 100644
|
|
--- a/src/test/java/org/bukkit/AnnotationTest.java
|
|
+++ b/src/test/java/org/bukkit/AnnotationTest.java
|
|
@@ -29,7 +29,13 @@ public class AnnotationTest {
|
|
"Lorg/jetbrains/annotations/Nullable;",
|
|
"Lorg/jetbrains/annotations/NotNull;",
|
|
"Lorg/jetbrains/annotations/Contract;",
|
|
- "Lorg/bukkit/UndefinedNullability;"
|
|
+ "Lorg/bukkit/UndefinedNullability;",
|
|
+ // Paper start
|
|
+ "Lorg/checkerframework/checker/nullness/qual/MonotonicNonNull;",
|
|
+ "Lorg/checkerframework/checker/nullness/qual/NonNull;",
|
|
+ "Lorg/checkerframework/checker/nullness/qual/Nullable;",
|
|
+ "Lorg/checkerframework/checker/nullness/qual/PolyNull;",
|
|
+ // Paper end
|
|
};
|
|
|
|
private static final String[] EXCLUDED_CLASSES = {
|
|
@@ -40,7 +46,17 @@ public class AnnotationTest {
|
|
"org/bukkit/util/io/Wrapper",
|
|
"org/bukkit/plugin/java/PluginClassLoader",
|
|
// Generic functional interface
|
|
- "org/bukkit/util/Consumer"
|
|
+ "org/bukkit/util/Consumer",
|
|
+ // Paper start
|
|
+ // Timings history is broken in terms of nullability due to guavas Function defining that the param is NonNull
|
|
+ "co/aikar/timings/TimingHistory$2",
|
|
+ "co/aikar/timings/TimingHistory$2$1",
|
|
+ "co/aikar/timings/TimingHistory$2$1$1",
|
|
+ "co/aikar/timings/TimingHistory$2$1$2",
|
|
+ "co/aikar/timings/TimingHistory$3",
|
|
+ "co/aikar/timings/TimingHistory$4",
|
|
+ "co/aikar/timings/TimingHistoryEntry$1"
|
|
+ // Paper end
|
|
};
|
|
|
|
@Test
|
|
@@ -67,14 +83,40 @@ public class AnnotationTest {
|
|
}
|
|
|
|
if (mustBeAnnotated(Type.getReturnType(method.desc)) && !isWellAnnotated(method.invisibleAnnotations)) {
|
|
+ // Paper start - Allow use of TYPE_USE annotations
|
|
+ boolean warn = true;
|
|
+ if (isWellAnnotated(method.visibleTypeAnnotations)) {
|
|
+ warn = false;
|
|
+ } else if (method.invisibleTypeAnnotations != null) {
|
|
+ dance: for (final org.objectweb.asm.tree.TypeAnnotationNode invisibleTypeAnnotation : method.invisibleTypeAnnotations) {
|
|
+ final org.objectweb.asm.TypeReference ref = new org.objectweb.asm.TypeReference(invisibleTypeAnnotation.typeRef);
|
|
+ if (ref.getSort() == org.objectweb.asm.TypeReference.METHOD_RETURN && java.util.Arrays.asList(ACCEPTED_ANNOTATIONS).contains(invisibleTypeAnnotation.desc)) {
|
|
+ warn = false;
|
|
+ break dance; // cha cha real smooth
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+ if (warn)
|
|
+ // Paper end
|
|
warn(errors, clazz, method, "return value");
|
|
}
|
|
|
|
Type[] paramTypes = Type.getArgumentTypes(method.desc);
|
|
List<ParameterNode> parameters = method.parameters;
|
|
|
|
+ dancing: // Paper
|
|
for (int i = 0; i < paramTypes.length; i++) {
|
|
if (mustBeAnnotated(paramTypes[i]) ^ isWellAnnotated(method.invisibleParameterAnnotations == null ? null : method.invisibleParameterAnnotations[i])) {
|
|
+ // Paper start
|
|
+ if (method.invisibleTypeAnnotations != null || method.visibleTypeAnnotations != null) {
|
|
+ for (final org.objectweb.asm.tree.TypeAnnotationNode invisibleTypeAnnotation : java.util.Objects.requireNonNullElse(method.invisibleTypeAnnotations, method.visibleTypeAnnotations)) {
|
|
+ final org.objectweb.asm.TypeReference ref = new org.objectweb.asm.TypeReference(invisibleTypeAnnotation.typeRef);
|
|
+ if (ref.getSort() == org.objectweb.asm.TypeReference.METHOD_FORMAL_PARAMETER && ref.getTypeParameterIndex() == i && java.util.Arrays.asList(ACCEPTED_ANNOTATIONS).contains(invisibleTypeAnnotation.desc)) {
|
|
+ continue dancing;
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+ // Paper end - Allow use of TYPE_USE annotations
|
|
ParameterNode paramNode = parameters == null ? null : parameters.get(i);
|
|
String paramName = paramNode == null ? null : paramNode.name;
|
|
|
|
@@ -91,13 +133,18 @@ public class AnnotationTest {
|
|
|
|
Collections.sort(errors);
|
|
|
|
- System.out.println(errors.size() + " missing annotation(s):");
|
|
+ StringBuilder builder = new StringBuilder()
|
|
+ .append("There ")
|
|
+ .append(errors.size() != 1 ? "are " : "is ")
|
|
+ .append(errors.size())
|
|
+ .append(" missing annotation")
|
|
+ .append(errors.size() != 1 ? "s:\n" : ":\n");
|
|
+
|
|
for (String message : errors) {
|
|
- System.out.print("\t");
|
|
- System.out.println(message);
|
|
+ builder.append("\t").append(message).append("\n");
|
|
}
|
|
|
|
- fail("There " + errors.size() + " are missing annotation(s)");
|
|
+ fail(builder.toString());
|
|
}
|
|
|
|
private static void collectClasses(@NotNull File from, @NotNull Map<String, ClassNode> to) throws IOException {
|
|
@@ -140,6 +187,11 @@ public class AnnotationTest {
|
|
// Exceptions are excluded
|
|
return false;
|
|
}
|
|
+ // Paper start
|
|
+ if (isInternal(clazz.invisibleAnnotations)) {
|
|
+ return false;
|
|
+ }
|
|
+ // Paper end
|
|
|
|
for (String excludedClass : EXCLUDED_CLASSES) {
|
|
if (excludedClass.equals(clazz.name)) {
|
|
@@ -152,7 +204,7 @@ public class AnnotationTest {
|
|
|
|
private static boolean isMethodIncluded(@NotNull ClassNode clazz, @NotNull MethodNode method, @NotNull Map<String, ClassNode> allClasses) {
|
|
// Exclude private, synthetic and deprecated methods
|
|
- if ((method.access & (Opcodes.ACC_PRIVATE | Opcodes.ACC_SYNTHETIC | Opcodes.ACC_DEPRECATED)) != 0) {
|
|
+ if ((method.access & (Opcodes.ACC_PRIVATE | Opcodes.ACC_SYNTHETIC | Opcodes.ACC_DEPRECATED)) != 0 || (method.access & (Opcodes.ACC_PRIVATE | Opcodes.ACC_PROTECTED | Opcodes.ACC_PUBLIC)) == 0) { // Paper - ignore package-private
|
|
return false;
|
|
}
|
|
|
|
@@ -170,11 +222,30 @@ public class AnnotationTest {
|
|
if ("<init>".equals(method.name) && isAnonymous(clazz)) {
|
|
return false;
|
|
}
|
|
+ // Paper start
|
|
+ if (isInternal(method.invisibleAnnotations)) {
|
|
+ return false;
|
|
+ }
|
|
+ // Paper end
|
|
|
|
return true;
|
|
}
|
|
+ // Paper start
|
|
+ private static boolean isInternal(List<? extends AnnotationNode> annotations) {
|
|
+ if (annotations == null) {
|
|
+ return false;
|
|
+ }
|
|
+ for (AnnotationNode node : annotations) {
|
|
+ if (node.desc.equals("Lorg/jetbrains/annotations/ApiStatus$Internal;")) {
|
|
+ return true;
|
|
+ }
|
|
+ }
|
|
+
|
|
+ return false;
|
|
+ }
|
|
+ // Paper end
|
|
|
|
- private static boolean isWellAnnotated(@Nullable List<AnnotationNode> annotations) {
|
|
+ private static boolean isWellAnnotated(@Nullable List<? extends AnnotationNode> annotations) { // Paper
|
|
if (annotations == null) {
|
|
return false;
|
|
}
|
|
diff --git a/src/test/java/org/bukkit/BukkitMirrorTest.java b/src/test/java/org/bukkit/BukkitMirrorTest.java
|
|
index 89ca06ebecdaadd5dfc7bc74473ca15ad36f6eff..5974ceea58940e1799f3589eac0e39b925a42c3b 100644
|
|
--- a/src/test/java/org/bukkit/BukkitMirrorTest.java
|
|
+++ b/src/test/java/org/bukkit/BukkitMirrorTest.java
|
|
@@ -9,6 +9,7 @@ import org.junit.jupiter.params.ParameterizedTest;
|
|
import org.junit.jupiter.params.provider.Arguments;
|
|
import org.junit.jupiter.params.provider.MethodSource;
|
|
|
|
+@org.junit.jupiter.api.Disabled // Paper
|
|
public class BukkitMirrorTest {
|
|
|
|
public static Stream<Arguments> data() {
|
|
diff --git a/src/test/java/org/bukkit/support/TestServer.java b/src/test/java/org/bukkit/support/TestServer.java
|
|
index 5709d52ed4ac4ce8dd8b0569281279f7305c5fb9..a47ee3ce660ec4467b5ed6a4b41fb2d19179a189 100644
|
|
--- a/src/test/java/org/bukkit/support/TestServer.java
|
|
+++ b/src/test/java/org/bukkit/support/TestServer.java
|
|
@@ -72,6 +72,11 @@ public final class TestServer {
|
|
UnsafeValues unsafeValues = mock(withSettings().stubOnly());
|
|
when(instance.getUnsafe()).thenReturn(unsafeValues);
|
|
|
|
+ // Paper start - testing changes
|
|
+ when(instance.getTag(anyString(), any(NamespacedKey.class), any())).thenAnswer(ignored -> new io.papermc.paper.testing.EmptyTag());
|
|
+ when(instance.getScoreboardCriteria(anyString())).thenReturn(null);
|
|
+ // Paper end - testing changes
|
|
+
|
|
Bukkit.setServer(instance);
|
|
}
|
|
|