mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-27 15:00:13 +01:00
adjust classreader tests for new directory structure
This commit is contained in:
parent
4cc2be301d
commit
7617b7cd09
5 changed files with 7 additions and 48 deletions
|
@ -18,7 +18,7 @@ import org.objectweb.asm.tree.MethodNode;
|
||||||
@Normal
|
@Normal
|
||||||
public class EntityRemoveEventTest {
|
public class EntityRemoveEventTest {
|
||||||
|
|
||||||
@ClassNodeTest(value = {ClassNodeTest.ClassType.CRAFT_BUKKIT, ClassNodeTest.ClassType.MINECRAFT_MODIFIED, ClassNodeTest.ClassType.MINECRAFT_UNMODIFIED},
|
@ClassNodeTest(value = ClassNodeTest.ClassType.CRAFT_BUKKIT,
|
||||||
excludedClasses = EntityAccess.class,
|
excludedClasses = EntityAccess.class,
|
||||||
excludedPackages = "net/minecraft/gametest/framework")
|
excludedPackages = "net/minecraft/gametest/framework")
|
||||||
public void testForMissing(ClassNode classNode) throws ClassNotFoundException {
|
public void testForMissing(ClassNode classNode) throws ClassNotFoundException {
|
||||||
|
|
|
@ -44,8 +44,6 @@ public class ClassNodeArgumentProvider implements ArgumentsProvider, AnnotationC
|
||||||
newValues[i] = switch (this.classTypes[i]) {
|
newValues[i] = switch (this.classTypes[i]) {
|
||||||
case BUKKIT -> ClassReaderTest.ClassType.BUKKIT;
|
case BUKKIT -> ClassReaderTest.ClassType.BUKKIT;
|
||||||
case CRAFT_BUKKIT -> ClassReaderTest.ClassType.CRAFT_BUKKIT;
|
case CRAFT_BUKKIT -> ClassReaderTest.ClassType.CRAFT_BUKKIT;
|
||||||
case MINECRAFT_UNMODIFIED -> ClassReaderTest.ClassType.MINECRAFT_UNMODIFIED;
|
|
||||||
case MINECRAFT_MODIFIED -> ClassReaderTest.ClassType.MINECRAFT_MODIFIED;
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package org.bukkit.support.provider;
|
package org.bukkit.support.provider;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
|
@ -13,8 +12,6 @@ import java.nio.file.Path;
|
||||||
import java.util.jar.JarEntry;
|
import java.util.jar.JarEntry;
|
||||||
import java.util.jar.JarFile;
|
import java.util.jar.JarFile;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
import net.minecraft.WorldVersion;
|
|
||||||
import net.minecraft.server.Main;
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.support.test.ClassReaderTest;
|
import org.bukkit.support.test.ClassReaderTest;
|
||||||
import org.junit.jupiter.api.extension.ExtensionContext;
|
import org.junit.jupiter.api.extension.ExtensionContext;
|
||||||
|
@ -27,15 +24,12 @@ public class ClassReaderArgumentProvider implements ArgumentsProvider, Annotatio
|
||||||
|
|
||||||
// Needs to be a class, which is present in the source, and not a test class
|
// Needs to be a class, which is present in the source, and not a test class
|
||||||
private static final URI CRAFT_BUKKIT_CLASSES;
|
private static final URI CRAFT_BUKKIT_CLASSES;
|
||||||
// Needs to be a class, which is from the minecraft package and not patch by CraftBukkit
|
|
||||||
private static final URI MINECRAFT_CLASSES;
|
|
||||||
// Needs to be a class, which is from the bukkit package and not a CraftBukkit class
|
// Needs to be a class, which is from the bukkit package and not a CraftBukkit class
|
||||||
private static final URI BUKKIT_CLASSES;
|
private static final URI BUKKIT_CLASSES;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
try {
|
try {
|
||||||
CRAFT_BUKKIT_CLASSES = Main.class.getProtectionDomain().getCodeSource().getLocation().toURI();
|
CRAFT_BUKKIT_CLASSES = org.bukkit.craftbukkit.Main.class.getProtectionDomain().getCodeSource().getLocation().toURI();
|
||||||
MINECRAFT_CLASSES = WorldVersion.class.getProtectionDomain().getCodeSource().getLocation().toURI();
|
|
||||||
BUKKIT_CLASSES = Bukkit.class.getProtectionDomain().getCodeSource().getLocation().toURI();
|
BUKKIT_CLASSES = Bukkit.class.getProtectionDomain().getCodeSource().getLocation().toURI();
|
||||||
} catch (URISyntaxException e) {
|
} catch (URISyntaxException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
|
@ -63,19 +57,11 @@ public class ClassReaderArgumentProvider implements ArgumentsProvider, Annotatio
|
||||||
}
|
}
|
||||||
|
|
||||||
public Stream<ClassReader> getClassReaders() {
|
public Stream<ClassReader> getClassReaders() {
|
||||||
assertNotEquals(ClassReaderArgumentProvider.CRAFT_BUKKIT_CLASSES, ClassReaderArgumentProvider.MINECRAFT_CLASSES, """
|
|
||||||
The Minecraft and CraftBukkit uri point to the same directory / file.
|
|
||||||
Please make sure the CRAFT_BUKKIT_CLASSES points to the test class directory and MINECRAFT_CLASSES to the minecraft server jar.
|
|
||||||
""");
|
|
||||||
|
|
||||||
Stream<InputStream> result = Stream.empty();
|
Stream<InputStream> result = Stream.empty();
|
||||||
|
|
||||||
if (this.contains(ClassReaderTest.ClassType.MINECRAFT_UNMODIFIED)) {
|
if (this.contains(ClassReaderTest.ClassType.CRAFT_BUKKIT)) {
|
||||||
result = Stream.concat(result, this.readMinecraftClasses());
|
result = Stream.concat(result, this.createCraftBukkitClasses());
|
||||||
}
|
|
||||||
|
|
||||||
if (this.contains(ClassReaderTest.ClassType.CRAFT_BUKKIT) || this.contains(ClassReaderTest.ClassType.MINECRAFT_MODIFIED)) {
|
|
||||||
result = Stream.concat(result, this.readCraftBukkitAndOrMinecraftModifiedClasses(this.contains(ClassReaderTest.ClassType.CRAFT_BUKKIT), this.contains(ClassReaderTest.ClassType.MINECRAFT_MODIFIED)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.contains(ClassReaderTest.ClassType.BUKKIT)) {
|
if (this.contains(ClassReaderTest.ClassType.BUKKIT)) {
|
||||||
|
@ -103,10 +89,6 @@ public class ClassReaderArgumentProvider implements ArgumentsProvider, Annotatio
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Stream<InputStream> readMinecraftClasses() {
|
|
||||||
return this.readJarFile(ClassReaderArgumentProvider.MINECRAFT_CLASSES, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Stream<InputStream> readBukkitClasses() {
|
private Stream<InputStream> readBukkitClasses() {
|
||||||
return this.readJarFile(ClassReaderArgumentProvider.BUKKIT_CLASSES, false);
|
return this.readJarFile(ClassReaderArgumentProvider.BUKKIT_CLASSES, false);
|
||||||
}
|
}
|
||||||
|
@ -159,13 +141,12 @@ public class ClassReaderArgumentProvider implements ArgumentsProvider, Annotatio
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Stream<InputStream> readCraftBukkitAndOrMinecraftModifiedClasses(boolean craftBukkit, boolean minecraftModified) {
|
private Stream<InputStream> createCraftBukkitClasses() {
|
||||||
try {
|
try {
|
||||||
return Files.walk(Path.of(ClassReaderArgumentProvider.CRAFT_BUKKIT_CLASSES))
|
return Files.walk(Path.of(ClassReaderArgumentProvider.CRAFT_BUKKIT_CLASSES))
|
||||||
.map(Path::toFile)
|
.map(Path::toFile)
|
||||||
.filter(File::isFile)
|
.filter(File::isFile)
|
||||||
.filter(file -> file.getName().endsWith(".class"))
|
.filter(file -> file.getName().endsWith(".class"))
|
||||||
.filter(file -> this.shouldInclude(this.removeHomeDirectory(file), craftBukkit, minecraftModified))
|
|
||||||
.filter(file -> this.filterPackageNames(this.removeHomeDirectory(file)))
|
.filter(file -> this.filterPackageNames(this.removeHomeDirectory(file)))
|
||||||
.filter(file -> this.filterClass(this.removeHomeDirectory(file)))
|
.filter(file -> this.filterClass(this.removeHomeDirectory(file)))
|
||||||
.map(file -> {
|
.map(file -> {
|
||||||
|
@ -184,22 +165,6 @@ public class ClassReaderArgumentProvider implements ArgumentsProvider, Annotatio
|
||||||
return file.getAbsolutePath().substring(ClassReaderArgumentProvider.CRAFT_BUKKIT_CLASSES.getPath().length());
|
return file.getAbsolutePath().substring(ClassReaderArgumentProvider.CRAFT_BUKKIT_CLASSES.getPath().length());
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean shouldInclude(String name, boolean craftBukkit, boolean minecraftModified) {
|
|
||||||
if (craftBukkit && minecraftModified) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (craftBukkit) {
|
|
||||||
return name.startsWith("org/bukkit/craftbukkit/");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (minecraftModified) {
|
|
||||||
return name.startsWith("net/minecraft/");
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void closeJarFile(JarFile jarFile) {
|
private void closeJarFile(JarFile jarFile) {
|
||||||
try {
|
try {
|
||||||
jarFile.close();
|
jarFile.close();
|
||||||
|
|
|
@ -14,7 +14,7 @@ import org.junit.jupiter.params.provider.ArgumentsSource;
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
public @interface ClassNodeTest {
|
public @interface ClassNodeTest {
|
||||||
|
|
||||||
ClassType[] value() default {ClassType.BUKKIT, ClassType.CRAFT_BUKKIT, ClassType.MINECRAFT_UNMODIFIED, ClassType.MINECRAFT_MODIFIED};
|
ClassType[] value() default {ClassType.BUKKIT, ClassType.CRAFT_BUKKIT};
|
||||||
|
|
||||||
Class<?>[] excludedClasses() default {};
|
Class<?>[] excludedClasses() default {};
|
||||||
|
|
||||||
|
@ -23,7 +23,5 @@ public @interface ClassNodeTest {
|
||||||
enum ClassType {
|
enum ClassType {
|
||||||
BUKKIT,
|
BUKKIT,
|
||||||
CRAFT_BUKKIT,
|
CRAFT_BUKKIT,
|
||||||
MINECRAFT_UNMODIFIED,
|
|
||||||
MINECRAFT_MODIFIED,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@ import org.junit.jupiter.params.provider.ArgumentsSource;
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
public @interface ClassReaderTest {
|
public @interface ClassReaderTest {
|
||||||
|
|
||||||
ClassType[] value() default {ClassType.BUKKIT, ClassType.CRAFT_BUKKIT, ClassType.MINECRAFT_UNMODIFIED, ClassType.MINECRAFT_MODIFIED};
|
ClassType[] value() default {ClassType.BUKKIT, ClassType.CRAFT_BUKKIT};
|
||||||
|
|
||||||
Class<?>[] excludedClasses() default {};
|
Class<?>[] excludedClasses() default {};
|
||||||
|
|
||||||
|
@ -23,7 +23,5 @@ public @interface ClassReaderTest {
|
||||||
enum ClassType {
|
enum ClassType {
|
||||||
BUKKIT,
|
BUKKIT,
|
||||||
CRAFT_BUKKIT,
|
CRAFT_BUKKIT,
|
||||||
MINECRAFT_UNMODIFIED,
|
|
||||||
MINECRAFT_MODIFIED,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue