diff --git a/src/main/java/net/md_5/specialsource/JarRemapper.java b/src/main/java/net/md_5/specialsource/JarRemapper.java index 39fe399..fd0b63b 100644 --- a/src/main/java/net/md_5/specialsource/JarRemapper.java +++ b/src/main/java/net/md_5/specialsource/JarRemapper.java @@ -165,10 +165,14 @@ public class JarRemapper extends CustomRemapper { return mapped == null ? name : mapped; } + public void remapJar(Jar jar, File target) throws IOException { + remapJar(jar, target, Collections.EMPTY_SET); + } + /** * Remap all the classes in a jar, writing a new jar to the target */ - public void remapJar(Jar jar, File target) throws IOException { + public void remapJar(Jar jar, File target, Set includes) throws IOException { if (jar == null) { return; } @@ -185,7 +189,7 @@ public class JarRemapper extends CustomRemapper { try (InputStream is = jar.getResource(name)) { byte[] data; - if (name.endsWith(".class")) { + if (name.endsWith(".class") && shouldHandle(name, includes)) { // remap classes name = name.substring(0, name.length() - CLASS_LEN); @@ -224,6 +228,23 @@ public class JarRemapper extends CustomRemapper { } } + private static boolean shouldHandle(String name, Set includes) { + if (includes.isEmpty()) { + return true; + } + + for (String match : includes) { + if (match.equals(".") && !name.contains("/")) { + return true; + } + if (name.startsWith(match)) { + return true; + } + } + + return false; + } + /** * Remap an individual class given an InputStream to its bytecode */ diff --git a/src/main/java/net/md_5/specialsource/SpecialSource.java b/src/main/java/net/md_5/specialsource/SpecialSource.java index 4b2fe40..a951f05 100644 --- a/src/main/java/net/md_5/specialsource/SpecialSource.java +++ b/src/main/java/net/md_5/specialsource/SpecialSource.java @@ -34,6 +34,8 @@ import net.md_5.specialsource.provider.JointProvider; import net.md_5.specialsource.provider.JarProvider; import java.io.*; import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; import java.util.List; import com.google.common.collect.BiMap; import com.google.common.collect.HashBiMap; @@ -134,6 +136,10 @@ public class SpecialSource { acceptsAll(asList("e", "excluded-packages"), "A comma seperated list of packages that should not be transformed, even if the srg specifies they should") .withRequiredArg() .ofType(String.class); + + acceptsAll(asList("only"), "Process only the specified packages. Similar to --excluded-packages but applies at the processing rather than loading phase") + .withRequiredArg() + .ofType(String.class); } }; @@ -286,7 +292,7 @@ public class SpecialSource { log("Remapping final jar"); JarRemapper jarRemapper = new JarRemapper(null, jarMapping, accessMapper); - jarRemapper.remapJar(jar3, (File) options.valueOf("out-jar")); + jarRemapper.remapJar(jar3, (File) options.valueOf("out-jar"), new HashSet((Collection) options.valuesOf("only"))); }