Skip to content

Commit 89664d7

Browse files
committed
got rid of javassist and org.reflections that used it
1 parent 0c77f4d commit 89664d7

5 files changed

Lines changed: 81 additions & 31 deletions

File tree

visor-api/fabric/build.gradle

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ configurations {
2222
version = version+"-api_fabric"
2323
dependencies {
2424
compileOnly(project(path: ':visor-api', configuration: 'namedElements'))
25-
compileOnly("org.reflections:reflections:0.10.2")
2625

2726
shadowCommon(project(path: ":visor-api", configuration: "namedElements")) { transitive false }
2827
common(project(path: ":visor-api", configuration: "namedElements")) { transitive false }
@@ -41,8 +40,6 @@ dependencies {
4140
shadowCommon(libs.atumvr.core) { transitive = false }
4241
shadowCommon(libs.atumvr.config)
4342

44-
shadowCommon("org.reflections:reflections:0.10.2") { transitive = false }
45-
shadowCommon("org.javassist:javassist:3.28.0-GA") { transitive = false }
4643

4744

4845
}
@@ -61,6 +58,7 @@ shadowJar {
6158
exclude "org.joml"
6259
exclude "org.lwjgl"
6360
exclude "org.slf4j"
61+
6462
duplicatesStrategy DuplicatesStrategy.EXCLUDE
6563
configurations = [
6664
project.configurations.shadowCommon
@@ -75,7 +73,6 @@ shadowJar {
7573
relocate("com.google.gson","me.phoenixra.libs.com.google.gson")
7674
relocate("redempt.crunch","me.phoenixra.libs.redempt.crunch")
7775

78-
relocate("org.reflections","me.phoenixra.libs.org.reflections")
7976
}
8077

8178
remapJar {

visor-api/forge/build.gradle

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ dependencies {
5454
shadowCommon(libs.atumvr.core) { transitive = false }
5555
shadowCommon(libs.atumvr.config)
5656

57-
shadowCommon("org.javassist:javassist:3.28.0-GA") { transitive = false }
5857

5958
}
6059

@@ -87,8 +86,6 @@ shadowJar {
8786
relocate("com.google.gson","me.phoenixra.libs.com.google.gson")
8887
relocate("redempt.crunch","me.phoenixra.libs.redempt.crunch")
8988

90-
relocate("org.reflections","me.phoenixra.libs.org.reflections")
91-
9289

9390

9491
}

visor-fabric/build.gradle

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ configurations {
2121
version = version+"-fabric"
2222
dependencies {
2323
compileOnly(project(path: ':visor-api', configuration: 'namedElements'))
24-
compileOnly("org.reflections:reflections:0.10.2")
2524

2625
shadowCommon(project(path: ":visor-api", configuration: "namedElements")) { transitive false }
2726
shadowCommon(project(path: ":visor-core", configuration: "transformProductionFabric")) { transitive false }
@@ -44,8 +43,6 @@ dependencies {
4443
shadowCommon(libs.atumvr.core) { transitive = false }
4544
shadowCommon(libs.atumvr.config)
4645

47-
shadowCommon("org.reflections:reflections:0.10.2") { transitive = false }
48-
shadowCommon("org.javassist:javassist:3.28.0-GA") { transitive = false }
4946

5047

5148
include(implementation(libs.lwjgl.openxr.get()))
@@ -60,7 +57,6 @@ dependencies {
6057
include(modImplementation(fabricApi.module("fabric-command-api-v2", fabricApiVersion)))
6158

6259

63-
6460
}
6561

6662
processResources {
@@ -77,6 +73,7 @@ shadowJar {
7773
exclude "org.joml"
7874
exclude "org.lwjgl"
7975
exclude "org.slf4j"
76+
8077
duplicatesStrategy DuplicatesStrategy.EXCLUDE
8178
configurations = [
8279
project.configurations.shadowCommon
@@ -91,7 +88,6 @@ shadowJar {
9188
relocate("com.google.gson","me.phoenixra.libs.com.google.gson")
9289
relocate("redempt.crunch","me.phoenixra.libs.redempt.crunch")
9390

94-
relocate("org.reflections","me.phoenixra.libs.org.reflections")
9591
}
9692

9793
remapJar {

visor-fabric/src/main/java/me/phoenixra/visor/loader/fabric/FabricModLoader.java

Lines changed: 78 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
1212
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
1313
import net.fabricmc.loader.api.FabricLoader;
14+
import net.fabricmc.loader.api.ModContainer;
1415
import net.minecraft.core.BlockPos;
1516
import net.minecraft.network.FriendlyByteBuf;
1617
import net.minecraft.network.protocol.Packet;
@@ -19,15 +20,22 @@
1920
import net.minecraft.world.item.ItemStack;
2021
import net.minecraft.world.level.block.state.BlockState;
2122
import org.jetbrains.annotations.NotNull;
22-
import org.reflections.Reflections;
23+
import org.objectweb.asm.*;
24+
2325

2426
import java.io.File;
27+
import java.io.IOException;
28+
import java.io.InputStream;
29+
import java.io.UncheckedIOException;
2530
import java.lang.annotation.Annotation;
31+
import java.nio.file.FileSystem;
32+
import java.nio.file.FileSystems;
33+
import java.nio.file.Files;
34+
import java.nio.file.Path;
35+
import java.util.ArrayList;
2636
import java.util.List;
2737
import java.util.Set;
28-
29-
import static org.reflections.scanners.Scanners.SubTypes;
30-
import static org.reflections.scanners.Scanners.TypesAnnotated;
38+
import java.util.stream.Stream;
3139

3240
public class FabricModLoader implements ModLoader {
3341
private final File configFolder = net.fabricmc.loader.api.FabricLoader.getInstance()
@@ -73,19 +81,74 @@ public double getItemEntityReach(double baseRange, ItemStack itemStack, Equipmen
7381
}
7482

7583

76-
@Override
77-
public @NotNull List<Class<?>> getClassesAnnotated(@NotNull Class<? extends Annotation> annotation,
78-
@NotNull String modId,
79-
@NotNull String packagePath) {
80-
Reflections reflections = new Reflections(
81-
packagePath,
82-
SubTypes, TypesAnnotated
83-
);
84-
85-
Set<Class<?>> annotated = reflections.getTypesAnnotatedWith(annotation);
86-
return annotated.stream().toList();
84+
public @NotNull List<Class<?>> getClassesAnnotated(
85+
@NotNull Class<? extends Annotation> annotation,
86+
@NotNull String modId,
87+
@NotNull String packagePath
88+
) {
89+
try {
90+
List<Class<?>> result = new ArrayList<>();
91+
92+
// Locate our mod container
93+
ModContainer container = FabricLoader.getInstance()
94+
.getModContainer(modId)
95+
.orElseThrow(() -> new IllegalArgumentException("Unknown mod: " + modId));
96+
97+
// Convert package to path form
98+
String pkgPath = packagePath.replace('.', '/');
99+
100+
// Iterate every root (jar or folder)
101+
for (Path root : container.getRootPaths()) {
102+
// resolve into each root
103+
Path pkgRoot = root.resolve(pkgPath);
104+
if (!Files.exists(pkgRoot)) continue;
105+
106+
try (Stream<Path> stream = Files.walk(pkgRoot)) {
107+
stream
108+
.filter(p -> p.getFileName().toString().endsWith(".class"))
109+
.forEach(classFile -> {
110+
try (InputStream in = Files.newInputStream(classFile)) {
111+
ClassReader reader = new ClassReader(in);
112+
reader.accept(new ClassVisitor(Opcodes.ASM9) {
113+
@Override
114+
public AnnotationVisitor visitAnnotation(String desc, boolean visible) {
115+
String found = Type.getType(desc).getClassName();
116+
if (found.equals(annotation.getName())) {
117+
// reconstruct FQCN from path
118+
Path rel = pkgRoot.relativize(classFile);
119+
String className = packagePath + "."
120+
+ rel.toString()
121+
.replace('/', '.')
122+
.replace('\\', '.')
123+
.replaceAll("\\.class$", "");
124+
try {
125+
result.add(
126+
Class.forName(
127+
className,
128+
false,
129+
Thread.currentThread().getContextClassLoader()
130+
)
131+
);
132+
} catch (ClassNotFoundException e) {
133+
throw new RuntimeException(e);
134+
}
135+
}
136+
return super.visitAnnotation(desc, visible);
137+
}
138+
}, ClassReader.SKIP_CODE | ClassReader.SKIP_DEBUG | ClassReader.SKIP_FRAMES);
139+
} catch (IOException e) {
140+
throw new UncheckedIOException(e);
141+
}
142+
});
143+
}
144+
}
145+
return result;
146+
}catch (Exception e){
147+
throw new RuntimeException(e);
148+
}
87149
}
88150

151+
89152
@Override
90153
public @NotNull Packet<?> createPacketToClient(@NotNull VisorPayloadToClient payload) {
91154
FriendlyByteBuf buffer = new FriendlyByteBuf(Unpooled.buffer());

visor-forge/build.gradle

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ dependencies {
5656
shadowCommon(libs.atumvr.core) { transitive = false }
5757
shadowCommon(libs.atumvr.config)
5858

59-
shadowCommon("org.javassist:javassist:3.28.0-GA") { transitive = false }
6059

6160

6261
forgeRuntimeLibrary(libs.lwjgl.openxr)
@@ -84,6 +83,7 @@ shadowJar {
8483
exclude "org.joml"
8584
exclude "org.lwjgl"
8685
exclude "org.slf4j"
86+
8787
duplicatesStrategy DuplicatesStrategy.EXCLUDE
8888
configurations = [
8989
project.configurations.shadowCommon,
@@ -99,9 +99,6 @@ shadowJar {
9999
relocate("com.google.gson","me.phoenixra.libs.com.google.gson")
100100
relocate("redempt.crunch","me.phoenixra.libs.redempt.crunch")
101101

102-
relocate("org.reflections","me.phoenixra.libs.org.reflections")
103-
104-
105102

106103
}
107104

0 commit comments

Comments
 (0)