diff --git a/.gitignore b/.gitignore index d408da02..40de2ba8 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,4 @@ netbeans .project .classpath .settings +todo diff --git a/brachyura-minecraft/src/main/java/io/github/coolcrabs/brachyura/fabric/FabricContext.java b/brachyura-minecraft/src/main/java/io/github/coolcrabs/brachyura/fabric/FabricContext.java index 593161bd..c5030630 100644 --- a/brachyura-minecraft/src/main/java/io/github/coolcrabs/brachyura/fabric/FabricContext.java +++ b/brachyura-minecraft/src/main/java/io/github/coolcrabs/brachyura/fabric/FabricContext.java @@ -24,7 +24,6 @@ import java.util.Map; import java.util.Optional; import java.util.Set; -import java.util.regex.Pattern; import java.util.stream.Collectors; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; @@ -158,9 +157,14 @@ public Map getRemappedClasses(BuildModule... modu }); r.put(fm, s); } + ArrayList remapDeps = new ArrayList<>(); + remapDeps.add(namedJar.get().jar); + for (ModDependency dep : remappedModDependencies.get()) { + if (dep.flags.contains(ModDependencyFlag.COMPILE)) remapDeps.add(dep.jarDependency.jar); + } new ProcessorChain( new RemapperProcessor( - getCompileDependencies(), + remapDeps, compmappings, compmappings.getNamespaceId(Namespaces.NAMED), compmappings.getNamespaceId(Namespaces.INTERMEDIARY), @@ -391,9 +395,6 @@ class RemapInfo { try (AtomicDirectory a = new AtomicDirectory(resultdir)) { ArrayList cp = new ArrayList<>(); cp.add(intermediaryjar.get().jar); - for (JavaJarDependency dep : mcClasspath.get()) { - cp.add(dep.jar); - } HashMap b = new HashMap<>(); HashMap c = new HashMap<>(); try (CloseableArrayList toClose = new CloseableArrayList()) { diff --git a/brachyura-minecraft/src/main/java/io/github/coolcrabs/brachyura/mappings/tinyremapper/RemapperProcessor.java b/brachyura-minecraft/src/main/java/io/github/coolcrabs/brachyura/mappings/tinyremapper/RemapperProcessor.java index 286c2327..7dab9aee 100644 --- a/brachyura-minecraft/src/main/java/io/github/coolcrabs/brachyura/mappings/tinyremapper/RemapperProcessor.java +++ b/brachyura-minecraft/src/main/java/io/github/coolcrabs/brachyura/mappings/tinyremapper/RemapperProcessor.java @@ -47,14 +47,14 @@ public class RemapperProcessor implements Processor { final MappingTree mappingTree; final int src; final int dst; - final boolean replaceLvt; + final boolean isNamedMc; - public RemapperProcessor(List classpath, MappingTree mappingTree, int src, int dst, boolean replaceLvt) { + public RemapperProcessor(List classpath, MappingTree mappingTree, int src, int dst, boolean isNamedMc) { this.classpath = classpath; this.mappingTree = mappingTree; this.src = src; this.dst = dst; - this.replaceLvt = replaceLvt; + this.isNamedMc = isNamedMc; } @Override @@ -116,8 +116,13 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO RecombobulatorRemapper remapper = new RecombobulatorRemapper(); remapper.setClasses(ins); remapper.setMappings(mappings); - if (replaceLvt) { + if (isNamedMc) { remapper.replaceLvtAndParams(); + remapper.fixSourceFiles(); + MappingIoMappings mim = (MappingIoMappings) mappings; + mim.addClassMapping(new Mutf8Slice("javax/annotation/Nullable"), new Mutf8Slice("org/jetbrains/annotations/Nullable")); + mim.addClassMapping(new Mutf8Slice("javax/annotation/Nonnull"), new Mutf8Slice("org/jetbrains/annotations/NotNull")); + mim.addClassMapping(new Mutf8Slice("javax/annotation/concurrent/Immutable"), new Mutf8Slice("org/jetbrains/annotations/Unmodifiable")); } ConcurrentLinkedQueue o = new ConcurrentLinkedQueue<>(); remapper.setOutput(new RemapperOutputConsumer() { diff --git a/brachyura-minecraft/src/test/java/io/github/coolcrabs/brachyura/fabric/FabricProjectTest.java b/brachyura-minecraft/src/test/java/io/github/coolcrabs/brachyura/fabric/FabricProjectTest.java index 4295910a..ffbed838 100644 --- a/brachyura-minecraft/src/test/java/io/github/coolcrabs/brachyura/fabric/FabricProjectTest.java +++ b/brachyura-minecraft/src/test/java/io/github/coolcrabs/brachyura/fabric/FabricProjectTest.java @@ -55,6 +55,7 @@ public void getModDependencies(ModDependencyCollector d) { jij(d.addMaven(FabricMaven.URL, new MavenId(FabricMaven.GROUP_ID + ".fabric-api", "fabric-game-rule-api-v1", "1.0.13+d7c144a860"), ModDependencyFlag.RUNTIME, ModDependencyFlag.COMPILE)); jij(d.addMaven(FabricMaven.URL, new MavenId(FabricMaven.GROUP_ID + ".fabric-api", "fabric-registry-sync-v0", "0.9.8+0d9ab37260"), ModDependencyFlag.RUNTIME, ModDependencyFlag.COMPILE)); jij(d.addMaven(Maven.MAVEN_CENTRAL, new MavenId("org.ini4j:ini4j:0.5.4"), ModDependencyFlag.RUNTIME, ModDependencyFlag.COMPILE)); + d.addMaven(Maven.MAVEN_CENTRAL, new MavenId("org.antlr:antlr4-runtime:4.11.1"), ModDependencyFlag.COMPILE, ModDependencyFlag.RUNTIME); }; @Override diff --git a/brachyura-minecraft/src/test/java/io/github/coolcrabs/brachyura/fabric/NoMixinProjectTest.java b/brachyura-minecraft/src/test/java/io/github/coolcrabs/brachyura/fabric/NoMixinProjectTest.java index afa899a3..41b22422 100644 --- a/brachyura-minecraft/src/test/java/io/github/coolcrabs/brachyura/fabric/NoMixinProjectTest.java +++ b/brachyura-minecraft/src/test/java/io/github/coolcrabs/brachyura/fabric/NoMixinProjectTest.java @@ -57,7 +57,7 @@ void compile() { long s2 = System.currentTimeMillis() - s; System.out.println(s2); // Seems to work accross java versions for now - TestUtil.assertSha256(b.jar, "fdfeb367b463839e2207b0c8bc887f1879b2157da838e51b1b0e98487c86e6ce"); + TestUtil.assertSha256(b.jar, "51f89d5ffdbae7c6a861168d12f7a4b852dbbd2ad2778342fe97224b12da454b"); } catch (Exception e) { e.printStackTrace(); throw e; diff --git a/build/src/main/java/io/github/coolcrabs/brachyura/build/Main.java b/build/src/main/java/io/github/coolcrabs/brachyura/build/Main.java index 95a4bdc3..f274f739 100644 --- a/build/src/main/java/io/github/coolcrabs/brachyura/build/Main.java +++ b/build/src/main/java/io/github/coolcrabs/brachyura/build/Main.java @@ -16,6 +16,7 @@ import java.nio.file.attribute.BasicFileAttributes; import java.security.DigestInputStream; import java.security.MessageDigest; +import java.util.Collections; import java.util.Comparator; import java.util.stream.Stream; @@ -48,13 +49,13 @@ public static void main(Path root, String[] localLibs, String[] mavenLibs) throw Stream b = Files.walk(a, 1); Path jar = b.filter(p -> p.toString().endsWith(".jar") && !p.toString().endsWith("-sources.jar") && !p.toString().endsWith("-test.jar")) - .sorted(Comparator.comparingLong(p -> { + .sorted(Collections.reverseOrder(Comparator.comparingLong(p -> { try { return Files.getLastModifiedTime(p).toMillis(); } catch (IOException e) { throw new RuntimeException(e); } - })).findFirst() + }))).findFirst() .orElseThrow(() -> new RuntimeException(lib)); b.close(); Path sources = jar.getParent().resolve(jar.getFileName().toString().replace(".jar", "-sources.jar")); diff --git a/recombobulator/src/main/java/io/github/coolcrabs/brachyura/recombobulator/remapper/MappingIoMappings.java b/recombobulator/src/main/java/io/github/coolcrabs/brachyura/recombobulator/remapper/MappingIoMappings.java index 3b7ca592..4a962845 100644 --- a/recombobulator/src/main/java/io/github/coolcrabs/brachyura/recombobulator/remapper/MappingIoMappings.java +++ b/recombobulator/src/main/java/io/github/coolcrabs/brachyura/recombobulator/remapper/MappingIoMappings.java @@ -157,6 +157,11 @@ class IntNameDescPairPair { if (conflict) throw new RuntimeException("Mapping conflict"); } + //3am hack + public void addClassMapping(Mutf8Slice src, Mutf8Slice dst) { + classMap.put(src, dst); + } + @Override public Mutf8Slice mapClass(Mutf8Slice srcCls) { return classMap.getOrDefault(srcCls, srcCls); diff --git a/recombobulator/src/main/java/io/github/coolcrabs/brachyura/recombobulator/remapper/RecombobulatorRemapper.java b/recombobulator/src/main/java/io/github/coolcrabs/brachyura/recombobulator/remapper/RecombobulatorRemapper.java index fba5cad5..71bae32c 100644 --- a/recombobulator/src/main/java/io/github/coolcrabs/brachyura/recombobulator/remapper/RecombobulatorRemapper.java +++ b/recombobulator/src/main/java/io/github/coolcrabs/brachyura/recombobulator/remapper/RecombobulatorRemapper.java @@ -111,6 +111,8 @@ import io.github.coolcrabs.brachyura.recombobulator.attribute.VerificationTypeObject; import io.github.coolcrabs.brachyura.recombobulator.attribute.VerificationTypeUninitialized; import io.github.coolcrabs.brachyura.recombobulator.util.ConstantPoolRefCounter; +import it.unimi.dsi.fastutil.ints.Int2IntRBTreeMap; +import it.unimi.dsi.fastutil.ints.Int2ObjectRBTreeMap; import it.unimi.dsi.fastutil.ints.IntArrayFIFOQueue; import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; @@ -120,6 +122,7 @@ public class RecombobulatorRemapper { Collection toOutput = new ArrayList<>(); Mappings mappings; boolean replaceLvtAndParams; + boolean fixSourceFiles; static final Mutf8Slice THIS_STR = new Mutf8Slice("this"); @@ -143,6 +146,10 @@ public void replaceLvtAndParams() { this.replaceLvtAndParams = true; } + public void fixSourceFiles() { + this.fixSourceFiles = true; + } + public static class Input { Supplier readSup; String path; @@ -173,7 +180,7 @@ public OutputFile(Supplier readSup, String path, Object tag) { static final Mutf8Slice STRING_CONCAT_FACTORY = new Mutf8Slice("java/lang/invoke/StringConcatFactory"); static final Mutf8Slice OBJECT_METHODS = new Mutf8Slice("java/lang/runtime/ObjectMethods"); - public static class DerefVisitor implements RecombobulatorVisitor { + public class DerefVisitor implements RecombobulatorVisitor { final ConstantPoolRefCounter refs; final ConstantPool cp; int utf8Size = 0; @@ -532,7 +539,7 @@ public void visitAttributeSourceDebugExtension(AttributeSourceDebugExtension el) @Override public void visitAttributeSourceFile(AttributeSourceFile el) { - //noop + if (fixSourceFiles) refs.ref(el.sourcefile_index, -1); } @Override @@ -615,16 +622,18 @@ public class RemapVisitor implements RecombobulatorVisitor { final Object2IntOpenHashMap utf8Map; final Object2IntOpenHashMap nameAndTypeMap; final IntArrayFIFOQueue openSlots; + final ConstantPoolRefCounter refs; Mutf8Slice clsName; - public RemapVisitor(ConstantPool cp, ConstantPool newCp, Mappings mappings, Object2IntOpenHashMap utf8Map, Object2IntOpenHashMap nameAndTypeMap, IntArrayFIFOQueue openSlots) { + public RemapVisitor(ConstantPool cp, ConstantPool newCp, Mappings mappings, Object2IntOpenHashMap utf8Map, Object2IntOpenHashMap nameAndTypeMap, IntArrayFIFOQueue openSlots, ConstantPoolRefCounter refs) { this.cp = cp; this.newCp = newCp; this.mappings = mappings; this.utf8Map = utf8Map; this.nameAndTypeMap = nameAndTypeMap; this.openSlots = openSlots; + this.refs = refs; } @Override @@ -640,6 +649,7 @@ public void visitClassInfo(ClassInfo el) { } } for (int i = 1; i <= cp.size(); i++) { + if (refs.getRef(i) == 0) continue; ConstantPoolEntry e = cp.getEntry(i); if (e instanceof ConstantFieldref) { ConstantFieldref o = (ConstantFieldref) e; @@ -738,6 +748,7 @@ public void visitClassInfo(ClassInfo el) { AttributeMethodParameters params; boolean isDynamic; int[] lvtp; + Int2ObjectRBTreeMap lvtTypeMap; @Override public void visitMethodInfo(MethodInfo el) { @@ -747,8 +758,20 @@ public void visitMethodInfo(MethodInfo el) { el.name_index = getUtf8Index(cp, newCp, utf8Map, openSlots, mapped.name); el.descriptor_index = getUtf8Index(cp, newCp, utf8Map, openSlots, mapped.desc); params = null; + lvtTypeMap = new Int2ObjectRBTreeMap<>(); for (Attribute a : el.attributes) { if (a instanceof AttributeMethodParameters) params = (AttributeMethodParameters) a; + if (a instanceof AttributeCode) { + AttributeCode c = (AttributeCode) a; + for (Attribute a0 : c.attributes) { + if (a0 instanceof AttributeLocalVariableTable) { + AttributeLocalVariableTable alvt = (AttributeLocalVariableTable) a0; + for (EntryLocalVariableTable elvt : alvt.local_variable_table) { + lvtTypeMap.put(elvt.index, Mappings.remapFieldDescriptor(mappings, utf8(cp, elvt.descriptor_index))); + } + } + } + } } int pcount = countParams(mapped.desc); int[] plvt = new int[pcount]; @@ -1096,7 +1119,36 @@ public void visitAttributeSourceDebugExtension(AttributeSourceDebugExtension el) @Override public void visitAttributeSourceFile(AttributeSourceFile el) { - //noop + if (!fixSourceFiles) return; + Mutf8Slice mcls = mappings.mapClass(clsName); + ByteBuffer bb = mcls.b; + int start = bb.position(); + int a = bb.limit() - 1; + for (; a > start; a--) { + byte c = bb.get(a); + if (c == (byte) '/') { + ++a; + break; + } + } + int b = a; + for (; b < bb.limit(); b++) { + byte c = bb.get(b); + if (c == (byte) '$') { + break; + } + } + int size = b - a; + byte[] r = new byte[size + 5]; + for (int i = 0; i < size; i++) { + r[i] = bb.get(a + i); + } + r[size] = '.'; + r[size + 1] = 'j'; + r[size + 2] = 'a'; + r[size + 3] = 'v'; + r[size + 4] = 'a'; + el.sourcefile_index = getUtf8Index(cp, newCp, utf8Map, openSlots, new Mutf8Slice(ByteBuffer.wrap(r))); } @Override @@ -1132,15 +1184,15 @@ public void visitEntryParameterAnnotations(EntryParameterAnnotations el) { @Override public void visitEntryLocalVariableTypeTable(EntryLocalVariableTypeTable el) { el.signature_index = getUtf8Index(cp, newCp, utf8Map, openSlots, Mappings.remapSignature(mappings, utf8(cp, el.signature_index))); - if (isDynamic && el.index == 0) { + if (replaceLvtAndParams && isDynamic && el.index == 0) { el.name_index = getUtf8Index(cp, newCp, utf8Map, openSlots, THIS_STR); - } else if (el.index < lvtp.length) { + } else if (replaceLvtAndParams && el.index < lvtp.length) { el.name_index = params.parameters.get(lvtp[el.index]).name_index; if (el.name_index == 0) { - el.name_index = getUtf8Index(cp, newCp, utf8Map, openSlots, new Mutf8Slice("param" + lvtp[el.index])); + el.name_index = getUtf8Index(cp, newCp, utf8Map, openSlots, new Mutf8Slice("p" + getLvNameTypeThing(lvtTypeMap.get(el.index)) + lvtp[el.index])); } } else if (replaceLvtAndParams) { - el.name_index = getUtf8Index(cp, newCp, utf8Map, openSlots, new Mutf8Slice("lv" + el.index)); + el.name_index = getUtf8Index(cp, newCp, utf8Map, openSlots, new Mutf8Slice("lv" + getLvNameTypeThing(lvtTypeMap.get(el.index)) + el.index)); } else { el.name_index = getUtf8Index(cp, newCp, utf8Map, openSlots, utf8(cp, el.name_index)); } @@ -1180,16 +1232,17 @@ public void visitEntryLineNumberTable(EntryLineNumberTable el) { @Override public void visitEntryLocalVariableTable(EntryLocalVariableTable el) { - el.descriptor_index = getUtf8Index(cp, newCp, utf8Map, openSlots, Mappings.remapFieldDescriptor(mappings, utf8(cp, el.descriptor_index))); - if (isDynamic && el.index == 0) { + Mutf8Slice desc = Mappings.remapFieldDescriptor(mappings, utf8(cp, el.descriptor_index)); + el.descriptor_index = getUtf8Index(cp, newCp, utf8Map, openSlots, desc); + if (replaceLvtAndParams && isDynamic && el.index == 0) { el.name_index = getUtf8Index(cp, newCp, utf8Map, openSlots, THIS_STR); - } else if (el.index < lvtp.length) { + } else if (replaceLvtAndParams && el.index < lvtp.length) { el.name_index = params.parameters.get(lvtp[el.index]).name_index; if (el.name_index == 0) { - el.name_index = getUtf8Index(cp, newCp, utf8Map, openSlots, new Mutf8Slice("param" + lvtp[el.index])); + el.name_index = getUtf8Index(cp, newCp, utf8Map, openSlots, new Mutf8Slice("p" + getLvNameTypeThing(desc) + lvtp[el.index])); } } else if (replaceLvtAndParams) { - el.name_index = getUtf8Index(cp, newCp, utf8Map, openSlots, new Mutf8Slice("lv" + el.index)); + el.name_index = getUtf8Index(cp, newCp, utf8Map, openSlots, new Mutf8Slice("lv" + getLvNameTypeThing(desc) + el.index)); } else { el.name_index = getUtf8Index(cp, newCp, utf8Map, openSlots, utf8(cp, el.name_index)); } @@ -1215,38 +1268,43 @@ public void run() { for (Input in : toRead) { futures.add( threadpool.submit(() -> { - ClassInfo ci = in.readSup.get(); - ConstantPool cp = ci.pool; - ConstantPoolRefCounter refs = new ConstantPoolRefCounter(cp); - ci.accept(refs); - DerefVisitor drefv = new DerefVisitor(cp, refs); - ci.accept(drefv); - // Build maps & freelist - Object2IntOpenHashMap utf8Map = new Object2IntOpenHashMap<>(drefv.utf8Size); - Object2IntOpenHashMap nameAndTypeMap = new Object2IntOpenHashMap<>(drefv.nameAndTypeSize); - IntArrayFIFOQueue openSlots = new IntArrayFIFOQueue(drefv.utf8Size + drefv.nameAndTypeSize); // TODO is this a reasonable sizing - for (int i = 1; i <= cp.size(); i++) { - if (refs.getRef(i) == 0) { - openSlots.enqueue(i); - } else { - ConstantPoolEntry e = cp.getEntry(i); - if (e instanceof ConstantUtf8) { - utf8Map.put(((ConstantUtf8)e).slice, i); - } else if (e instanceof ConstantNameAndType) { - ConstantNameAndType o = (ConstantNameAndType) e; - nameAndTypeMap.put(new NameDescPair(utf8(cp, o.name_index), utf8(cp, o.descriptor_index)), i); + try { + ClassInfo ci = in.readSup.get(); + ConstantPool cp = ci.pool; + ConstantPoolRefCounter refs = new ConstantPoolRefCounter(cp); + ci.accept(refs); + DerefVisitor drefv = new DerefVisitor(cp, refs); + ci.accept(drefv); + // Build maps & freelist + Object2IntOpenHashMap utf8Map = new Object2IntOpenHashMap<>(drefv.utf8Size); + Object2IntOpenHashMap nameAndTypeMap = new Object2IntOpenHashMap<>(drefv.nameAndTypeSize); + IntArrayFIFOQueue openSlots = new IntArrayFIFOQueue(drefv.utf8Size + drefv.nameAndTypeSize); // TODO is this a reasonable sizing + for (int i = 1; i <= cp.size(); i++) { + if (refs.getRef(i) == 0) { + openSlots.enqueue(i); + } else { + ConstantPoolEntry e = cp.getEntry(i); + if (e instanceof ConstantUtf8) { + utf8Map.put(((ConstantUtf8)e).slice, i); + } else if (e instanceof ConstantNameAndType) { + ConstantNameAndType o = (ConstantNameAndType) e; + nameAndTypeMap.put(new NameDescPair(utf8(cp, o.name_index), utf8(cp, o.descriptor_index)), i); + } } } + // Remap everything + ConstantPool newCp = cp.duplicate(); + RemapVisitor remapVisitor = new RemapVisitor(cp, newCp, mappings, utf8Map, nameAndTypeMap, openSlots, refs); + ci.accept(remapVisitor); + while (!openSlots.isEmpty()) { + newCp.setEntry(openSlots.dequeueInt(), new ConstantInteger(1337)); // B) + } + ci.pool = newCp; + output.outputClass(cls2Utf8(newCp, ci.this_class) + ".class", ci, in.tag); + } catch (Exception e) { + Logger.error("Error remapping {}", in.path); + throw e; } - // Remap everything - ConstantPool newCp = cp.duplicate(); - RemapVisitor remapVisitor = new RemapVisitor(cp, newCp, mappings, utf8Map, nameAndTypeMap, openSlots); - ci.accept(remapVisitor); - while (!openSlots.isEmpty()) { - newCp.setEntry(openSlots.dequeueInt(), new ConstantInteger(1337)); // B) - } - ci.pool = newCp; - output.outputClass(cls2Utf8(newCp, ci.this_class) + ".class", ci, in.tag); }) ); } @@ -1266,6 +1324,81 @@ public void run() { } } + static String getLvNameTypeThing(Mutf8Slice desc) { + if (desc == null) { + return ""; + } + ByteBuffer b = desc.b; + int start = b.position(); + int end = b.limit(); + int arraycnt = 0; + String typeStr = null; + loop: + for (int i = start; i < end; i++) { + byte character = b.get(i); + switch (character) { + case '[': + arraycnt += 1; + break; + case 'B': + typeStr = "Byte"; + break loop; + case 'C': + typeStr = "Char"; + break loop; + case 'D': + typeStr = "Double"; + break loop; + case 'F': + typeStr = "Float"; + break loop; + case 'I': + typeStr = "Int"; + break loop; + case 'J': + typeStr = "Long"; + break loop; + case 'S': + typeStr = "Short"; + break loop; + case 'Z': + typeStr = "Boolean"; + break loop; + case 'L': + int simpleClassStart = i + 1; + int classEnd = -1; + for (int j = i + 1; j < end; j++) { + byte c = b.get(j); + if (c == ';') { + classEnd = j; + break; + } else if (c == '/') { + simpleClassStart = j + 1; + } + } + String typeStr0 = new Mutf8Slice(ByteBufferUtil.slice(b, simpleClassStart, classEnd)).toString(); + StringBuilder sb = new StringBuilder(typeStr0.length()); + for (int j = 0; j < typeStr0.length(); j++) { + char c = typeStr0.charAt(j); + if (Character.isJavaIdentifierPart(c)) { + sb.append(c); + } + } + typeStr = sb.toString(); + break loop; + default: + throw new RuntimeException("Illegal desc: " + desc.toString() + " " + ((char)character)); + } + } + if (arraycnt == 0) { + return typeStr; + } else if (arraycnt == 1) { + return typeStr + "Array"; + } else { + return arraycnt + "D" + typeStr + "Array"; + } + } + static int getUtf8Index(ConstantPool cp, ConstantPool newCp, Object2IntOpenHashMap utf8Map, IntArrayFIFOQueue openSlots, Mutf8Slice utf8) { int index = utf8Map.getOrDefault(utf8, 0); if (index == 0) { diff --git a/recombobulator/src/test/java/io/github/coolcrabs/brachyura/recombobulator/remapper/InherTestTmp.java b/recombobulator/src/test/java/io/github/coolcrabs/brachyura/recombobulator/remapper/InherTestTmp.java deleted file mode 100644 index 79f39e5d..00000000 --- a/recombobulator/src/test/java/io/github/coolcrabs/brachyura/recombobulator/remapper/InherTestTmp.java +++ /dev/null @@ -1,96 +0,0 @@ -package io.github.coolcrabs.brachyura.recombobulator.remapper; - -import java.io.IOException; -import java.math.BigDecimal; -import java.nio.ByteBuffer; -import java.nio.file.FileSystem; -import java.nio.file.FileVisitResult; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.SimpleFileVisitor; -import java.nio.file.attribute.BasicFileAttributes; -import java.util.HashMap; -import java.util.Map; -import java.util.Map.Entry; -import java.util.function.Supplier; - -import org.junit.jupiter.api.Test; - -import io.github.coolcrabs.brachyura.recombobulator.ClassInfo; -import io.github.coolcrabs.brachyura.recombobulator.FileSystemUtil; -import io.github.coolcrabs.brachyura.recombobulator.Mutf8Slice; -import io.github.coolcrabs.brachyura.recombobulator.Obtainor; -import io.github.coolcrabs.brachyura.recombobulator.RecombobulatorOptions; -import io.github.coolcrabs.brachyura.recombobulator.remapper.InheritanceMap.InheritanceGroup; -import net.fabricmc.mappingio.MappingReader; -import net.fabricmc.mappingio.format.MappingFormat; -import net.fabricmc.mappingio.tree.MemoryMappingTree; - -public class InherTestTmp { - // @Test - // void e() throws IOException { - // int[] cnt = new int[1]; - // Map> classes = new HashMap<>(); - // try ( - // FileSystem fs = FileSystemUtil.newJarFileSystem(Obtainor.getMc()) - // ) { - // Files.walkFileTree(fs.getPath("/"), new SimpleFileVisitor(){ - // @Override - // public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { - // String fileString = file.toString(); - // RecombobulatorOptions options = new RecombobulatorOptions(); - // if (fileString.endsWith(".class")) { - // Mutf8Slice clsName = new Mutf8Slice(fileString.substring(1).replace(".class", "")); - // ClassInfo ci = new ClassInfo(ByteBuffer.wrap(Files.readAllBytes(file)), options); - // cnt[0] += ci.methods.size(); - // classes.put(clsName, () -> ci); - // } - // return FileVisitResult.CONTINUE; - // } - // }); - // } - // System.out.println(cnt[0]); - // long start = System.nanoTime(); - // InheritanceMap imap = new InheritanceMap(); - // imap.load(classes, true); - // long end = System.nanoTime(); - // System.out.println(new BigDecimal(end - start).divide(new BigDecimal(1000000000))); - // int i = 0; - // int wat = 0; - // long yeet0 = 0; - // long yeet1 = 0; - // for (Entry> a : imap.inheritanceMap.entrySet()) { - // for (Entry ig : a.getValue().entrySet()) { - // int j = 0; - // InheritanceGroup ig0 = ig.getValue(); - // while (ig0.down != null) { - // ++j; - // ig0 = ig0.down; - // } - // i = Math.max(i, j); - // // if (j > 1) { - // yeet0 += j; - // yeet1 += 1; - // // } - // if (j == 1702) { - // ++wat; - // System.out.println(ig.getValue().id); - // System.out.println(a.getKey()); - // System.out.println(ig.getKey()); - // // System.out.println(); - // } - // } - // } - // System.out.println(i); - // System.out.println(wat); - // System.out.println(yeet0 / (double) yeet1); - // Path inter = Obtainor.getInt(); - // MemoryMappingTree tree = new MemoryMappingTree(); - // MappingReader.read(inter, MappingFormat.TINY, tree); - // start = System.nanoTime(); - // MappingIoMappings m = new MappingIoMappings(tree, tree.getNamespaceId("official"), tree.getNamespaceId("intermediary"), imap); - // end = System.nanoTime(); - // System.out.println(new BigDecimal(end - start).divide(new BigDecimal(1000000000))); - // System.out.println(m.methodMap.size()); - // } -}