Add reverse and output shade relocation flags

Removed the ^/@-style input specifications, in favor of
command-line options (which apply to all mappings loaded):

--in-shade-relocation: applies to srg-in input names
--out-shade-relocation: applies to srg-in output names
--reverse: reverses srg-in input/output names

Output shading relocation is useful if remapping through
--srg-in obf2cb.srg, and you want versioned names to match CB.
This commit is contained in:
Agaricus 2013-02-21 21:32:05 -08:00
parent 49e2b341c0
commit 16a1c725dc
2 changed files with 38 additions and 54 deletions

View File

@ -93,45 +93,6 @@ public class JarMapping {
return mapped;
}
/**
* Load mappings given a (path) specification, optionally:
* - reversed through a prefix '^'
* - relocated through a suffix '@oldpath1=newpath1,oldpath2=newpath2'...
*
* Intended for convenient command-line usage.
*/
public void loadMappings(String spec) throws IOException {
boolean reverse;
if (spec.startsWith("^")) {
reverse = true;
spec = spec.substring(1);
} else {
reverse = false;
}
if ((new File(spec)).isDirectory()) {
loadMappingsDir((new File(spec)), reverse);
return;
}
int n = spec.lastIndexOf('@');
String path;
JarMappingLoadTransformer inputTransformer;
if (n == -1) {
path = spec;
inputTransformer = null;
} else {
path = spec.substring(0, n);
inputTransformer = new ShadeRelocationSimulator(spec.substring(n + 1));
}
BufferedReader reader = new BufferedReader(new FileReader(path));
loadMappings(reader, inputTransformer, null, reverse);
}
/**
* Load mappings from an MCP directory
*/

View File

@ -69,9 +69,18 @@ public class SpecialSource {
acceptsAll(asList("m", "srg-in"), "Mapping file input")
.withRequiredArg()
.describedAs("path[@relocations...]")
.ofType(String.class);
acceptsAll(asList("R", "in-shade-relocation", "shade-relocation"), "Simulate maven-shade-plugin relocation patterns on srg-in input names")
.withRequiredArg()
.withValuesSeparatedBy(',');
acceptsAll(asList("out-shade-relocation"), "Simulate maven-shade-plugin relocation patterns on srg-in output names")
.withRequiredArg()
.withValuesSeparatedBy(',');
acceptsAll(asList("r", "reverse"), "Reverse input/output names on srg-in");
acceptsAll(asList("i", "in-jar"), "Input jar to remap")
.withRequiredArg()
.ofType(File.class);
@ -80,10 +89,6 @@ public class SpecialSource {
.withRequiredArg()
.ofType(File.class);
acceptsAll(asList("R", "shade-relocation"), "Simulate maven-shade-plugin relocation patterns on srg-in")
.withRequiredArg()
.withValuesSeparatedBy(',');
acceptsAll(asList("l", "live"), "Enable runtime inheritance lookup");
acceptsAll(asList("L", "live-remapped"), "Enable runtime inheritance lookup through a mapping");
@ -136,19 +141,37 @@ public class SpecialSource {
jarMapping = new JarMapping();
// Optional shade relocation, on input or output names
JarMappingLoadTransformer inputTransformer = null;
JarMappingLoadTransformer outputTransformer = null;
if (options.has("in-shade-relocation")) {
@SuppressWarnings("unchecked")
List<String> relocations = (List<String>) options.valuesOf("in-shade-relocation");
inputTransformer = new ShadeRelocationSimulator(relocations);
}
if (options.has("out-shade-relocation")) {
@SuppressWarnings("unchecked")
List<String> relocations = (List<String>) options.valuesOf("out-shade-relocation");
outputTransformer = new ShadeRelocationSimulator(relocations);
}
boolean reverse = options.has("reverse");
// Load each mapping
@SuppressWarnings("unchecked")
List<String> specs = (List<String>) options.valuesOf("srg-in");
List<String> filenames = (List<String>) options.valuesOf("srg-in");
for (String filename : filenames) {
File file = new File(filename);
for (String spec : specs) {
if (options.has("shade-relocation")) {
// legacy command-line option support
// (new way is filename@... from the command-line, or loadMappings() programmatically)
@SuppressWarnings("unchecked")
List<String> relocations = (List<String>) options.valuesOf("shade-relocation");
spec += "@" + Joiner.on(',').join(relocations);
if (file.isDirectory()) {
jarMapping.loadMappingsDir(file, reverse);
} else {
jarMapping.loadMappings(new BufferedReader(new FileReader(file)), inputTransformer, outputTransformer, reverse);
}
jarMapping.loadMappings(spec);
}
} else {
System.err.println("No mappings given, first-jar/second-jar or srg-in required");