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
This commit is contained in:
Agaricus 2013-01-29 20:56:44 -08:00
parent 4725e6d913
commit 8ee18916f1
2 changed files with 29 additions and 15 deletions

View File

@ -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<String, ArrayList<String>> inheritanceMap = new HashMap<String, ArrayList<String>>();
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<String, String> 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<String> parents = Arrays.asList(tokens).subList(1, tokens.length - 1);
List<String> parents = Arrays.asList(tokens).subList(1, tokens.length);
if (classMap == null) {
inheritanceMap.put(className, new ArrayList<String>(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<String> remappedParents = new ArrayList<String>();
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);
}
}
}

View File

@ -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<String, String> 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"));
}