Move loadMappings() dir/file logic to JarMapping
Instead of in the command-line interface.. this allows other code providing an interface to SpecialSource to easily pass user-supplied options for loading mappings.
This commit is contained in:
parent
91803d03ea
commit
a6e18b0665
@ -142,6 +142,47 @@ public class JarMapping {
|
|||||||
loadMappings(new BufferedReader(new FileReader(file)), null, null, false);
|
loadMappings(new BufferedReader(new FileReader(file)), null, null, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param filename A filename of a .srg/.csrg or an MCP directory of .srg+.csv, local or remote
|
||||||
|
* @param reverse Swap input and output mappings
|
||||||
|
* @param numeric When reading mapping directory, ignore .csv
|
||||||
|
* @param inShadeRelocation Apply relocation on mapping input
|
||||||
|
* @param outShadeRelocation Apply relocation on mapping output
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
public void loadMappings(String filename, boolean reverse, boolean numeric, String inShadeRelocation, String outShadeRelocation) throws IOException {
|
||||||
|
// Optional shade relocation, on input or output names
|
||||||
|
JarMappingLoadTransformer inputTransformer = null;
|
||||||
|
JarMappingLoadTransformer outputTransformer = null;
|
||||||
|
|
||||||
|
if (inShadeRelocation != null) {
|
||||||
|
inputTransformer = new ShadeRelocationSimulator(inShadeRelocation);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (outShadeRelocation != null) {
|
||||||
|
outputTransformer = new ShadeRelocationSimulator(outShadeRelocation);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (new File(filename).isDirectory() || filename.endsWith("/")) {
|
||||||
|
// Existing local dir or dir URL
|
||||||
|
|
||||||
|
if (inputTransformer != null || outputTransformer != null) {
|
||||||
|
throw new IllegalArgumentException("loadMappings("+filename+"): shade relocation not supported on directories"); // yet
|
||||||
|
}
|
||||||
|
|
||||||
|
loadMappingsDir(filename, reverse, numeric);
|
||||||
|
} else {
|
||||||
|
// File
|
||||||
|
|
||||||
|
if (numeric) {
|
||||||
|
throw new IllegalArgumentException("loadMappings("+filename+"): numeric only supported on directories, not files");
|
||||||
|
}
|
||||||
|
|
||||||
|
loadMappings(new BufferedReader(new FileReader(URLDownloader.getLocalFile(filename))), inputTransformer, outputTransformer, reverse);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load a mapping given a .csrg file
|
* Load a mapping given a .csrg file
|
||||||
*
|
*
|
||||||
|
@ -71,12 +71,10 @@ public class SpecialSource {
|
|||||||
acceptsAll(asList("n", "numeric-srg"), "Use numeric .srg mappings (not .csv) with srg-in dir");
|
acceptsAll(asList("n", "numeric-srg"), "Use numeric .srg mappings (not .csv) with srg-in dir");
|
||||||
|
|
||||||
acceptsAll(asList("R", "in-shade-relocation", "shade-relocation"), "Simulate maven-shade-plugin relocation patterns on srg-in input names")
|
acceptsAll(asList("R", "in-shade-relocation", "shade-relocation"), "Simulate maven-shade-plugin relocation patterns on srg-in input names")
|
||||||
.withRequiredArg()
|
.withRequiredArg();
|
||||||
.withValuesSeparatedBy(',');
|
|
||||||
|
|
||||||
acceptsAll(asList("out-shade-relocation"), "Simulate maven-shade-plugin relocation patterns on srg-in output names")
|
acceptsAll(asList("out-shade-relocation"), "Simulate maven-shade-plugin relocation patterns on srg-in output names")
|
||||||
.withRequiredArg()
|
.withRequiredArg();
|
||||||
.withValuesSeparatedBy(',');
|
|
||||||
|
|
||||||
acceptsAll(asList("r", "reverse"), "Reverse input/output names on srg-in");
|
acceptsAll(asList("r", "reverse"), "Reverse input/output names on srg-in");
|
||||||
|
|
||||||
@ -141,35 +139,17 @@ public class SpecialSource {
|
|||||||
|
|
||||||
jarMapping = new JarMapping();
|
jarMapping = new JarMapping();
|
||||||
|
|
||||||
// Optional shade relocation, on input or output names
|
// Loading options
|
||||||
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");
|
boolean reverse = options.has("reverse");
|
||||||
|
boolean numeric = options.has("numeric-srg");
|
||||||
|
String inShadeRelocation = (String) options.valueOf("in-shade-relocation");
|
||||||
|
String outShadeRelocation = (String) options.valueOf("out-shade-relocation");
|
||||||
|
|
||||||
// Load each mapping
|
// Load each mapping
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
List<String> filenames = (List<String>) options.valuesOf("srg-in");
|
List<String> filenames = (List<String>) options.valuesOf("srg-in");
|
||||||
for (String filename : filenames) {
|
for (String filename : filenames) {
|
||||||
if (new File(filename).isDirectory() || filename.endsWith("/")) { // existing local dir or dir URL
|
jarMapping.loadMappings(filename, reverse, numeric, inShadeRelocation, outShadeRelocation);
|
||||||
jarMapping.loadMappingsDir(filename, reverse, options.has("numeric-srg"));
|
|
||||||
} else {
|
|
||||||
jarMapping.loadMappings(new BufferedReader(new FileReader(URLDownloader.getLocalFile(filename))), inputTransformer, outputTransformer, reverse);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} 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");
|
||||||
|
Loading…
Reference in New Issue
Block a user