Add CLI alternate syntax for shade relocation
--srg-in ../jars/1.4.7/cb2pkgmcp.srg --shade-relocation net.minecraft.server=net.minecraft.server.v1_4_R1,org.bouncycastle=net.minecraft.v1_4_R1.org.bouncycastle --srg-in ../jars/1.4.7/cb2pkgmcp.srg@net.minecraft.server=net.minecraft.server.v1_4_R1,org.bouncycastle=net.minecraft.v1_4_R1.org.bouncycastle
This commit is contained in:
parent
5b02d05ed2
commit
2cb7a3c96d
@ -48,6 +48,7 @@ public class JarMapping {
|
|||||||
loadMappings(reader, shader);
|
loadMappings(reader, shader);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the inheritance map used for caching superclass/interfaces. This call be omitted to
|
* Set the inheritance map used for caching superclass/interfaces. This call be omitted to
|
||||||
* use a local cache, or set to your own global cache.
|
* use a local cache, or set to your own global cache.
|
||||||
@ -91,6 +92,30 @@ public class JarMapping {
|
|||||||
return mapped;
|
return mapped;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load mappings given a (path) specification, optionally relocated
|
||||||
|
* through a suffix @oldpath1=newpath1,oldpath2=newpath2...
|
||||||
|
*
|
||||||
|
* Intended for convenient command-line usage.
|
||||||
|
*/
|
||||||
|
public void loadMappings(String spec) throws IOException {
|
||||||
|
int n = spec.lastIndexOf('@');
|
||||||
|
String path;
|
||||||
|
ShadeRelocationSimulator shader;
|
||||||
|
|
||||||
|
if (n == -1) {
|
||||||
|
path = spec;
|
||||||
|
shader = null;
|
||||||
|
} else {
|
||||||
|
path = spec.substring(0, n);
|
||||||
|
shader = new ShadeRelocationSimulator(spec.substring(n + 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
BufferedReader reader = new BufferedReader(new FileReader(path));
|
||||||
|
|
||||||
|
loadMappings(reader, shader);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load a mapping given a .csrg file
|
* Load a mapping given a .csrg file
|
||||||
*
|
*
|
||||||
|
@ -28,10 +28,7 @@
|
|||||||
*/
|
*/
|
||||||
package net.md_5.specialsource;
|
package net.md_5.specialsource;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.*;
|
||||||
import java.util.LinkedHashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Simulate a small subset of the maven-shade-plugin class relocation
|
* Simulate a small subset of the maven-shade-plugin class relocation
|
||||||
@ -72,10 +69,15 @@ public class ShadeRelocationSimulator {
|
|||||||
String pattern = pair.substring(0, index);
|
String pattern = pair.substring(0, index);
|
||||||
String shadedPattern = pair.substring(index + 1);
|
String shadedPattern = pair.substring(index + 1);
|
||||||
|
|
||||||
|
System.out.println("reloc:"+pattern+" -> "+shadedPattern);
|
||||||
relocations.put(toInternalName(pattern), toInternalName(shadedPattern));
|
relocations.put(toInternalName(pattern), toInternalName(shadedPattern));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ShadeRelocationSimulator(String string) {
|
||||||
|
this(Arrays.asList(string.split(",")));
|
||||||
|
}
|
||||||
|
|
||||||
public String shadeClassName(String className) {
|
public String shadeClassName(String className) {
|
||||||
for (Map.Entry<String, String> entry : relocations.entrySet()) {
|
for (Map.Entry<String, String> entry : relocations.entrySet()) {
|
||||||
String pattern = entry.getKey();
|
String pattern = entry.getKey();
|
||||||
|
@ -33,6 +33,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import com.google.common.base.Joiner;
|
||||||
import com.google.common.collect.BiMap;
|
import com.google.common.collect.BiMap;
|
||||||
import com.google.common.collect.HashBiMap;
|
import com.google.common.collect.HashBiMap;
|
||||||
import joptsimple.OptionException;
|
import joptsimple.OptionException;
|
||||||
@ -68,7 +69,8 @@ public class SpecialSource {
|
|||||||
|
|
||||||
acceptsAll(asList("m", "srg-in"), "Mapping file input")
|
acceptsAll(asList("m", "srg-in"), "Mapping file input")
|
||||||
.withRequiredArg()
|
.withRequiredArg()
|
||||||
.ofType(File.class);
|
.describedAs("path[@relocations...]")
|
||||||
|
.ofType(String.class);
|
||||||
|
|
||||||
acceptsAll(asList("i", "in-jar"), "Input jar to remap")
|
acceptsAll(asList("i", "in-jar"), "Input jar to remap")
|
||||||
.withRequiredArg()
|
.withRequiredArg()
|
||||||
@ -131,20 +133,20 @@ public class SpecialSource {
|
|||||||
jarMapping = new JarMapping(visitor1, visitor2, (File) options.valueOf("srg-out"), options.has("compact"), options.has("generate-dupes"));
|
jarMapping = new JarMapping(visitor1, visitor2, (File) options.valueOf("srg-out"), options.has("compact"), options.has("generate-dupes"));
|
||||||
} else if (options.has("srg-in")) {
|
} else if (options.has("srg-in")) {
|
||||||
// Load mappings, possibly shaded
|
// Load mappings, possibly shaded
|
||||||
ShadeRelocationSimulator shadeRelocationSimulator = null;
|
String spec = (String) options.valueOf("srg-in");
|
||||||
|
|
||||||
if (options.has("shade-relocation")) {
|
if (options.has("shade-relocation")) {
|
||||||
|
// legacy command-line option support
|
||||||
|
// (new way is filename@... from the command-line, or loadMappings() programmatically)
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
List<String> relocations = (List<String>) options.valuesOf("shade-relocation");
|
List<String> relocations = (List<String>) options.valuesOf("shade-relocation");
|
||||||
shadeRelocationSimulator = new ShadeRelocationSimulator(relocations);
|
spec += "@" + Joiner.on(',').join(relocations);
|
||||||
|
|
||||||
for (Map.Entry<String, String> entry : shadeRelocationSimulator.relocations.entrySet()) {
|
|
||||||
log("Relocation: " + entry.getKey() + " -> " + entry.getValue());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
jarMapping = new JarMapping();
|
||||||
|
|
||||||
log("Loading mappings");
|
log("Loading mappings");
|
||||||
BufferedReader reader = new BufferedReader(new FileReader((File) options.valueOf("srg-in")));
|
jarMapping.loadMappings(spec);
|
||||||
jarMapping = new JarMapping(reader, shadeRelocationSimulator);
|
|
||||||
} else {
|
} else {
|
||||||
System.err.println("No mappings given, first-jar/second-jar or srg-in required");
|
System.err.println("No mappings given, first-jar/second-jar or srg-in required");
|
||||||
parser.printHelpOn(System.err);
|
parser.printHelpOn(System.err);
|
||||||
|
Loading…
Reference in New Issue
Block a user