diff --git a/src/main/java/net/md_5/specialsource/JarMapping.java b/src/main/java/net/md_5/specialsource/JarMapping.java index f1f521e..3d9b43d 100644 --- a/src/main/java/net/md_5/specialsource/JarMapping.java +++ b/src/main/java/net/md_5/specialsource/JarMapping.java @@ -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 */ diff --git a/src/main/java/net/md_5/specialsource/SpecialSource.java b/src/main/java/net/md_5/specialsource/SpecialSource.java index 7bbe5f4..e71c75a 100644 --- a/src/main/java/net/md_5/specialsource/SpecialSource.java +++ b/src/main/java/net/md_5/specialsource/SpecialSource.java @@ -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 relocations = (List) options.valuesOf("in-shade-relocation"); + + inputTransformer = new ShadeRelocationSimulator(relocations); + } + + if (options.has("out-shade-relocation")) { + @SuppressWarnings("unchecked") + List relocations = (List) options.valuesOf("out-shade-relocation"); + + outputTransformer = new ShadeRelocationSimulator(relocations); + } + + boolean reverse = options.has("reverse"); + + // Load each mapping @SuppressWarnings("unchecked") - List specs = (List) options.valuesOf("srg-in"); + List filenames = (List) 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 relocations = (List) 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");