From 8ee18916f15d1b2babe1063a4a1f00337a39a915 Mon Sep 17 00:00:00 2001 From: Agaricus Date: Tue, 29 Jan 2013 20:56:44 -0800 Subject: [PATCH] Add remapped inheritance map file reading The inheritance map, as generated with --write-inheritance/-H, can now be read using --read-inheritance/-H. It will be remapped through the currently loaded inverse mapping before supplying the inheritance provider. Example usage: java -cp target/SpecialSource-1.3-SNAPSHOT-shaded.jar net.md_5.specialsource.SpecialSource --shade-relocation net.minecraft.server=net.minecraft.server.v1_4_R1 --shade-relocation org.bouncycastle=net.minecraft.v1_4_R1.org.bouncycastle --srg-in ../jars/1.4.7/cb2obf.csrg --in-jar ../IncompatiblePlugin/target/bukkit-sample-plugin-0.5.jar --out-jar /tmp/sp/out.jar -h /tmp/h where the inheritance map was previously generated using: java -cp target/SpecialSource-1.3-SNAPSHOT-shaded.jar:mcpc-plus-1.4.7-R0.2-SNAPSHOT.jar net.md_5.specialsource.SpecialSource --srg-in ~/minecraft/1.4.x/jars/1.4.7/cb2obf.csrg --live --write-inheritance /tmp/h --- .../md_5/specialsource/InheritanceMap.java | 36 ++++++++++++------- .../net/md_5/specialsource/SpecialSource.java | 8 +++-- 2 files changed, 29 insertions(+), 15 deletions(-) diff --git a/src/main/java/net/md_5/specialsource/InheritanceMap.java b/src/main/java/net/md_5/specialsource/InheritanceMap.java index 0ef1f22..a8fe0f0 100644 --- a/src/main/java/net/md_5/specialsource/InheritanceMap.java +++ b/src/main/java/net/md_5/specialsource/InheritanceMap.java @@ -29,6 +29,7 @@ package net.md_5.specialsource; import com.google.common.base.Joiner; +import com.google.common.collect.BiMap; import java.io.BufferedReader; import java.io.File; @@ -40,14 +41,6 @@ public class InheritanceMap implements IInheritanceProvider { public final Map> inheritanceMap = new HashMap>(); - public InheritanceMap() { - - } - - public InheritanceMap(BufferedReader bufferedReader) throws IOException { - load(bufferedReader); - } - /** * Generate an inheritance map for the given classes */ @@ -102,20 +95,39 @@ public class InheritanceMap implements IInheritanceProvider { } } - public void load(BufferedReader reader) throws IOException { + public void load(BufferedReader reader, BiMap classMap) throws IOException { String line; while ((line = reader.readLine()) != null) { String[] tokens = line.split(" "); if (tokens.length < 2) { - continue; + throw new IOException("Invalid inheritance map file line: " + line); } String className = tokens[0]; - List parents = Arrays.asList(tokens).subList(1, tokens.length - 1); + List parents = Arrays.asList(tokens).subList(1, tokens.length); - inheritanceMap.put(className, new ArrayList(parents)); + if (classMap == null) { + inheritanceMap.put(className, new ArrayList(parents)); + } else { + String remappedClassName = JarRemapper.mapTypeName(className, /*packageMap*/null, classMap, /*defaultIfUnmapped*/null); + if (remappedClassName == null) { + throw new IOException("Inheritance map input class not remapped: " + className); + } + + ArrayList remappedParents = new ArrayList(); + for (String parent : parents) { + String remappedParent = JarRemapper.mapTypeName(parent, /*packageMap*/null, classMap, /*defaultIfUnmapped*/null); + if (remappedParent == null) { + throw new IOException("Inheritance map parent class not remapped: " + parent); + } + + remappedParents.add(remappedParent); + } + + inheritanceMap.put(remappedClassName, remappedParents); + } } } diff --git a/src/main/java/net/md_5/specialsource/SpecialSource.java b/src/main/java/net/md_5/specialsource/SpecialSource.java index 88cb6b4..1df4fee 100644 --- a/src/main/java/net/md_5/specialsource/SpecialSource.java +++ b/src/main/java/net/md_5/specialsource/SpecialSource.java @@ -33,6 +33,8 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; +import com.google.common.collect.BiMap; +import com.google.common.collect.HashBiMap; import joptsimple.OptionException; import joptsimple.OptionParser; import joptsimple.OptionSet; @@ -162,7 +164,9 @@ public class SpecialSource { InheritanceMap inheritanceMap = new InheritanceMap(); BufferedReader reader = new BufferedReader(new FileReader((File) options.valueOf("read-inheritance"))); - inheritanceMap.load(reader); + + BiMap inverseClassMap = HashBiMap.create(jarMapping.classes).inverse(); + inheritanceMap.load(reader, inverseClassMap); log("Loaded inheritance map for "+inheritanceMap.inheritanceMap.size()+" classes"); inheritanceProviders.add(inheritanceMap); @@ -181,8 +185,6 @@ public class SpecialSource { inheritanceProviders.add(new JarInheritanceProvider(jar3)); - - JarRemapper jarRemapper = new JarRemapper(jarMapping, inheritanceProviders); jarRemapper.remapJar(jar3, (File) options.valueOf("out-jar")); }