Skip to content

Commit a221ca7

Browse files
committed
fix: index jdk classes with jrt filesystem
1 parent 07c9a56 commit a221ca7

1 file changed

Lines changed: 15 additions & 29 deletions

File tree

filament/src/main/java/net/fabricmc/filament/enigma/annotations/AnnotationsIndex.java

Lines changed: 15 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,17 @@
33
import java.io.IOException;
44
import java.io.InputStream;
55
import java.io.UncheckedIOException;
6+
import java.net.URI;
67
import java.nio.file.Files;
78
import java.nio.file.Path;
9+
import java.nio.file.Paths;
810
import java.util.ArrayList;
911
import java.util.Collection;
12+
import java.util.Collections;
1013
import java.util.List;
1114
import java.util.concurrent.CompletableFuture;
1215
import java.util.stream.Stream;
1316
import java.util.zip.ZipEntry;
14-
import java.util.zip.ZipFile;
1517

1618
import cuchaz.enigma.api.view.ProjectView;
1719
import org.objectweb.asm.ClassReader;
@@ -34,7 +36,7 @@ public static CompletableFuture<AnnotationsIndex> index(ProjectView project) {
3436
}
3537
});
3638

37-
indexJdkClasses(annotations, allClasses);
39+
indexJdkClasses(Collections.synchronizedList(annotations), Collections.synchronizedList(allClasses));
3840

3941
return new AnnotationsIndex(annotations, allClasses);
4042
}).whenComplete((annotationsIndex, throwable) -> {
@@ -45,37 +47,21 @@ public static CompletableFuture<AnnotationsIndex> index(ProjectView project) {
4547
}
4648

4749
private static void indexJdkClasses(List<String> annotations, List<String> allClasses) {
48-
String javaHome = System.getProperty("java.home");
49-
Path modulesPath = Path.of(javaHome, "jmods");
50+
try (Stream<Path> classes = Files.walk(Paths.get(URI.create("jrt:/"))).parallel()) {
51+
classes.forEach(path -> {
52+
if (!Files.isRegularFile(path)) return;
53+
if (!path.getFileName().toString().endsWith(".class")) return;
5054

51-
try (Stream<Path> modules = Files.walk(modulesPath)) {
52-
modules.forEach(module -> {
53-
if (!module.toString().endsWith(".jmod")) {
54-
return;
55-
}
56-
57-
try (ZipFile zipFile = new ZipFile(module.toFile())) {
58-
List<? extends ZipEntry> classEntries = zipFile.stream()
59-
.filter(entry -> entry.getName().startsWith("classes/") && entry.getName().endsWith(".class"))
60-
.toList();
55+
try (InputStream in = Files.newInputStream(path)) {
56+
ClassReader reader = new ClassReader(in);
6157

62-
for (ZipEntry classEntry : classEntries) {
63-
allClasses.add(getClassName(classEntry));
64-
}
58+
allClasses.add(reader.getClassName());
6559

66-
classEntries.parallelStream().forEach(entry -> {
67-
try (InputStream in = zipFile.getInputStream(entry)) {
68-
ClassReader reader = new ClassReader(in);
69-
70-
if ((reader.getAccess() & Opcodes.ACC_ANNOTATION) != 0) {
71-
synchronized (annotations) {
72-
annotations.add(getClassName(entry));
73-
}
74-
}
75-
} catch (IOException e) {
76-
throw new UncheckedIOException(e);
60+
if ((reader.getAccess() & Opcodes.ACC_ANNOTATION) != 0) {
61+
synchronized (annotations) {
62+
annotations.add(reader.getClassName());
7763
}
78-
});
64+
}
7965
} catch (IOException e) {
8066
throw new UncheckedIOException(e);
8167
}

0 commit comments

Comments
 (0)