Add support for packages.csv mappings

If packages.csv is found in a mapping directory, the
classes in .srg will be mapped through it. This is an
alternative to reading packages.srg, which isn't present
in the FML distribution (only joined.srg+packages.csv).
This commit is contained in:
Agaricus 2013-02-27 13:35:32 -08:00
parent ea80a4eb91
commit 888aecfe22
2 changed files with 53 additions and 11 deletions

View File

@ -42,15 +42,34 @@ import java.util.Map;
*/ */
public class CSVMappingTransformer extends JarMappingLoadTransformer { public class CSVMappingTransformer extends JarMappingLoadTransformer {
private final Map<String, String> fieldMap; private final Map<String, String> fieldMap; // numeric srg name field_### -> descriptive csv name
private final Map<String, String> methodMap; private final Map<String, String> methodMap; // numeric srg name func_### -> descriptive csv name
private final Map<String, String> classPackageMap; // class src name -> repackaged full class name
public CSVMappingTransformer(File fieldsCsv, File methodsCsv) throws IOException { public CSVMappingTransformer(File fieldsCsv, File methodsCsv, File packagesCsv) throws IOException {
fieldMap = new HashMap<String, String>(); fieldMap = new HashMap<String, String>();
methodMap = new HashMap<String, String>(); methodMap = new HashMap<String, String>();
readIntoMap(fieldsCsv, fieldMap); readIntoMap(fieldsCsv, fieldMap);
readIntoMap(methodsCsv, methodMap); readIntoMap(methodsCsv, methodMap);
if (packagesCsv.exists()) {
// repackaged (FML)
classPackageMap = new HashMap<String, String>();
Map<String, String> packages = new HashMap<String, String>();
readIntoMap(packagesCsv, packages);
for (Map.Entry<String, String> entry : packages.entrySet()) {
String classSimpleName = entry.getKey();
String newPackageName = entry.getValue();
classPackageMap.put("net/minecraft/src/" + classSimpleName, newPackageName + "/" + classSimpleName);
}
} else {
// flat package (vanilla MCP)
classPackageMap = null;
}
} }
private void readIntoMap(File file, Map<String, String> map) throws IOException { private void readIntoMap(File file, Map<String, String> map) throws IOException {
@ -62,16 +81,14 @@ public class CSVMappingTransformer extends JarMappingLoadTransformer {
continue; continue;
} }
if (line.length < 4) { if (line.length < 2) {
throw new IllegalArgumentException("Invalid csv line: " + line); throw new IllegalArgumentException("Invalid csv line: " + line);
} }
String numericName = line[0]; String key = line[0];
String descriptiveName = line[1]; String value = line[1];
//String side = line[2];
//String javadoc = line[3];
map.put(numericName, descriptiveName); map.put(key, value);
} }
} }
@ -84,4 +101,28 @@ public class CSVMappingTransformer extends JarMappingLoadTransformer {
public String transformMethodName(String methodName) { public String transformMethodName(String methodName) {
return methodMap.get(methodName); return methodMap.get(methodName);
} }
@Override
public String transformClassName(String className) {
if (classPackageMap == null) {
return className;
}
String newPackage = classPackageMap.get(className);
if (newPackage == null) {
return className;
}
return JarRemapper.mapTypeName(className, null, classPackageMap, className);
}
@Override
public String transformMethodDescriptor(String oldDescriptor) {
if (classPackageMap == null) {
return oldDescriptor;
}
MethodDescriptorTransformer methodDescriptorTransformer = new MethodDescriptorTransformer(null, classPackageMap);
return methodDescriptorTransformer.transform(oldDescriptor);
}
} }

View File

@ -126,14 +126,15 @@ public class JarMapping {
// Read output names through csv mappings, if available // Read output names through csv mappings, if available
File fieldsCsv = new File(dir.getPath() + sep + "fields.csv"); File fieldsCsv = new File(dir.getPath() + sep + "fields.csv");
File methodsCsv = new File(dir.getPath() + sep + "methods.csv"); File methodsCsv = new File(dir.getPath() + sep + "methods.csv");
File packagesCsv = new File(dir.getPath() + sep + "packages.csv"); // FML repackaging, optional
CSVMappingTransformer outputTransformer; CSVMappingTransformer outputTransformer;
if (fieldsCsv.exists() && methodsCsv.exists()) { if (fieldsCsv.exists() && methodsCsv.exists()) {
// they want descriptive "csv" names // they want descriptive "csv" names
outputTransformer = new CSVMappingTransformer(fieldsCsv, methodsCsv); outputTransformer = new CSVMappingTransformer(fieldsCsv, methodsCsv, packagesCsv);
} else { } else {
// they want numeric "srg" names, for some reason // they want numeric "srg" names, for some reason (TODO: option to override)
outputTransformer = null; outputTransformer = null;
} }